blob: 3df7b41be4b6447c73783abf03808b38ca2ee586 [file] [log] [blame]
Jens Axboeebac4652005-12-08 15:25:21 +01001#ifndef FIO_OS_H
2#define FIO_OS_H
3
Jens Axboea14ca442009-12-20 22:24:10 +01004#include <sys/types.h>
Bruce Cran03e20d62011-01-02 20:14:54 +01005#include <pthread.h>
Jens Axboea14ca442009-12-20 22:24:10 +01006#include <unistd.h>
Bruce Cranecc314b2011-01-04 10:59:30 +01007#include <stdlib.h>
Jens Axboea14ca442009-12-20 22:24:10 +01008
Jens Axboeebac4652005-12-08 15:25:21 +01009#if defined(__linux__)
10#include "os-linux.h"
11#elif defined(__FreeBSD__)
12#include "os-freebsd.h"
YAMAMOTO Takashi74524402010-05-12 15:06:46 +020013#elif defined(__NetBSD__)
14#include "os-netbsd.h"
Jens Axboe2c0ecd22006-06-08 13:25:41 +020015#elif defined(__sun__)
16#include "os-solaris.h"
Jens Axboe2afd8262009-12-14 23:08:42 +010017#elif defined(__APPLE__)
18#include "os-mac.h"
Cigy Cyriacbf2e8212010-08-10 19:51:11 -040019#elif defined(_AIX)
20#include "os-aix.h"
Jens Axboec00a2282011-07-08 20:56:06 +020021#elif defined(__hpux)
22#include "os-hpux.h"
Bruce Cran03e20d62011-01-02 20:14:54 +010023#elif defined(__CYGWIN__)
24#include "os-windows.h"
Jens Axboeebac4652005-12-08 15:25:21 +010025#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
Jens Axboe5921e802008-05-30 15:02:38 +020042#ifndef FIO_HAVE_STRSEP
Jens Axboe00fb3c82008-05-30 22:17:45 +020043#include "../lib/strsep.h"
Jens Axboe5921e802008-05-30 15:02:38 +020044#endif
45
Jens Axboe8e239ca2010-08-11 10:29:12 -040046#ifdef MSG_DONTWAIT
47#define OS_MSG_DONTWAIT MSG_DONTWAIT
48#endif
49
Jens Axboeebac4652005-12-08 15:25:21 +010050#ifndef FIO_HAVE_FADVISE
Bruce Cranecc314b2011-01-04 10:59:30 +010051#define posix_fadvise(fd, off, len, advice) (0)
Jens Axboeebac4652005-12-08 15:25:21 +010052
Shawn Lewis4d8947d2007-07-25 07:51:58 +020053#ifndef POSIX_FADV_DONTNEED
Jens Axboeebac4652005-12-08 15:25:21 +010054#define POSIX_FADV_DONTNEED (0)
55#define POSIX_FADV_SEQUENTIAL (0)
56#define POSIX_FADV_RANDOM (0)
Shawn Lewis4d8947d2007-07-25 07:51:58 +020057#endif
Jens Axboeebac4652005-12-08 15:25:21 +010058#endif /* FIO_HAVE_FADVISE */
59
60#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboee8462bd2009-07-06 12:59:04 +020061#define fio_setaffinity(pid, mask) (0)
Jens Axboebe4ecfd2008-12-08 14:10:52 +010062#define fio_getaffinity(pid, mask) do { } while (0)
63#define fio_cpu_clear(mask, cpu) do { } while (0)
Jens Axboe85daf2c2009-01-05 09:40:13 +010064#define fio_cpuset_exit(mask) (-1)
YAMAMOTO Takashi74524402010-05-12 15:06:46 +020065typedef unsigned long os_cpu_mask_t;
Jens Axboeebac4652005-12-08 15:25:21 +010066#endif
67
68#ifndef FIO_HAVE_IOPRIO
69#define ioprio_set(which, who, prio) (0)
70#endif
71
Jens Axboe2c0ecd22006-06-08 13:25:41 +020072#ifndef FIO_HAVE_ODIRECT
Jens Axboe7d424762006-06-08 13:26:31 +020073#define OS_O_DIRECT 0
74#else
75#define OS_O_DIRECT O_DIRECT
Jens Axboe2c0ecd22006-06-08 13:25:41 +020076#endif
77
Jens Axboe74b025b2006-12-19 15:18:14 +010078#ifndef FIO_HAVE_HUGETLB
79#define SHM_HUGETLB 0
Shawn Lewis4d8947d2007-07-25 07:51:58 +020080#ifndef FIO_HUGE_PAGE
Jens Axboe74b025b2006-12-19 15:18:14 +010081#define FIO_HUGE_PAGE 0
Shawn Lewis4d8947d2007-07-25 07:51:58 +020082#endif
Jens Axboe74b025b2006-12-19 15:18:14 +010083#else
Jens Axboecb25df62007-03-23 08:23:30 +010084#ifndef FIO_HUGE_PAGE
Jens Axboeee0e0a72007-03-19 10:50:47 +010085#define FIO_HUGE_PAGE 4194304
Jens Axboe74b025b2006-12-19 15:18:14 +010086#endif
Jens Axboecb25df62007-03-23 08:23:30 +010087#endif
Jens Axboe74b025b2006-12-19 15:18:14 +010088
Jens Axboe5921e802008-05-30 15:02:38 +020089#ifndef FIO_O_NOATIME
90#define FIO_O_NOATIME 0
91#endif
92
Jens Axboedc873b62008-06-04 20:13:04 +020093#ifndef OS_RAND_MAX
94#define OS_RAND_MAX RAND_MAX
95#endif
96
Bruce Cranecc314b2011-01-04 10:59:30 +010097#ifdef FIO_HAVE_CLOCK_MONOTONIC
98#define FIO_TIMER_CLOCK CLOCK_MONOTONIC
99#else
100#define FIO_TIMER_CLOCK CLOCK_REALTIME
101#endif
102
Jens Axboe07e5b262007-04-02 14:46:07 +0200103#ifndef FIO_HAVE_RAWBIND
Jens Axboe8cc7afa2007-04-17 09:06:43 +0200104#define fio_lookup_raw(dev, majdev, mindev) 1
Jens Axboe07e5b262007-04-02 14:46:07 +0200105#endif
106
Jens Axboe58483fa2011-01-19 11:09:58 -0700107#ifndef FIO_PREFERRED_ENGINE
108#define FIO_PREFERRED_ENGINE "sync"
109#endif
110
Jens Axboefca70352011-07-06 20:12:54 +0200111#ifndef FIO_MAX_JOBS
112#define FIO_MAX_JOBS 2048
113#endif
114
Jens Axboe5e62c222007-05-22 13:27:30 +0200115#ifndef FIO_HAVE_BLKTRACE
116static inline int is_blktrace(const char *fname)
117{
118 return 0;
119}
Jens Axboe5921e802008-05-30 15:02:38 +0200120struct thread_data;
Jens Axboe5e62c222007-05-22 13:27:30 +0200121static inline int load_blktrace(struct thread_data *td, const char *fname)
122{
123 return 1;
124}
125#endif
126
Jens Axboeeb7ccf32009-04-29 09:48:04 +0200127#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
Jens Axboe792d5512009-09-22 17:12:29 +0200143#ifdef FIO_USE_GENERIC_BDEV_SIZE
Bruce Cranecc314b2011-01-04 10:59:30 +0100144static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
Jens Axboe792d5512009-09-22 17:12:29 +0200145{
Jens Axboe3b2e1462009-12-15 08:58:10 +0100146 off_t end;
Jens Axboe792d5512009-09-22 17:12:29 +0200147
Jens Axboe3b2e1462009-12-15 08:58:10 +0100148 *bytes = 0;
149
Bruce Cranecc314b2011-01-04 10:59:30 +0100150 end = lseek(f->fd, 0, SEEK_END);
Jens Axboe792d5512009-09-22 17:12:29 +0200151 if (end < 0)
152 return errno;
153
154 *bytes = end;
155 return 0;
156}
157#endif
158
Jens Axboe53531372009-12-15 10:28:37 +0100159#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
Jens Axboe2e3bd4c2010-05-17 12:29:57 +0200176#ifndef FIO_HAVE_FS_STAT
177static inline unsigned long long get_fs_size(const char *path)
178{
179 return 0;
180}
181#endif
182
Jens Axboec00a2282011-07-08 20:56:06 +0200183#ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
184static inline unsigned int cpus_online(void)
185{
186 return sysconf(_SC_NPROCESSORS_ONLN);
187}
188#endif
189
Jens Axboeebac4652005-12-08 15:25:21 +0100190#endif