From 7ad86ff0a66a4a7aa4d78a22ed03dd20bb60ada6 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 3 Nov 2022 14:27:11 +0800 Subject: [PATCH] crimson/os/alienstore: use boost::counting_iterator for setting cpuset less repeatings this way. Signed-off-by: Kefu Chai --- src/crimson/os/alienstore/alien_store.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/crimson/os/alienstore/alien_store.cc b/src/crimson/os/alienstore/alien_store.cc index 68d268408cc..d32f722e52e 100644 --- a/src/crimson/os/alienstore/alien_store.cc +++ b/src/crimson/os/alienstore/alien_store.cc @@ -5,9 +5,12 @@ #include "alien_store.h" #include "alien_log.h" +#include +#include #include #include #include +#include #include #include @@ -104,15 +107,14 @@ seastar::future<> AlienStore::start() // [0, N_CORES_FOR_SEASTAR) are reserved for seastar reactors // [N_CORES_FOR_SEASTAR, ..] are assigned to alien threads. if (!cpu_cores.has_value()) { - if (long nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); - nr_cpus > N_CORES_FOR_SEASTAR ) { - seastar::resource::cpuset cpuset; - for (unsigned i = N_CORES_FOR_SEASTAR; i < nr_cpus; i++) { - cpuset.insert(i); - } - cpu_cores = cpuset; - } else { + seastar::resource::cpuset cpuset; + std::copy(boost::counting_iterator(N_CORES_FOR_SEASTAR), + boost::counting_iterator(sysconf(_SC_NPROCESSORS_ONLN)), + std::inserter(cpuset, cpuset.end())); + if (cpuset.empty()) { logger().error("{}: unable to get nproc: {}", __func__, errno); + } else { + cpu_cores = cpuset; } } const auto num_threads =