Commit | Line | Data |
---|---|---|
ec5c6b12 AC |
1 | #ifndef FIO_OS_ANDROID_H |
2 | #define FIO_OS_ANDROID_H | |
3 | ||
4 | #define FIO_OS os_android | |
5 | ||
6 | #include <sys/ioctl.h> | |
7 | #include <sys/uio.h> | |
8 | #include <sys/syscall.h> | |
9 | #include <sys/vfs.h> | |
10 | #include <unistd.h> | |
11 | #include <fcntl.h> | |
12 | #include <errno.h> | |
13 | #include <sched.h> | |
14 | #include <linux/unistd.h> | |
15 | #include <linux/major.h> | |
ec5c6b12 | 16 | |
ec5c6b12 AC |
17 | #include "binject.h" |
18 | #include "../file.h" | |
19 | ||
20 | #define FIO_HAVE_DISK_UTIL | |
ec5c6b12 AC |
21 | #define FIO_HAVE_IOSCHED_SWITCH |
22 | #define FIO_HAVE_ODIRECT | |
23 | #define FIO_HAVE_HUGETLB | |
24 | #define FIO_HAVE_BLKTRACE | |
ec5c6b12 AC |
25 | #define FIO_HAVE_PSHARED_MUTEX |
26 | #define FIO_HAVE_CL_SIZE | |
ec5c6b12 AC |
27 | #define FIO_HAVE_FS_STAT |
28 | #define FIO_HAVE_TRIM | |
ec5c6b12 AC |
29 | #define FIO_HAVE_GETTID |
30 | #define FIO_USE_GENERIC_INIT_RANDOM_STATE | |
31 | #define FIO_HAVE_E4_ENG | |
32 | #define FIO_HAVE_BYTEORDER_FUNCS | |
6d0e9f83 | 33 | #define FIO_HAVE_MMAP_HUGE |
a5e0ee11 | 34 | #define FIO_NO_HAVE_SHM_H |
ec5c6b12 AC |
35 | |
36 | #define OS_MAP_ANON MAP_ANONYMOUS | |
37 | ||
38 | #define posix_madvise madvise | |
39 | #define POSIX_MADV_DONTNEED MADV_DONTNEED | |
40 | #define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL | |
41 | #define POSIX_MADV_RANDOM MADV_RANDOM | |
42 | #ifdef MADV_REMOVE | |
43 | #define FIO_MADV_FREE MADV_REMOVE | |
44 | #endif | |
a5e0ee11 O |
45 | #ifndef MAP_HUGETLB |
46 | #define MAP_HUGETLB 0x40000 /* arch specific */ | |
47 | #endif | |
ec5c6b12 AC |
48 | |
49 | ||
50 | /* | |
51 | * The Android NDK doesn't currently export <sys/shm.h>, so define the | |
52 | * necessary stuff here. | |
53 | */ | |
54 | ||
55 | #include <linux/shm.h> | |
56 | #define SHM_HUGETLB 04000 | |
57 | ||
58 | static inline int shmctl (int __shmid, int __cmd, struct shmid_ds *__buf) | |
59 | { | |
60 | return syscall(__NR_shmctl, __shmid, __cmd, __buf); | |
61 | } | |
62 | ||
63 | static inline int shmget (key_t __key, size_t __size, int __shmflg) | |
64 | { | |
65 | return syscall(__NR_shmget, __key, __size, __shmflg); | |
66 | } | |
67 | ||
68 | static inline void *shmat (int __shmid, const void *__shmaddr, int __shmflg) | |
69 | { | |
70 | return (void *)syscall(__NR_shmat, __shmid, __shmaddr, __shmflg); | |
71 | } | |
72 | ||
73 | static inline int shmdt (const void *__shmaddr) | |
74 | { | |
75 | return syscall(__NR_shmctl, __shmaddr); | |
76 | } | |
77 | ||
78 | ||
ec5c6b12 AC |
79 | #define SPLICE_DEF_SIZE (64*1024) |
80 | ||
81 | #ifndef BLKGETSIZE64 | |
82 | #define BLKGETSIZE64 _IOR(0x12,114,size_t) | |
83 | #endif | |
84 | ||
85 | #ifndef BLKFLSBUF | |
86 | #define BLKFLSBUF _IO(0x12,97) | |
87 | #endif | |
88 | ||
89 | #ifndef BLKDISCARD | |
90 | #define BLKDISCARD _IO(0x12,119) | |
91 | #endif | |
92 | ||
93 | static inline int blockdev_invalidate_cache(struct fio_file *f) | |
94 | { | |
95 | return ioctl(f->fd, BLKFLSBUF); | |
96 | } | |
97 | ||
98 | static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) | |
99 | { | |
100 | if (!ioctl(f->fd, BLKGETSIZE64, bytes)) | |
101 | return 0; | |
102 | ||
103 | return errno; | |
104 | } | |
105 | ||
106 | static inline unsigned long long os_phys_mem(void) | |
107 | { | |
108 | long pagesize, pages; | |
109 | ||
110 | pagesize = sysconf(_SC_PAGESIZE); | |
111 | pages = sysconf(_SC_PHYS_PAGES); | |
112 | if (pages == -1 || pagesize == -1) | |
113 | return 0; | |
114 | ||
115 | return (unsigned long long) pages * (unsigned long long) pagesize; | |
116 | } | |
117 | ||
118 | typedef struct { unsigned short r[3]; } os_random_state_t; | |
119 | ||
120 | static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) | |
121 | { | |
122 | rs->r[0] = seed & 0xffff; | |
123 | seed >>= 16; | |
124 | rs->r[1] = seed & 0xffff; | |
125 | seed >>= 16; | |
126 | rs->r[2] = seed & 0xffff; | |
127 | seed48(rs->r); | |
128 | } | |
129 | ||
130 | static inline long os_random_long(os_random_state_t *rs) | |
131 | { | |
132 | return nrand48(rs->r); | |
133 | } | |
134 | ||
135 | #ifdef O_NOATIME | |
136 | #define FIO_O_NOATIME O_NOATIME | |
137 | #else | |
138 | #define FIO_O_NOATIME 0 | |
139 | #endif | |
140 | ||
ec5c6b12 AC |
141 | #define fio_swap16(x) __bswap_16(x) |
142 | #define fio_swap32(x) __bswap_32(x) | |
143 | #define fio_swap64(x) __bswap_64(x) | |
144 | ||
145 | #define CACHE_LINE_FILE \ | |
146 | "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size" | |
147 | ||
148 | static inline int arch_cache_line_size(void) | |
149 | { | |
150 | char size[32]; | |
151 | int fd, ret; | |
152 | ||
153 | fd = open(CACHE_LINE_FILE, O_RDONLY); | |
154 | if (fd < 0) | |
155 | return -1; | |
156 | ||
157 | ret = read(fd, size, sizeof(size)); | |
158 | ||
159 | close(fd); | |
160 | ||
161 | if (ret <= 0) | |
162 | return -1; | |
163 | else | |
164 | return atoi(size); | |
165 | } | |
166 | ||
167 | static inline unsigned long long get_fs_size(const char *path) | |
168 | { | |
169 | unsigned long long ret; | |
170 | struct statfs s; | |
171 | ||
172 | if (statfs(path, &s) < 0) | |
173 | return -1ULL; | |
174 | ||
175 | ret = s.f_bsize; | |
176 | ret *= (unsigned long long) s.f_bfree; | |
177 | return ret; | |
178 | } | |
179 | ||
180 | static inline int os_trim(int fd, unsigned long long start, | |
181 | unsigned long long len) | |
182 | { | |
183 | uint64_t range[2]; | |
184 | ||
185 | range[0] = start; | |
186 | range[1] = len; | |
187 | ||
188 | if (!ioctl(fd, BLKDISCARD, range)) | |
189 | return 0; | |
190 | ||
191 | return errno; | |
192 | } | |
193 | ||
194 | #endif |