Merge branch 'master' of ssh://brick.kernel.dk/data/git/fio
[fio.git] / os / os.h
1 #ifndef FIO_OS_H
2 #define FIO_OS_H
3
4 #if defined(__linux__)
5 #include "os-linux.h"
6 #elif defined(__FreeBSD__)
7 #include "os-freebsd.h"
8 #elif defined(__sun__)
9 #include "os-solaris.h"
10 #else
11 #error "unsupported os"
12 #endif
13
14 #ifdef FIO_HAVE_LIBAIO
15 #include <libaio.h>
16 #endif
17
18 #ifdef FIO_HAVE_POSIXAIO
19 #include <aio.h>
20 #endif
21
22 #ifdef FIO_HAVE_SGIO
23 #include <linux/fs.h>
24 #include <scsi/sg.h>
25 #endif
26
27 #ifndef FIO_HAVE_STRSEP
28 #include "../lib/strsep.h"
29 #endif
30
31 #ifndef FIO_HAVE_FADVISE
32 #define fadvise(fd, off, len, advice)   (0)
33
34 #ifndef POSIX_FADV_DONTNEED
35 #define POSIX_FADV_DONTNEED     (0)
36 #define POSIX_FADV_SEQUENTIAL   (0)
37 #define POSIX_FADV_RANDOM       (0)
38 #endif
39 #endif /* FIO_HAVE_FADVISE */
40
41 #ifndef FIO_HAVE_CPU_AFFINITY
42 #define fio_setaffinity(pid, mask)      (0)
43 #define fio_getaffinity(pid, mask)      do { } while (0)
44 #define fio_cpu_clear(mask, cpu)        do { } while (0)
45 #define fio_cpuset_exit(mask)           (-1)
46 #endif
47
48 #ifndef FIO_HAVE_IOPRIO
49 #define ioprio_set(which, who, prio)    (0)
50 #endif
51
52 #ifndef FIO_HAVE_ODIRECT
53 #define OS_O_DIRECT                     0
54 #else
55 #define OS_O_DIRECT                     O_DIRECT
56 #endif
57
58 #ifndef FIO_HAVE_HUGETLB
59 #define SHM_HUGETLB                     0
60 #ifndef FIO_HUGE_PAGE
61 #define FIO_HUGE_PAGE                   0
62 #endif
63 #else
64 #ifndef FIO_HUGE_PAGE
65 #define FIO_HUGE_PAGE                   4194304
66 #endif
67 #endif
68
69 #ifndef FIO_O_NOATIME
70 #define FIO_O_NOATIME                   0
71 #endif
72
73 #ifndef OS_RAND_MAX
74 #define OS_RAND_MAX                     RAND_MAX
75 #endif
76
77 #ifndef FIO_HAVE_RAWBIND
78 #define fio_lookup_raw(dev, majdev, mindev)     1
79 #endif
80
81 #ifndef FIO_HAVE_BLKTRACE
82 static inline int is_blktrace(const char *fname)
83 {
84         return 0;
85 }
86 struct thread_data;
87 static inline int load_blktrace(struct thread_data *td, const char *fname)
88 {
89         return 1;
90 }
91 #endif
92
93 #define FIO_DEF_CL_SIZE         128
94
95 static inline int os_cache_line_size(void)
96 {
97 #ifdef FIO_HAVE_CL_SIZE
98         int ret = arch_cache_line_size();
99
100         if (ret <= 0)
101                 return FIO_DEF_CL_SIZE;
102
103         return ret;
104 #else
105         return FIO_DEF_CL_SIZE;
106 #endif
107 }
108
109 #ifdef FIO_USE_GENERIC_BDEV_SIZE
110 static inline int blockdev_size(int fd, unsigned long long *bytes)
111 {
112         off_t end = lseek(fd, 0, SEEK_END);
113
114         if (end < 0)
115                 return errno;
116
117         *bytes = end;
118         return 0;
119 }
120 #endif
121
122 #endif