Make Windows-specific throttling code conditional

- Wrap throttling logic in #ifdef _WIN32 blocks in Miner.cpp
- Remove Windows-specific includes from Worker.cpp and CpuWorker.cpp
- Restore Worker.cpp to original platform-neutral state
- Throttling now only compiles on Windows, Linux builds should work
This commit is contained in:
JorySeverijnse 2025-12-13 23:55:45 +01:00
parent 84a9cc83f4
commit cc4f3e01f6
4 changed files with 15 additions and 1480 deletions

File diff suppressed because it is too large Load Diff

View File

@ -20,22 +20,6 @@
#include "backend/common/Worker.h" #include "backend/common/Worker.h"
#include "base/kernel/Platform.h" #include "base/kernel/Platform.h"
#include "crypto/common/VirtualMemory.h" #include "crypto/common/VirtualMemory.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include <windows.h>
#include <cstdint>
#include <algorithm>
// Global throttling state
static bool g_isThrottled = false;
static uint64_t g_originalAffinity = 0;
namespace xmrig {
void setThrottlingState(bool throttled, uint64_t originalAffinity) {
g_isThrottled = throttled;
g_originalAffinity = originalAffinity;
}
}
xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) : xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
@ -44,28 +28,6 @@ xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
{ {
m_node = VirtualMemory::bindToNUMANode(affinity); m_node = VirtualMemory::bindToNUMANode(affinity);
// Store original affinity on first call Platform::trySetThreadAffinity(affinity);
static bool firstCall = true;
if (firstCall) {
g_originalAffinity = affinity;
firstCall = false;
}
// Apply throttling if active
if (g_isThrottled) {
// Calculate 25% of cores
const uint32_t totalCores = 8; // TODO: Get actual core count
const uint32_t coresToUse = std::max(1u, totalCores / 4);
uint64_t throttledAffinity = 0;
for (uint32_t i = 0; i < coresToUse; ++i) {
throttledAffinity |= (1ULL << i);
}
LOG_INFO("WORKER: Setting throttled affinity=%llu, original=%llu", throttledAffinity, g_originalAffinity);
Platform::trySetThreadAffinity(throttledAffinity);
} else {
LOG_INFO("WORKER: Setting original affinity=%llu", g_originalAffinity);
Platform::trySetThreadAffinity(g_originalAffinity);
}
Platform::setThreadPriority(priority); Platform::setThreadPriority(priority);
} }

View File

@ -20,7 +20,6 @@
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <algorithm> #include <algorithm>
#include <windows.h>
#include "backend/cpu/Cpu.h" #include "backend/cpu/Cpu.h"

View File

@ -19,7 +19,9 @@
#include <algorithm> #include <algorithm>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#ifdef _WIN32
#include <windows.h> #include <windows.h>
#endif
#include "core/Miner.h" #include "core/Miner.h"
@ -695,29 +697,36 @@ void xmrig::Miner::onTimer(const Timer *)
autoPause(d_ptr->user_active, Platform::isUserActive(config->idleTime()), YELLOW_BOLD("user active"), GREEN_BOLD("user inactive")); autoPause(d_ptr->user_active, Platform::isUserActive(config->idleTime()), YELLOW_BOLD("user active"), GREEN_BOLD("user inactive"));
} }
#ifdef _WIN32
if (config->isThrottleOnActive()) { if (config->isThrottleOnActive()) {
const bool userActive = Platform::isUserActive(config->throttleIdleTime()); const bool userActive = Platform::isUserActive(config->throttleIdleTime());
static bool lastThrottleState = false; static bool lastThrottleState = false;
static DWORD cachedTotalCores = 0;
if (userActive != lastThrottleState) { if (cachedTotalCores == 0) {
// Get actual core count dynamically
SYSTEM_INFO sysInfo; SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo); GetSystemInfo(&sysInfo);
DWORD totalCores = sysInfo.dwNumberOfProcessors; cachedTotalCores = sysInfo.dwNumberOfProcessors;
}
if (userActive != lastThrottleState) {
if (userActive) { if (userActive) {
// 25% of cores for throttling // 25% of cores for throttling
DWORD coresToUse = std::max(1UL, totalCores / 4); DWORD coresToUse = std::max(1UL, cachedTotalCores / 4);
DWORD_PTR throttleMask = (1ULL << coresToUse) - 1; // First N cores DWORD_PTR throttleMask = (1ULL << coresToUse) - 1; // First N cores
SetProcessAffinityMask(GetCurrentProcess(), throttleMask); SetProcessAffinityMask(GetCurrentProcess(), throttleMask);
} else { } else {
// All cores for full performance // All cores for full performance
DWORD_PTR fullMask = (totalCores >= 64) ? (DWORD_PTR)-1 : ((1ULL << totalCores) - 1); DWORD_PTR fullMask = (cachedTotalCores >= 64) ? (DWORD_PTR)-1 : ((1ULL << cachedTotalCores) - 1);
SetProcessAffinityMask(GetCurrentProcess(), fullMask); SetProcessAffinityMask(GetCurrentProcess(), fullMask);
} }
lastThrottleState = userActive; lastThrottleState = userActive;
} }
} }
#endif
lastThrottleState = userActive;
}
}
if (stopMiner) { if (stopMiner) {
stop(); stop();