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
This commit is contained in:
JorySeverijnse 2025-12-13 18:54:15 +01:00
parent ea6b600fb2
commit afdbb02c49

View File

@ -385,8 +385,14 @@ void xmrig::CpuWorker<N>::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);