os.h revision 2e3bd4c21cc239fbda992a4ede89ebb85f550920
1ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_OS_H 2ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define FIO_OS_H 3ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 4a14ca44ada0708be91ed7741a32176bef4801cc4Jens Axboe#include <sys/types.h> 5a14ca44ada0708be91ed7741a32176bef4801cc4Jens Axboe#include <unistd.h> 6a14ca44ada0708be91ed7741a32176bef4801cc4Jens Axboe 7ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#if defined(__linux__) 8ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include "os-linux.h" 9ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#elif defined(__FreeBSD__) 10ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include "os-freebsd.h" 117452440e1efb40680fdc951eebc7499a95a62f86YAMAMOTO Takashi#elif defined(__NetBSD__) 127452440e1efb40680fdc951eebc7499a95a62f86YAMAMOTO Takashi#include "os-netbsd.h" 132c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe#elif defined(__sun__) 142c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe#include "os-solaris.h" 152afd826bf6cd19900aee70ae14ede92d91b6f4c0Jens Axboe#elif defined(__APPLE__) 162afd826bf6cd19900aee70ae14ede92d91b6f4c0Jens Axboe#include "os-mac.h" 17ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#else 18ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#error "unsupported os" 19ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 20ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 21ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifdef FIO_HAVE_LIBAIO 22ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <libaio.h> 23ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 24ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 25ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifdef FIO_HAVE_POSIXAIO 26ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <aio.h> 27ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 28ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 29ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifdef FIO_HAVE_SGIO 30ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <linux/fs.h> 31ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#include <scsi/sg.h> 32ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 33ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 345921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#ifndef FIO_HAVE_STRSEP 3500fb3c8dcbb940338fea9f6cab689b4924266305Jens Axboe#include "../lib/strsep.h" 365921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 375921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe 38ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_FADVISE 39ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define fadvise(fd, off, len, advice) (0) 40ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 414d8947de2b50578a4f6290be567cb5de5bf46776Shawn Lewis#ifndef POSIX_FADV_DONTNEED 42ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define POSIX_FADV_DONTNEED (0) 43ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define POSIX_FADV_SEQUENTIAL (0) 44ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define POSIX_FADV_RANDOM (0) 454d8947de2b50578a4f6290be567cb5de5bf46776Shawn Lewis#endif 46ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif /* FIO_HAVE_FADVISE */ 47ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 48ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_CPU_AFFINITY 49e8462bd8250cf3ff2d41f17e1a4d4cefc70b6b37Jens Axboe#define fio_setaffinity(pid, mask) (0) 50be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe#define fio_getaffinity(pid, mask) do { } while (0) 51be4ecfdf6c8daa75c4df8ac875c9a87da80d81a0Jens Axboe#define fio_cpu_clear(mask, cpu) do { } while (0) 5285daf2c1102ed4fdf1477cfd372046efbe08046eJens Axboe#define fio_cpuset_exit(mask) (-1) 537452440e1efb40680fdc951eebc7499a95a62f86YAMAMOTO Takashitypedef unsigned long os_cpu_mask_t; 54ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 55ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 56ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#ifndef FIO_HAVE_IOPRIO 57ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#define ioprio_set(which, who, prio) (0) 58ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 59ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe 602c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe#ifndef FIO_HAVE_ODIRECT 617d4247639268fdcc1769fc57564d79791042950dJens Axboe#define OS_O_DIRECT 0 627d4247639268fdcc1769fc57564d79791042950dJens Axboe#else 637d4247639268fdcc1769fc57564d79791042950dJens Axboe#define OS_O_DIRECT O_DIRECT 642c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe#endif 652c0ecd28459b6a1b236c865defb5ef76ce8bfa02Jens Axboe 6674b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#ifndef FIO_HAVE_HUGETLB 6774b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#define SHM_HUGETLB 0 684d8947de2b50578a4f6290be567cb5de5bf46776Shawn Lewis#ifndef FIO_HUGE_PAGE 6974b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#define FIO_HUGE_PAGE 0 704d8947de2b50578a4f6290be567cb5de5bf46776Shawn Lewis#endif 7174b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#else 72cb25df61fbe19065b41bee131d19335d615c676bJens Axboe#ifndef FIO_HUGE_PAGE 73ee0e0a718f069fae189be800c2a6e2f5c28ff9f0Jens Axboe#define FIO_HUGE_PAGE 4194304 7474b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe#endif 75cb25df61fbe19065b41bee131d19335d615c676bJens Axboe#endif 7674b025b071b5bfbffa7ad7682b66b749e8d1f955Jens Axboe 775921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#ifndef FIO_O_NOATIME 785921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#define FIO_O_NOATIME 0 795921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe#endif 805921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe 81dc873b6f4a536c332b72cce268d5a7ccd356a891Jens Axboe#ifndef OS_RAND_MAX 82dc873b6f4a536c332b72cce268d5a7ccd356a891Jens Axboe#define OS_RAND_MAX RAND_MAX 83dc873b6f4a536c332b72cce268d5a7ccd356a891Jens Axboe#endif 84dc873b6f4a536c332b72cce268d5a7ccd356a891Jens Axboe 8507e5b2646f673a56c05a53c6a84bf5d0c949d290Jens Axboe#ifndef FIO_HAVE_RAWBIND 868cc7afa91ddc5a0980b9d2dbfdd66e1511a0d4b1Jens Axboe#define fio_lookup_raw(dev, majdev, mindev) 1 8707e5b2646f673a56c05a53c6a84bf5d0c949d290Jens Axboe#endif 8807e5b2646f673a56c05a53c6a84bf5d0c949d290Jens Axboe 895e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe#ifndef FIO_HAVE_BLKTRACE 905e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboestatic inline int is_blktrace(const char *fname) 915e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe{ 925e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe return 0; 935e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe} 945921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboestruct thread_data; 955e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboestatic inline int load_blktrace(struct thread_data *td, const char *fname) 965e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe{ 975e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe return 1; 985e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe} 995e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe#endif 1005e62c22a669c7a8c03b7871852cf85ad6d355980Jens Axboe 101eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe#define FIO_DEF_CL_SIZE 128 102eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe 103eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboestatic inline int os_cache_line_size(void) 104eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe{ 105eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe#ifdef FIO_HAVE_CL_SIZE 106eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe int ret = arch_cache_line_size(); 107eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe 108eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe if (ret <= 0) 109eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe return FIO_DEF_CL_SIZE; 110eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe 111eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe return ret; 112eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe#else 113eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe return FIO_DEF_CL_SIZE; 114eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe#endif 115eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe} 116eb7ccf38bf2e9208b593d021c50e9ad2ec0781eaJens Axboe 117792d551747e83601121afce033a66f357c9fc439Jens Axboe#ifdef FIO_USE_GENERIC_BDEV_SIZE 118792d551747e83601121afce033a66f357c9fc439Jens Axboestatic inline int blockdev_size(int fd, unsigned long long *bytes) 119792d551747e83601121afce033a66f357c9fc439Jens Axboe{ 1203b2e1464ae58caf42c74ab4bdeaa5eae7c38a23fJens Axboe off_t end; 121792d551747e83601121afce033a66f357c9fc439Jens Axboe 1223b2e1464ae58caf42c74ab4bdeaa5eae7c38a23fJens Axboe *bytes = 0; 1233b2e1464ae58caf42c74ab4bdeaa5eae7c38a23fJens Axboe 1243b2e1464ae58caf42c74ab4bdeaa5eae7c38a23fJens Axboe end = lseek(fd, 0, SEEK_END); 125792d551747e83601121afce033a66f357c9fc439Jens Axboe if (end < 0) 126792d551747e83601121afce033a66f357c9fc439Jens Axboe return errno; 127792d551747e83601121afce033a66f357c9fc439Jens Axboe 128792d551747e83601121afce033a66f357c9fc439Jens Axboe *bytes = end; 129792d551747e83601121afce033a66f357c9fc439Jens Axboe return 0; 130792d551747e83601121afce033a66f357c9fc439Jens Axboe} 131792d551747e83601121afce033a66f357c9fc439Jens Axboe#endif 132792d551747e83601121afce033a66f357c9fc439Jens Axboe 133535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe#ifdef FIO_USE_GENERIC_RAND 134535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboetypedef unsigned int os_random_state_t; 135535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe 136535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboestatic inline void os_random_seed(unsigned long seed, os_random_state_t *rs) 137535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe{ 138535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe srand(seed); 139535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe} 140535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe 141535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboestatic inline long os_random_long(os_random_state_t *rs) 142535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe{ 143535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe long val; 144535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe 145535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe val = rand_r(rs); 146535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe return val; 147535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe} 148535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe#endif 149535313705d69dc16f27ca38acf2f9bf7205e410dJens Axboe 1502e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe#ifndef FIO_HAVE_FS_STAT 1512e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboestatic inline unsigned long long get_fs_size(const char *path) 1522e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe{ 1532e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe return 0; 1542e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe} 1552e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe#endif 1562e3bd4c21cc239fbda992a4ede89ebb85f550920Jens Axboe 157ebac4655dd3624f3296ff83be48e0cdc02852f1Jens Axboe#endif 158