7 #include <sys/sysctl.h>
14 #ifndef CLOCK_MONOTONIC
15 #define CLOCK_MONOTONIC 1
18 #ifndef CLOCK_REALTIME
19 #define CLOCK_REALTIME 1
22 #define FIO_HAVE_POSIXAIO
23 #define FIO_HAVE_CLOCK_MONOTONIC
24 #define FIO_USE_GENERIC_RAND
26 #define OS_MAP_ANON MAP_ANON
28 typedef off_t off64_t;
30 /* OS X as of 10.6 doesn't have the timer_* functions.
31 * Emulate the functionality using setitimer and sigaction here
36 typedef unsigned int clockid_t;
37 typedef unsigned int timer_t;
40 struct timespec it_value;
41 struct timespec it_interval;
44 static struct sigevent fio_timers[MAX_TIMERS];
45 static unsigned int num_timers = 0;
47 static inline int timer_create(clockid_t clockid, struct sigevent *restrict evp,
48 timer_t *restrict timerid)
50 int current_timer = num_timers;
51 fio_timers[current_timer] = *evp;
54 *timerid = current_timer;
58 static void sig_alrm(int signum)
62 for (int i = 0; i < num_timers; i++) {
63 if (fio_timers[i].sigev_notify_function == NULL)
66 if (fio_timers[i].sigev_notify == SIGEV_THREAD)
67 fio_timers[i].sigev_notify_function(sv);
68 else if (fio_timers[i].sigev_notify == SIGEV_SIGNAL)
69 kill(getpid(), fio_timers[i].sigev_signo);
73 static inline int timer_settime(timer_t timerid, int flags,
74 const struct itimerspec *value, struct itimerspec *ovalue)
78 struct itimerval tv_out;
81 tv.it_interval.tv_sec = value->it_interval.tv_sec;
82 tv.it_interval.tv_usec = value->it_interval.tv_nsec / 1000;
84 tv.it_value.tv_sec = value->it_value.tv_sec;
85 tv.it_value.tv_usec = value->it_value.tv_nsec / 1000;
87 sa.sa_handler = sig_alrm;
88 sigemptyset(&sa.sa_mask);
91 rc = sigaction(SIGALRM, &sa, NULL);
94 rc = setitimer(ITIMER_REAL, &tv, &tv_out);
96 if (!rc && ovalue != NULL) {
97 ovalue->it_interval.tv_sec = tv_out.it_interval.tv_sec;
98 ovalue->it_interval.tv_nsec = tv_out.it_interval.tv_usec * 1000;
99 ovalue->it_value.tv_sec = tv_out.it_value.tv_sec;
100 ovalue->it_value.tv_nsec = tv_out.it_value.tv_usec * 1000;
106 static inline int timer_delete(timer_t timer)
111 #define FIO_OS_DIRECTIO
112 static inline int fio_set_odirect(int fd)
114 if (fcntl(fd, F_NOCACHE, 1) == -1)
119 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
122 if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, bytes) == -1)
124 if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &temp) == -1)
130 static inline int blockdev_invalidate_cache(struct fio_file *f)
135 static inline unsigned long long os_phys_mem(void)
137 int mib[2] = { CTL_HW, HW_PHYSMEM };
138 unsigned long long mem;
139 size_t len = sizeof(mem);
141 sysctl(mib, 2, &mem, &len, NULL, 0);