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:
parent
84a9cc83f4
commit
cc4f3e01f6
1435
session-ses_4e7c.md
1435
session-ses_4e7c.md
File diff suppressed because it is too large
Load Diff
@ -20,22 +20,6 @@
|
||||
#include "backend/common/Worker.h"
|
||||
#include "base/kernel/Platform.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) :
|
||||
@ -44,28 +28,6 @@ xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
|
||||
{
|
||||
m_node = VirtualMemory::bindToNUMANode(affinity);
|
||||
|
||||
// Store original affinity on first call
|
||||
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::trySetThreadAffinity(affinity);
|
||||
Platform::setThreadPriority(priority);
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <algorithm>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#include "backend/cpu/Cpu.h"
|
||||
|
||||
@ -19,7 +19,9 @@
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
#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"));
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (config->isThrottleOnActive()) {
|
||||
const bool userActive = Platform::isUserActive(config->throttleIdleTime());
|
||||
static bool lastThrottleState = false;
|
||||
static DWORD cachedTotalCores = 0;
|
||||
|
||||
if (userActive != lastThrottleState) {
|
||||
// Get actual core count dynamically
|
||||
if (cachedTotalCores == 0) {
|
||||
SYSTEM_INFO sysInfo;
|
||||
GetSystemInfo(&sysInfo);
|
||||
DWORD totalCores = sysInfo.dwNumberOfProcessors;
|
||||
cachedTotalCores = sysInfo.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
if (userActive != lastThrottleState) {
|
||||
if (userActive) {
|
||||
// 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
|
||||
SetProcessAffinityMask(GetCurrentProcess(), throttleMask);
|
||||
} else {
|
||||
// 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);
|
||||
}
|
||||
lastThrottleState = userActive;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
lastThrottleState = userActive;
|
||||
}
|
||||
}
|
||||
|
||||
if (stopMiner) {
|
||||
stop();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user