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_INIT_RANDOM_STATE
20 #define FIO_HAVE_GETTID
21 #define FIO_HAVE_CHARDEV_SIZE
22 #define FIO_HAVE_NATIVE_FALLOCATE
24 #define OS_MAP_ANON MAP_ANON
26 #define fio_swap16(x) OSSwapInt16(x)
27 #define fio_swap32(x) OSSwapInt32(x)
28 #define fio_swap64(x) OSSwapInt64(x)
30 #ifndef CONFIG_CLOCKID_T
31 typedef unsigned int clockid_t;
34 #define FIO_OS_DIRECTIO
35 static inline int fio_set_odirect(struct fio_file *f)
37 if (fcntl(f->fd, F_NOCACHE, 1) == -1)
42 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
47 if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1)
49 if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1)
53 *bytes *= block_count;
57 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
60 * Could be a raw block device, this is better than just assuming
61 * we can't get the size at all.
63 if (!blockdev_size(f, bytes))
70 static inline int blockdev_invalidate_cache(struct fio_file *f)
75 static inline unsigned long long os_phys_mem(void)
77 int mib[2] = { CTL_HW, HW_PHYSMEM };
78 unsigned long long mem;
79 size_t len = sizeof(mem);
81 sysctl(mib, 2, &mem, &len, NULL, 0);
85 #ifndef CONFIG_HAVE_GETTID
86 static inline int gettid(void)
88 return mach_thread_self();
92 static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
94 fstore_t store = {F_ALLOCATEALL, F_PEOFPOSMODE, offset, len};
95 if (fcntl(f->fd, F_PREALLOCATE, &store) != -1) {
96 if (ftruncate(f->fd, len) == 0)