From: "W. Wesley Groleau (Wes)" <wwgrol@PSESERV3.FW.HAC.COM>
Subject: Ada.Real_Time alternative
Date: 1996/12/16
Date: 1996-12-16T00:00:00+00:00 [thread overview]
Message-ID: <9612162228.AA19154@most> (raw)
/*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
* 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 <errno.h>
#include <time.h>
#include <sys/times.h>
/* 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
*/
reply other threads:[~1996-12-16 0:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox