From: Kefu Chai Date: Thu, 3 Nov 2022 06:27:11 +0000 (+0800) Subject: crimson/os/alienstore: use boost::counting_iterator for setting cpuset X-Git-Tag: v18.1.0~928^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7ad86ff0a66a4a7aa4d78a22ed03dd20bb60ada6;p=ceph-ci.git crimson/os/alienstore: use boost::counting_iterator for setting cpuset less repeatings this way. Signed-off-by: Kefu Chai --- 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 =