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