34 #ifndef GRPC_CORE_SUPPORT_TIME_PRECISE_H_
35 #define GRPC_CORE_SUPPORT_TIME_PRECISE_H_
41 #ifdef GRPC_TIMERS_RDTSC
43 static void gpr_get_cycle_counter(
long long int *clk) {
45 __asm__
volatile(
"rdtsc" :
"=A"(ret));
50 #elif defined(__x86_64__) || defined(__amd64__)
51 static void gpr_get_cycle_counter(
long long int *clk) {
52 unsigned long long low, high;
53 __asm__
volatile(
"rdtsc" :
"=a"(low),
"=d"(high));
54 *clk = (high << 32) | low;
59 static long long cycles_per_second = 0;
60 static void gpr_precise_clock_init() {
61 time_t start = time(NULL);
62 gpr_precise_clock start_cycle;
63 gpr_precise_clock end_cycle;
64 while (time(NULL) == start)
66 gpr_get_cycle_counter(&start_cycle);
67 while (time(NULL) == start + 1)
69 gpr_get_cycle_counter(&end_cycle);
70 cycles_per_second = end_cycle - start_cycle;
73 static double grpc_precise_clock_scaling_factor() {
75 return 1e6 / cycles_per_second;
79 long long int counter;
80 gpr_get_cycle_counter(&counter);
82 clk->
tv_sec = counter / cycles_per_second;
83 clk->
tv_nsec = counter % cycles_per_second;
time_t tv_sec
Definition: time.h:64
void gpr_once_init(gpr_once *once, void(*init_routine)(void))
gpr_clock_type clock_type
Against which clock was this time measured? (or GPR_TIMESPAN if this is a relative time meaure) ...
Definition: time.h:68
pthread_once_t gpr_once
Definition: sync_posix.h:43
int tv_nsec
Definition: time.h:65
#define GPR_ONCE_INIT
Definition: sync_posix.h:45
gpr_timespec gpr_now(gpr_clock_type clock)