diff --git a/rts/System/Platform/CpuTopologyGeneric.cpp b/rts/System/Platform/CpuTopologyGeneric.cpp new file mode 100644 index 00000000000..cfad9fe7faa --- /dev/null +++ b/rts/System/Platform/CpuTopologyGeneric.cpp @@ -0,0 +1,45 @@ +/* This file is part of the Recoil engine (GPL v2 or later), see LICENSE.html */ + +// Generic, platform-agnostic cpu_topology implementation for tool builds +// (e.g. unitsync) that link the thread pool for parallel work but never pin +// threads. It reports every logical core as a single group of performance +// cores with no P/E split, no SMT/hyper-threading distinction and no cache +// grouping, and requests no thread pinning. This satisfies the three +// cpu_topology symbols pulled in by CpuID/Threading without dragging in the +// real per-platform topology detection (Platform/{Linux,Win,Mac}/CpuTopology.cpp). +// +// The engine and dedicated server do NOT use this; they link the real +// per-platform implementation for sim-worker pinning. + +#include "CpuTopology.h" + +#include +#include + +namespace cpu_topology { + +ThreadPinPolicy GetThreadPinPolicy() { + return THREAD_PIN_POLICY_NONE; +} + +ProcessorMasks GetProcessorMasks() { + ProcessorMasks processorMasks; + + // Masks are 32 bits wide; cap to match the real per-platform implementations + // (MAX_CPUS == 32). Treat every logical core as a performance core so that + // CPUID::EnumerateCores() derives a correct logical-core count for the pool. + const unsigned int logicalCores = std::min(32u, std::thread::hardware_concurrency()); + + processorMasks.performanceCoreMask = + (logicalCores >= 32u) ? ~0u : ((1u << logicalCores) - 1u); + + return processorMasks; +} + +ProcessorCaches GetProcessorCache() { + // No cache grouping: the only consumers (the affinity/pinning helpers in + // Threading.cpp) are never reached on the tool path. + return ProcessorCaches{}; +} + +} // namespace cpu_topology diff --git a/tools/unitsync/CMakeLists.txt b/tools/unitsync/CMakeLists.txt index 00f124f0a78..db456d8d365 100644 --- a/tools/unitsync/CMakeLists.txt +++ b/tools/unitsync/CMakeLists.txt @@ -82,6 +82,10 @@ set(main_files "${ENGINE_SRC_ROOT}/System/Misc/SpringTime.cpp" "${ENGINE_SRC_ROOT}/System/Platform/CpuID.cpp" "${ENGINE_SRC_ROOT}/System/Platform/CpuTopologyCommon.cpp" + ## unitsync needs the thread pool (for parallel archive scanning) but never + ## pins threads, so it links a generic cpu_topology instead of the real + ## per-platform Platform/{Linux,Win,Mac}/CpuTopology.cpp detection. + "${ENGINE_SRC_ROOT}/System/Platform/CpuTopologyGeneric.cpp" "${ENGINE_SRC_ROOT}/System/Platform/Misc.cpp" "${ENGINE_SRC_ROOT}/System/Platform/ScopedFileLock.cpp" "${ENGINE_SRC_ROOT}/System/Platform/Threading.cpp" @@ -102,20 +106,24 @@ set(main_files "${ENGINE_SRC_ROOT}/System/StringUtil.cpp" ) if (WIN32) - list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Win/CpuTopology.cpp") list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Win/Hardware.cpp") list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Win/WinVersion.cpp") list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/SharedLib.cpp") list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Win/DllLib.cpp") else (WIN32) - list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Linux/CpuTopology.cpp") list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Linux/Hardware.cpp") list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Linux/ThreadSupport.cpp") endif (WIN32) +# The shared engine threading source list pulls in the real per-platform +# Platform/{Linux,Win,Mac}/CpuTopology.cpp. unitsync links a generic +# cpu_topology instead (see main_files above), so strip the platform file here. +set(unitsync_threading_files ${sources_engine_System_Threading}) +list(FILTER unitsync_threading_files EXCLUDE REGEX "Platform/(Linux|Win|Mac)/CpuTopology\\.cpp$") + set(unitsync_files ${sources_engine_System_FileSystem} - ${sources_engine_System_Threading} + ${unitsync_threading_files} ${sources_engine_System_Log} ${sources_engine_System_Log_sinkFile} ${sources_engine_System_Log_sinkOutputDebugString}