9 #include <sys/sysctl.h>
13 #include <mach/mach_init.h>
14 #include <machine/endian.h>
15 #include <libkern/OSByteOrder.h>
19 #define FIO_USE_GENERIC_RAND
20 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
21 #define FIO_HAVE_GETTID
22 #define FIO_HAVE_CHARDEV_SIZE
23 #define FIO_HAVE_NATIVE_FALLOCATE
25 #define OS_MAP_ANON MAP_ANON
27 #define fio_swap16(x) OSSwapInt16(x)
28 #define fio_swap32(x) OSSwapInt32(x)
29 #define fio_swap64(x) OSSwapInt64(x)
32 * OSX has a pitifully small shared memory segment by default,
33 * so default to a lower number of max jobs supported
35 #define FIO_MAX_JOBS 128
37 typedef off_t off64_t;
39 #ifndef CONFIG_CLOCKID_T
40 typedef unsigned int clockid_t;
43 #define FIO_OS_DIRECTIO
44 static inline int fio_set_odirect(struct fio_file *f)
46 if (fcntl(f->fd, F_NOCACHE, 1) == -1)
51 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
56 if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1)
58 if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1)
62 *bytes *= block_count;
66 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
69 * Could be a raw block device, this is better than just assuming
70 * we can't get the size at all.
72 if (!blockdev_size(f, bytes))
79 static inline int blockdev_invalidate_cache(struct fio_file *f)
84 static inline unsigned long long os_phys_mem(void)
86 int mib[2] = { CTL_HW, HW_PHYSMEM };
87 unsigned long long mem;
88 size_t len = sizeof(mem);
90 sysctl(mib, 2, &mem, &len, NULL, 0);
94 static inline int gettid(void)
96 return mach_thread_self();
100 * For some reason, there's no header definition for fdatasync(), even
103 extern int fdatasync(int fd);
105 static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
107 fstore_t store = {F_ALLOCATEALL, F_PEOFPOSMODE, offset, len};
108 if (fcntl(f->fd, F_PREALLOCATE, &store) != -1) {
109 if (ftruncate(f->fd, len) == 0)