From 1d6ab00d970c4aab91c9e874cbbb6734bd4177cb Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 27 Jan 2023 15:12:07 +0100 Subject: [PATCH] Initialize Configuration#Concurrency also from /sys/fs/cgroup/cpuset.cpus.effective --- lib/base/configuration.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/base/configuration.cpp b/lib/base/configuration.cpp index 4b25d8932f4..3d438201351 100644 --- a/lib/base/configuration.cpp +++ b/lib/base/configuration.cpp @@ -78,30 +78,33 @@ int Configuration::Concurrency{([]() -> int { #ifdef __linux__ { - auto rawCpus (ReadSysLine("/sys/fs/cgroup/cpuset/cpuset.cpus")); + for (auto* cpuset : {"/sys/fs/cgroup/cpuset.cpus.effective", "/sys/fs/cgroup/cpuset/cpuset.cpus"}) { + auto rawCpus (ReadSysLine(cpuset)); - if (rawCpus.length()) { - std::vector ranges; - boost::split(ranges, rawCpus, is_any_of(",")); + if (rawCpus.length()) { + std::vector ranges; + boost::split(ranges, rawCpus, is_any_of(",")); - std::set cpus; + std::set cpus; - for (auto& range : ranges) { - std::vector rangeEnds; - boost::split(rangeEnds, range, is_any_of("-")); + for (auto& range : ranges) { + std::vector rangeEnds; + boost::split(rangeEnds, range, is_any_of("-")); - if (rangeEnds.size() > 1u) { - auto to (boost::lexical_cast(rangeEnds.at(1))); + if (rangeEnds.size() > 1u) { + auto to (boost::lexical_cast(rangeEnds.at(1))); - for (auto i (boost::lexical_cast(rangeEnds.at(0))); i <= to; ++i) { - cpus.emplace(i); + for (auto i (boost::lexical_cast(rangeEnds.at(0))); i <= to; ++i) { + cpus.emplace(i); + } + } else { + cpus.emplace(boost::lexical_cast(rangeEnds.at(0))); } - } else { - cpus.emplace(boost::lexical_cast(rangeEnds.at(0))); } - } - concurrency = cpus.size(); + concurrency = cpus.size(); + break; + } } }