13 static int clock_gettime_works = 0;
18 #define HASH_SIZE (1 << HASH_BITS)
20 static struct list_head hash[HASH_SIZE];
21 static int gtod_inited;
24 struct list_head list;
29 static struct gtod_log *find_hash(void *caller)
31 unsigned long h = hash_ptr(caller, HASH_BITS);
32 struct list_head *entry;
34 list_for_each(entry, &hash[h]) {
35 struct gtod_log *log = list_entry(entry, struct gtod_log, list);
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_LIST_HEAD(&log->list);
56 h = hash_ptr(caller, HASH_BITS);
57 list_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 list_head *entry;
81 list_for_each(entry, &hash[i]) {
82 log = list_entry(entry, struct gtod_log, list);
84 printf("function %p, calls %lu\n", log->caller, log->calls);
85 total_calls += log->calls;
89 printf("Total %lu gettimeofday\n", total_calls);
92 static void fio_init gtod_init(void)
96 for (i = 0; i < HASH_SIZE; i++)
97 INIT_LIST_HEAD(&hash[i]);
102 #endif /* FIO_DEBUG_TIME */
104 #ifdef FIO_DEBUG_TIME
105 void fio_gettime(struct timeval *tp, void *caller)
107 void fio_gettime(struct timeval *tp, void fio_unused *caller)
110 #ifdef FIO_DEBUG_TIME
112 caller = __builtin_return_address(0);
114 gtod_log_caller(caller);
116 if (!clock_gettime_works) {
118 gettimeofday(tp, NULL);
122 if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
123 clock_gettime_works = 0;
127 tp->tv_sec = ts.tv_sec;
128 tp->tv_usec = ts.tv_nsec / 1000;