4 #define FIO_OS os_linux
8 #include <sys/syscall.h>
15 #include <linux/unistd.h>
16 #include <linux/raw.h>
17 #include <linux/major.h>
22 #define FIO_HAVE_CPU_AFFINITY
23 #define FIO_HAVE_DISK_UTIL
25 #define FIO_HAVE_IOPRIO
26 #define FIO_HAVE_IOSCHED_SWITCH
27 #define FIO_HAVE_ODIRECT
28 #define FIO_HAVE_HUGETLB
29 #define FIO_HAVE_RAWBIND
30 #define FIO_HAVE_BLKTRACE
31 #define FIO_HAVE_PSHARED_MUTEX
32 #define FIO_HAVE_CL_SIZE
33 #define FIO_HAVE_CGROUPS
34 #define FIO_HAVE_FS_STAT
36 #define FIO_HAVE_BINJECT
37 #define FIO_HAVE_GETTID
38 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
41 #define FIO_HAVE_MMAP_HUGE
44 #define OS_MAP_ANON MAP_ANONYMOUS
46 typedef cpu_set_t os_cpu_mask_t;
48 typedef struct drand48_data os_random_state_t;
50 #ifdef CONFIG_3ARG_AFFINITY
51 #define fio_setaffinity(pid, cpumask) \
52 sched_setaffinity((pid), sizeof(cpumask), &(cpumask))
53 #define fio_getaffinity(pid, ptr) \
54 sched_getaffinity((pid), sizeof(cpu_set_t), (ptr))
55 #elif defined(CONFIG_2ARG_AFFINITY)
56 #define fio_setaffinity(pid, cpumask) \
57 sched_setaffinity((pid), &(cpumask))
58 #define fio_getaffinity(pid, ptr) \
59 sched_getaffinity((pid), (ptr))
62 #define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask))
63 #define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask))
65 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
71 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
76 #define FIO_MAX_CPUS CPU_SETSIZE
78 static inline int ioprio_set(int which, int who, int ioprio)
80 return syscall(__NR_ioprio_set, which, who, ioprio);
83 static inline int gettid(void)
85 return syscall(__NR_gettid);
88 #define SPLICE_DEF_SIZE (64*1024)
98 IOPRIO_WHO_PROCESS = 1,
103 #define IOPRIO_BITS 16
104 #define IOPRIO_CLASS_SHIFT 13
107 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
111 #define BLKFLSBUF _IO(0x12,97)
115 #define BLKDISCARD _IO(0x12,119)
118 static inline int blockdev_invalidate_cache(struct fio_file *f)
120 return ioctl(f->fd, BLKFLSBUF);
123 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
125 if (!ioctl(f->fd, BLKGETSIZE64, bytes))
131 static inline unsigned long long os_phys_mem(void)
133 long pagesize, pages;
135 pagesize = sysconf(_SC_PAGESIZE);
136 pages = sysconf(_SC_PHYS_PAGES);
137 if (pages == -1 || pagesize == -1)
140 return (unsigned long long) pages * (unsigned long long) pagesize;
143 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
148 static inline long os_random_long(os_random_state_t *rs)
156 static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
158 struct raw_config_request rq;
161 if (major(dev) != RAW_MAJOR)
165 * we should be able to find /dev/rawctl or /dev/raw/rawctl
167 fd = open("/dev/rawctl", O_RDONLY);
169 fd = open("/dev/raw/rawctl", O_RDONLY);
174 rq.raw_minor = minor(dev);
175 if (ioctl(fd, RAW_GETBIND, &rq) < 0) {
181 *majdev = rq.block_major;
182 *mindev = rq.block_minor;
187 #define FIO_O_NOATIME O_NOATIME
189 #define FIO_O_NOATIME 0
193 #define FIO_MADV_FREE MADV_REMOVE
196 #define fio_swap16(x) __bswap_16(x)
197 #define fio_swap32(x) __bswap_32(x)
198 #define fio_swap64(x) __bswap_64(x)
200 #define CACHE_LINE_FILE \
201 "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
203 static inline int arch_cache_line_size(void)
208 fd = open(CACHE_LINE_FILE, O_RDONLY);
212 ret = read(fd, size, sizeof(size));
222 static inline unsigned long long get_fs_size(const char *path)
224 unsigned long long ret;
227 if (statfs(path, &s) < 0)
231 ret *= (unsigned long long) s.f_bfree;
235 static inline int os_trim(int fd, unsigned long long start,
236 unsigned long long len)
243 if (!ioctl(fd, BLKDISCARD, range))
249 #ifdef CONFIG_SCHED_IDLE
250 static inline int fio_set_sched_idle(void)
252 struct sched_param p = { .sched_priority = 0, };
253 return sched_setscheduler(gettid(), SCHED_IDLE, &p);