9 #include <sys/sysctl.h>
13 #include <mach/mach_init.h>
14 #include <machine/endian.h>
15 #include <libkern/OSByteOrder.h>
17 #include "../arch/arch.h"
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
24 #define FIO_HAVE_CPU_HAS
26 #define OS_MAP_ANON MAP_ANON
28 #define fio_swap16(x) OSSwapInt16(x)
29 #define fio_swap32(x) OSSwapInt32(x)
30 #define fio_swap64(x) OSSwapInt64(x)
32 #ifdef CONFIG_PTHREAD_GETAFFINITY
33 #define FIO_HAVE_GET_THREAD_AFFINITY
34 #define fio_get_thread_affinity(mask) \
35 pthread_getaffinity_np(pthread_self(), sizeof(mask), &(mask))
38 #ifndef CONFIG_CLOCKID_T
39 typedef unsigned int clockid_t;
42 #define FIO_OS_DIRECTIO
43 static inline int fio_set_odirect(struct fio_file *f)
45 if (fcntl(f->fd, F_NOCACHE, 1) == -1)
50 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
55 if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1)
57 if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1)
61 *bytes *= block_count;
65 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
68 * Could be a raw block device, this is better than just assuming
69 * we can't get the size at all.
71 if (!blockdev_size(f, bytes))
78 static inline int blockdev_invalidate_cache(struct fio_file *f)
83 static inline unsigned long long os_phys_mem(void)
85 int mib[2] = { CTL_HW, HW_PHYSMEM };
86 unsigned long long mem;
87 size_t len = sizeof(mem);
89 sysctl(mib, 2, &mem, &len, NULL, 0);
93 #ifndef CONFIG_HAVE_GETTID
94 static inline int gettid(void)
96 return mach_thread_self();
100 static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
102 fstore_t store = {F_ALLOCATEALL, F_PEOFPOSMODE, offset, len};
103 if (fcntl(f->fd, F_PREALLOCATE, &store) != -1) {
104 if (ftruncate(f->fd, len) == 0)
111 static inline bool os_cpu_has(cpu_features feature)
113 /* just check for arm on OSX for now, we know that has it */
114 if (feature != CPU_ARM64_CRC32C)
116 return FIO_ARCH == arch_aarch64;