Title: | DEC Ada |
Notice: | Ada is no longer a trademark of the US Government |
Moderator: | KMOOSE::CMCCUTCHEON |
Created: | Mon Jan 27 1986 |
Last Modified: | Fri Jun 06 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 3874 |
Total number of notes: | 16668 |
We have a customer using ADA 3.3 on UNIX 4.0b they need a real-time clock with a resolution of 1 microsecond. They recompiled their kernel with MICRO_TIME and can get this resolution using a simple C program (noted below), but in ADA using the Calendar package they can only get around 60 microseconds resolution. Any ideas? Pat CSC Atlanta -------------------------- ADA program. with Text_IO; use Text_IO; with Calendar; use Calendar; procedure Test is package Dur_IO is new Fixed_IO(Standard.Duration); count : NATURAL := 50; count_arr : ARRAY (1..count) OF Calendar.Time; begin for idx in 1..count loop count_arr(idx) := Calendar.Clock; end loop; for idx in 1..count loop Put("Time: "); Dur_IO.Put(Calendar.Seconds(count_arr(idx)), Fore => 10, Aft => 12); New_Line; end loop; end Test; ---------------------- C program: #include <sys/timers.h> #define LOOPCNT 5 int dummy() {} main () { int i; struct timespec dummyspec[LOOPCNT]; for (i=0; i < LOOPCNT; i++) { dummyspec[i].tv_sec = dummyspec[i].tv_nsec = 0L; } printf("Starting ...\n"); for (i=0; i < LOOPCNT; i++) { getclock(TIMEOFDAY, &dummyspec[i]); } printf("... done!\n"); for (i=0; i < LOOPCNT; i++) { printf("%2d :-> %ld Sec %ld nS \n", i, dummyspec[i].tv_sec, dummyspec[i].tv_nsec); } }
T.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
3874.1 | the problem is fixed point types | FLOYD::YODER | It's 999,943 to 1 but it just might work | Mon Jun 02 1997 13:25 | 20 |
In fact, the Time type used in Calendar does have an accuracy of 1 microsecond if the kernel has been changed; Calendar uses the same data structures as the C routines internally, and calls the C runtimes using pragma Interface(C,...). The problem is that Duration'Small is about 64 microseconds, which means that any conversion to a Duration will destroy accuracy. This in turn is because DEC Ada only supports 32-bit fixed point types. However, you're no worse off in Ada than you are in C, which doesn't support longer fixed point types either. :-) You can yourself use pragma Interface(C, ...) to call the C runtimes. Just find CALENDAR.ADA in the sources for PAL (the Predefined Ada Library) and write something similar to the CLOCK function there. I'd suggest imitating the Ada.Real_Time package of Ada95, which was devised to meet the needs of real-time programmers; the customer could write the routines as they became needed. A crude alternative to this is to use, say, Unchecked_Conversion on items of type Calendar.Time to convert them to a datatype that exposes the internal details (the datatype can be lifted from CALENDAR.ADA). If anything is unclear about the above, I'll be happy to explain further. |