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;
69 #include "../oslib/strsep.h"
72 #ifndef CONFIG_STRLCAT
73 #include "../oslib/strlcat.h"
77 #define OS_MSG_DONTWAIT MSG_DONTWAIT
80 #ifndef POSIX_FADV_DONTNEED
81 #define POSIX_FADV_DONTNEED (0)
82 #define POSIX_FADV_SEQUENTIAL (0)
83 #define POSIX_FADV_RANDOM (0)
84 #define POSIX_FADV_NORMAL (0)
87 #ifndef FIO_HAVE_CPU_AFFINITY
88 #define fio_cpu_clear(mask, cpu) do { } while (0)
89 typedef unsigned long os_cpu_mask_t;
91 static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
96 static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
101 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
106 static inline int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu_index)
111 extern int fio_cpus_split(os_cpu_mask_t *mask, unsigned int cpu);
114 #ifndef FIO_HAVE_IOPRIO
115 #define ioprio_set(which, who, prioclass, prio) (0)
118 #ifndef FIO_HAVE_ODIRECT
119 #define OS_O_DIRECT 0
121 #define OS_O_DIRECT O_DIRECT
125 #define FIO_O_ATOMIC OS_O_ATOMIC
127 #define FIO_O_ATOMIC 0
130 #ifndef FIO_HAVE_HUGETLB
131 #define SHM_HUGETLB 0
132 #define MAP_HUGETLB 0
133 #ifndef FIO_HUGE_PAGE
134 #define FIO_HUGE_PAGE 0
137 #ifndef FIO_HUGE_PAGE
138 #define FIO_HUGE_PAGE 4194304
142 #ifndef FIO_HAVE_MMAP_HUGE
143 #define MAP_HUGETLB 0
146 #ifndef FIO_O_NOATIME
147 #define FIO_O_NOATIME 0
151 #define OS_RAND_MAX RAND_MAX
154 #ifndef FIO_HAVE_RAWBIND
155 #define fio_lookup_raw(dev, majdev, mindev) 1
158 #ifndef FIO_PREFERRED_ENGINE
159 #define FIO_PREFERRED_ENGINE "psync"
162 #ifndef FIO_OS_PATH_SEPARATOR
163 #define FIO_OS_PATH_SEPARATOR "/"
166 #ifndef FIO_PREFERRED_CLOCK_SOURCE
167 #ifdef CONFIG_CLOCK_GETTIME
168 #define FIO_PREFERRED_CLOCK_SOURCE CS_CGETTIME
170 #define FIO_PREFERRED_CLOCK_SOURCE CS_GTOD
175 #define FIO_MAX_JOBS 4096
178 #ifndef CONFIG_SOCKLEN_T
179 typedef unsigned int socklen_t;
182 #ifndef FIO_OS_HAS_CTIME_R
183 #define os_ctime_r(x, y, z) (void) ctime_r((x), (y))
186 #ifdef FIO_USE_GENERIC_SWAP
187 static inline uint16_t fio_swap16(uint16_t val)
189 return (val << 8) | (val >> 8);
192 static inline uint32_t fio_swap32(uint32_t val)
194 val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
196 return (val >> 16) | (val << 16);
199 static inline uint64_t fio_swap64(uint64_t val)
201 val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
202 ((val & 0x00ff00ff00ff00ffULL) << 8);
203 val = ((val & 0xffff0000ffff0000ULL) >> 16) |
204 ((val & 0x0000ffff0000ffffULL) << 16);
206 return (val >> 32) | (val << 32);
210 #ifndef FIO_HAVE_BYTEORDER_FUNCS
211 #ifdef CONFIG_LITTLE_ENDIAN
212 #define __le16_to_cpu(x) (x)
213 #define __le32_to_cpu(x) (x)
214 #define __le64_to_cpu(x) (x)
215 #define __cpu_to_le16(x) (x)
216 #define __cpu_to_le32(x) (x)
217 #define __cpu_to_le64(x) (x)
219 #define __le16_to_cpu(x) fio_swap16(x)
220 #define __le32_to_cpu(x) fio_swap32(x)
221 #define __le64_to_cpu(x) fio_swap64(x)
222 #define __cpu_to_le16(x) fio_swap16(x)
223 #define __cpu_to_le32(x) fio_swap32(x)
224 #define __cpu_to_le64(x) fio_swap64(x)
226 #endif /* FIO_HAVE_BYTEORDER_FUNCS */
229 #define le16_to_cpu(val) ({ \
230 typecheck(uint16_t, val); \
231 __le16_to_cpu(val); \
233 #define le32_to_cpu(val) ({ \
234 typecheck(uint32_t, val); \
235 __le32_to_cpu(val); \
237 #define le64_to_cpu(val) ({ \
238 typecheck(uint64_t, val); \
239 __le64_to_cpu(val); \
243 #define cpu_to_le16(val) ({ \
244 typecheck(uint16_t, val); \
245 __cpu_to_le16(val); \
247 #define cpu_to_le32(val) ({ \
248 typecheck(uint32_t, val); \
249 __cpu_to_le32(val); \
251 #define cpu_to_le64(val) ({ \
252 typecheck(uint64_t, val); \
253 __cpu_to_le64(val); \
256 #ifndef FIO_HAVE_BLKTRACE
257 static inline int is_blktrace(const char *fname, int *need_swap)
262 static inline int load_blktrace(struct thread_data *td, const char *fname,
269 #define FIO_DEF_CL_SIZE 128
271 static inline int os_cache_line_size(void)
273 #ifdef FIO_HAVE_CL_SIZE
274 int ret = arch_cache_line_size();
277 return FIO_DEF_CL_SIZE;
281 return FIO_DEF_CL_SIZE;
285 #ifdef FIO_USE_GENERIC_BDEV_SIZE
286 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
292 end = lseek(f->fd, 0, SEEK_END);
301 #ifdef FIO_USE_GENERIC_RAND
302 typedef unsigned int os_random_state_t;
304 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
309 static inline long os_random_long(os_random_state_t *rs)
318 #ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE
319 extern void td_fill_rand_seeds(struct thread_data *td);
321 * Initialize the various random states we need (random io, block size ranges,
322 * read/write mix, etc).
324 static inline int init_random_state(struct thread_data *td, unsigned long *rand_seeds, int size)
328 fd = open("/dev/urandom", O_RDONLY);
333 if (read(fd, rand_seeds, size) < size) {
339 td_fill_rand_seeds(td);
344 #ifndef FIO_HAVE_FS_STAT
345 static inline unsigned long long get_fs_free_size(const char *path)
352 #define FIO_HAVE_CPU_ONLINE_SYSCONF
353 static inline unsigned int cpus_online(void)
355 return sysconf(_SC_NPROCESSORS_CONF);
359 #ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
360 static inline unsigned int cpus_online(void)
362 return sysconf(_SC_NPROCESSORS_ONLN);
367 #ifdef FIO_HAVE_CPU_AFFINITY
368 static inline int CPU_COUNT(os_cpu_mask_t *mask)
370 int max_cpus = cpus_online();
373 for (i = 0, nr_cpus = 0; i < max_cpus; i++)
374 if (fio_cpu_isset(mask, i))
382 #ifndef FIO_HAVE_GETTID
383 static inline int gettid(void)
389 #ifndef FIO_HAVE_SHM_ATTACH_REMOVED
390 static inline int shm_attach_to_open_removed(void)