28 #include <graphlab/parallel/pthread_tools.hpp>
29 #include <graphlab/util/timer.hpp>
36 void alarm_wakeup(
int i);
39 class hundredms_timer {
43 tout_val.it_interval.tv_sec = 0;
44 tout_val.it_interval.tv_usec = 0;
45 tout_val.it_value.tv_sec = 0;
46 tout_val.it_value.tv_usec = 50000;
47 signal(SIGALRM,alarm_wakeup);
48 setitimer(ITIMER_REAL, &tout_val,0);
53 struct itimerval tout_val;
58 signal(SIGALRM, SIG_IGN);
62 hundredms_timer hmstimer;
65 void alarm_wakeup(
int i) {
66 if (hmstimer.stop)
return;
67 signal(SIGALRM,alarm_wakeup);
69 double realtime = hmstimer.ti.current_time() ;
71 hmstimer.ctr = (size_t)(realtime * 10);
72 setitimer(ITIMER_REAL, &(hmstimer.tout_val), 0);
79 return float(hmstimer.ctr) / 10;
86 return hmstimer.ctr * 100;
91 struct timespec timeout;
92 timeout.tv_sec = sleeplen;
94 while (nanosleep(&timeout, &timeout) == -1);
102 struct timespec timeout;
103 timeout.tv_sec = sleeplen / 1000;
104 timeout.tv_nsec = (sleeplen % 1000) * 1000000;
105 while (nanosleep(&timeout, &timeout) == -1);
111 static unsigned long long rtdsc_ticks_per_sec = 0;
112 static mutex rtdsc_ticks_per_sec_mutex;
114 unsigned long long estimate_ticks_per_second() {
115 if (rtdsc_ticks_per_sec == 0) {
116 rtdsc_ticks_per_sec_mutex.
lock();
117 if (rtdsc_ticks_per_sec == 0) {
118 unsigned long long tstart = rdtsc();
120 unsigned long long tend = rdtsc();
121 rtdsc_ticks_per_sec = tend - tstart;
123 rtdsc_ticks_per_sec_mutex.
unlock();
125 return rtdsc_ticks_per_sec;