Commit | Line | Data |
---|---|---|
ebac4655 JA |
1 | #ifndef FIO_OS_H |
2 | #define FIO_OS_H | |
3 | ||
a14ca44a | 4 | #include <sys/types.h> |
03e20d68 | 5 | #include <pthread.h> |
a14ca44a JA |
6 | #include <unistd.h> |
7 | ||
ebac4655 JA |
8 | #if defined(__linux__) |
9 | #include "os-linux.h" | |
10 | #elif defined(__FreeBSD__) | |
11 | #include "os-freebsd.h" | |
7452440e YT |
12 | #elif defined(__NetBSD__) |
13 | #include "os-netbsd.h" | |
2c0ecd28 JA |
14 | #elif defined(__sun__) |
15 | #include "os-solaris.h" | |
2afd826b JA |
16 | #elif defined(__APPLE__) |
17 | #include "os-mac.h" | |
bf2e821a CC |
18 | #elif defined(_AIX) |
19 | #include "os-aix.h" | |
03e20d68 BC |
20 | #elif defined(__CYGWIN__) |
21 | #include "os-windows.h" | |
ebac4655 JA |
22 | #else |
23 | #error "unsupported os" | |
24 | #endif | |
25 | ||
26 | #ifdef FIO_HAVE_LIBAIO | |
27 | #include <libaio.h> | |
28 | #endif | |
29 | ||
30 | #ifdef FIO_HAVE_POSIXAIO | |
31 | #include <aio.h> | |
32 | #endif | |
33 | ||
34 | #ifdef FIO_HAVE_SGIO | |
35 | #include <linux/fs.h> | |
36 | #include <scsi/sg.h> | |
37 | #endif | |
38 | ||
5921e80c | 39 | #ifndef FIO_HAVE_STRSEP |
00fb3c8d | 40 | #include "../lib/strsep.h" |
5921e80c JA |
41 | #endif |
42 | ||
8e239cae JA |
43 | #ifdef MSG_DONTWAIT |
44 | #define OS_MSG_DONTWAIT MSG_DONTWAIT | |
45 | #endif | |
46 | ||
ebac4655 JA |
47 | #ifndef FIO_HAVE_FADVISE |
48 | #define fadvise(fd, off, len, advice) (0) | |
49 | ||
4d8947de | 50 | #ifndef POSIX_FADV_DONTNEED |
ebac4655 JA |
51 | #define POSIX_FADV_DONTNEED (0) |
52 | #define POSIX_FADV_SEQUENTIAL (0) | |
53 | #define POSIX_FADV_RANDOM (0) | |
4d8947de | 54 | #endif |
ebac4655 JA |
55 | #endif /* FIO_HAVE_FADVISE */ |
56 | ||
57 | #ifndef FIO_HAVE_CPU_AFFINITY | |
e8462bd8 | 58 | #define fio_setaffinity(pid, mask) (0) |
be4ecfdf JA |
59 | #define fio_getaffinity(pid, mask) do { } while (0) |
60 | #define fio_cpu_clear(mask, cpu) do { } while (0) | |
85daf2c1 | 61 | #define fio_cpuset_exit(mask) (-1) |
7452440e | 62 | typedef unsigned long os_cpu_mask_t; |
ebac4655 JA |
63 | #endif |
64 | ||
65 | #ifndef FIO_HAVE_IOPRIO | |
66 | #define ioprio_set(which, who, prio) (0) | |
67 | #endif | |
68 | ||
2c0ecd28 | 69 | #ifndef FIO_HAVE_ODIRECT |
7d424763 JA |
70 | #define OS_O_DIRECT 0 |
71 | #else | |
72 | #define OS_O_DIRECT O_DIRECT | |
2c0ecd28 JA |
73 | #endif |
74 | ||
74b025b0 JA |
75 | #ifndef FIO_HAVE_HUGETLB |
76 | #define SHM_HUGETLB 0 | |
4d8947de | 77 | #ifndef FIO_HUGE_PAGE |
74b025b0 | 78 | #define FIO_HUGE_PAGE 0 |
4d8947de | 79 | #endif |
74b025b0 | 80 | #else |
cb25df61 | 81 | #ifndef FIO_HUGE_PAGE |
ee0e0a71 | 82 | #define FIO_HUGE_PAGE 4194304 |
74b025b0 | 83 | #endif |
cb25df61 | 84 | #endif |
74b025b0 | 85 | |
5921e80c JA |
86 | #ifndef FIO_O_NOATIME |
87 | #define FIO_O_NOATIME 0 | |
88 | #endif | |
89 | ||
dc873b6f JA |
90 | #ifndef OS_RAND_MAX |
91 | #define OS_RAND_MAX RAND_MAX | |
92 | #endif | |
93 | ||
07e5b264 | 94 | #ifndef FIO_HAVE_RAWBIND |
8cc7afa9 | 95 | #define fio_lookup_raw(dev, majdev, mindev) 1 |
07e5b264 JA |
96 | #endif |
97 | ||
5e62c22a JA |
98 | #ifndef FIO_HAVE_BLKTRACE |
99 | static inline int is_blktrace(const char *fname) | |
100 | { | |
101 | return 0; | |
102 | } | |
5921e80c | 103 | struct thread_data; |
5e62c22a JA |
104 | static inline int load_blktrace(struct thread_data *td, const char *fname) |
105 | { | |
106 | return 1; | |
107 | } | |
108 | #endif | |
109 | ||
eb7ccf38 JA |
110 | #define FIO_DEF_CL_SIZE 128 |
111 | ||
112 | static inline int os_cache_line_size(void) | |
113 | { | |
114 | #ifdef FIO_HAVE_CL_SIZE | |
115 | int ret = arch_cache_line_size(); | |
116 | ||
117 | if (ret <= 0) | |
118 | return FIO_DEF_CL_SIZE; | |
119 | ||
120 | return ret; | |
121 | #else | |
122 | return FIO_DEF_CL_SIZE; | |
123 | #endif | |
124 | } | |
125 | ||
792d5517 JA |
126 | #ifdef FIO_USE_GENERIC_BDEV_SIZE |
127 | static inline int blockdev_size(int fd, unsigned long long *bytes) | |
128 | { | |
3b2e1464 | 129 | off_t end; |
792d5517 | 130 | |
3b2e1464 JA |
131 | *bytes = 0; |
132 | ||
133 | end = lseek(fd, 0, SEEK_END); | |
792d5517 JA |
134 | if (end < 0) |
135 | return errno; | |
136 | ||
137 | *bytes = end; | |
138 | return 0; | |
139 | } | |
140 | #endif | |
141 | ||
53531370 JA |
142 | #ifdef FIO_USE_GENERIC_RAND |
143 | typedef unsigned int os_random_state_t; | |
144 | ||
145 | static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) | |
146 | { | |
147 | srand(seed); | |
148 | } | |
149 | ||
150 | static inline long os_random_long(os_random_state_t *rs) | |
151 | { | |
152 | long val; | |
153 | ||
154 | val = rand_r(rs); | |
155 | return val; | |
156 | } | |
157 | #endif | |
158 | ||
2e3bd4c2 JA |
159 | #ifndef FIO_HAVE_FS_STAT |
160 | static inline unsigned long long get_fs_size(const char *path) | |
161 | { | |
162 | return 0; | |
163 | } | |
164 | #endif | |
165 | ||
ebac4655 | 166 | #endif |