X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=os%2Fos-android.h;h=cdae7030e1609d02b7a7acf40377fc84eb11d57c;hp=3da39531bff53c5f931e9557b240ac8c883824ec;hb=eec97b935abb714bf498c96a8f18ec1104c75fd4;hpb=49758e11f3658686ccd1c61724a5eba142f3ee4f diff --git a/os/os-android.h b/os/os-android.h index 3da39531..cdae7030 100644 --- a/os/os-android.h +++ b/os/os-android.h @@ -4,6 +4,7 @@ #define FIO_OS os_android #include +#include #include #include #include @@ -13,40 +14,45 @@ #include #include #include -#include +#include -#include "indirect.h" +#include "./os-linux-syscall.h" #include "binject.h" #include "../file.h" #define FIO_HAVE_DISK_UTIL -#define FIO_HAVE_SPLICE #define FIO_HAVE_IOSCHED_SWITCH +#define FIO_HAVE_IOPRIO +#define FIO_HAVE_IOPRIO_CLASS #define FIO_HAVE_ODIRECT #define FIO_HAVE_HUGETLB #define FIO_HAVE_BLKTRACE -#define FIO_HAVE_STRSEP -#define FIO_HAVE_POSIXAIO_FSYNC #define FIO_HAVE_PSHARED_MUTEX #define FIO_HAVE_CL_SIZE -#define FIO_HAVE_FDATASYNC #define FIO_HAVE_FS_STAT #define FIO_HAVE_TRIM -#define FIO_HAVE_CLOCK_MONOTONIC #define FIO_HAVE_GETTID #define FIO_USE_GENERIC_INIT_RANDOM_STATE #define FIO_HAVE_E4_ENG #define FIO_HAVE_BYTEORDER_FUNCS +#define FIO_HAVE_MMAP_HUGE +#define FIO_NO_HAVE_SHM_H #define OS_MAP_ANON MAP_ANONYMOUS +#ifndef POSIX_MADV_DONTNEED #define posix_madvise madvise #define POSIX_MADV_DONTNEED MADV_DONTNEED #define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL #define POSIX_MADV_RANDOM MADV_RANDOM +#endif + #ifdef MADV_REMOVE #define FIO_MADV_FREE MADV_REMOVE #endif +#ifndef MAP_HUGETLB +#define MAP_HUGETLB 0x40000 /* arch specific */ +#endif /* @@ -57,58 +63,102 @@ #include #define SHM_HUGETLB 04000 +#include +#include +#include + +#define ASHMEM_DEVICE "/dev/ashmem" + static inline int shmctl (int __shmid, int __cmd, struct shmid_ds *__buf) { - return syscall(__NR_shmctl, __shmid, __cmd, __buf); + int ret=0; + if (__cmd == IPC_RMID) + { + int length = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); + struct ashmem_pin pin = {0 , length}; + ret = ioctl(__shmid, ASHMEM_UNPIN, &pin); + close(__shmid); + } + return ret; } static inline int shmget (key_t __key, size_t __size, int __shmflg) { - return syscall(__NR_shmget, __key, __size, __shmflg); + int fd,ret; + char key[11]; + + fd = open(ASHMEM_DEVICE, O_RDWR); + if (fd < 0) + return fd; + + sprintf(key,"%d",__key); + ret = ioctl(fd, ASHMEM_SET_NAME, key); + if (ret < 0) + goto error; + + ret = ioctl(fd, ASHMEM_SET_SIZE, __size); + if (ret < 0) + goto error; + + return fd; + +error: + close(fd); + return ret; } static inline void *shmat (int __shmid, const void *__shmaddr, int __shmflg) { - return (void *)syscall(__NR_shmat, __shmid, __shmaddr, __shmflg); + size_t *ptr, size = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); + ptr = mmap(NULL, size + sizeof(size_t), PROT_READ | PROT_WRITE, MAP_SHARED, __shmid, 0); + *ptr = size; //save size at beginning of buffer, for use with munmap + return &ptr[1]; } static inline int shmdt (const void *__shmaddr) { - return syscall(__NR_shmctl, __shmaddr); + size_t *ptr, size; + ptr = (size_t *)__shmaddr; + ptr--; + size = *ptr; //find mmap size which we stored at the beginning of the buffer + return munmap((void *)ptr, size + sizeof(size_t)); } +#define SPLICE_DEF_SIZE (64*1024) -/* - * Just check for SPLICE_F_MOVE, if that isn't there, assume the others - * aren't either. - */ -#ifndef SPLICE_F_MOVE -#define SPLICE_F_MOVE (0x01) /* move pages instead of copying */ -#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */ - /* we may still block on the fd we splice */ - /* from/to, of course */ -#define SPLICE_F_MORE (0x04) /* expect more data */ -#define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */ - -static inline int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out, - size_t len, unsigned int flags) -{ - return syscall(__NR_sys_splice, fdin, off_in, fdout, off_out, len, flags); -} +enum { + IOPRIO_CLASS_NONE, + IOPRIO_CLASS_RT, + IOPRIO_CLASS_BE, + IOPRIO_CLASS_IDLE, +}; -static inline int tee(int fdin, int fdout, size_t len, unsigned int flags) -{ - return syscall(__NR_sys_tee, fdin, fdout, len, flags); -} +enum { + IOPRIO_WHO_PROCESS = 1, + IOPRIO_WHO_PGRP, + IOPRIO_WHO_USER, +}; + +#define IOPRIO_BITS 16 +#define IOPRIO_CLASS_SHIFT 13 -static inline int vmsplice(int fd, const struct iovec *iov, - unsigned long nr_segs, unsigned int flags) +#define IOPRIO_MIN_PRIO 0 /* highest priority */ +#define IOPRIO_MAX_PRIO 7 /* lowest priority */ + +#define IOPRIO_MIN_PRIO_CLASS 0 +#define IOPRIO_MAX_PRIO_CLASS 3 + +static inline int ioprio_set(int which, int who, int ioprio_class, int ioprio) { - return syscall(__NR_sys_vmsplice, fd, iov, nr_segs, flags); + /* + * If no class is set, assume BE + */ + if (!ioprio_class) + ioprio_class = IOPRIO_CLASS_BE; + + ioprio |= ioprio_class << IOPRIO_CLASS_SHIFT; + return syscall(__NR_ioprio_set, which, who, ioprio); } -#endif - -#define SPLICE_DEF_SIZE (64*1024) #ifndef BLKGETSIZE64 #define BLKGETSIZE64 _IOR(0x12,114,size_t) @@ -170,14 +220,6 @@ static inline long os_random_long(os_random_state_t *rs) #define FIO_O_NOATIME 0 #endif -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define FIO_LITTLE_ENDIAN -#elif __BYTE_ORDER == __BIG_ENDIAN -#define FIO_BIG_ENDIAN -#else -#error "Unknown endianness" -#endif - #define fio_swap16(x) __bswap_16(x) #define fio_swap32(x) __bswap_32(x) #define fio_swap64(x) __bswap_64(x) @@ -204,7 +246,7 @@ static inline int arch_cache_line_size(void) return atoi(size); } -static inline unsigned long long get_fs_size(const char *path) +static inline unsigned long long get_fs_free_size(const char *path) { unsigned long long ret; struct statfs s; @@ -231,4 +273,12 @@ static inline int os_trim(int fd, unsigned long long start, return errno; } +#ifdef CONFIG_SCHED_IDLE +static inline int fio_set_sched_idle(void) +{ + struct sched_param p = { .sched_priority = 0, }; + return sched_setscheduler(gettid(), SCHED_IDLE, &p); +} +#endif + #endif