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>
23 #define FIO_HAVE_CPU_AFFINITY
24 #define FIO_HAVE_DISK_UTIL
26 #define FIO_HAVE_IOPRIO
27 #define FIO_HAVE_IOSCHED_SWITCH
28 #define FIO_HAVE_ODIRECT
29 #define FIO_HAVE_HUGETLB
30 #define FIO_HAVE_RAWBIND
31 #define FIO_HAVE_BLKTRACE
32 #define FIO_HAVE_PSHARED_MUTEX
33 #define FIO_HAVE_CL_SIZE
34 #define FIO_HAVE_CGROUPS
35 #define FIO_HAVE_FS_STAT
37 #define FIO_HAVE_BINJECT
38 #define FIO_HAVE_GETTID
39 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
42 #define FIO_HAVE_MMAP_HUGE
45 #define OS_MAP_ANON MAP_ANONYMOUS
47 typedef cpu_set_t os_cpu_mask_t;
49 typedef struct drand48_data os_random_state_t;
51 #ifdef CONFIG_3ARG_AFFINITY
52 #define fio_setaffinity(pid, cpumask) \
53 sched_setaffinity((pid), sizeof(cpumask), &(cpumask))
54 #define fio_getaffinity(pid, ptr) \
55 sched_getaffinity((pid), sizeof(cpu_set_t), (ptr))
56 #elif defined(CONFIG_2ARG_AFFINITY)
57 #define fio_setaffinity(pid, cpumask) \
58 sched_setaffinity((pid), &(cpumask))
59 #define fio_getaffinity(pid, ptr) \
60 sched_getaffinity((pid), (ptr))
63 #define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask))
64 #define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (mask))
66 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
72 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
77 #define FIO_MAX_CPUS CPU_SETSIZE
79 static inline int ioprio_set(int which, int who, int ioprio)
81 return syscall(__NR_ioprio_set, which, who, ioprio);
84 static inline int gettid(void)
86 return syscall(__NR_gettid);
89 #define SPLICE_DEF_SIZE (64*1024)
99 IOPRIO_WHO_PROCESS = 1,
104 #define IOPRIO_BITS 16
105 #define IOPRIO_CLASS_SHIFT 13
108 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
112 #define BLKFLSBUF _IO(0x12,97)
116 #define BLKDISCARD _IO(0x12,119)
119 static inline int blockdev_invalidate_cache(struct fio_file *f)
121 return ioctl(f->fd, BLKFLSBUF);
124 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
126 if (!ioctl(f->fd, BLKGETSIZE64, bytes))
132 static inline unsigned long long os_phys_mem(void)
134 long pagesize, pages;
136 pagesize = sysconf(_SC_PAGESIZE);
137 pages = sysconf(_SC_PHYS_PAGES);
138 if (pages == -1 || pagesize == -1)
141 return (unsigned long long) pages * (unsigned long long) pagesize;
144 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
149 static inline long os_random_long(os_random_state_t *rs)
157 static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
159 struct raw_config_request rq;
162 if (major(dev) != RAW_MAJOR)
166 * we should be able to find /dev/rawctl or /dev/raw/rawctl
168 fd = open("/dev/rawctl", O_RDONLY);
170 fd = open("/dev/raw/rawctl", O_RDONLY);
175 rq.raw_minor = minor(dev);
176 if (ioctl(fd, RAW_GETBIND, &rq) < 0) {
182 *majdev = rq.block_major;
183 *mindev = rq.block_minor;
188 #define FIO_O_NOATIME O_NOATIME
190 #define FIO_O_NOATIME 0
194 #define FIO_MADV_FREE MADV_REMOVE
197 #if __BYTE_ORDER == __LITTLE_ENDIAN
198 #define FIO_LITTLE_ENDIAN
199 #elif __BYTE_ORDER == __BIG_ENDIAN
200 #define FIO_BIG_ENDIAN
202 #error "Unknown endianness"
205 #define fio_swap16(x) __bswap_16(x)
206 #define fio_swap32(x) __bswap_32(x)
207 #define fio_swap64(x) __bswap_64(x)
209 #define CACHE_LINE_FILE \
210 "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
212 static inline int arch_cache_line_size(void)
217 fd = open(CACHE_LINE_FILE, O_RDONLY);
221 ret = read(fd, size, sizeof(size));
231 static inline unsigned long long get_fs_size(const char *path)
233 unsigned long long ret;
236 if (statfs(path, &s) < 0)
240 ret *= (unsigned long long) s.f_bfree;
244 static inline int os_trim(int fd, unsigned long long start,
245 unsigned long long len)
252 if (!ioctl(fd, BLKDISCARD, range))