9 struct timeval *fio_tv;
10 int fio_gtod_offload = 0;
11 int fio_gtod_cpu = -1;
12 static pthread_t gtod_thread;
14 void fio_gtod_init(void)
16 fio_tv = smalloc(sizeof(struct timeval));
20 static void fio_gtod_update(void)
22 gettimeofday(fio_tv, NULL);
25 static void *gtod_thread_main(void *data)
27 struct fio_mutex *mutex = data;
32 * As long as we have jobs around, update the clock. It would be nice
33 * to have some way of NOT hammering that CPU with gettimeofday(),
34 * but I'm not sure what to use outside of a simple CPU nop to relax
35 * it - we don't want to lose precision.
45 int fio_start_gtod_thread(void)
47 struct fio_mutex *mutex;
51 mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
55 pthread_attr_init(&attr);
56 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
57 ret = pthread_create(>od_thread, &attr, gtod_thread_main, NULL);
58 pthread_attr_destroy(&attr);
60 log_err("Can't create gtod thread: %s\n", strerror(ret));
64 ret = pthread_detach(gtod_thread);
66 log_err("Can't detatch gtod thread: %s\n", strerror(ret));
70 dprint(FD_MUTEX, "wait on startup_mutex\n");
71 fio_mutex_down(mutex);
72 dprint(FD_MUTEX, "done waiting on startup_mutex\n");
74 fio_mutex_remove(mutex);