12 static int clock_gettime_works = 0;
17 #define HASH_SIZE (1 << HASH_BITS)
19 static struct list_head hash[HASH_SIZE];
20 static int gtod_inited;
23 struct list_head list;
28 static struct gtod_log *find_hash(void *caller)
30 unsigned long h = hash_ptr(caller, HASH_BITS);
31 struct list_head *entry;
33 list_for_each(entry, &hash[h]) {
34 struct gtod_log *log = list_entry(entry, struct gtod_log, list);
36 if (log->caller == caller)
43 static struct gtod_log *find_log(void *caller)
45 struct gtod_log *log = find_hash(caller);
50 log = malloc(sizeof(*log));
51 INIT_LIST_HEAD(&log->list);
55 h = hash_ptr(caller, HASH_BITS);
56 list_add_tail(&log->list, &hash[h]);
62 static void gtod_log_caller(void *caller)
65 struct gtod_log *log = find_log(caller);
71 static void fio_exit fio_dump_gtod(void)
73 unsigned long total_calls = 0;
76 for (i = 0; i < HASH_SIZE; i++) {
77 struct list_head *entry;
80 list_for_each(entry, &hash[i]) {
81 log = list_entry(entry, struct gtod_log, list);
83 printf("function %p, calls %lu\n", log->caller, log->calls);
84 total_calls += log->calls;
88 printf("Total %lu gettimeofday\n", total_calls);
91 static void fio_init gtod_init(void)
95 for (i = 0; i < HASH_SIZE; i++)
96 INIT_LIST_HEAD(&hash[i]);
101 #endif /* FIO_DEBUG_TIME */
103 #ifdef FIO_DEBUG_TIME
104 void fio_gettime(struct timeval *tp, void *caller)
106 void fio_gettime(struct timeval *tp, void fio_unused *caller)
109 #ifdef FIO_DEBUG_TIME
111 caller = __builtin_return_address(0);
113 gtod_log_caller(caller);
115 if (!clock_gettime_works) {
117 gettimeofday(tp, NULL);
121 if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
122 clock_gettime_works = 0;
126 tp->tv_sec = ts.tv_sec;
127 tp->tv_usec = ts.tv_nsec / 1000;