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>
22 #define FIO_HAVE_DISK_UTIL
23 #define FIO_HAVE_SPLICE
24 #define FIO_HAVE_IOSCHED_SWITCH
25 #define FIO_HAVE_ODIRECT
26 #define FIO_HAVE_HUGETLB
27 #define FIO_HAVE_BLKTRACE
28 #define FIO_HAVE_STRSEP
29 #define FIO_HAVE_POSIXAIO_FSYNC
30 #define FIO_HAVE_PSHARED_MUTEX
31 #define FIO_HAVE_CL_SIZE
32 #define FIO_HAVE_FDATASYNC
33 #define FIO_HAVE_FS_STAT
35 #define FIO_HAVE_CLOCK_MONOTONIC
36 #define FIO_HAVE_GETTID
37 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
38 #define FIO_HAVE_E4_ENG
39 #define FIO_HAVE_BYTEORDER_FUNCS
41 #define OS_MAP_ANON MAP_ANONYMOUS
43 #define posix_madvise madvise
44 #define POSIX_MADV_DONTNEED MADV_DONTNEED
45 #define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
46 #define POSIX_MADV_RANDOM MADV_RANDOM
48 #define FIO_MADV_FREE MADV_REMOVE
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);
82 * Just check for SPLICE_F_MOVE, if that isn't there, assume the others
86 #define SPLICE_F_MOVE (0x01) /* move pages instead of copying */
87 #define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
88 /* we may still block on the fd we splice */
89 /* from/to, of course */
90 #define SPLICE_F_MORE (0x04) /* expect more data */
91 #define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */
93 static inline int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out,
94 size_t len, unsigned int flags)
96 return syscall(__NR_sys_splice, fdin, off_in, fdout, off_out, len, flags);
99 static inline int tee(int fdin, int fdout, size_t len, unsigned int flags)
101 return syscall(__NR_sys_tee, fdin, fdout, len, flags);
104 static inline int vmsplice(int fd, const struct iovec *iov,
105 unsigned long nr_segs, unsigned int flags)
107 return syscall(__NR_sys_vmsplice, fd, iov, nr_segs, flags);
111 #define SPLICE_DEF_SIZE (64*1024)
114 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
118 #define BLKFLSBUF _IO(0x12,97)
122 #define BLKDISCARD _IO(0x12,119)
125 static inline int blockdev_invalidate_cache(struct fio_file *f)
127 return ioctl(f->fd, BLKFLSBUF);
130 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
132 if (!ioctl(f->fd, BLKGETSIZE64, bytes))
138 static inline unsigned long long os_phys_mem(void)
140 long pagesize, pages;
142 pagesize = sysconf(_SC_PAGESIZE);
143 pages = sysconf(_SC_PHYS_PAGES);
144 if (pages == -1 || pagesize == -1)
147 return (unsigned long long) pages * (unsigned long long) pagesize;
150 typedef struct { unsigned short r[3]; } os_random_state_t;
152 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
154 rs->r[0] = seed & 0xffff;
156 rs->r[1] = seed & 0xffff;
158 rs->r[2] = seed & 0xffff;
162 static inline long os_random_long(os_random_state_t *rs)
164 return nrand48(rs->r);
168 #define FIO_O_NOATIME O_NOATIME
170 #define FIO_O_NOATIME 0
173 #if __BYTE_ORDER == __LITTLE_ENDIAN
174 #define FIO_LITTLE_ENDIAN
175 #elif __BYTE_ORDER == __BIG_ENDIAN
176 #define FIO_BIG_ENDIAN
178 #error "Unknown endianness"
181 #define fio_swap16(x) __bswap_16(x)
182 #define fio_swap32(x) __bswap_32(x)
183 #define fio_swap64(x) __bswap_64(x)
185 #define CACHE_LINE_FILE \
186 "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
188 static inline int arch_cache_line_size(void)
193 fd = open(CACHE_LINE_FILE, O_RDONLY);
197 ret = read(fd, size, sizeof(size));
207 static inline unsigned long long get_fs_size(const char *path)
209 unsigned long long ret;
212 if (statfs(path, &s) < 0)
216 ret *= (unsigned long long) s.f_bfree;
220 static inline int os_trim(int fd, unsigned long long start,
221 unsigned long long len)
228 if (!ioctl(fd, BLKDISCARD, range))