Include fio version in normal output
[fio.git] / os / os.h
... / ...
CommitLineData
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#ifdef MSG_DONTWAIT
41#define OS_MSG_DONTWAIT MSG_DONTWAIT
42#endif
43
44#ifndef FIO_HAVE_FADVISE
45#define fadvise(fd, off, len, advice) (0)
46
47#ifndef POSIX_FADV_DONTNEED
48#define POSIX_FADV_DONTNEED (0)
49#define POSIX_FADV_SEQUENTIAL (0)
50#define POSIX_FADV_RANDOM (0)
51#endif
52#endif /* FIO_HAVE_FADVISE */
53
54#ifndef FIO_HAVE_CPU_AFFINITY
55#define fio_setaffinity(pid, mask) (0)
56#define fio_getaffinity(pid, mask) do { } while (0)
57#define fio_cpu_clear(mask, cpu) do { } while (0)
58#define fio_cpuset_exit(mask) (-1)
59typedef unsigned long os_cpu_mask_t;
60#endif
61
62#ifndef FIO_HAVE_IOPRIO
63#define ioprio_set(which, who, prio) (0)
64#endif
65
66#ifndef FIO_HAVE_ODIRECT
67#define OS_O_DIRECT 0
68#else
69#define OS_O_DIRECT O_DIRECT
70#endif
71
72#ifndef FIO_HAVE_HUGETLB
73#define SHM_HUGETLB 0
74#ifndef FIO_HUGE_PAGE
75#define FIO_HUGE_PAGE 0
76#endif
77#else
78#ifndef FIO_HUGE_PAGE
79#define FIO_HUGE_PAGE 4194304
80#endif
81#endif
82
83#ifndef FIO_O_NOATIME
84#define FIO_O_NOATIME 0
85#endif
86
87#ifndef OS_RAND_MAX
88#define OS_RAND_MAX RAND_MAX
89#endif
90
91#ifndef FIO_HAVE_RAWBIND
92#define fio_lookup_raw(dev, majdev, mindev) 1
93#endif
94
95#ifndef FIO_HAVE_BLKTRACE
96static inline int is_blktrace(const char *fname)
97{
98 return 0;
99}
100struct thread_data;
101static inline int load_blktrace(struct thread_data *td, const char *fname)
102{
103 return 1;
104}
105#endif
106
107#define FIO_DEF_CL_SIZE 128
108
109static inline int os_cache_line_size(void)
110{
111#ifdef FIO_HAVE_CL_SIZE
112 int ret = arch_cache_line_size();
113
114 if (ret <= 0)
115 return FIO_DEF_CL_SIZE;
116
117 return ret;
118#else
119 return FIO_DEF_CL_SIZE;
120#endif
121}
122
123#ifdef FIO_USE_GENERIC_BDEV_SIZE
124static inline int blockdev_size(int fd, unsigned long long *bytes)
125{
126 off_t end;
127
128 *bytes = 0;
129
130 end = lseek(fd, 0, SEEK_END);
131 if (end < 0)
132 return errno;
133
134 *bytes = end;
135 return 0;
136}
137#endif
138
139#ifdef FIO_USE_GENERIC_RAND
140typedef unsigned int os_random_state_t;
141
142static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
143{
144 srand(seed);
145}
146
147static inline long os_random_long(os_random_state_t *rs)
148{
149 long val;
150
151 val = rand_r(rs);
152 return val;
153}
154#endif
155
156#ifndef FIO_HAVE_FS_STAT
157static inline unsigned long long get_fs_size(const char *path)
158{
159 return 0;
160}
161#endif
162
163#endif