Commit | Line | Data |
---|---|---|
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 | |
e2e58886 JA |
17 | #include "../file.h" |
18 | ||
53531370 | 19 | #define FIO_USE_GENERIC_RAND |
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 |
2afd826b JA |
24 | |
25 | #define OS_MAP_ANON MAP_ANON | |
26 | ||
ff245192 JA |
27 | #define fio_swap16(x) OSSwapInt16(x) |
28 | #define fio_swap32(x) OSSwapInt32(x) | |
29 | #define fio_swap64(x) OSSwapInt64(x) | |
30 | ||
fca70358 JA |
31 | /* |
32 | * OSX has a pitifully small shared memory segment by default, | |
33 | * so default to a lower number of max jobs supported | |
34 | */ | |
35 | #define FIO_MAX_JOBS 128 | |
36 | ||
331539ac | 37 | typedef off_t off64_t; |
2afd826b | 38 | |
25f8227d | 39 | #ifndef CONFIG_CLOCKID_T |
9b836561 | 40 | typedef unsigned int clockid_t; |
25f8227d | 41 | #endif |
9b836561 | 42 | |
7e8ad197 | 43 | #define FIO_OS_DIRECTIO |
2905de74 | 44 | static inline int fio_set_odirect(struct fio_file *f) |
7e8ad197 | 45 | { |
2905de74 | 46 | if (fcntl(f->fd, F_NOCACHE, 1) == -1) |
7e8ad197 SN |
47 | return errno; |
48 | return 0; | |
49 | } | |
50 | ||
c64646f0 SN |
51 | static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) |
52 | { | |
79d73100 JA |
53 | uint32_t block_size; |
54 | uint64_t block_count; | |
55 | ||
56 | if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1) | |
c64646f0 | 57 | return errno; |
79d73100 | 58 | if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1) |
c64646f0 | 59 | return errno; |
79d73100 JA |
60 | |
61 | *bytes = block_size; | |
62 | *bytes *= block_count; | |
63 | return 0; | |
c64646f0 SN |
64 | } |
65 | ||
b42ffd19 JA |
66 | static inline int chardev_size(struct fio_file *f, unsigned long long *bytes) |
67 | { | |
68 | /* | |
69 | * Could be a raw block device, this is better than just assuming | |
70 | * we can't get the size at all. | |
71 | */ | |
72 | if (!blockdev_size(f, bytes)) | |
73 | return 0; | |
74 | ||
75 | *bytes = -1ULL; | |
76 | return 0; | |
77 | } | |
78 | ||
9b836561 | 79 | static inline int blockdev_invalidate_cache(struct fio_file *f) |
2afd826b | 80 | { |
22de5d77 | 81 | return ENOTSUP; |
2afd826b JA |
82 | } |
83 | ||
84 | static inline unsigned long long os_phys_mem(void) | |
85 | { | |
86 | int mib[2] = { CTL_HW, HW_PHYSMEM }; | |
87 | unsigned long long mem; | |
88 | size_t len = sizeof(mem); | |
89 | ||
90 | sysctl(mib, 2, &mem, &len, NULL, 0); | |
91 | return mem; | |
92 | } | |
e8d588e4 JA |
93 | |
94 | static inline int gettid(void) | |
95 | { | |
96 | return mach_thread_self(); | |
97 | } | |
5351f564 JA |
98 | |
99 | /* | |
100 | * For some reason, there's no header definition for fdatasync(), even | |
101 | * if it exists. | |
102 | */ | |
103 | extern int fdatasync(int fd); | |
104 | ||
2c3e17be SW |
105 | static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len) |
106 | { | |
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) | |
110 | return true; | |
111 | } | |
112 | ||
113 | return false; | |
114 | } | |
115 | ||
2afd826b | 116 | #endif |