9 struct timeval *fio_tv = NULL;
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));
18 log_err("fio: smalloc pool exhausted\n");
21 static void fio_gtod_update(void)
24 gettimeofday(fio_tv, NULL);
27 static void *gtod_thread_main(void *data)
29 struct fio_mutex *mutex = data;
34 * As long as we have jobs around, update the clock. It would be nice
35 * to have some way of NOT hammering that CPU with gettimeofday(),
36 * but I'm not sure what to use outside of a simple CPU nop to relax
37 * it - we don't want to lose precision.
47 int fio_start_gtod_thread(void)
49 struct fio_mutex *mutex;
53 mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
57 pthread_attr_init(&attr);
58 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
59 ret = pthread_create(>od_thread, &attr, gtod_thread_main, NULL);
60 pthread_attr_destroy(&attr);
62 log_err("Can't create gtod thread: %s\n", strerror(ret));
66 ret = pthread_detach(gtod_thread);
68 log_err("Can't detatch gtod thread: %s\n", strerror(ret));
72 dprint(FD_MUTEX, "wait on startup_mutex\n");
73 fio_mutex_down(mutex);
74 dprint(FD_MUTEX, "done waiting on startup_mutex\n");
76 fio_mutex_remove(mutex);