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
This commit is contained in:
parent
684ea9d08a
commit
ea6b600fb2
@ -20,6 +20,7 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <algorithm>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#include "backend/cpu/Cpu.h"
|
||||
@ -382,11 +383,13 @@ void xmrig::CpuWorker<N>::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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user