From ea6b600fb246428ef5d6661db03afc3474a20183 Mon Sep 17 00:00:00 2001 From: JorySeverijnse Date: Sat, 13 Dec 2025 18:42:07 +0100 Subject: [PATCH] Implement Windows API affinity throttling like working version - Use SetProcessAffinityMask directly instead of sleep approach - Limit to first 2 cores (0x3) when user active ~25% usage - Use all cores (-1) when user inactive - Add windows.h include for Windows API - This matches the working implementation approach --- src/backend/cpu/CpuWorker.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index 6d225b3a..75c0d43f 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "backend/cpu/Cpu.h" @@ -382,11 +383,13 @@ void xmrig::CpuWorker::start() m_count += N; } - // Apply timing-based throttling when user is active - // Simple approach: sleep 75% of time to achieve ~25% CPU usage + // Apply Windows API affinity throttling when user is active if (m_isThrottled) { - // Sleep for longer to ensure actual throttling effect - std::this_thread::sleep_for(std::chrono::milliseconds(900)); + // User is active - limit to first 2 cores (~25% on 8-core system) + SetProcessAffinityMask(GetCurrentProcess(), 0x3); + } else { + // User is idle - use all cores + SetProcessAffinityMask(GetCurrentProcess(), (DWORD_PTR)-1); } if (m_yield) {