1 #ifndef FIO_OS_ANDROID_H
2 #define FIO_OS_ANDROID_H
4 #define FIO_OS os_android
8 #include <sys/syscall.h>
14 #include <linux/unistd.h>
15 #include <linux/major.h>
16 #include <asm/byteorder.h>
21 #define FIO_HAVE_DISK_UTIL
22 #define FIO_HAVE_IOSCHED_SWITCH
23 #define FIO_HAVE_IOPRIO
24 #define FIO_HAVE_ODIRECT
25 #define FIO_HAVE_HUGETLB
26 #define FIO_HAVE_BLKTRACE
27 #define FIO_HAVE_PSHARED_MUTEX
28 #define FIO_HAVE_CL_SIZE
29 #define FIO_HAVE_FS_STAT
31 #define FIO_HAVE_GETTID
32 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
33 #define FIO_HAVE_E4_ENG
34 #define FIO_HAVE_BYTEORDER_FUNCS
35 #define FIO_HAVE_MMAP_HUGE
36 #define FIO_NO_HAVE_SHM_H
38 #define OS_MAP_ANON MAP_ANONYMOUS
40 #define posix_madvise madvise
41 #define POSIX_MADV_DONTNEED MADV_DONTNEED
42 #define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
43 #define POSIX_MADV_RANDOM MADV_RANDOM
45 #define FIO_MADV_FREE MADV_REMOVE
48 #define MAP_HUGETLB 0x40000 /* arch specific */
53 * The Android NDK doesn't currently export <sys/shm.h>, so define the
54 * necessary stuff here.
57 #include <linux/shm.h>
58 #define SHM_HUGETLB 04000
60 static inline int shmctl (int __shmid, int __cmd, struct shmid_ds *__buf)
62 return syscall(__NR_shmctl, __shmid, __cmd, __buf);
65 static inline int shmget (key_t __key, size_t __size, int __shmflg)
67 return syscall(__NR_shmget, __key, __size, __shmflg);
70 static inline void *shmat (int __shmid, const void *__shmaddr, int __shmflg)
72 return (void *)syscall(__NR_shmat, __shmid, __shmaddr, __shmflg);
75 static inline int shmdt (const void *__shmaddr)
77 return syscall(__NR_shmctl, __shmaddr);
81 #define SPLICE_DEF_SIZE (64*1024)
91 IOPRIO_WHO_PROCESS = 1,
96 #define IOPRIO_BITS 16
97 #define IOPRIO_CLASS_SHIFT 13
99 static inline int ioprio_set(int which, int who, int ioprio_class, int ioprio)
102 * If no class is set, assume BE
105 ioprio_class = IOPRIO_CLASS_BE;
107 ioprio |= ioprio_class << IOPRIO_CLASS_SHIFT;
108 return syscall(__NR_ioprio_set, which, who, ioprio);
112 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
116 #define BLKFLSBUF _IO(0x12,97)
120 #define BLKDISCARD _IO(0x12,119)
123 static inline int blockdev_invalidate_cache(struct fio_file *f)
125 return ioctl(f->fd, BLKFLSBUF);
128 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
130 if (!ioctl(f->fd, BLKGETSIZE64, bytes))
136 static inline unsigned long long os_phys_mem(void)
138 long pagesize, pages;
140 pagesize = sysconf(_SC_PAGESIZE);
141 pages = sysconf(_SC_PHYS_PAGES);
142 if (pages == -1 || pagesize == -1)
145 return (unsigned long long) pages * (unsigned long long) pagesize;
148 typedef struct { unsigned short r[3]; } os_random_state_t;
150 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
152 rs->r[0] = seed & 0xffff;
154 rs->r[1] = seed & 0xffff;
156 rs->r[2] = seed & 0xffff;
160 static inline long os_random_long(os_random_state_t *rs)
162 return nrand48(rs->r);
166 #define FIO_O_NOATIME O_NOATIME
168 #define FIO_O_NOATIME 0
171 #define fio_swap16(x) __bswap_16(x)
172 #define fio_swap32(x) __bswap_32(x)
173 #define fio_swap64(x) __bswap_64(x)
175 #define CACHE_LINE_FILE \
176 "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
178 static inline int arch_cache_line_size(void)
183 fd = open(CACHE_LINE_FILE, O_RDONLY);
187 ret = read(fd, size, sizeof(size));
197 static inline unsigned long long get_fs_size(const char *path)
199 unsigned long long ret;
202 if (statfs(path, &s) < 0)
206 ret *= (unsigned long long) s.f_bfree;
210 static inline int os_trim(int fd, unsigned long long start,
211 unsigned long long len)
218 if (!ioctl(fd, BLKDISCARD, range))