| From 02fd5b722bdfef2e7ce8d4aeb1bc65308d37003f Mon Sep 17 00:00:00 2001 |
| From: Bart Van Assche <bvanassche@acm.org> |
| Date: Wed, 24 Aug 2022 13:42:29 -0700 |
| Subject: [PATCH] Enable CPU affinity support on Android |
| |
| This patch enables the --cpumask=, --cpus_allowed= and |
| --cpus_allowed_policy= fio options. |
| |
| Signed-off-by: Bart Van Assche <bvanassche@acm.org> |
| --- |
| os/os-android.h | 26 ++++++++++++++++++++++++++ |
| 1 file changed, 26 insertions(+) |
| |
| diff --git a/os/os-android.h b/os/os-android.h |
| index 2f73d249..34534239 100644 |
| --- a/os/os-android.h |
| +++ b/os/os-android.h |
| @@ -24,6 +24,7 @@ |
| #define __has_builtin(x) 0 // Compatibility with non-clang compilers. |
| #endif |
| |
| +#define FIO_HAVE_CPU_AFFINITY |
| #define FIO_HAVE_DISK_UTIL |
| #define FIO_HAVE_IOSCHED_SWITCH |
| #define FIO_HAVE_IOPRIO |
| @@ -44,6 +45,13 @@ |
| |
| #define OS_MAP_ANON MAP_ANONYMOUS |
| |
| +typedef cpu_set_t os_cpu_mask_t; |
| + |
| +#define fio_setaffinity(pid, cpumask) \ |
| + sched_setaffinity((pid), sizeof(cpumask), &(cpumask)) |
| +#define fio_getaffinity(pid, ptr) \ |
| + sched_getaffinity((pid), sizeof(cpu_set_t), (ptr)) |
| + |
| #ifndef POSIX_MADV_DONTNEED |
| #define posix_madvise madvise |
| #define POSIX_MADV_DONTNEED MADV_DONTNEED |
| @@ -64,6 +72,24 @@ |
| pthread_getaffinity_np(pthread_self(), sizeof(mask), &(mask)) |
| #endif |
| |
| +#define fio_cpu_clear(mask, cpu) CPU_CLR((cpu), (mask)) |
| +#define fio_cpu_set(mask, cpu) CPU_SET((cpu), (mask)) |
| +#define fio_cpu_isset(mask, cpu) (CPU_ISSET((cpu), (mask)) != 0) |
| +#define fio_cpu_count(mask) CPU_COUNT((mask)) |
| + |
| +static inline int fio_cpuset_init(os_cpu_mask_t *mask) |
| +{ |
| + CPU_ZERO(mask); |
| + return 0; |
| +} |
| + |
| +static inline int fio_cpuset_exit(os_cpu_mask_t *mask) |
| +{ |
| + return 0; |
| +} |
| + |
| +#define FIO_MAX_CPUS CPU_SETSIZE |
| + |
| #ifndef CONFIG_NO_SHM |
| /* |
| * Bionic doesn't support SysV shared memory, so implement it using ashmem |