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