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 | ||
93bcfd20 | 19 | #define FIO_USE_GENERIC_INIT_RANDOM_STATE |
e8d588e4 | 20 | #define FIO_HAVE_GETTID |
b42ffd19 | 21 | #define FIO_HAVE_CHARDEV_SIZE |
2c3e17be | 22 | #define FIO_HAVE_NATIVE_FALLOCATE |
2afd826b JA |
23 | |
24 | #define OS_MAP_ANON MAP_ANON | |
25 | ||
ff245192 JA |
26 | #define fio_swap16(x) OSSwapInt16(x) |
27 | #define fio_swap32(x) OSSwapInt32(x) | |
28 | #define fio_swap64(x) OSSwapInt64(x) | |
29 | ||
e9d2a04d TK |
30 | #ifdef CONFIG_PTHREAD_GETAFFINITY |
31 | #define FIO_HAVE_GET_THREAD_AFFINITY | |
32 | #define fio_get_thread_affinity(mask) \ | |
33 | pthread_getaffinity_np(pthread_self(), sizeof(mask), &(mask)) | |
34 | #endif | |
35 | ||
25f8227d | 36 | #ifndef CONFIG_CLOCKID_T |
9b836561 | 37 | typedef unsigned int clockid_t; |
25f8227d | 38 | #endif |
9b836561 | 39 | |
7e8ad197 | 40 | #define FIO_OS_DIRECTIO |
2905de74 | 41 | static inline int fio_set_odirect(struct fio_file *f) |
7e8ad197 | 42 | { |
2905de74 | 43 | if (fcntl(f->fd, F_NOCACHE, 1) == -1) |
7e8ad197 SN |
44 | return errno; |
45 | return 0; | |
46 | } | |
47 | ||
c64646f0 SN |
48 | static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) |
49 | { | |
79d73100 JA |
50 | uint32_t block_size; |
51 | uint64_t block_count; | |
52 | ||
53 | if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1) | |
c64646f0 | 54 | return errno; |
79d73100 | 55 | if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1) |
c64646f0 | 56 | return errno; |
79d73100 JA |
57 | |
58 | *bytes = block_size; | |
59 | *bytes *= block_count; | |
60 | return 0; | |
c64646f0 SN |
61 | } |
62 | ||
b42ffd19 JA |
63 | static inline int chardev_size(struct fio_file *f, unsigned long long *bytes) |
64 | { | |
65 | /* | |
66 | * Could be a raw block device, this is better than just assuming | |
67 | * we can't get the size at all. | |
68 | */ | |
69 | if (!blockdev_size(f, bytes)) | |
70 | return 0; | |
71 | ||
72 | *bytes = -1ULL; | |
73 | return 0; | |
74 | } | |
75 | ||
9b836561 | 76 | static inline int blockdev_invalidate_cache(struct fio_file *f) |
2afd826b | 77 | { |
22de5d77 | 78 | return ENOTSUP; |
2afd826b JA |
79 | } |
80 | ||
81 | static inline unsigned long long os_phys_mem(void) | |
82 | { | |
83 | int mib[2] = { CTL_HW, HW_PHYSMEM }; | |
84 | unsigned long long mem; | |
85 | size_t len = sizeof(mem); | |
86 | ||
87 | sysctl(mib, 2, &mem, &len, NULL, 0); | |
88 | return mem; | |
89 | } | |
e8d588e4 | 90 | |
de5ed0e4 | 91 | #ifndef CONFIG_HAVE_GETTID |
e8d588e4 JA |
92 | static inline int gettid(void) |
93 | { | |
94 | return mach_thread_self(); | |
95 | } | |
de5ed0e4 | 96 | #endif |
5351f564 | 97 | |
2c3e17be SW |
98 | static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len) |
99 | { | |
100 | fstore_t store = {F_ALLOCATEALL, F_PEOFPOSMODE, offset, len}; | |
101 | if (fcntl(f->fd, F_PREALLOCATE, &store) != -1) { | |
102 | if (ftruncate(f->fd, len) == 0) | |
103 | return true; | |
104 | } | |
105 | ||
106 | return false; | |
107 | } | |
108 | ||
2afd826b | 109 | #endif |