Oasis3 4.0.2
nsclock.c
Go to the documentation of this file.
00001 #ifndef key_noIO
00002 
00003 #include <stdio.h>
00004 #include <time.h>
00005 
00006 #ifdef __sgi
00007 
00008 long delta_t=0;         // clock resolution in nanoseconds
00009 
00010 long sgi_ticks_per_sec_() { // returns inverse clock resolution (1/sec)
00011   struct timespec t;
00012   clock_getres( CLOCK_SGI_CYCLE, &t );
00013   delta_t = (long)t.tv_sec*1000000000 + (long)t.tv_nsec;
00014   return 1000000000/delta_t;
00015 }
00016 
00017 long sgi_tick_() {      // returns current time in units of delta_t
00018   struct timespec t;
00019   if( delta_t==0 ) (void) sgi_ticks_per_sec_(); // initialize delta_t if needed
00020   clock_gettime( CLOCK_SGI_CYCLE, &t );
00021   return ( (long)t.tv_sec*1000000000+(long)t.tv_nsec )/delta_t;
00022 }
00023 
00024 long sgi_max_tick_() {      // clock rollover point is 2^max_tick
00025 #include <sys/syssgi.h>
00026   return syssgi(SGI_CYCLECNTR_SIZE);
00027 }
00028 #endif
00029 
00030 #ifdef test_nsclock
00031 void main() {
00032 #ifdef __sgi
00033   printf( "ticks per second=%li\n", sgi_ticks_per_sec_() );
00034   printf( "delta_t=%li\n", delta_t );
00035   printf( "max tick=%li\n", sgi_max_tick_() );
00036 #else
00037   printf( "ticks per second=%i\n", CLOCKS_PER_SEC );
00038 #endif
00039 }
00040 #endif
00041 
00042 #endif
 All Data Structures Namespaces Files Functions Variables Defines