From e051564d73b09aca2f80a1ce5cac783d5ce6e720 Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 3 May 2024 21:14:48 +0800 Subject: [PATCH 1/4] Update Miner.cpp Add library --- src/core/Miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 9cc9092b3..1f8ef5043 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -19,7 +19,7 @@ #include #include #include - +#include #include "core/Miner.h" #include "core/Taskbar.h" From 7ad834de927eab715622adc76dc01a44c7b91bbf Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 3 May 2024 21:21:33 +0800 Subject: [PATCH 2/4] Update Miner.h Add attribute sleepNanoSeconds --- src/core/Miner.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/Miner.h b/src/core/Miner.h index bb4293d08..26883cb36 100644 --- a/src/core/Miner.h +++ b/src/core/Miner.h @@ -48,6 +48,8 @@ public: Miner(Controller *controller); ~Miner() override; + int sleepNanoSeconds; + bool isEnabled() const; bool isEnabled(const Algorithm &algorithm) const; const Algorithms &algorithms() const; From d170db1ed3c3d85c46c22705588aec41c3929607 Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 3 May 2024 21:25:47 +0800 Subject: [PATCH 3/4] Update Miner.cpp Parse value from the environment variable named as XMRIG_SLEEP_NANOSECONDS --- src/core/Miner.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 1f8ef5043..4aa86fbaa 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -380,6 +380,14 @@ public: xmrig::Miner::Miner(Controller *controller) : d_ptr(new MinerPrivate(controller)) { + + + // Read the environment variable + const char* envNanoSeconds = std::getenv("XMRIG_SLEEP_NANOSECONDS"); + + // Default value if not configured + sleepNanoSeconds = (envNanoSeconds != nullptr) ? std::atoi(envNanoSeconds) : 0; + const int priority = controller->config()->cpu().priority(); if (priority >= 0) { Platform::setProcessPriority(priority); From 531657cb4584caf64e04da315f566553be6302d8 Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 3 May 2024 21:29:19 +0800 Subject: [PATCH 4/4] Update Miner.cpp Add the effective line which enables slowing down the mining process by sleeping for given nanoseconds --- src/core/Miner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 4aa86fbaa..95389b2e5 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -457,6 +457,8 @@ const std::vector &xmrig::Miner::backends() const xmrig::Job xmrig::Miner::job() const { + std::this_thread::sleep_for(std::chrono::nanoseconds(sleepNanoSeconds)); + std::lock_guard lock(mutex); return d_ptr->job;