22 #if defined(__linux__)
24 #elif defined(__FreeBSD__)
25 #include "os-freebsd.h"
26 #elif defined(__NetBSD__)
27 #include "os-netbsd.h"
28 #elif defined(__sun__)
29 #include "os-solaris.h"
30 #elif defined(__APPLE__)
36 #elif defined(__CYGWIN__)
37 #include "os-windows.h"
39 #error "unsupported os"
42 #ifdef FIO_HAVE_LIBAIO
46 #ifdef FIO_HAVE_POSIXAIO
48 #ifndef FIO_OS_HAVE_AIOCB_TYPEDEF
49 typedef struct aiocb os_aiocb_t;
58 #ifndef FIO_HAVE_STRSEP
59 #include "../lib/strsep.h"
63 #define OS_MSG_DONTWAIT MSG_DONTWAIT
66 #ifndef FIO_HAVE_FADVISE
67 #define posix_fadvise(fd, off, len, advice) (0)
69 #ifndef POSIX_FADV_DONTNEED
70 #define POSIX_FADV_DONTNEED (0)
71 #define POSIX_FADV_SEQUENTIAL (0)
72 #define POSIX_FADV_RANDOM (0)
74 #endif /* FIO_HAVE_FADVISE */
76 #ifndef FIO_HAVE_CPU_AFFINITY
77 #define fio_setaffinity(pid, mask) (0)
78 #define fio_getaffinity(pid, mask) do { } while (0)
79 #define fio_cpu_clear(mask, cpu) do { } while (0)
80 #define fio_cpuset_exit(mask) (-1)
81 typedef unsigned long os_cpu_mask_t;
84 #ifndef FIO_HAVE_IOPRIO
85 #define ioprio_set(which, who, prio) (0)
88 #ifndef FIO_HAVE_ODIRECT
91 #define OS_O_DIRECT O_DIRECT
94 #ifndef FIO_HAVE_HUGETLB
97 #define FIO_HUGE_PAGE 0
100 #ifndef FIO_HUGE_PAGE
101 #define FIO_HUGE_PAGE 4194304
105 #ifndef FIO_O_NOATIME
106 #define FIO_O_NOATIME 0
110 #define OS_RAND_MAX RAND_MAX
113 #ifdef FIO_HAVE_CLOCK_MONOTONIC
114 #define FIO_TIMER_CLOCK CLOCK_MONOTONIC
116 #define FIO_TIMER_CLOCK CLOCK_REALTIME
119 #ifndef FIO_HAVE_RAWBIND
120 #define fio_lookup_raw(dev, majdev, mindev) 1
123 #ifndef FIO_PREFERRED_ENGINE
124 #define FIO_PREFERRED_ENGINE "sync"
128 #define FIO_MAX_JOBS 2048
131 #ifndef FIO_OS_HAVE_SOCKLEN_T
132 typedef socklen_t fio_socklen_t;
135 #ifdef FIO_USE_GENERIC_SWAP
136 static inline uint16_t fio_swap16(uint16_t val)
138 return (val << 8) | (val >> 8);
141 static inline uint32_t fio_swap32(uint32_t val)
143 val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
145 return (val >> 16) | (val << 16);
148 static inline uint64_t fio_swap64(uint64_t val)
150 val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
151 ((val & 0x00ff00ff00ff00ffULL) << 8);
152 val = ((val & 0xffff0000ffff0000ULL) >> 16) |
153 ((val & 0x0000ffff0000ffffULL) << 16);
155 return (val >> 32) | (val << 32);
159 #ifdef FIO_LITTLE_ENDIAN
160 #define __le16_to_cpu(x) (x)
161 #define __le32_to_cpu(x) (x)
162 #define __le64_to_cpu(x) (x)
163 #define __cpu_to_le16(x) (x)
164 #define __cpu_to_le32(x) (x)
165 #define __cpu_to_le64(x) (x)
167 #define __le16_to_cpu(x) fio_swap16(x)
168 #define __le32_to_cpu(x) fio_swap32(x)
169 #define __le64_to_cpu(x) fio_swap64(x)
170 #define __cpu_to_le16(x) fio_swap16(x)
171 #define __cpu_to_le32(x) fio_swap32(x)
172 #define __cpu_to_le64(x) fio_swap64(x)
175 #define le16_to_cpu(val) ({ \
176 uint16_t *__val = &(val); \
177 __le16_to_cpu(*__val); \
179 #define le32_to_cpu(val) ({ \
180 uint32_t *__val = &(val); \
181 __le32_to_cpu(*__val); \
183 #define le64_to_cpu(val) ({ \
184 uint64_t *__val = &(val); \
185 __le64_to_cpu(*__val); \
187 #define cpu_to_le16(val) ({ \
188 uint16_t *__val = &(val); \
189 __cpu_to_le16(*__val); \
191 #define cpu_to_le32(val) ({ \
192 uint32_t *__val = &(val); \
193 __cpu_to_le32(*__val); \
195 #define cpu_to_le64(val) ({ \
196 uint64_t *__val = &(val); \
197 __cpu_to_le64(*__val); \
200 #ifndef FIO_HAVE_BLKTRACE
201 static inline int is_blktrace(const char *fname)
206 static inline int load_blktrace(struct thread_data *td, const char *fname)
212 #define FIO_DEF_CL_SIZE 128
214 static inline int os_cache_line_size(void)
216 #ifdef FIO_HAVE_CL_SIZE
217 int ret = arch_cache_line_size();
220 return FIO_DEF_CL_SIZE;
224 return FIO_DEF_CL_SIZE;
228 #ifdef FIO_USE_GENERIC_BDEV_SIZE
229 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
235 end = lseek(f->fd, 0, SEEK_END);
244 #ifdef FIO_USE_GENERIC_RAND
245 typedef unsigned int os_random_state_t;
247 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
252 static inline long os_random_long(os_random_state_t *rs)
261 #ifndef FIO_HAVE_FS_STAT
262 static inline unsigned long long get_fs_size(const char *path)
268 #ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
269 static inline unsigned int cpus_online(void)
271 return sysconf(_SC_NPROCESSORS_ONLN);
275 #ifndef FIO_HAVE_GETTID
276 static inline int gettid(void)