5 #include <sys/sysctl.h>
12 #ifndef CLOCK_MONOTONIC
13 #define CLOCK_MONOTONIC 1
16 #ifndef CLOCK_REALTIME
17 #define CLOCK_REALTIME 1
20 #define FIO_HAVE_POSIXAIO
21 #define FIO_HAVE_CLOCK_MONOTONIC
22 #define FIO_USE_GENERIC_BDEV_SIZE
23 #define FIO_USE_GENERIC_RAND
25 #define OS_MAP_ANON MAP_ANON
27 typedef off_t off64_t;
29 /* OS X as of 10.6 doesn't have the timer_* functions.
30 * Emulate the functionality using setitimer and sigaction here
35 typedef unsigned int clockid_t;
36 typedef unsigned int timer_t;
39 struct timespec it_value;
40 struct timespec it_interval;
43 static struct sigevent fio_timers[MAX_TIMERS];
44 static unsigned int num_timers = 0;
46 static inline int timer_create(clockid_t clockid, struct sigevent *restrict evp,
47 timer_t *restrict timerid)
49 int current_timer = num_timers;
50 fio_timers[current_timer] = *evp;
53 *timerid = current_timer;
57 static void sig_alrm(int signum)
61 for (int i = 0; i < num_timers; i++) {
62 if (fio_timers[i].sigev_notify_function == NULL)
65 if (fio_timers[i].sigev_notify == SIGEV_THREAD)
66 fio_timers[i].sigev_notify_function(sv);
67 else if (fio_timers[i].sigev_notify == SIGEV_SIGNAL)
68 kill(getpid(), fio_timers[i].sigev_signo);
72 static inline int timer_settime(timer_t timerid, int flags,
73 const struct itimerspec *value, struct itimerspec *ovalue)
77 struct itimerval tv_out;
80 tv.it_interval.tv_sec = value->it_interval.tv_sec;
81 tv.it_interval.tv_usec = value->it_interval.tv_nsec / 1000;
83 tv.it_value.tv_sec = value->it_value.tv_sec;
84 tv.it_value.tv_usec = value->it_value.tv_nsec / 1000;
86 sa.sa_handler = sig_alrm;
87 sigemptyset(&sa.sa_mask);
90 rc = sigaction(SIGALRM, &sa, NULL);
93 rc = setitimer(ITIMER_REAL, &tv, &tv_out);
95 if (!rc && ovalue != NULL) {
96 ovalue->it_interval.tv_sec = tv_out.it_interval.tv_sec;
97 ovalue->it_interval.tv_nsec = tv_out.it_interval.tv_usec * 1000;
98 ovalue->it_value.tv_sec = tv_out.it_value.tv_sec;
99 ovalue->it_value.tv_nsec = tv_out.it_value.tv_usec * 1000;
105 static inline int timer_delete(timer_t timer)
110 static inline int blockdev_invalidate_cache(struct fio_file *f)
115 static inline unsigned long long os_phys_mem(void)
117 int mib[2] = { CTL_HW, HW_PHYSMEM };
118 unsigned long long mem;
119 size_t len = sizeof(mem);
121 sysctl(mib, 2, &mem, &len, NULL, 0);