Make SH port work for packagers that don't differentiate between SH4 and SH4A
[fio.git] / os / os.h
... / ...
CommitLineData
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(__hpux)
22#include "os-hpux.h"
23#elif defined(__CYGWIN__)
24#include "os-windows.h"
25#else
26#error "unsupported os"
27#endif
28
29#ifdef FIO_HAVE_LIBAIO
30#include <libaio.h>
31#endif
32
33#ifdef FIO_HAVE_POSIXAIO
34#include <aio.h>
35#endif
36
37#ifdef FIO_HAVE_SGIO
38#include <linux/fs.h>
39#include <scsi/sg.h>
40#endif
41
42#ifndef FIO_HAVE_STRSEP
43#include "../lib/strsep.h"
44#endif
45
46#ifdef MSG_DONTWAIT
47#define OS_MSG_DONTWAIT MSG_DONTWAIT
48#endif
49
50#ifndef FIO_HAVE_FADVISE
51#define posix_fadvise(fd, off, len, advice) (0)
52
53#ifndef POSIX_FADV_DONTNEED
54#define POSIX_FADV_DONTNEED (0)
55#define POSIX_FADV_SEQUENTIAL (0)
56#define POSIX_FADV_RANDOM (0)
57#endif
58#endif /* FIO_HAVE_FADVISE */
59
60#ifndef FIO_HAVE_CPU_AFFINITY
61#define fio_setaffinity(pid, mask) (0)
62#define fio_getaffinity(pid, mask) do { } while (0)
63#define fio_cpu_clear(mask, cpu) do { } while (0)
64#define fio_cpuset_exit(mask) (-1)
65typedef unsigned long os_cpu_mask_t;
66#endif
67
68#ifndef FIO_HAVE_IOPRIO
69#define ioprio_set(which, who, prio) (0)
70#endif
71
72#ifndef FIO_HAVE_ODIRECT
73#define OS_O_DIRECT 0
74#else
75#define OS_O_DIRECT O_DIRECT
76#endif
77
78#ifndef FIO_HAVE_HUGETLB
79#define SHM_HUGETLB 0
80#ifndef FIO_HUGE_PAGE
81#define FIO_HUGE_PAGE 0
82#endif
83#else
84#ifndef FIO_HUGE_PAGE
85#define FIO_HUGE_PAGE 4194304
86#endif
87#endif
88
89#ifndef FIO_O_NOATIME
90#define FIO_O_NOATIME 0
91#endif
92
93#ifndef OS_RAND_MAX
94#define OS_RAND_MAX RAND_MAX
95#endif
96
97#ifdef FIO_HAVE_CLOCK_MONOTONIC
98#define FIO_TIMER_CLOCK CLOCK_MONOTONIC
99#else
100#define FIO_TIMER_CLOCK CLOCK_REALTIME
101#endif
102
103#ifndef FIO_HAVE_RAWBIND
104#define fio_lookup_raw(dev, majdev, mindev) 1
105#endif
106
107#ifndef FIO_PREFERRED_ENGINE
108#define FIO_PREFERRED_ENGINE "sync"
109#endif
110
111#ifndef FIO_MAX_JOBS
112#define FIO_MAX_JOBS 2048
113#endif
114
115#ifndef FIO_HAVE_BLKTRACE
116static inline int is_blktrace(const char *fname)
117{
118 return 0;
119}
120struct thread_data;
121static inline int load_blktrace(struct thread_data *td, const char *fname)
122{
123 return 1;
124}
125#endif
126
127#define FIO_DEF_CL_SIZE 128
128
129static inline int os_cache_line_size(void)
130{
131#ifdef FIO_HAVE_CL_SIZE
132 int ret = arch_cache_line_size();
133
134 if (ret <= 0)
135 return FIO_DEF_CL_SIZE;
136
137 return ret;
138#else
139 return FIO_DEF_CL_SIZE;
140#endif
141}
142
143#ifdef FIO_USE_GENERIC_BDEV_SIZE
144static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
145{
146 off_t end;
147
148 *bytes = 0;
149
150 end = lseek(f->fd, 0, SEEK_END);
151 if (end < 0)
152 return errno;
153
154 *bytes = end;
155 return 0;
156}
157#endif
158
159#ifdef FIO_USE_GENERIC_RAND
160typedef unsigned int os_random_state_t;
161
162static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
163{
164 srand(seed);
165}
166
167static inline long os_random_long(os_random_state_t *rs)
168{
169 long val;
170
171 val = rand_r(rs);
172 return val;
173}
174#endif
175
176#ifndef FIO_HAVE_FS_STAT
177static inline unsigned long long get_fs_size(const char *path)
178{
179 return 0;
180}
181#endif
182
183#ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
184static inline unsigned int cpus_online(void)
185{
186 return sysconf(_SC_NPROCESSORS_ONLN);
187}
188#endif
189
190#ifndef FIO_HAVE_GETTID
191static inline int gettid(void)
192{
193 return getpid();
194}
195#endif
196
197#endif