Optimize fio_gettime_offload()
[fio.git] / gettime.h
1 #ifndef FIO_GETTIME_H
2 #define FIO_GETTIME_H
3
4 #include <sys/time.h>
5
6 #include "arch/arch.h"
7 #include "lib/seqlock.h"
8
9 /*
10  * Clock sources
11  */
12 enum fio_cs {
13         CS_GTOD         = 1,
14         CS_CGETTIME,
15         CS_CPUCLOCK,
16         CS_INVAL,
17 };
18
19 extern void fio_gettime(struct timespec *, void *);
20 extern void fio_gtod_init(void);
21 extern void fio_clock_init(void);
22 extern int fio_start_gtod_thread(void);
23 extern int fio_monotonic_clocktest(int debug);
24 extern void fio_local_clock_init(void);
25
26 extern struct fio_ts {
27         struct seqlock seqlock;
28         struct timespec ts;
29 } *fio_ts;
30
31 static inline int fio_gettime_offload(struct timespec *ts)
32 {
33         unsigned int seq;
34
35         if (!fio_ts)
36                 return 0;
37
38         do {
39                 seq = read_seqlock_begin(&fio_ts->seqlock);
40                 *ts = fio_ts->ts;
41         } while (read_seqlock_retry(&fio_ts->seqlock, seq));
42
43         return 1;
44 }
45
46 extern void fio_gtod_set_cpu(unsigned int cpu);
47
48 #endif