Add FreeBSD cpu affinity support.
Since FreeBSD has different thread and process IDs, assume that fio_setaffinity
will always be called with a tid and fio_getaffinity with a pid.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/os/os-freebsd.h b/os/os-freebsd.h
index c55a7c3..57ce409 100644
--- a/os/os-freebsd.h
+++ b/os/os-freebsd.h
@@ -8,6 +8,8 @@
#include <sys/disk.h>
#include <sys/thr.h>
#include <sys/socket.h>
+#include <sys/param.h>
+#include <sys/cpuset.h>
#include "../file.h"
@@ -16,6 +18,7 @@
#define FIO_USE_GENERIC_INIT_RANDOM_STATE
#define FIO_HAVE_CHARDEV_SIZE
#define FIO_HAVE_GETTID
+#define FIO_HAVE_CPU_AFFINITY
#define OS_MAP_ANON MAP_ANON
@@ -25,6 +28,34 @@
typedef off_t off64_t;
+typedef cpuset_t os_cpu_mask_t;
+
+#define fio_cpu_clear(mask, cpu) (void) CPU_CLR((cpu), (mask))
+#define fio_cpu_set(mask, cpu) (void) CPU_SET((cpu), (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;
+}
+
+static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask)
+{
+ return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, pid, sizeof(cpumask), &cpumask);
+}
+
+static inline int fio_getaffinity(int pid, os_cpu_mask_t *cpumask)
+{
+ return cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, sizeof(cpumask), cpumask);
+}
+
+#define FIO_MAX_CPUS CPU_SETSIZE
+
static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
{
off_t size;