5 #include <sys/socket.h>
12 #include "../arch/arch.h" /* IWYU pragma: export */
13 #include "../lib/types.h"
35 /* IWYU pragma: begin_exports */
36 #if defined(__ANDROID__)
37 #include "os-android.h"
38 #elif defined(__linux__)
40 #elif defined(__FreeBSD__)
41 #include "os-freebsd.h"
42 #elif defined(__OpenBSD__)
43 #include "os-openbsd.h"
44 #elif defined(__NetBSD__)
45 #include "os-netbsd.h"
46 #elif defined(__sun__)
47 #include "os-solaris.h"
48 #elif defined(__APPLE__)
55 #include "os-windows.h"
56 #elif defined (__DragonFly__)
57 #include "os-dragonfly.h"
59 #error "unsupported os"
66 #ifdef CONFIG_POSIXAIO
68 #ifndef FIO_OS_HAVE_AIOCB_TYPEDEF
69 typedef struct aiocb os_aiocb_t;
74 #include "../oslib/strsep.h"
77 #ifndef CONFIG_STRLCAT
78 #include "../oslib/strlcat.h"
80 /* IWYU pragma: end_exports */
83 #define OS_MSG_DONTWAIT MSG_DONTWAIT
86 #ifndef POSIX_FADV_DONTNEED
87 #define POSIX_FADV_DONTNEED (0)
88 #define POSIX_FADV_SEQUENTIAL (0)
89 #define POSIX_FADV_RANDOM (0)
90 #define POSIX_FADV_NORMAL (0)
93 #ifndef FIO_HAVE_CPU_AFFINITY
94 #define fio_cpu_clear(mask, cpu) do { } while (0)
95 typedef unsigned long os_cpu_mask_t;
97 static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
102 static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
107 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
112 static inline int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu_index)
117 extern int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu);
120 #ifndef FIO_HAVE_IOPRIO
121 #define ioprio_value(prioclass, prio) (0)
122 #define ioprio_set(which, who, prioclass, prio) (0)
125 #ifndef FIO_HAVE_ODIRECT
126 #define OS_O_DIRECT 0
128 #define OS_O_DIRECT O_DIRECT
132 #define FIO_O_ATOMIC OS_O_ATOMIC
134 #define FIO_O_ATOMIC 0
137 #ifndef FIO_HAVE_HUGETLB
138 #define SHM_HUGETLB 0
139 #define MAP_HUGETLB 0
140 #ifndef FIO_HUGE_PAGE
141 #define FIO_HUGE_PAGE 0
144 #ifndef FIO_HUGE_PAGE
145 #define FIO_HUGE_PAGE 4194304
149 #ifndef FIO_HAVE_MMAP_HUGE
150 #define MAP_HUGETLB 0
153 #ifndef FIO_O_NOATIME
154 #define FIO_O_NOATIME 0
158 #define OS_RAND_MAX RAND_MAX
161 #ifndef FIO_PREFERRED_ENGINE
162 #define FIO_PREFERRED_ENGINE "psync"
165 #ifndef FIO_OS_PATH_SEPARATOR
166 #define FIO_OS_PATH_SEPARATOR '/'
169 #ifndef FIO_PREFERRED_CLOCK_SOURCE
170 #ifdef CONFIG_CLOCK_GETTIME
171 #define FIO_PREFERRED_CLOCK_SOURCE CS_CGETTIME
173 #define FIO_PREFERRED_CLOCK_SOURCE CS_GTOD
177 #ifndef CONFIG_SOCKLEN_T
178 typedef unsigned int socklen_t;
181 #ifndef FIO_OS_HAS_CTIME_R
182 #define os_ctime_r(x, y, z) (void) ctime_r((x), (y))
185 #ifdef FIO_USE_GENERIC_SWAP
186 static inline uint16_t fio_swap16(uint16_t val)
188 return (val << 8) | (val >> 8);
191 static inline uint32_t fio_swap32(uint32_t val)
193 val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
195 return (val >> 16) | (val << 16);
198 static inline uint64_t fio_swap64(uint64_t val)
200 val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
201 ((val & 0x00ff00ff00ff00ffULL) << 8);
202 val = ((val & 0xffff0000ffff0000ULL) >> 16) |
203 ((val & 0x0000ffff0000ffffULL) << 16);
205 return (val >> 32) | (val << 32);
209 #ifndef FIO_HAVE_BYTEORDER_FUNCS
210 #ifdef CONFIG_LITTLE_ENDIAN
211 #define __be16_to_cpu(x) fio_swap16(x)
212 #define __be32_to_cpu(x) fio_swap32(x)
213 #define __be64_to_cpu(x) fio_swap64(x)
214 #define __le16_to_cpu(x) (x)
215 #define __le32_to_cpu(x) (x)
216 #define __le64_to_cpu(x) (x)
217 #define __cpu_to_be16(x) fio_swap16(x)
218 #define __cpu_to_be32(x) fio_swap32(x)
219 #define __cpu_to_be64(x) fio_swap64(x)
220 #define __cpu_to_le16(x) (x)
221 #define __cpu_to_le32(x) (x)
222 #define __cpu_to_le64(x) (x)
224 #define __be16_to_cpu(x) (x)
225 #define __be32_to_cpu(x) (x)
226 #define __be64_to_cpu(x) (x)
227 #define __le16_to_cpu(x) fio_swap16(x)
228 #define __le32_to_cpu(x) fio_swap32(x)
229 #define __le64_to_cpu(x) fio_swap64(x)
230 #define __cpu_to_be16(x) (x)
231 #define __cpu_to_be32(x) (x)
232 #define __cpu_to_be64(x) (x)
233 #define __cpu_to_le16(x) fio_swap16(x)
234 #define __cpu_to_le32(x) fio_swap32(x)
235 #define __cpu_to_le64(x) fio_swap64(x)
237 #endif /* FIO_HAVE_BYTEORDER_FUNCS */
240 #define be16_to_cpu(val) ({ \
241 typecheck(uint16_t, val); \
242 __be16_to_cpu(val); \
244 #define be32_to_cpu(val) ({ \
245 typecheck(uint32_t, val); \
246 __be32_to_cpu(val); \
248 #define be64_to_cpu(val) ({ \
249 typecheck(uint64_t, val); \
250 __be64_to_cpu(val); \
252 #define le16_to_cpu(val) ({ \
253 typecheck(uint16_t, val); \
254 __le16_to_cpu(val); \
256 #define le32_to_cpu(val) ({ \
257 typecheck(uint32_t, val); \
258 __le32_to_cpu(val); \
260 #define le64_to_cpu(val) ({ \
261 typecheck(uint64_t, val); \
262 __le64_to_cpu(val); \
266 #define cpu_to_be16(val) ({ \
267 typecheck(uint16_t, val); \
268 __cpu_to_be16(val); \
270 #define cpu_to_be32(val) ({ \
271 typecheck(uint32_t, val); \
272 __cpu_to_be32(val); \
274 #define cpu_to_be64(val) ({ \
275 typecheck(uint64_t, val); \
276 __cpu_to_be64(val); \
278 #define cpu_to_le16(val) ({ \
279 typecheck(uint16_t, val); \
280 __cpu_to_le16(val); \
282 #define cpu_to_le32(val) ({ \
283 typecheck(uint32_t, val); \
284 __cpu_to_le32(val); \
286 #define cpu_to_le64(val) ({ \
287 typecheck(uint64_t, val); \
288 __cpu_to_le64(val); \
291 #define FIO_DEF_CL_SIZE 128
293 static inline int os_cache_line_size(void)
295 #ifdef FIO_HAVE_CL_SIZE
296 int ret = arch_cache_line_size();
299 return FIO_DEF_CL_SIZE;
303 return FIO_DEF_CL_SIZE;
307 #ifdef FIO_USE_GENERIC_BDEV_SIZE
308 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
314 end = lseek(f->fd, 0, SEEK_END);
323 #ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE
324 static inline int init_random_seeds(uint64_t *rand_seeds, int size)
328 fd = open("/dev/urandom", O_RDONLY);
333 if (read(fd, rand_seeds, size) < size) {
343 #ifndef FIO_HAVE_FS_STAT
344 static inline unsigned long long get_fs_free_size(const char *path)
350 #ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
351 static inline unsigned int cpus_online(void)
353 return sysconf(_SC_NPROCESSORS_ONLN);
358 #ifdef FIO_HAVE_CPU_AFFINITY
359 static inline int CPU_COUNT(os_cpu_mask_t *mask)
361 int max_cpus = cpus_online();
364 for (i = 0, nr_cpus = 0; i < max_cpus; i++)
365 if (fio_cpu_isset(mask, i))
373 #ifndef FIO_HAVE_GETTID
374 #ifndef CONFIG_HAVE_GETTID
375 static inline int gettid(void)
382 #ifndef FIO_HAVE_SHM_ATTACH_REMOVED
383 static inline int shm_attach_to_open_removed(void)
389 #ifndef FIO_HAVE_NATIVE_FALLOCATE
390 static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
397 #if defined(CONFIG_POSIX_FALLOCATE) || defined(FIO_HAVE_NATIVE_FALLOCATE)
398 # define FIO_HAVE_DEFAULT_FALLOCATE
401 #ifndef FIO_HAVE_CPU_HAS
402 static inline bool os_cpu_has(cpu_features feature)
408 #ifndef FIO_EMULATED_MKDIR_TWO
409 # define fio_mkdir(path, mode) mkdir(path, mode)
412 #endif /* FIO_OS_H */