00001 #ifndef CLASSLIB_TIME_INFO_H 00002 # define CLASSLIB_TIME_INFO_H 00003 00004 //<<<<<< INCLUDES >>>>>> 00005 00006 # include "classlib/utils/IntBits.h" 00007 00008 namespace lat { 00009 //<<<<<< PUBLIC DEFINES >>>>>> 00010 //<<<<<< PUBLIC CONSTANTS >>>>>> 00011 //<<<<<< PUBLIC TYPES >>>>>> 00012 //<<<<<< PUBLIC VARIABLES >>>>>> 00013 //<<<<<< PUBLIC FUNCTIONS >>>>>> 00014 //<<<<<< CLASS DECLARATIONS >>>>>> 00015 00057 class TimeInfo 00058 { 00059 public: 00060 // FIXME: feature bits for...? 00061 // - whether real cycles are exact or derived 00062 // - whether real nsecs are exact or derived 00063 // - whether real nsecs were derived from cycles and mhz 00064 // - whether real cycles were derived from nsecs and mhz 00065 // - (the above four for virtual) 00066 // - whether virtual nsecs were derived from process times 00067 // - real/virtual resolution 00068 // - sleep resolution 00069 00073 static const int FEATURE_EXACT_MHZ = 1; 00074 00077 static const int FEATURE_TIME_EPOCH = 2; 00078 00081 static const int FEATURE_REAL_COUNT_EPOCH = 4; 00082 00086 static const int FEATURE_PROCESS_TIMES = 16; 00087 00089 typedef double NanoSecs; 00090 00092 typedef IntBits<64>::SLeast NanoTicks; 00093 00094 static void init (void); 00095 static double mhz (void); 00096 static double ghz (void); 00097 static unsigned features (); 00098 00099 static NanoSecs realNsecs (void); 00100 static NanoTicks realCycles (void); 00101 static NanoSecs virtualNsecs (void); 00102 static NanoTicks virtualCycles (void); 00103 00104 // FIXME: Wall clock/real time support? This really is #Time. 00105 // Would be neat however if we can find out accurate process 00106 // start-up time. Do we need more than just processTimes()? 00107 // 00108 // POSIX systems with clock_gettime() may provide CLOCK_REALTIME 00109 // (= wall), CLOCK_MONOTONIC (= real), CLOCK_PROCESS_CPUTIME_ID (= 00110 // virtual) and CLOCK_THREAD_CPUTIME_ID (= virtual thread-specific) 00111 // -- check. 00112 00113 // FIXME: Provide estimate of clock read overhead? 00114 00115 // high-res monotonic process time consumption 00116 static void processTimes (NanoSecs &user, NanoSecs &system, 00117 NanoSecs &real); 00118 static NanoSecs processUserTime (void); 00119 static NanoSecs processSystemTime (void); 00120 static NanoSecs processCpuTime (void); 00121 static NanoSecs processIdleTime (void); 00122 static NanoSecs processRealTime (void); 00123 00124 // high-res system timer; not (necessarily) anchored to process 00125 // time but guaranteed to be monotonic; usually measures system 00126 // time since boot or something like that. 00127 static NanoSecs time (void); 00128 static NanoSecs elapsedTime (void); 00129 static NanoSecs resolution (void); 00130 00131 // high-res napping 00132 static void sleep (NanoSecs secs); 00133 static void msleep (NanoSecs msecs); 00134 static void usleep (NanoSecs usecs); 00135 static void nanosleep (NanoSecs nanosecs); 00136 00137 private: 00138 static void spin (NanoSecs duration, NanoTicks &low, NanoTicks &high); 00139 00140 static bool s_initialised; 00141 static unsigned s_features; 00142 static double s_ghz; 00143 static double s_hiResFactor; 00144 static NanoSecs s_clockBase; 00145 }; 00146 00147 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> 00148 00149 } // namespace lat 00150 #endif // CLASSLIB_TIME_INFO_H