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)
26 gettimeofday(&__tv, NULL);
27 fio_tv->tv_sec = __tv.tv_sec;
29 fio_tv->tv_usec = __tv.tv_usec;
34 static void *gtod_thread_main(void *data)
36 struct fio_mutex *mutex = data;
41 * As long as we have jobs around, update the clock. It would be nice
42 * to have some way of NOT hammering that CPU with gettimeofday(),
43 * but I'm not sure what to use outside of a simple CPU nop to relax
44 * it - we don't want to lose precision.
54 int fio_start_gtod_thread(void)
56 struct fio_mutex *mutex;
60 mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
64 pthread_attr_init(&attr);
65 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
66 ret = pthread_create(>od_thread, &attr, gtod_thread_main, mutex);
67 pthread_attr_destroy(&attr);
69 log_err("Can't create gtod thread: %s\n", strerror(ret));
73 ret = pthread_detach(gtod_thread);
75 log_err("Can't detatch gtod thread: %s\n", strerror(ret));
79 dprint(FD_MUTEX, "wait on startup_mutex\n");
80 fio_mutex_down(mutex);
81 dprint(FD_MUTEX, "done waiting on startup_mutex\n");
83 fio_mutex_remove(mutex);