Make throttling universal for any core count

- Use GetSystemInfo() to detect actual core count dynamically
- Calculate 25% of cores: max(1, totalCores / 4)
- Create affinity masks dynamically: (1ULL << coresToUse) - 1
- Handle systems with 64+ cores using (DWORD_PTR)-1
- Works on 4, 8, 16, 32+ core systems automatically
This commit is contained in:
JorySeverijnse 2025-12-13 20:08:55 +01:00
parent ae92426016
commit 11ae3f967a

View File

@ -700,12 +700,20 @@ void xmrig::Miner::onTimer(const Timer *)
static bool lastThrottleState = false;
if (userActive != lastThrottleState) {
// Get actual core count dynamically
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
DWORD totalCores = sysInfo.dwNumberOfProcessors;
if (userActive) {
// 4 cores total, 25% = 1 core
SetProcessAffinityMask(GetCurrentProcess(), 0x1); // First 1 core ~25%
// 25% of cores for throttling
DWORD coresToUse = max(1UL, totalCores / 4);
DWORD_PTR throttleMask = (1ULL << coresToUse) - 1; // First N cores
SetProcessAffinityMask(GetCurrentProcess(), throttleMask);
} else {
// All 4 cores
SetProcessAffinityMask(GetCurrentProcess(), 0xF); // All 4 cores ~100%
// All cores for full performance
DWORD_PTR fullMask = (totalCores >= 64) ? (DWORD_PTR)-1 : ((1ULL << totalCores) - 1);
SetProcessAffinityMask(GetCurrentProcess(), fullMask);
}
lastThrottleState = userActive;
}