12 static int clock_gettime_works;
17 #define HASH_SIZE (1 << HASH_BITS)
19 static struct flist_head hash[HASH_SIZE];
20 static int gtod_inited;
23 struct flist_head list;
28 static struct gtod_log *find_hash(void *caller)
30 unsigned long h = hash_ptr(caller, HASH_BITS);
31 struct flist_head *entry;
33 flist_for_each(entry, &hash[h]) {
34 struct gtod_log *log = flist_entry(entry, struct gtod_log,
37 if (log->caller == caller)
44 static struct gtod_log *find_log(void *caller)
46 struct gtod_log *log = find_hash(caller);
51 log = malloc(sizeof(*log));
52 INIT_FLIST_HEAD(&log->list);
56 h = hash_ptr(caller, HASH_BITS);
57 flist_add_tail(&log->list, &hash[h]);
63 static void gtod_log_caller(void *caller)
66 struct gtod_log *log = find_log(caller);
72 static void fio_exit fio_dump_gtod(void)
74 unsigned long total_calls = 0;
77 for (i = 0; i < HASH_SIZE; i++) {
78 struct flist_head *entry;
81 flist_for_each(entry, &hash[i]) {
82 log = flist_entry(entry, struct gtod_log, list);
84 printf("function %p, calls %lu\n", log->caller,
86 total_calls += log->calls;
90 printf("Total %lu gettimeofday\n", total_calls);
93 static void fio_init gtod_init(void)
97 for (i = 0; i < HASH_SIZE; i++)
98 INIT_FLIST_HEAD(&hash[i]);
103 #endif /* FIO_DEBUG_TIME */
105 #ifdef FIO_DEBUG_TIME
106 void fio_gettime(struct timeval *tp, void *caller)
108 void fio_gettime(struct timeval *tp, void fio_unused *caller)
111 #ifdef FIO_DEBUG_TIME
113 caller = __builtin_return_address(0);
115 gtod_log_caller(caller);
117 if (!clock_gettime_works) {
119 gettimeofday(tp, NULL);
123 if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
124 clock_gettime_works = 0;
128 tp->tv_sec = ts.tv_sec;
129 tp->tv_usec = ts.tv_nsec / 1000;