Skip to content

Commit

Permalink
Initialize Configuration#Concurrency also from /sys/fs/cgroup/cpuset.…
Browse files Browse the repository at this point in the history
…cpus.effective
  • Loading branch information
Al2Klimov committed Apr 5, 2023
1 parent b788114 commit 1d6ab00
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions lib/base/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> ranges;
boost::split(ranges, rawCpus, is_any_of(","));
if (rawCpus.length()) {
std::vector<std::string> ranges;
boost::split(ranges, rawCpus, is_any_of(","));

std::set<uintmax_t> cpus;
std::set<uintmax_t> cpus;

for (auto& range : ranges) {
std::vector<std::string> rangeEnds;
boost::split(rangeEnds, range, is_any_of("-"));
for (auto& range : ranges) {
std::vector<std::string> rangeEnds;
boost::split(rangeEnds, range, is_any_of("-"));

if (rangeEnds.size() > 1u) {
auto to (boost::lexical_cast<uintmax_t>(rangeEnds.at(1)));
if (rangeEnds.size() > 1u) {
auto to (boost::lexical_cast<uintmax_t>(rangeEnds.at(1)));

for (auto i (boost::lexical_cast<uintmax_t>(rangeEnds.at(0))); i <= to; ++i) {
cpus.emplace(i);
for (auto i (boost::lexical_cast<uintmax_t>(rangeEnds.at(0))); i <= to; ++i) {
cpus.emplace(i);
}
} else {
cpus.emplace(boost::lexical_cast<uintmax_t>(rangeEnds.at(0)));
}
} else {
cpus.emplace(boost::lexical_cast<uintmax_t>(rangeEnds.at(0)));
}
}

concurrency = cpus.size();
concurrency = cpus.size();
break;
}
}
}

Expand Down

0 comments on commit 1d6ab00

Please sign in to comment.