9 struct timeval *fio_tv = NULL;
10 int fio_gtod_offload = 0;
11 static pthread_t gtod_thread;
12 #ifdef FIO_HAVE_CPU_AFFINITY
13 static os_cpu_mask_t fio_gtod_cpumask;
16 void fio_gtod_init(void)
21 fio_tv = smalloc(sizeof(struct timeval));
23 log_err("fio: smalloc pool exhausted\n");
26 static void fio_gtod_update(void)
31 gettimeofday(&__tv, NULL);
32 fio_tv->tv_sec = __tv.tv_sec;
34 fio_tv->tv_usec = __tv.tv_usec;
39 struct gtod_cpu_data {
40 struct fio_mutex *mutex;
44 static void *gtod_thread_main(void *data)
46 struct fio_mutex *mutex = data;
48 fio_setaffinity(gettid(), fio_gtod_cpumask);
52 * As long as we have jobs around, update the clock. It would be nice
53 * to have some way of NOT hammering that CPU with gettimeofday(),
54 * but I'm not sure what to use outside of a simple CPU nop to relax
55 * it - we don't want to lose precision.
65 int fio_start_gtod_thread(void)
67 struct fio_mutex *mutex;
71 mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
75 pthread_attr_init(&attr);
76 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
77 ret = pthread_create(>od_thread, &attr, gtod_thread_main, mutex);
78 pthread_attr_destroy(&attr);
80 log_err("Can't create gtod thread: %s\n", strerror(ret));
84 ret = pthread_detach(gtod_thread);
86 log_err("Can't detatch gtod thread: %s\n", strerror(ret));
90 dprint(FD_MUTEX, "wait on startup_mutex\n");
91 fio_mutex_down(mutex);
92 dprint(FD_MUTEX, "done waiting on startup_mutex\n");
94 fio_mutex_remove(mutex);
98 void fio_gtod_set_cpu(unsigned int cpu)
100 #ifdef FIO_HAVE_CPU_AFFINITY
101 fio_cpu_set(&fio_gtod_cpumask, cpu);