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