From 531be189e35a4c5955bb3a9e6d60d52fa3427243 Mon Sep 17 00:00:00 2001 From: Willem Jan Withagen Date: Fri, 11 Jan 2019 18:40:22 +0100 Subject: [PATCH] common/numa: Add shim routines for NUMA on FreeBSD. FreeBSD has some of the numa features, but for now faking them will do. Also don't test NUMA on FreeBSD. Signed-off-by: Willem Jan Withagen --- src/common/blkdev.cc | 24 ++++++++++++++++++++++++ src/common/compat.cc | 9 +++++++++ src/common/numa.cc | 32 +++++++++++++++++++++++++++++++- src/common/numa.h | 1 + src/include/compat.h | 6 ++++++ src/test/common/CMakeLists.txt | 3 +++ 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index 1c03ffb1f40..43e4be0a0a6 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -765,6 +765,11 @@ int BlkDev::get_size(int64_t *psize) const return ret; } +int64_t BlkDev::get_int_property(blkdev_prop_t prop) const +{ + return 0; +} + bool BlkDev::support_discard() const { return false; @@ -785,6 +790,11 @@ bool BlkDev::is_rotational() const return false; } +int BlkDev::get_numa_node(int *node) const +{ + return -1; +} + int BlkDev::model(char *model, size_t max) const { return -EOPNOTSUPP; @@ -866,6 +876,11 @@ int BlkDev::get_size(int64_t *psize) const return ret; } +int64_t BlkDev::get_int_property(blkdev_prop_t prop) const +{ + return 0; +} + bool BlkDev::support_discard() const { #ifdef FREEBSD_WITH_TRIM @@ -934,6 +949,15 @@ bool BlkDev::is_rotational() const #endif } +int BlkDev::get_numa_node(int *node) const +{ + int numa = get_int_property(BLKDEV_PROP_NUMA_NODE); + if (numa < 0) + return -1; + *node = numa; + return 0; +} + int BlkDev::model(char *model, size_t max) const { struct diocgattr_arg arg; diff --git a/src/common/compat.cc b/src/common/compat.cc index 1cfc4db973a..3380d1cd031 100644 --- a/src/common/compat.cc +++ b/src/common/compat.cc @@ -184,3 +184,12 @@ fail: return (errno = save_errno, -1); #endif } + +#if defined(__FreeBSD__) +int sched_setaffinity(pid_t pid, size_t cpusetsize, + cpu_set_t *mask) +{ + return 0; +} +#endif + diff --git a/src/common/numa.cc b/src/common/numa.cc index 9ec29fa95f2..c75f50088eb 100644 --- a/src/common/numa.cc +++ b/src/common/numa.cc @@ -12,7 +12,7 @@ // list - +#if defined(__linux__) int parse_cpu_set_list(const char *s, size_t *cpu_set_size, cpu_set_t *cpu_set) @@ -133,3 +133,33 @@ int get_numa_node_cpu_set( ::close(fd); return r; } + +#elif defined(__FreeBSD__) + +int parse_cpu_set_list(const char *s, + size_t *cpu_set_size, + cpu_set_t *cpu_set) +{ + return -ENOTSUP; +} + +std::string cpu_set_to_str_list(size_t cpu_set_size, + const cpu_set_t *cpu_set) +{ + return {}; +} + +std::set cpu_set_to_set(size_t cpu_set_size, + const cpu_set_t *cpu_set) +{ + return {}; +} + +int get_numa_node_cpu_set(int node, + size_t *cpu_set_size, + cpu_set_t *cpu_set) +{ + return -ENOTSUP; +} + +#endif diff --git a/src/common/numa.h b/src/common/numa.h index 85f91b30eeb..4acb8280c8f 100644 --- a/src/common/numa.h +++ b/src/common/numa.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include #include diff --git a/src/include/compat.h b/src/include/compat.h index 949bb406e8b..3463c98d2b8 100644 --- a/src/include/compat.h +++ b/src/include/compat.h @@ -36,6 +36,12 @@ /* And include the extra required include file */ #include +#include +#include +#define cpu_set_t cpuset_t +int sched_setaffinity(pid_t pid, size_t cpusetsize, + cpu_set_t *mask); + #endif /* __FreeBSD__ */ #if defined(__APPLE__) || defined(__FreeBSD__) diff --git a/src/test/common/CMakeLists.txt b/src/test/common/CMakeLists.txt index 9578822c626..71fb77cda91 100644 --- a/src/test/common/CMakeLists.txt +++ b/src/test/common/CMakeLists.txt @@ -28,12 +28,15 @@ add_executable(unittest_lockdep add_ceph_unittest(unittest_lockdep) target_link_libraries(unittest_lockdep ceph-common global) +# FreeBSD only has shims to support NUMA, no functional code. +if(LINUX) # unittest_numa add_executable(unittest_numa test_numa.cc ) add_ceph_unittest(unittest_numa) target_link_libraries(unittest_numa ceph-common) +endif() # unittest_bloom_filter add_executable(unittest_bloom_filter -- 2.39.5