Enable crc32c accelleration for arm64 on OSX
[fio.git] / os / os-mac.h
CommitLineData
2afd826b
JA
1#ifndef FIO_OS_APPLE_H
2#define FIO_OS_APPLE_H
3
cca84643
JA
4#define FIO_OS os_mac
5
2afd826b 6#include <errno.h>
7e8ad197 7#include <fcntl.h>
c64646f0 8#include <sys/disk.h>
2afd826b 9#include <sys/sysctl.h>
9b836561
BC
10#include <sys/time.h>
11#include <unistd.h>
12#include <signal.h>
3dee087c 13#include <mach/mach_init.h>
ff245192
JA
14#include <machine/endian.h>
15#include <libkern/OSByteOrder.h>
2afd826b 16
1e8ec88f 17#include "../arch/arch.h"
e2e58886
JA
18#include "../file.h"
19
93bcfd20 20#define FIO_USE_GENERIC_INIT_RANDOM_STATE
e8d588e4 21#define FIO_HAVE_GETTID
b42ffd19 22#define FIO_HAVE_CHARDEV_SIZE
2c3e17be 23#define FIO_HAVE_NATIVE_FALLOCATE
1e8ec88f 24#define FIO_HAVE_CPU_HAS
2afd826b
JA
25
26#define OS_MAP_ANON MAP_ANON
27
ff245192
JA
28#define fio_swap16(x) OSSwapInt16(x)
29#define fio_swap32(x) OSSwapInt32(x)
30#define fio_swap64(x) OSSwapInt64(x)
31
e9d2a04d
TK
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))
36#endif
37
25f8227d 38#ifndef CONFIG_CLOCKID_T
9b836561 39typedef unsigned int clockid_t;
25f8227d 40#endif
9b836561 41
7e8ad197 42#define FIO_OS_DIRECTIO
2905de74 43static inline int fio_set_odirect(struct fio_file *f)
7e8ad197 44{
2905de74 45 if (fcntl(f->fd, F_NOCACHE, 1) == -1)
7e8ad197
SN
46 return errno;
47 return 0;
48}
49
c64646f0
SN
50static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
51{
79d73100
JA
52 uint32_t block_size;
53 uint64_t block_count;
54
55 if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1)
c64646f0 56 return errno;
79d73100 57 if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1)
c64646f0 58 return errno;
79d73100
JA
59
60 *bytes = block_size;
61 *bytes *= block_count;
62 return 0;
c64646f0
SN
63}
64
b42ffd19
JA
65static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
66{
67 /*
68 * Could be a raw block device, this is better than just assuming
69 * we can't get the size at all.
70 */
71 if (!blockdev_size(f, bytes))
72 return 0;
73
74 *bytes = -1ULL;
75 return 0;
76}
77
9b836561 78static inline int blockdev_invalidate_cache(struct fio_file *f)
2afd826b 79{
22de5d77 80 return ENOTSUP;
2afd826b
JA
81}
82
83static inline unsigned long long os_phys_mem(void)
84{
85 int mib[2] = { CTL_HW, HW_PHYSMEM };
86 unsigned long long mem;
87 size_t len = sizeof(mem);
88
89 sysctl(mib, 2, &mem, &len, NULL, 0);
90 return mem;
91}
e8d588e4 92
de5ed0e4 93#ifndef CONFIG_HAVE_GETTID
e8d588e4
JA
94static inline int gettid(void)
95{
96 return mach_thread_self();
97}
de5ed0e4 98#endif
5351f564 99
2c3e17be
SW
100static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
101{
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)
105 return true;
106 }
107
108 return false;
109}
110
1e8ec88f
JA
111static inline bool os_cpu_has(cpu_features feature)
112{
113 /* just check for arm on OSX for now, we know that has it */
114 if (feature != CPU_ARM64_CRC32C)
115 return false;
116 return FIO_ARCH == arch_aarch64;
117}
118
2afd826b 119#endif