Move affinity logic to centralized Miner timer
- Remove affinity setting from worker threads (causing conflicts) - Add Windows API affinity control to Miner.cpp timer - Centralized location prevents multiple threads fighting over affinity - Set 25% cores when active, 100% when inactive - Add windows.h include for SetProcessAffinityMask
This commit is contained in:
parent
1c9256d1e8
commit
9289d2ceaa
@ -383,25 +383,7 @@ void xmrig::CpuWorker<N>::start()
|
||||
m_count += N;
|
||||
}
|
||||
|
||||
// Apply Windows API affinity throttling when user is active
|
||||
// Only change affinity when state actually changes, not every loop
|
||||
static bool lastThrottleState = false;
|
||||
if (m_isThrottled != lastThrottleState) {
|
||||
if (m_isThrottled) {
|
||||
// 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);
|
||||
}
|
||||
lastThrottleState = m_isThrottled;
|
||||
}
|
||||
|
||||
|
||||
if (m_yield) {
|
||||
std::this_thread::yield();
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#include "core/Miner.h"
|
||||
@ -700,8 +701,18 @@ void xmrig::Miner::onTimer(const Timer *)
|
||||
|
||||
if (userActive != lastThrottleState) {
|
||||
if (userActive) {
|
||||
// User is active - calculate 25% of total cores
|
||||
const uint32_t totalCores = 8; // TODO: Get actual core count
|
||||
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);
|
||||
LOG_INFO("%s " YELLOW_BOLD("user active - throttling to 25% of cores"), Tags::miner());
|
||||
} else {
|
||||
// User is idle - use all cores
|
||||
SetProcessAffinityMask(GetCurrentProcess(), (DWORD_PTR)-1);
|
||||
LOG_INFO("%s " GREEN_BOLD("user inactive - using all cores"), Tags::miner());
|
||||
}
|
||||
lastThrottleState = userActive;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user