Fixup bad logging types
[fio.git] / os / os-android.h
CommitLineData
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>
da52c582 16#include <asm/byteorder.h>
ec5c6b12 17
ec5c6b12
AC
18#include "binject.h"
19#include "../file.h"
20
21#define FIO_HAVE_DISK_UTIL
ec5c6b12 22#define FIO_HAVE_IOSCHED_SWITCH
177380ab 23#define FIO_HAVE_IOPRIO
ec5c6b12
AC
24#define FIO_HAVE_ODIRECT
25#define FIO_HAVE_HUGETLB
26#define FIO_HAVE_BLKTRACE
ec5c6b12
AC
27#define FIO_HAVE_PSHARED_MUTEX
28#define FIO_HAVE_CL_SIZE
ec5c6b12
AC
29#define FIO_HAVE_FS_STAT
30#define FIO_HAVE_TRIM
ec5c6b12
AC
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
6d0e9f83 35#define FIO_HAVE_MMAP_HUGE
a5e0ee11 36#define FIO_NO_HAVE_SHM_H
ec5c6b12
AC
37
38#define OS_MAP_ANON MAP_ANONYMOUS
39
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
44#ifdef MADV_REMOVE
45#define FIO_MADV_FREE MADV_REMOVE
46#endif
a5e0ee11
O
47#ifndef MAP_HUGETLB
48#define MAP_HUGETLB 0x40000 /* arch specific */
49#endif
ec5c6b12
AC
50
51
52/*
53 * The Android NDK doesn't currently export <sys/shm.h>, so define the
54 * necessary stuff here.
55 */
56
57#include <linux/shm.h>
58#define SHM_HUGETLB 04000
59
60static inline int shmctl (int __shmid, int __cmd, struct shmid_ds *__buf)
61{
62 return syscall(__NR_shmctl, __shmid, __cmd, __buf);
63}
64
65static inline int shmget (key_t __key, size_t __size, int __shmflg)
66{
67 return syscall(__NR_shmget, __key, __size, __shmflg);
68}
69
70static inline void *shmat (int __shmid, const void *__shmaddr, int __shmflg)
71{
72 return (void *)syscall(__NR_shmat, __shmid, __shmaddr, __shmflg);
73}
74
75static inline int shmdt (const void *__shmaddr)
76{
77 return syscall(__NR_shmctl, __shmaddr);
78}
79
80
ec5c6b12
AC
81#define SPLICE_DEF_SIZE (64*1024)
82
177380ab
AC
83enum {
84 IOPRIO_CLASS_NONE,
85 IOPRIO_CLASS_RT,
86 IOPRIO_CLASS_BE,
87 IOPRIO_CLASS_IDLE,
88};
89
90enum {
91 IOPRIO_WHO_PROCESS = 1,
92 IOPRIO_WHO_PGRP,
93 IOPRIO_WHO_USER,
94};
95
96#define IOPRIO_BITS 16
97#define IOPRIO_CLASS_SHIFT 13
98
a415b2cc
AC
99static inline int ioprio_set(int which, int who, int ioprio_class, int ioprio)
100{
101 /*
102 * If no class is set, assume BE
103 */
104 if (!ioprio_class)
105 ioprio_class = IOPRIO_CLASS_BE;
106
107 ioprio |= ioprio_class << IOPRIO_CLASS_SHIFT;
108 return syscall(__NR_ioprio_set, which, who, ioprio);
109}
110
ec5c6b12
AC
111#ifndef BLKGETSIZE64
112#define BLKGETSIZE64 _IOR(0x12,114,size_t)
113#endif
114
115#ifndef BLKFLSBUF
116#define BLKFLSBUF _IO(0x12,97)
117#endif
118
119#ifndef BLKDISCARD
120#define BLKDISCARD _IO(0x12,119)
121#endif
122
123static inline int blockdev_invalidate_cache(struct fio_file *f)
124{
125 return ioctl(f->fd, BLKFLSBUF);
126}
127
128static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
129{
130 if (!ioctl(f->fd, BLKGETSIZE64, bytes))
131 return 0;
132
133 return errno;
134}
135
136static inline unsigned long long os_phys_mem(void)
137{
138 long pagesize, pages;
139
140 pagesize = sysconf(_SC_PAGESIZE);
141 pages = sysconf(_SC_PHYS_PAGES);
142 if (pages == -1 || pagesize == -1)
143 return 0;
144
145 return (unsigned long long) pages * (unsigned long long) pagesize;
146}
147
148typedef struct { unsigned short r[3]; } os_random_state_t;
149
150static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
151{
152 rs->r[0] = seed & 0xffff;
153 seed >>= 16;
154 rs->r[1] = seed & 0xffff;
155 seed >>= 16;
156 rs->r[2] = seed & 0xffff;
157 seed48(rs->r);
158}
159
160static inline long os_random_long(os_random_state_t *rs)
161{
162 return nrand48(rs->r);
163}
164
165#ifdef O_NOATIME
166#define FIO_O_NOATIME O_NOATIME
167#else
168#define FIO_O_NOATIME 0
169#endif
170
ec5c6b12
AC
171#define fio_swap16(x) __bswap_16(x)
172#define fio_swap32(x) __bswap_32(x)
173#define fio_swap64(x) __bswap_64(x)
174
175#define CACHE_LINE_FILE \
176 "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
177
178static inline int arch_cache_line_size(void)
179{
180 char size[32];
181 int fd, ret;
182
183 fd = open(CACHE_LINE_FILE, O_RDONLY);
184 if (fd < 0)
185 return -1;
186
187 ret = read(fd, size, sizeof(size));
188
189 close(fd);
190
191 if (ret <= 0)
192 return -1;
193 else
194 return atoi(size);
195}
196
197static inline unsigned long long get_fs_size(const char *path)
198{
199 unsigned long long ret;
200 struct statfs s;
201
202 if (statfs(path, &s) < 0)
203 return -1ULL;
204
205 ret = s.f_bsize;
206 ret *= (unsigned long long) s.f_bfree;
207 return ret;
208}
209
210static inline int os_trim(int fd, unsigned long long start,
211 unsigned long long len)
212{
213 uint64_t range[2];
214
215 range[0] = start;
216 range[1] = len;
217
218 if (!ioctl(fd, BLKDISCARD, range))
219 return 0;
220
221 return errno;
222}
223
224#endif