9 struct timespec *fio_ts = NULL;
10 int fio_gtod_offload = 0;
11 static pthread_t gtod_thread;
12 static os_cpu_mask_t fio_gtod_cpumask;
14 void fio_gtod_init(void)
19 fio_ts = smalloc(sizeof(*fio_ts));
21 log_err("fio: smalloc pool exhausted\n");
24 static void fio_gtod_update(void)
29 gettimeofday(&__tv, NULL);
30 fio_ts->tv_sec = __tv.tv_sec;
32 fio_ts->tv_nsec = __tv.tv_usec * 1000;
37 struct gtod_cpu_data {
38 struct fio_mutex *mutex;
42 static void *gtod_thread_main(void *data)
44 struct fio_mutex *mutex = data;
47 ret = fio_setaffinity(gettid(), fio_gtod_cpumask);
52 log_err("gtod: setaffinity failed\n");
57 * As long as we have jobs around, update the clock. It would be nice
58 * to have some way of NOT hammering that CPU with gettimeofday(),
59 * but I'm not sure what to use outside of a simple CPU nop to relax
60 * it - we don't want to lose precision.
70 int fio_start_gtod_thread(void)
72 struct fio_mutex *mutex;
76 mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
80 pthread_attr_init(&attr);
81 pthread_attr_setstacksize(&attr, 2 * PTHREAD_STACK_MIN);
82 ret = pthread_create(>od_thread, &attr, gtod_thread_main, mutex);
83 pthread_attr_destroy(&attr);
85 log_err("Can't create gtod thread: %s\n", strerror(ret));
89 ret = pthread_detach(gtod_thread);
91 log_err("Can't detach gtod thread: %s\n", strerror(ret));
95 dprint(FD_MUTEX, "wait on startup_mutex\n");
96 fio_mutex_down(mutex);
97 dprint(FD_MUTEX, "done waiting on startup_mutex\n");
99 fio_mutex_remove(mutex);
103 void fio_gtod_set_cpu(unsigned int cpu)
105 #ifdef FIO_HAVE_CPU_AFFINITY
106 fio_cpu_set(&fio_gtod_cpumask, cpu);