Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions rts/System/Platform/CpuTopologyGeneric.cpp
Original file line number Diff line number Diff line change
@@ -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 <algorithm>
#include <thread>

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
14 changes: 11 additions & 3 deletions tools/unitsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}
Expand Down
Loading