5 #include <sys/socket.h>
11 #include "../arch/arch.h"
12 #include "../lib/types.h"
30 #if defined(__ANDROID__)
31 #include "os-android.h"
32 #elif defined(__linux__)
34 #elif defined(__FreeBSD__)
35 #include "os-freebsd.h"
36 #elif defined(__OpenBSD__)
37 #include "os-openbsd.h"
38 #elif defined(__NetBSD__)
39 #include "os-netbsd.h"
40 #elif defined(__sun__)
41 #include "os-solaris.h"
42 #elif defined(__APPLE__)
49 #include "os-windows.h"
50 #elif defined (__DragonFly__)
51 #include "os-dragonfly.h"
53 #error "unsupported os"
56 #ifdef CONFIG_POSIXAIO
58 #ifndef FIO_OS_HAVE_AIOCB_TYPEDEF
59 typedef struct aiocb os_aiocb_t;
64 #include "../oslib/strsep.h"
67 #ifndef CONFIG_STRLCAT
68 #include "../oslib/strlcat.h"
72 #define OS_MSG_DONTWAIT MSG_DONTWAIT
75 #ifndef POSIX_FADV_DONTNEED
76 #define POSIX_FADV_DONTNEED (0)
77 #define POSIX_FADV_SEQUENTIAL (0)
78 #define POSIX_FADV_RANDOM (0)
79 #define POSIX_FADV_NORMAL (0)
82 #ifndef FIO_HAVE_CPU_AFFINITY
83 #define fio_cpu_clear(mask, cpu) do { } while (0)
84 typedef unsigned long os_cpu_mask_t;
86 static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
91 static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
96 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
101 static inline int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu_index)
106 extern int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu);
109 #ifndef FIO_HAVE_IOPRIO
110 #define ioprio_set(which, who, prioclass, prio) (0)
113 #ifndef FIO_HAVE_ODIRECT
114 #define OS_O_DIRECT 0
116 #define OS_O_DIRECT O_DIRECT
120 #define FIO_O_ATOMIC OS_O_ATOMIC
122 #define FIO_O_ATOMIC 0
125 #ifndef FIO_HAVE_HUGETLB
126 #define SHM_HUGETLB 0
127 #define MAP_HUGETLB 0
128 #ifndef FIO_HUGE_PAGE
129 #define FIO_HUGE_PAGE 0
132 #ifndef FIO_HUGE_PAGE
133 #define FIO_HUGE_PAGE 4194304
137 #ifndef FIO_HAVE_MMAP_HUGE
138 #define MAP_HUGETLB 0
141 #ifndef FIO_O_NOATIME
142 #define FIO_O_NOATIME 0
146 #define OS_RAND_MAX RAND_MAX
149 #ifndef FIO_HAVE_RAWBIND
150 #define fio_lookup_raw(dev, majdev, mindev) 1
153 #ifndef FIO_PREFERRED_ENGINE
154 #define FIO_PREFERRED_ENGINE "psync"
157 #ifndef FIO_OS_PATH_SEPARATOR
158 #define FIO_OS_PATH_SEPARATOR "/"
161 #ifndef FIO_PREFERRED_CLOCK_SOURCE
162 #ifdef CONFIG_CLOCK_GETTIME
163 #define FIO_PREFERRED_CLOCK_SOURCE CS_CGETTIME
165 #define FIO_PREFERRED_CLOCK_SOURCE CS_GTOD
170 #define FIO_MAX_JOBS 4096
173 #ifndef CONFIG_SOCKLEN_T
174 typedef unsigned int socklen_t;
177 #ifndef FIO_OS_HAS_CTIME_R
178 #define os_ctime_r(x, y, z) (void) ctime_r((x), (y))
181 #ifdef FIO_USE_GENERIC_SWAP
182 static inline uint16_t fio_swap16(uint16_t val)
184 return (val << 8) | (val >> 8);
187 static inline uint32_t fio_swap32(uint32_t val)
189 val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
191 return (val >> 16) | (val << 16);
194 static inline uint64_t fio_swap64(uint64_t val)
196 val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
197 ((val & 0x00ff00ff00ff00ffULL) << 8);
198 val = ((val & 0xffff0000ffff0000ULL) >> 16) |
199 ((val & 0x0000ffff0000ffffULL) << 16);
201 return (val >> 32) | (val << 32);
205 #ifndef FIO_HAVE_BYTEORDER_FUNCS
206 #ifdef CONFIG_LITTLE_ENDIAN
207 #define __le16_to_cpu(x) (x)
208 #define __le32_to_cpu(x) (x)
209 #define __le64_to_cpu(x) (x)
210 #define __cpu_to_le16(x) (x)
211 #define __cpu_to_le32(x) (x)
212 #define __cpu_to_le64(x) (x)
214 #define __le16_to_cpu(x) fio_swap16(x)
215 #define __le32_to_cpu(x) fio_swap32(x)
216 #define __le64_to_cpu(x) fio_swap64(x)
217 #define __cpu_to_le16(x) fio_swap16(x)
218 #define __cpu_to_le32(x) fio_swap32(x)
219 #define __cpu_to_le64(x) fio_swap64(x)
221 #endif /* FIO_HAVE_BYTEORDER_FUNCS */
224 #define le16_to_cpu(val) ({ \
225 typecheck(uint16_t, val); \
226 __le16_to_cpu(val); \
228 #define le32_to_cpu(val) ({ \
229 typecheck(uint32_t, val); \
230 __le32_to_cpu(val); \
232 #define le64_to_cpu(val) ({ \
233 typecheck(uint64_t, val); \
234 __le64_to_cpu(val); \
238 #define cpu_to_le16(val) ({ \
239 typecheck(uint16_t, val); \
240 __cpu_to_le16(val); \
242 #define cpu_to_le32(val) ({ \
243 typecheck(uint32_t, val); \
244 __cpu_to_le32(val); \
246 #define cpu_to_le64(val) ({ \
247 typecheck(uint64_t, val); \
248 __cpu_to_le64(val); \
251 #define FIO_DEF_CL_SIZE 128
253 static inline int os_cache_line_size(void)
255 #ifdef FIO_HAVE_CL_SIZE
256 int ret = arch_cache_line_size();
259 return FIO_DEF_CL_SIZE;
263 return FIO_DEF_CL_SIZE;
267 #ifdef FIO_USE_GENERIC_BDEV_SIZE
268 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
274 end = lseek(f->fd, 0, SEEK_END);
283 #ifdef FIO_USE_GENERIC_RAND
284 typedef unsigned int os_random_state_t;
286 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
291 static inline long os_random_long(os_random_state_t *rs)
300 #ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE
301 static inline int init_random_seeds(unsigned long *rand_seeds, int size)
305 fd = open("/dev/urandom", O_RDONLY);
310 if (read(fd, rand_seeds, size) < size) {
320 #ifndef FIO_HAVE_FS_STAT
321 static inline unsigned long long get_fs_free_size(const char *path)
327 #ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
328 static inline unsigned int cpus_online(void)
330 return sysconf(_SC_NPROCESSORS_ONLN);
335 #ifdef FIO_HAVE_CPU_AFFINITY
336 static inline int CPU_COUNT(os_cpu_mask_t *mask)
338 int max_cpus = cpus_online();
341 for (i = 0, nr_cpus = 0; i < max_cpus; i++)
342 if (fio_cpu_isset(mask, i))
350 #ifndef FIO_HAVE_GETTID
351 static inline int gettid(void)
357 #ifndef FIO_HAVE_SHM_ATTACH_REMOVED
358 static inline int shm_attach_to_open_removed(void)
364 #ifndef FIO_HAVE_NATIVE_FALLOCATE
365 static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
372 #if defined(CONFIG_POSIX_FALLOCATE) || defined(FIO_HAVE_NATIVE_FALLOCATE)
373 # define FIO_HAVE_ANY_FALLOCATE