5 #include "lib/seqlock.h"
9 int fio_gtod_offload = 0;
10 static pthread_t gtod_thread;
11 static os_cpu_mask_t fio_gtod_cpumask;
13 void fio_gtod_init(void)
18 fio_ts = smalloc(sizeof(*fio_ts));
21 static void fio_gtod_update(void)
28 gettimeofday(&__tv, NULL);
30 write_seqlock_begin(&fio_ts->seqlock);
31 fio_ts->ts.tv_sec = __tv.tv_sec;
32 fio_ts->ts.tv_nsec = __tv.tv_usec * 1000;
33 write_seqlock_end(&fio_ts->seqlock);
36 struct gtod_cpu_data {
41 static void *gtod_thread_main(void *data)
43 struct fio_sem *sem = data;
46 ret = fio_setaffinity(gettid(), fio_gtod_cpumask);
51 log_err("gtod: setaffinity failed\n");
56 * As long as we have jobs around, update the clock. It would be nice
57 * to have some way of NOT hammering that CPU with gettimeofday(),
58 * but I'm not sure what to use outside of a simple CPU nop to relax
59 * it - we don't want to lose precision.
69 int fio_start_gtod_thread(void)
75 sem = fio_sem_init(FIO_SEM_LOCKED);
79 pthread_attr_init(&attr);
80 pthread_attr_setstacksize(&attr, 2 * PTHREAD_STACK_MIN);
81 ret = pthread_create(>od_thread, &attr, gtod_thread_main, sem);
82 pthread_attr_destroy(&attr);
84 log_err("Can't create gtod thread: %s\n", strerror(ret));
88 ret = pthread_detach(gtod_thread);
90 log_err("Can't detach gtod thread: %s\n", strerror(ret));
94 dprint(FD_MUTEX, "wait on startup_sem\n");
96 dprint(FD_MUTEX, "done waiting on startup_sem\n");
102 void fio_gtod_set_cpu(unsigned int cpu)
104 #ifdef FIO_HAVE_CPU_AFFINITY
105 fio_cpu_set(&fio_gtod_cpumask, cpu);