os.h revision 836fcc0fceb233ebcc41ee63b4ea5cae20b678a4
1ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_OS_H 2ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define FIO_OS_H 3ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 4a14ca44ada0708be91ed7741a32176bef4801cc4Jens Axboe#include <sys/types.h> 5203913ea773a19dce4a885204e9d7681b89429feBruce Cran#include <sys/socket.h> 693bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran#include <fcntl.h> 703e20d687566753b90383571e5e152c5142bdffdBruce Cran#include <pthread.h> 8a14ca44ada0708be91ed7741a32176bef4801cc4Jens Axboe#include <unistd.h> 9ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6feBruce Cran#include <stdlib.h> 10a14ca44ada0708be91ed7741a32176bef4801cc4Jens Axboe 11836fcc0fceb233ebcc41ee63b4ea5cae20b678a4Jens Axboe#include "../arch/arch.h" 12836fcc0fceb233ebcc41ee63b4ea5cae20b678a4Jens Axboe 13cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboeenum { 14cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_linux = 1, 15cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_aix, 16cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_freebsd, 17cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_hpux, 18cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_mac, 19cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_netbsd, 20cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_solaris, 21cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_windows, 22ec5c6b125c1eab992882602158bab54957aa733dAaron Carroll os_android, 23cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe 24cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe os_nr, 25cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe}; 26cca84643cc10cd72b0b453ff92ccb8643ba51493Jens Axboe 27ec5c6b125c1eab992882602158bab54957aa733dAaron Carroll#if defined(__ANDROID__) 28ec5c6b125c1eab992882602158bab54957aa733dAaron Carroll#include "os-android.h" 29ec5c6b125c1eab992882602158bab54957aa733dAaron Carroll#elif defined(__linux__) 30ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include "os-linux.h" 31ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#elif defined(__FreeBSD__) 32ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include "os-freebsd.h" 337452440e1efb40680fdc951eebc7499a95a62f86YAMAMOTO Takashi#elif defined(__NetBSD__) 347452440e1efb40680fdc951eebc7499a95a62f86YAMAMOTO Takashi#include "os-netbsd.h" 352c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe#elif defined(__sun__) 362c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe#include "os-solaris.h" 372afd826bf6cd19900aee70ae14ede92d91b6f4c0Jens Axboe#elif defined(__APPLE__) 382afd826bf6cd19900aee70ae14ede92d91b6f4c0Jens Axboe#include "os-mac.h" 39bf2e821a55d8aa3de1cda7288a0e22883110fdc6Cigy Cyriac#elif defined(_AIX) 40bf2e821a55d8aa3de1cda7288a0e22883110fdc6Cigy Cyriac#include "os-aix.h" 41c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboe#elif defined(__hpux) 42c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboe#include "os-hpux.h" 4393bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran#elif defined(WIN32) 4403e20d687566753b90383571e5e152c5142bdffdBruce Cran#include "os-windows.h" 45ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#else 46ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#error "unsupported os" 47ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 48ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 4967bf982340d95ca98098ea050b54b4c7adb116c0Jens Axboe#ifdef CONFIG_POSIXAIO 50ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <aio.h> 51e97c14423a5688d7adfb342c16363c263cb741f9Jens Axboe#ifndef FIO_OS_HAVE_AIOCB_TYPEDEF 52e97c14423a5688d7adfb342c16363c263cb741f9Jens Axboetypedef struct aiocb os_aiocb_t; 53e97c14423a5688d7adfb342c16363c263cb741f9Jens Axboe#endif 54ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 55ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 56ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifdef FIO_HAVE_SGIO 57ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <linux/fs.h> 58ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <scsi/sg.h> 59ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 60ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 6167bf982340d95ca98098ea050b54b4c7adb116c0Jens Axboe#ifdef CONFIG_STRSEP 6200fb3c8dcbb940338fea9f6cab689b4924266305Jens Axboe#include "../lib/strsep.h" 635921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 645921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe 658e239cae8aae89f07a885ffcc985600ce9c65d5dJens Axboe#ifdef MSG_DONTWAIT 668e239cae8aae89f07a885ffcc985600ce9c65d5dJens Axboe#define OS_MSG_DONTWAIT MSG_DONTWAIT 678e239cae8aae89f07a885ffcc985600ce9c65d5dJens Axboe#endif 688e239cae8aae89f07a885ffcc985600ce9c65d5dJens Axboe 694d8947de2b50578a4f6290be567cb5de5bf46776Shawn Lewis#ifndef POSIX_FADV_DONTNEED 70ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define POSIX_FADV_DONTNEED (0) 71ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define POSIX_FADV_SEQUENTIAL (0) 72ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define POSIX_FADV_RANDOM (0) 734d8947de2b50578a4f6290be567cb5de5bf46776Shawn Lewis#endif 74ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 75ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_CPU_AFFINITY 76e8462bd8250cf3ff2d41f17e1a4d4cefc70b6b37Jens Axboe#define fio_setaffinity(pid, mask) (0) 77be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe#define fio_getaffinity(pid, mask) do { } while (0) 78be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe#define fio_cpu_clear(mask, cpu) do { } while (0) 7985daf2c1102ed4fdf1477cfd372046efbe08046eJens Axboe#define fio_cpuset_exit(mask) (-1) 807452440e1efb40680fdc951eebc7499a95a62f86YAMAMOTO Takashitypedef unsigned long os_cpu_mask_t; 81ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 82ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 83ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_IOPRIO 8428727df79348d4ebbd8fd4b0dd89bbca035f68d0Jens Axboe#define ioprio_set(which, who, prioclass, prio) (0) 85ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 86ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 872c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe#ifndef FIO_HAVE_ODIRECT 887d4247639268fdcc1769fc57564d79791042950dJens Axboe#define OS_O_DIRECT 0 897d4247639268fdcc1769fc57564d79791042950dJens Axboe#else 907d4247639268fdcc1769fc57564d79791042950dJens Axboe#define OS_O_DIRECT O_DIRECT 912c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe#endif 922c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe 9374b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#ifndef FIO_HAVE_HUGETLB 9474b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#define SHM_HUGETLB 0 95d6dc02fbe47fa6b4752df7a2ed52447506d68b45Jens Axboe#define MAP_HUGETLB 0 964d8947de2b50578a4f6290be567cb5de5bf46776Shawn Lewis#ifndef FIO_HUGE_PAGE 9774b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#define FIO_HUGE_PAGE 0 984d8947de2b50578a4f6290be567cb5de5bf46776Shawn Lewis#endif 9974b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#else 100cb25df61fbe19065b41bee131d19335d615c676bJens Axboe#ifndef FIO_HUGE_PAGE 101ee0e0a718f069fae189be800c2a6e2f5c28ff9f0Jens Axboe#define FIO_HUGE_PAGE 4194304 10274b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#endif 103cb25df61fbe19065b41bee131d19335d615c676bJens Axboe#endif 10474b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe 10539b9356872f27c1a48a2ab09a5252dffd1de22d2Jens Axboe#ifndef FIO_HAVE_MMAP_HUGE 10639b9356872f27c1a48a2ab09a5252dffd1de22d2Jens Axboe#define MAP_HUGETLB 0 10739b9356872f27c1a48a2ab09a5252dffd1de22d2Jens Axboe#endif 10839b9356872f27c1a48a2ab09a5252dffd1de22d2Jens Axboe 1095921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#ifndef FIO_O_NOATIME 1105921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#define FIO_O_NOATIME 0 1115921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 1125921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe 113dc873b6f4a536c332b72cce268d5a7ccd356a891Jens Axboe#ifndef OS_RAND_MAX 114dc873b6f4a536c332b72cce268d5a7ccd356a891Jens Axboe#define OS_RAND_MAX RAND_MAX 115dc873b6f4a536c332b72cce268d5a7ccd356a891Jens Axboe#endif 116dc873b6f4a536c332b72cce268d5a7ccd356a891Jens Axboe 11707e5b2646f673a56c05a53c6a84bf5d0c949d290Jens Axboe#ifndef FIO_HAVE_RAWBIND 1188cc7afa91ddc5a0980b9d2dbfdd66e1511a0d4b1Jens Axboe#define fio_lookup_raw(dev, majdev, mindev) 1 11907e5b2646f673a56c05a53c6a84bf5d0c949d290Jens Axboe#endif 12007e5b2646f673a56c05a53c6a84bf5d0c949d290Jens Axboe 12158483fa41bb08def4dbd3c4c9624116b643c7599Jens Axboe#ifndef FIO_PREFERRED_ENGINE 12258483fa41bb08def4dbd3c4c9624116b643c7599Jens Axboe#define FIO_PREFERRED_ENGINE "sync" 12358483fa41bb08def4dbd3c4c9624116b643c7599Jens Axboe#endif 12458483fa41bb08def4dbd3c4c9624116b643c7599Jens Axboe 125b9fd788f0e8adacc33316107594e9eb0463743d7Bruce Cran#ifndef FIO_OS_PATH_SEPARATOR 126b9fd788f0e8adacc33316107594e9eb0463743d7Bruce Cran#define FIO_OS_PATH_SEPARATOR "/" 127b9fd788f0e8adacc33316107594e9eb0463743d7Bruce Cran#endif 128b9fd788f0e8adacc33316107594e9eb0463743d7Bruce Cran 12916de1bf91ca80e62ce257a24cae471fab140bbe0Bruce Cran#ifndef FIO_PREFERRED_CLOCK_SOURCE 13016de1bf91ca80e62ce257a24cae471fab140bbe0Bruce Cran#define FIO_PREFERRED_CLOCK_SOURCE CS_CGETTIME 13116de1bf91ca80e62ce257a24cae471fab140bbe0Bruce Cran#endif 13216de1bf91ca80e62ce257a24cae471fab140bbe0Bruce Cran 133fca7035863bd570270376a0c06776e5549ff813eJens Axboe#ifndef FIO_MAX_JOBS 134fca7035863bd570270376a0c06776e5549ff813eJens Axboe#define FIO_MAX_JOBS 2048 135fca7035863bd570270376a0c06776e5549ff813eJens Axboe#endif 136fca7035863bd570270376a0c06776e5549ff813eJens Axboe 13767bf982340d95ca98098ea050b54b4c7adb116c0Jens Axboe#ifndef CONFIG_SOCKLEN_T 13867bf982340d95ca98098ea050b54b4c7adb116c0Jens Axboetypedef unsigned int socklen_t; 1395ba13ea6968cf2773f10d34376afe28ef81aeee5Jens Axboe#endif 1405ba13ea6968cf2773f10d34376afe28ef81aeee5Jens Axboe 14145054cbec0e624de3b79a795d7dfe1c64cdea934Saurabh De#ifndef FIO_OS_HAS_CTIME_R 1421f81991ed356dd7257aef2c715ba9a24d9af93a5Jens Axboe#define os_ctime_r(x, y, z) (void) ctime_r((x), (y)) 14345054cbec0e624de3b79a795d7dfe1c64cdea934Saurabh De#endif 14445054cbec0e624de3b79a795d7dfe1c64cdea934Saurabh De 145901ebe18bdca90032e2fe107a1410385da80d18bJens Axboe#ifdef FIO_USE_GENERIC_SWAP 1469677bec37d1b9d2949116cdc3d691a4d3e534cbeJens Axboestatic inline uint16_t fio_swap16(uint16_t val) 147232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe{ 148232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe return (val << 8) | (val >> 8); 149232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe} 150232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe 151901ebe18bdca90032e2fe107a1410385da80d18bJens Axboestatic inline uint32_t fio_swap32(uint32_t val) 152232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe{ 153232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8); 154232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe 155232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe return (val >> 16) | (val << 16); 156232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe} 157232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe 158901ebe18bdca90032e2fe107a1410385da80d18bJens Axboestatic inline uint64_t fio_swap64(uint64_t val) 159232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe{ 160232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe val = ((val & 0xff00ff00ff00ff00ULL) >> 8) | 161232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe ((val & 0x00ff00ff00ff00ffULL) << 8); 162232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe val = ((val & 0xffff0000ffff0000ULL) >> 16) | 163232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe ((val & 0x0000ffff0000ffffULL) << 16); 164232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe 165232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe return (val >> 32) | (val << 32); 166232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe} 167232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe#endif 168232f9b73353e0322fe135d3029beecedaed7a17bJens Axboe 169ec5c6b125c1eab992882602158bab54957aa733dAaron Carroll#ifndef FIO_HAVE_BYTEORDER_FUNCS 1700dcebdf4a70ef0d8144b8fcba763ae87e7fc74b5Jens Axboe#ifdef CONFIG_LITTLE_ENDIAN 1718111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __le16_to_cpu(x) (x) 1728111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __le32_to_cpu(x) (x) 1738111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __le64_to_cpu(x) (x) 1748111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __cpu_to_le16(x) (x) 1758111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __cpu_to_le32(x) (x) 1768111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __cpu_to_le64(x) (x) 1778111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#else 1788111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __le16_to_cpu(x) fio_swap16(x) 1798111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __le32_to_cpu(x) fio_swap32(x) 1808111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __le64_to_cpu(x) fio_swap64(x) 1818111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __cpu_to_le16(x) fio_swap16(x) 1828111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __cpu_to_le32(x) fio_swap32(x) 1838111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define __cpu_to_le64(x) fio_swap64(x) 1848111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#endif 185ec5c6b125c1eab992882602158bab54957aa733dAaron Carroll#endif /* FIO_HAVE_BYTEORDER_FUNCS */ 1868111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe 1878111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define le16_to_cpu(val) ({ \ 1888111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe uint16_t *__val = &(val); \ 1898111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe __le16_to_cpu(*__val); \ 1908111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe}) 1918111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define le32_to_cpu(val) ({ \ 1928111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe uint32_t *__val = &(val); \ 1938111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe __le32_to_cpu(*__val); \ 1948111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe}) 1958111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define le64_to_cpu(val) ({ \ 1968111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe uint64_t *__val = &(val); \ 1978111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe __le64_to_cpu(*__val); \ 1988111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe}) 1998111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define cpu_to_le16(val) ({ \ 2008111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe uint16_t *__val = &(val); \ 2018111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe __cpu_to_le16(*__val); \ 2028111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe}) 2038111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define cpu_to_le32(val) ({ \ 2048111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe uint32_t *__val = &(val); \ 2058111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe __cpu_to_le32(*__val); \ 2068111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe}) 2078111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe#define cpu_to_le64(val) ({ \ 2088111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe uint64_t *__val = &(val); \ 2098111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe __cpu_to_le64(*__val); \ 2108111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe}) 2118111092fd5dfc2fbdfc9b5b30094b74de982bddbJens Axboe 2125e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe#ifndef FIO_HAVE_BLKTRACE 2135e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboestatic inline int is_blktrace(const char *fname) 2145e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe{ 2155e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe return 0; 2165e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe} 2175921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboestruct thread_data; 2185e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboestatic inline int load_blktrace(struct thread_data *td, const char *fname) 2195e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe{ 2205e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe return 1; 2215e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe} 2225e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe#endif 2235e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe 224eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe#define FIO_DEF_CL_SIZE 128 225eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe 226eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboestatic inline int os_cache_line_size(void) 227eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe{ 228eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe#ifdef FIO_HAVE_CL_SIZE 229eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe int ret = arch_cache_line_size(); 230eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe 231eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe if (ret <= 0) 232eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe return FIO_DEF_CL_SIZE; 233eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe 234eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe return ret; 235eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe#else 236eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe return FIO_DEF_CL_SIZE; 237eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe#endif 238eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe} 239eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe 240792d551747e83601121afce033a66f357c9fc439Jens Axboe#ifdef FIO_USE_GENERIC_BDEV_SIZE 241ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6feBruce Cranstatic inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) 242792d551747e83601121afce033a66f357c9fc439Jens Axboe{ 2433b2e1464ae58caf42c74ab4bdeaa5eae7c38a23fJens Axboe off_t end; 244792d551747e83601121afce033a66f357c9fc439Jens Axboe 2453b2e1464ae58caf42c74ab4bdeaa5eae7c38a23fJens Axboe *bytes = 0; 2463b2e1464ae58caf42c74ab4bdeaa5eae7c38a23fJens Axboe 247ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6feBruce Cran end = lseek(f->fd, 0, SEEK_END); 248792d551747e83601121afce033a66f357c9fc439Jens Axboe if (end < 0) 249792d551747e83601121afce033a66f357c9fc439Jens Axboe return errno; 250792d551747e83601121afce033a66f357c9fc439Jens Axboe 251792d551747e83601121afce033a66f357c9fc439Jens Axboe *bytes = end; 252792d551747e83601121afce033a66f357c9fc439Jens Axboe return 0; 253792d551747e83601121afce033a66f357c9fc439Jens Axboe} 254792d551747e83601121afce033a66f357c9fc439Jens Axboe#endif 255792d551747e83601121afce033a66f357c9fc439Jens Axboe 256535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe#ifdef FIO_USE_GENERIC_RAND 257535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboetypedef unsigned int os_random_state_t; 258535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe 259535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboestatic inline void os_random_seed(unsigned long seed, os_random_state_t *rs) 260535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe{ 261535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe srand(seed); 262535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe} 263535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe 264535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboestatic inline long os_random_long(os_random_state_t *rs) 265535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe{ 266535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe long val; 267535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe 268535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe val = rand_r(rs); 269535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe return val; 270535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe} 271535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe#endif 272535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe 27393bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran#ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE 27493bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cranextern void td_fill_rand_seeds(struct thread_data *td); 27593bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran/* 27693bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran * Initialize the various random states we need (random io, block size ranges, 27793bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran * read/write mix, etc). 27893bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran */ 27993bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cranstatic inline int init_random_state(struct thread_data *td, unsigned long *rand_seeds, int size) 28093bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran{ 28193bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran int fd; 28293bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran 28393bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran fd = open("/dev/urandom", O_RDONLY); 28493bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran if (fd == -1) { 28593bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran return 1; 28693bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran } 28793bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran 28893bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran if (read(fd, rand_seeds, size) < size) { 28993bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran close(fd); 29093bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran return 1; 29193bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran } 29293bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran 29393bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran close(fd); 29493bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran td_fill_rand_seeds(td); 29593bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran return 0; 29693bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran} 29793bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran#endif 29893bcfd20e37cef8cec350fe06d3a086724c9f257Bruce Cran 2992e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe#ifndef FIO_HAVE_FS_STAT 3002e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboestatic inline unsigned long long get_fs_size(const char *path) 3012e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe{ 3022e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe return 0; 3032e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe} 3042e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe#endif 3052e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe 306c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboe#ifndef FIO_HAVE_CPU_ONLINE_SYSCONF 307c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboestatic inline unsigned int cpus_online(void) 308c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboe{ 309c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboe return sysconf(_SC_NPROCESSORS_ONLN); 310c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboe} 311c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboe#endif 312c00a22894b82ff53b42c1e741a7b4828199a1388Jens Axboe 31347f767c113be7448eb8aa9d4a9f9aa8f760ef642Jens Axboe#ifndef FIO_HAVE_GETTID 31447f767c113be7448eb8aa9d4a9f9aa8f760ef642Jens Axboestatic inline int gettid(void) 31547f767c113be7448eb8aa9d4a9f9aa8f760ef642Jens Axboe{ 31647f767c113be7448eb8aa9d4a9f9aa8f760ef642Jens Axboe return getpid(); 31747f767c113be7448eb8aa9d4a9f9aa8f760ef642Jens Axboe} 31847f767c113be7448eb8aa9d4a9f9aa8f760ef642Jens Axboe#endif 31947f767c113be7448eb8aa9d4a9f9aa8f760ef642Jens Axboe 320ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 321