X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=os%2Fos-android.h;h=18eb39ce052884b58dedc2f8f7a256281ab8aa95;hb=1ae82d673cf5e704b93da56655f6189f43a1592e;hp=acb19a8adea70d9c150a4554a83d1bcd1ee7e6f9;hpb=62720129955be364c937534fe98024403ce5ba19;p=fio.git diff --git a/os/os-android.h b/os/os-android.h index acb19a8a..18eb39ce 100644 --- a/os/os-android.h +++ b/os/os-android.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -17,7 +18,6 @@ #include #include "./os-linux-syscall.h" -#include "binject.h" #include "../file.h" #ifndef __has_builtin // Optional of course. @@ -32,6 +32,7 @@ #define FIO_HAVE_HUGETLB #define FIO_HAVE_BLKTRACE #define FIO_HAVE_CL_SIZE +#define FIO_HAVE_CGROUPS #define FIO_HAVE_FS_STAT #define FIO_HAVE_TRIM #define FIO_HAVE_GETTID @@ -57,6 +58,12 @@ #define MAP_HUGETLB 0x40000 /* arch specific */ #endif +#ifdef CONFIG_PTHREAD_GETAFFINITY +#define FIO_HAVE_GET_THREAD_AFFINITY +#define fio_get_thread_affinity(mask) \ + pthread_getaffinity_np(pthread_self(), sizeof(mask), &(mask)) +#endif + #ifndef CONFIG_NO_SHM /* * Bionic doesn't support SysV shared memeory, so implement it using ashmem @@ -64,11 +71,15 @@ #include #include #include +#include +#if __ANDROID_API__ >= __ANDROID_API_O__ +#include +#else +#define ASHMEM_DEVICE "/dev/ashmem" +#endif #define shmid_ds shmid64_ds #define SHM_HUGETLB 04000 -#define ASHMEM_DEVICE "/dev/ashmem" - static inline int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf) { int ret=0; @@ -82,6 +93,16 @@ static inline int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf) return ret; } +#if __ANDROID_API__ >= __ANDROID_API_O__ +static inline int shmget(key_t __key, size_t __size, int __shmflg) +{ + char keybuf[11]; + + sprintf(keybuf, "%d", __key); + + return ASharedMemory_create(keybuf, __size + sizeof(uint64_t)); +} +#else static inline int shmget(key_t __key, size_t __size, int __shmflg) { int fd,ret; @@ -96,7 +117,8 @@ static inline int shmget(key_t __key, size_t __size, int __shmflg) if (ret < 0) goto error; - ret = ioctl(fd, ASHMEM_SET_SIZE, __size); + /* Stores size in first 8 bytes, allocate extra space */ + ret = ioctl(fd, ASHMEM_SET_SIZE, __size + sizeof(uint64_t)); if (ret < 0) goto error; @@ -106,22 +128,24 @@ error: close(fd); return ret; } +#endif static inline void *shmat(int __shmid, const void *__shmaddr, int __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]; + size_t size = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); + /* Needs to be 8-byte aligned to prevent SIGBUS on 32-bit ARM */ + uint64_t *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, __shmid, 0); + /* Save size at beginning of buffer, for use with munmap */ + *ptr = size; + return ptr + 1; } static inline int shmdt (const void *__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)); + /* Find mmap size which we stored at the beginning of the buffer */ + uint64_t *ptr = (uint64_t *)__shmaddr - 1; + size_t size = *ptr; + return munmap(ptr, size); } #endif @@ -149,16 +173,26 @@ enum { #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) +static inline int ioprio_value(int ioprio_class, int ioprio) { /* * If no class is set, assume BE */ - if (!ioprio_class) - ioprio_class = IOPRIO_CLASS_BE; + if (!ioprio_class) + ioprio_class = IOPRIO_CLASS_BE; + + return (ioprio_class << IOPRIO_CLASS_SHIFT) | ioprio; +} + +static inline bool ioprio_value_is_class_rt(unsigned int priority) +{ + return (priority >> IOPRIO_CLASS_SHIFT) == IOPRIO_CLASS_RT; +} - ioprio |= ioprio_class << IOPRIO_CLASS_SHIFT; - return syscall(__NR_ioprio_set, which, who, ioprio); +static inline int ioprio_set(int which, int who, int ioprio_class, int ioprio) +{ + return syscall(__NR_ioprio_set, which, who, + ioprio_value(ioprio_class, ioprio)); } #ifndef BLKGETSIZE64 @@ -198,23 +232,6 @@ static inline unsigned long long os_phys_mem(void) return (unsigned long long) pages * (unsigned long long) pagesize; } -typedef struct { unsigned short r[3]; } os_random_state_t; - -static inline void os_random_seed(unsigned long seed, os_random_state_t *rs) -{ - rs->r[0] = seed & 0xffff; - seed >>= 16; - rs->r[1] = seed & 0xffff; - seed >>= 16; - rs->r[2] = seed & 0xffff; - seed48(rs->r); -} - -static inline long os_random_long(os_random_state_t *rs) -{ - return nrand48(rs->r); -} - #ifdef O_NOATIME #define FIO_O_NOATIME O_NOATIME #else @@ -270,7 +287,7 @@ static inline unsigned long long get_fs_free_size(const char *path) return ret; } -static inline int os_trim(int fd, unsigned long long start, +static inline int os_trim(struct fio_file *f, unsigned long long start, unsigned long long len) { uint64_t range[2]; @@ -278,7 +295,7 @@ static inline int os_trim(int fd, unsigned long long start, range[0] = start; range[1] = len; - if (!ioctl(fd, BLKDISCARD, range)) + if (!ioctl(f->fd, BLKDISCARD, range)) return 0; return errno;