diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index 863fa0750..246002707 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -109,6 +109,14 @@ public: } + size_t ways() + { + std::lock_guard lock(mutex); + + return status.ways; + } + + Algorithm algo; Controller *controller; LaunchStatus status; @@ -135,6 +143,25 @@ xmrig::CpuBackend::~CpuBackend() } +std::pair xmrig::CpuBackend::hugePages() const +{ + std::pair pages(0, 0); + +# ifdef XMRIG_ALGO_RANDOMX + if (d_ptr->algo.family() == Algorithm::RANDOM_X) { + pages = Rx::hugePages(); + } +# endif + + std::lock_guard lock(d_ptr->mutex); + + pages.first += d_ptr->status.hugePages; + pages.second += d_ptr->status.pages; + + return pages; +} + + bool xmrig::CpuBackend::isEnabled() const { return d_ptr->controller->config()->cpu().isEnabled(); @@ -292,25 +319,14 @@ rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const out.AddMember("asm", false, allocator); # endif - d_ptr->mutex.lock(); - uint64_t pages[2] = { d_ptr->status.hugePages, d_ptr->status.pages }; - const size_t ways = d_ptr->status.ways; - d_ptr->mutex.unlock(); - -# ifdef XMRIG_ALGO_RANDOMX - if (d_ptr->algo.family() == Algorithm::RANDOM_X) { - const auto rxPages = Rx::hugePages(); - pages[0] += rxPages.first; - pages[1] += rxPages.second; - } -# endif + const auto pages = hugePages(); rapidjson::Value hugepages(rapidjson::kArrayType); - hugepages.PushBack(pages[0], allocator); - hugepages.PushBack(pages[1], allocator); + hugepages.PushBack(pages.first, allocator); + hugepages.PushBack(pages.second, allocator); out.AddMember("hugepages", hugepages, allocator); - out.AddMember("memory", static_cast(d_ptr->algo.isValid() ? (ways * d_ptr->algo.l3()) : 0), allocator); + out.AddMember("memory", static_cast(d_ptr->algo.isValid() ? (d_ptr->ways() * d_ptr->algo.l3()) : 0), allocator); if (d_ptr->threads.empty() || !hashrate()) { return out; diff --git a/src/backend/cpu/CpuBackend.h b/src/backend/cpu/CpuBackend.h index 9e71c2470..bedef5ca1 100644 --- a/src/backend/cpu/CpuBackend.h +++ b/src/backend/cpu/CpuBackend.h @@ -26,6 +26,9 @@ #define XMRIG_CPUBACKEND_H +#include + + #include "backend/common/interfaces/IBackend.h" @@ -43,6 +46,8 @@ public: CpuBackend(Controller *controller); ~CpuBackend() override; + std::pair hugePages() const; + protected: bool isEnabled() const override; bool isEnabled(const Algorithm &algorithm) const override; diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index a1c65ed26..4406ce529 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -145,10 +145,24 @@ public: reply.AddMember("ua", StringRef(Platform::userAgent()), allocator); reply.AddMember("cpu", Cpu::toJSON(doc), allocator); - if (version == 1) { - reply.AddMember("hugepages", false, allocator); + Value hugepages; + + if (!backends.empty() && backends.front()->type() == "cpu") { + const auto pages = static_cast(backends.front())->hugePages(); + if (version > 1) { + hugepages.SetArray(); + hugepages.PushBack(pages.first, allocator); + hugepages.PushBack(pages.second, allocator); + } + else { + hugepages = pages.first == pages.second; + } + } + else { + hugepages = false; } + reply.AddMember("hugepages", hugepages, allocator); reply.AddMember("donate_level", controller->config()->pools().donateLevel(), allocator); Value algo(kArrayType);