9 struct timeval *fio_tv = 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_tv = smalloc(sizeof(struct timeval));
21 log_err("fio: smalloc pool exhausted\n");
24 static void fio_gtod_update(void)
29 gettimeofday(&__tv, NULL);
30 fio_tv->tv_sec = __tv.tv_sec;
32 fio_tv->tv_usec = __tv.tv_usec;
37 struct gtod_cpu_data {
38 struct fio_mutex *mutex;
42 static void *gtod_thread_main(void *data)
44 struct fio_mutex *mutex = data;
46 fio_setaffinity(gettid(), fio_gtod_cpumask);
50 * As long as we have jobs around, update the clock. It would be nice
51 * to have some way of NOT hammering that CPU with gettimeofday(),
52 * but I'm not sure what to use outside of a simple CPU nop to relax
53 * it - we don't want to lose precision.
63 int fio_start_gtod_thread(void)
65 struct fio_mutex *mutex;
69 mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
73 pthread_attr_init(&attr);
74 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
75 ret = pthread_create(>od_thread, &attr, gtod_thread_main, mutex);
76 pthread_attr_destroy(&attr);
78 log_err("Can't create gtod thread: %s\n", strerror(ret));
82 ret = pthread_detach(gtod_thread);
84 log_err("Can't detatch gtod thread: %s\n", strerror(ret));
88 dprint(FD_MUTEX, "wait on startup_mutex\n");
89 fio_mutex_down(mutex);
90 dprint(FD_MUTEX, "done waiting on startup_mutex\n");
92 fio_mutex_remove(mutex);
96 void fio_gtod_set_cpu(unsigned int cpu)
98 #ifdef FIO_HAVE_CPU_AFFINITY
99 fio_cpu_set(&fio_gtod_cpumask, cpu);