38 #ifndef included_time_h
39 #define included_time_h
79 #if defined(__x86_64__) || defined(i386)
84 asm volatile (
"rdtsc":
"=a" (
a),
"=d" (d));
88 #elif defined (__powerpc64__)
94 asm volatile (
"mftb %0":
"=r" (t));
98 #elif defined (__SPU__)
104 return spu_rdch (0x8);
110 #elif defined (__powerpc__)
120 "cmpw %[hi1],%[hi2]\n"
121 "bne 1b\n":[hi1]
"=r" (hi1),[hi2]
"=r" (hi2),[
lo]
"=r" (
lo));
125 #elif defined (__aarch64__)
131 asm volatile (
"mrs %0, cntvct_el0":
"=r" (vct));
135 #elif defined (__arm__)
136 #if defined(__ARM_ARCH_8A__)
141 asm volatile (
"mrrc p15, 0, %Q0, %R0, c9":
"=r" (tsc));
144 #elif defined(__ARM_ARCH_7A__)
149 asm volatile (
"mrc p15, 0, %0, c9, c13, 0":
"=r" (tsc));
157 asm volatile (
"mrc p15, 0, %[lo], c15, c12, 1":[
lo]
"=r" (
lo));
162 #elif defined (__xtensa__)
171 #elif defined (__TMS320C6X__)
178 asm volatile (
" dint\n"
180 " mvc .s2 TSCH,%1\n" " rint\n":
"=b" (l),
"=b" (
h));
182 return ((
u64)
h << 32) | l;
185 #elif defined(_mips) && __mips == 64
191 asm volatile (
"rdhwr %0,$31\n":
"=r" (result));
196 #error "don't know how to read CPU time stamp"
206 #define CLIB_US_TIME_PERIOD (1e-6)
207 #define CLIB_US_TIME_FREQ (1.0/CLIB_US_TIME_PERIOD)
212 u64 l =
c->last_cpu_time;
213 u64 t =
c->total_cpu_time;
216 c->total_cpu_time = t;
217 c->last_cpu_time = n;
218 rv = t *
c->seconds_per_clock;
221 c->last_verify_cpu_time) >>
c->log2_clocks_per_frequency_verify))
227 #define CLIB_TIME_MAX (1.7976931348623157e+308)
248 #include <sys/time.h>
249 #include <sys/resource.h>
251 #include <sys/syscall.h>
259 clock_gettime (CLOCK_REALTIME, &ts);
263 syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts);
265 return ts.tv_sec + 1e-9 * ts.tv_nsec;
274 clock_gettime (CLOCK_REALTIME, &ts);
276 syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts);
278 return 1e9 * ts.tv_sec + ts.tv_nsec;
286 clock_gettime (CLOCK_REALTIME, &ts);
288 syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts);
298 getrusage (RUSAGE_SELF, &u);
299 return u.ru_utime.tv_sec + 1e-6 * u.ru_utime.tv_usec
300 + u.ru_stime.tv_sec + 1e-6 * u.ru_stime.tv_usec;
306 struct timespec ts, tsrem;
308 ts.tv_nsec = 1e9 * (dt - (
f64) ts.tv_sec);
310 while (nanosleep (&ts, &tsrem) < 0)