os.h revision 86e53416e5758d56e950af6cfbe407065ef36879
1dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_OS_H
2dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define FIO_OS_H
3dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
4dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <sys/types.h>
5dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <sys/socket.h>
6dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <fcntl.h>
7dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <pthread.h>
8dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <unistd.h>
9dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <stdlib.h>
10dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
11dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixterenum {
12dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	os_linux = 1,
13dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	os_aix,
14dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	os_freebsd,
15dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	os_hpux,
16dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	os_mac,
1746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	os_netbsd,
1846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	os_solaris,
1946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	os_windows,
2046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	os_android,
21dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
22dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	os_nr,
23dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter};
24dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
25dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#if defined(__ANDROID__)
26dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-android.h"
27dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#elif defined(__linux__)
28dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-linux.h"
29dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#elif defined(__FreeBSD__)
30dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-freebsd.h"
31dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#elif defined(__NetBSD__)
32dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-netbsd.h"
33dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#elif defined(__sun__)
34dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-solaris.h"
35dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#elif defined(__APPLE__)
36dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-mac.h"
37dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#elif defined(_AIX)
38dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-aix.h"
39dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#elif defined(__hpux)
40dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-hpux.h"
41dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#elif defined(WIN32)
42dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include "os-windows.h"
43dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#else
44dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#error "unsupported os"
45dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
46dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
47dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifdef CONFIG_POSIXAIO
48dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <aio.h>
49dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_OS_HAVE_AIOCB_TYPEDEF
50dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixtertypedef struct aiocb os_aiocb_t;
51dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
52dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
53dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
54dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifdef FIO_HAVE_SGIO
55dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <linux/fs.h>
56dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#include <scsi/sg.h>
5746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
5846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
5946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef CONFIG_STRSEP
6046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#include "../lib/strsep.h"
6146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
6246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
6346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifdef MSG_DONTWAIT
6446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define OS_MSG_DONTWAIT	MSG_DONTWAIT
6546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
6646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
6746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef POSIX_FADV_DONTNEED
6846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define POSIX_FADV_DONTNEED	(0)
6946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define POSIX_FADV_SEQUENTIAL	(0)
7046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define POSIX_FADV_RANDOM	(0)
7146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
7246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
7346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_HAVE_CPU_AFFINITY
7446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define fio_setaffinity(pid, mask)	(0)
7546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define fio_getaffinity(pid, mask)	do { } while (0)
7646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define fio_cpu_clear(mask, cpu)	do { } while (0)
77dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define fio_cpuset_exit(mask)		(-1)
78dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixtertypedef unsigned long os_cpu_mask_t;
79dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
80dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
8146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_HAVE_IOPRIO
82dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define ioprio_set(which, who, prio)	(0)
83dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
84dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
8546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_HAVE_ODIRECT
86dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define OS_O_DIRECT			0
87dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#else
88dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define OS_O_DIRECT			O_DIRECT
8946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
9046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
91dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_HAVE_HUGETLB
9246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define SHM_HUGETLB			0
93dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define MAP_HUGETLB			0
94dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_HUGE_PAGE
95dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define FIO_HUGE_PAGE			0
9646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
9746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#else
98dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_HUGE_PAGE
9946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define FIO_HUGE_PAGE			4194304
100dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
101dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
102dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
10346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_HAVE_MMAP_HUGE
10446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define MAP_HUGETLB			0
105dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
10646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
107dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_O_NOATIME
108dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define FIO_O_NOATIME			0
109dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
11046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
11146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef OS_RAND_MAX
112dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define OS_RAND_MAX			RAND_MAX
11346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
114dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
115dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_HAVE_RAWBIND
116dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define fio_lookup_raw(dev, majdev, mindev)	1
11746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
11846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
119dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_PREFERRED_ENGINE
12046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define FIO_PREFERRED_ENGINE	"sync"
121dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
122dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
123dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_OS_PATH_SEPARATOR
12446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define FIO_OS_PATH_SEPARATOR	"/"
12546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
126dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
12746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_PREFERRED_CLOCK_SOURCE
128dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifdef CONFIG_CLOCK_GETTIME
129dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define FIO_PREFERRED_CLOCK_SOURCE	CS_CGETTIME
130dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#else
13146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define FIO_PREFERRED_CLOCK_SOURCE	CS_GTOD
13246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
133dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
13446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
135dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_MAX_JOBS
136dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define FIO_MAX_JOBS		2048
137dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#endif
13846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
13946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef CONFIG_SOCKLEN_T
140dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixtertypedef unsigned int socklen_t;
14146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
142dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
143dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_OS_HAS_CTIME_R
144dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define os_ctime_r(x, y, z)     (void) ctime_r((x), (y))
14546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
14646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
147dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifdef FIO_USE_GENERIC_SWAP
14846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline uint16_t fio_swap16(uint16_t val)
149dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter{
150dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	return (val << 8) | (val >> 8);
151dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter}
152dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
15346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline uint32_t fio_swap32(uint32_t val)
154dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter{
15546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
156dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
157dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	return (val >> 16) | (val << 16);
158dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter}
159dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
16046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline uint64_t fio_swap64(uint64_t val)
161dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter{
16246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
163dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	      ((val & 0x00ff00ff00ff00ffULL) << 8);
164dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	val = ((val & 0xffff0000ffff0000ULL) >> 16) |
165dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	      ((val & 0x0000ffff0000ffffULL) << 16);
16646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
16746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return (val >> 32) | (val << 32);
168dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter}
16946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
170dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
171dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifndef FIO_HAVE_BYTEORDER_FUNCS
172dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifdef CONFIG_LITTLE_ENDIAN
17346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __le16_to_cpu(x)		(x)
17446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __le32_to_cpu(x)		(x)
175dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#define __le64_to_cpu(x)		(x)
17646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __cpu_to_le16(x)		(x)
17746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __cpu_to_le32(x)		(x)
17846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __cpu_to_le64(x)		(x)
17946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#else
18046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __le16_to_cpu(x)		fio_swap16(x)
18146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __le32_to_cpu(x)		fio_swap32(x)
18246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __le64_to_cpu(x)		fio_swap64(x)
18346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __cpu_to_le16(x)		fio_swap16(x)
18446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __cpu_to_le32(x)		fio_swap32(x)
18546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define __cpu_to_le64(x)		fio_swap64(x)
18646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
18746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif /* FIO_HAVE_BYTEORDER_FUNCS */
18846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
18946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define le16_to_cpu(val) ({			\
19046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	uint16_t *__val = &(val);		\
19146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	__le16_to_cpu(*__val);			\
19246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan})
19346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define le32_to_cpu(val) ({			\
19446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	uint32_t *__val = &(val);		\
19546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	__le32_to_cpu(*__val);			\
19646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan})
19746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define le64_to_cpu(val) ({			\
198dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	uint64_t *__val = &(val);		\
19946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	__le64_to_cpu(*__val);			\
20046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan})
20146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define cpu_to_le16(val) ({			\
20246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	uint16_t *__val = &(val);		\
20346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	__cpu_to_le16(*__val);			\
20446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan})
20546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define cpu_to_le32(val) ({			\
20646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	uint32_t *__val = &(val);		\
20746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	__cpu_to_le32(*__val);			\
20846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan})
20946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define cpu_to_le64(val) ({			\
21046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	uint64_t *__val = &(val);		\
21146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	__cpu_to_le64(*__val);			\
21246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan})
21346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
21446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_HAVE_BLKTRACE
21546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline int is_blktrace(const char *fname)
21646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
21746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return 0;
21846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
21946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstruct thread_data;
22046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline int load_blktrace(struct thread_data *td, const char *fname)
22146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
22246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return 1;
22346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
22446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
22546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
22646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#define FIO_DEF_CL_SIZE		128
22746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
22846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline int os_cache_line_size(void)
22946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
23046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifdef FIO_HAVE_CL_SIZE
23146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	int ret = arch_cache_line_size();
23246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
23346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	if (ret <= 0)
23446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan		return FIO_DEF_CL_SIZE;
23546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
23646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return ret;
23746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#else
23846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return FIO_DEF_CL_SIZE;
23946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
24046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
24146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
24246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifdef FIO_USE_GENERIC_BDEV_SIZE
24346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
24446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
24546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	off_t end;
24646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
24746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	*bytes = 0;
24846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
24946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	end = lseek(f->fd, 0, SEEK_END);
25046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	if (end < 0)
25146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan		return errno;
25246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
25346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	*bytes = end;
25446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return 0;
25546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
25646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
25746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
258dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter#ifdef FIO_USE_GENERIC_RAND
25946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chantypedef unsigned int os_random_state_t;
26046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
26146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
26246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
26346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	srand(seed);
26446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
26546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
26646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline long os_random_long(os_random_state_t *rs)
267dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter{
26846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	long val;
26946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
27046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	val = rand_r(rs);
27146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return val;
27246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
27346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
27446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
27546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE
276dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixterextern void td_fill_rand_seeds(struct thread_data *td);
27746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan/*
27846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan * Initialize the various random states we need (random io, block size ranges,
27946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan * read/write mix, etc).
28046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan */
28146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline int init_random_state(struct thread_data *td, unsigned long *rand_seeds, int size)
28246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
28346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	int fd;
28446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
285dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter	fd = open("/dev/urandom", O_RDONLY);
28646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	if (fd == -1) {
28746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan		return 1;
28846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	}
28946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
29046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	if (read(fd, rand_seeds, size) < size) {
29146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan		close(fd);
29246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan		return 1;
29346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	}
29446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
29546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	close(fd);
29646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	td_fill_rand_seeds(td);
29746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return 0;
29846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
29946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
30046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
30146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_HAVE_FS_STAT
302dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixterstatic inline unsigned long long get_fs_size(const char *path)
30346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
30446108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return 0;
30546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
30646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
30746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
30846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_HAVE_CPU_ONLINE_SYSCONF
30946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline unsigned int cpus_online(void)
31046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
31146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return sysconf(_SC_NPROCESSORS_ONLN);
31246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
31346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
314dd1c93d5709e32713961cfd95fe30489a4ad2d26Ken Mixter
31546108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#ifndef FIO_HAVE_GETTID
31646108a219a4b812dd8f36fee479a0340ea5963f5Ben Chanstatic inline int gettid(void)
31746108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan{
31846108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan	return getpid();
31946108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan}
32046108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
32146108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan
32246108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan#endif
32346108a219a4b812dd8f36fee479a0340ea5963f5Ben Chan