7 struct timespec *fio_ts = NULL;
8 int fio_gtod_offload = 0;
9 static pthread_t gtod_thread;
10 static os_cpu_mask_t fio_gtod_cpumask;
12 void fio_gtod_init(void)
17 fio_ts = smalloc(sizeof(*fio_ts));
19 log_err("fio: smalloc pool exhausted\n");
22 static void fio_gtod_update(void)
27 gettimeofday(&__tv, NULL);
28 fio_ts->tv_sec = __tv.tv_sec;
30 fio_ts->tv_nsec = __tv.tv_usec * 1000;
35 struct gtod_cpu_data {
40 static void *gtod_thread_main(void *data)
42 struct fio_sem *sem = data;
45 ret = fio_setaffinity(gettid(), fio_gtod_cpumask);
50 log_err("gtod: setaffinity failed\n");
55 * As long as we have jobs around, update the clock. It would be nice
56 * to have some way of NOT hammering that CPU with gettimeofday(),
57 * but I'm not sure what to use outside of a simple CPU nop to relax
58 * it - we don't want to lose precision.
68 int fio_start_gtod_thread(void)
74 sem = fio_sem_init(FIO_SEM_LOCKED);
78 pthread_attr_init(&attr);
79 pthread_attr_setstacksize(&attr, 2 * PTHREAD_STACK_MIN);
80 ret = pthread_create(>od_thread, &attr, gtod_thread_main, sem);
81 pthread_attr_destroy(&attr);
83 log_err("Can't create gtod thread: %s\n", strerror(ret));
87 ret = pthread_detach(gtod_thread);
89 log_err("Can't detach gtod thread: %s\n", strerror(ret));
93 dprint(FD_MUTEX, "wait on startup_sem\n");
95 dprint(FD_MUTEX, "done waiting on startup_sem\n");
101 void fio_gtod_set_cpu(unsigned int cpu)
103 #ifdef FIO_HAVE_CPU_AFFINITY
104 fio_cpu_set(&fio_gtod_cpumask, cpu);