From 564f9f9c858ce8bc7af47a7b7763c11b1b0a467c Mon Sep 17 00:00:00 2001 From: anematode Date: Wed, 27 May 2026 07:05:56 +0200 Subject: [PATCH] Fix sloppy L3 cache detection code Fixes https://github.com/official-stockfish/Stockfish/issues/6857 Many thanks to Andrew for the repro closes https://github.com/official-stockfish/Stockfish/pull/6858 No functional change --- src/numa.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/numa.h b/src/numa.h index afd868dd0..bc704dff9 100644 --- a/src/numa.h +++ b/src/numa.h @@ -1166,23 +1166,18 @@ class NumaConfig { #if defined(__linux__) && !defined(__ANDROID__) std::set seenCpus; - auto nextUnseenCpu = [&seenCpus]() { - for (CpuIndex i = 0;; ++i) - if (!seenCpus.count(i)) - return i; - }; - while (true) + for (const auto& [next, _] : systemConfig.nodeByCpu) { - CpuIndex next = nextUnseenCpu(); - auto siblingsStr = + if (seenCpus.count(next)) + continue; + + auto siblingsStr = read_file_to_string("/sys/devices/system/cpu/cpu" + std::to_string(next) + "/cache/index3/shared_cpu_list"); if (!siblingsStr.has_value() || siblingsStr->empty()) - { - break; // we have read all available CPUs - } + continue; L3Domain domain; for (size_t c : indices_from_shortened_string(*siblingsStr))