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));
20 static void fio_gtod_update(void)
25 gettimeofday(&__tv, NULL);
26 fio_ts->tv_sec = __tv.tv_sec;
28 fio_ts->tv_nsec = __tv.tv_usec * 1000;
33 struct gtod_cpu_data {
38 static void *gtod_thread_main(void *data)
40 struct fio_sem *sem = data;
43 ret = fio_setaffinity(gettid(), fio_gtod_cpumask);
48 log_err("gtod: setaffinity failed\n");
53 * As long as we have jobs around, update the clock. It would be nice
54 * to have some way of NOT hammering that CPU with gettimeofday(),
55 * but I'm not sure what to use outside of a simple CPU nop to relax
56 * it - we don't want to lose precision.
66 int fio_start_gtod_thread(void)
72 sem = fio_sem_init(FIO_SEM_LOCKED);
76 pthread_attr_init(&attr);
77 pthread_attr_setstacksize(&attr, 2 * PTHREAD_STACK_MIN);
78 ret = pthread_create(>od_thread, &attr, gtod_thread_main, sem);
79 pthread_attr_destroy(&attr);
81 log_err("Can't create gtod thread: %s\n", strerror(ret));
85 ret = pthread_detach(gtod_thread);
87 log_err("Can't detach gtod thread: %s\n", strerror(ret));
91 dprint(FD_MUTEX, "wait on startup_sem\n");
93 dprint(FD_MUTEX, "done waiting on startup_sem\n");
99 void fio_gtod_set_cpu(unsigned int cpu)
101 #ifdef FIO_HAVE_CPU_AFFINITY
102 fio_cpu_set(&fio_gtod_cpumask, cpu);