Commit e545b9a9 authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

skip CacheLocality optimizations if there are offline CPUs

Summary:
CacheLocality's parsing code for /proc/cpuinfo doesn't properly
handle systems in which there are offline CPUs. This diff makes it so
we fall back onto the sequential cache locality implementation in the
problematic scenarios.

This should address https://github.com/facebook/folly/issues/1208

Reviewed By: shixiao

Differential Revision: D17093176

fbshipit-source-id: 4da3a9dc53622f829af37ed70a2531c66fd92ddb
parent 27045b27
......@@ -196,6 +196,7 @@ CacheLocality CacheLocality::readFromProcCpuinfoLines(
size_t physicalId = 0;
size_t coreId = 0;
std::vector<std::tuple<size_t, size_t, size_t>> cpus;
size_t maxCpu = 0;
for (auto iter = lines.rbegin(); iter != lines.rend(); ++iter) {
auto& line = *iter;
if (!procCpuinfoLineRelevant(line)) {
......@@ -219,6 +220,7 @@ CacheLocality CacheLocality::readFromProcCpuinfoLines(
coreId = parseLeadingNumber(arg);
} else if (line.find("processor") == 0) {
auto cpu = parseLeadingNumber(arg);
maxCpu = std::max(cpu, maxCpu);
cpus.emplace_back(physicalId, coreId, cpu);
}
}
......@@ -226,6 +228,10 @@ CacheLocality CacheLocality::readFromProcCpuinfoLines(
if (cpus.empty()) {
throw std::runtime_error("no CPUs parsed from /proc/cpuinfo");
}
if (maxCpu != cpus.size() - 1) {
throw std::runtime_error(
"offline CPUs not supported for /proc/cpuinfo cache locality source");
}
std::sort(cpus.begin(), cpus.end());
size_t cpusPerCore = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment