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