From afdbb02c49addb1d6ab018a09029cdc0b8d6af89 Mon Sep 17 00:00:00 2001 From: JorySeverijnse Date: Sat, 13 Dec 2025 18:54:15 +0100 Subject: [PATCH] Fix dynamic core calculation for proper throttling - Calculate 25% of total cores instead of hardcoded 2 cores - Use std::max(1u, totalCores / 4) to ensure minimum 1 core - Build affinity mask dynamically for calculated cores - This should fix stuck at 50% issue and scale properly --- src/backend/cpu/CpuWorker.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index 75c0d43f..0de0396c 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -385,8 +385,14 @@ void xmrig::CpuWorker::start() // Apply Windows API affinity throttling when user is active if (m_isThrottled) { - // User is active - limit to first 2 cores (~25% on 8-core system) - SetProcessAffinityMask(GetCurrentProcess(), 0x3); + // User is active - calculate 25% of total cores + const uint32_t totalCores = Cpu::info()->threads(); + const uint32_t coresToUse = std::max(1u, totalCores / 4); + uint64_t affinityMask = 0; + for (uint32_t i = 0; i < coresToUse; ++i) { + affinityMask |= (1ULL << i); + } + SetProcessAffinityMask(GetCurrentProcess(), affinityMask); } else { // User is idle - use all cores SetProcessAffinityMask(GetCurrentProcess(), (DWORD_PTR)-1);