From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4f78aec7fc874c6,start X-Google-Attributes: gid103376,public From: "W. Wesley Groleau (Wes)" Subject: Ada.Real_Time alternative Date: 1996/12/16 Message-ID: <9612162228.AA19154@most> X-Deja-AN: 204652613 sender: Ada programming language comments: Gated by NETNEWS@AUVM.AMERICAN.EDU mailer: Elm [revision: 70.85] newsgroups: comp.lang.ada Date: 1996-12-16T00:00:00+00:00 List-Id: /*------------------------------------------------------------------------- *------------------------------------------------------------------------- * C : Ada_Real_Time_Support.c *------------------------------------------------------------------------- *------------------------------------------------------------------------- *---------------------------CONTROL INFORMATION--------------------------- * Hughes Defense Communications * Fort Wayne, Indiana * * Project name: AFATDS * Contract Number: DAAB07-90-C-E708 * CSCI: Reuse * CSC: Ada 95 Emulation * Unit: Ada.Real_Time * * Control Number: * Creation Date: 13 Dec 1996 * Designer: Wes Groleau * Programmer: Wes Groleau * * Language: C * * Host Environment: HP UX 9.x on PA RISC * HP UX 9.x on 680x0 * Solaris on Sparc * SCO Unix on Pentium * * Host Translator: default 'cc' from O.S. vendor * gcc 2.4.5 or 2.7.2 (depending on machine) * * Change History: * Revision Date Author Description of Change * * Description: This file provides a way to measure elapsed time * that is NOT affected by any priviliged process * calling date(1), settimeofday(2), stime(2), or * any other method for setting "wall" clock time. * This code will work with no changes on all the * listed systems. By using the tick value to * interpret the output of the clock, the calling * code can be made portable as well. * CLK_TCK is 50 on HP UX/680x0; 100 on the others. * Maximum error in seconds is 1/CLK_TCK. * With CLK_TCK 100, range is over 248.5 days. * With CLK_TCK 50, range is twice that. * Calling code can extend the range by detecting * by detecting wrap-around and applying a correction. * * OTHER DETAILS HAVE BEEN PROVIDED IN A MESSAGE TO * THE chat@gnat.com MAILING LIST AND TO comp.lang.ada * PLEASE READ THAT MESSAGE FOR MORE DETAILS. */ #include #include #include /* documentation is the man page for times(2) */ long Ada_Real_Time_Tick() { return CLK_TCK; } long Ada_Real_Time_Clock() { struct tms Dummy; return times(&Dummy); } main() /* this is just the test driver. test commands: * a.out; sleep 20; a.out * do twice--second time, change system "wall" clock during sleep. * verify that difference between "seconds" is reasonably close * to elapsed time on first run, and is not affected by time change * on second run. * repeat with much longer sleep to verify that imprecision * is due only to overhead of other commands, i.e., amount of * error is nearly constant, not affected by length of delay. * also compare 'uptime' with 'seconds' - should match */ { printf ("RTC: %dl\n", Ada_Real_Time_Clock() ); printf ("errno: %d\n", errno ); /* just checking :-) */ printf ("Tick: %dl\n", Ada_Real_Time_Tick() ); printf ("Seconds: %20.6f\n", (float) Ada_Real_Time_Clock() / (float) Ada_Real_Time_Tick() ); } /* Test Results * * Platform Compiler sleep measured time * normal w/ clock change * * 680x0 cc 20 20.560000 * 680x0 cc 3600 3600.860000 * 680x0 gcc 20 20.437000 * RISC cc 20 20.030000 20.030000 * RISC cc 20 20.890000 * RISC cc 1634* 1594.470000* * RISC gcc 20 20.030273 20.029296 * RISC gcc 20 20.040273 * Sparc gcc 20 20.000000 * Sparc gcc 100 100.250000 * Pentium cc 20 20.260000 * * * the starred measurements were obtained by 'a.out; date' * executed twice--'sleep' was not used, and the "wall" clock * was not changed. * * "seconds" is time since startup? * 680x0 (pseserv3) very close/9 days * RISC uptime 5:12 (h:mm); no measurable error * Sparc lost ~3 min./44 days * Pentium / SCO NO - up 5 days 3:37, times gave about 6 days */