More flexible API handling for mining backends.
This commit is contained in:
parent
36da54b8ce
commit
f9f04e4b2e
4 changed files with 54 additions and 48 deletions
|
@ -37,6 +37,7 @@ namespace xmrig {
|
||||||
|
|
||||||
class Algorithm;
|
class Algorithm;
|
||||||
class Hashrate;
|
class Hashrate;
|
||||||
|
class IApiRequest;
|
||||||
class IWorker;
|
class IWorker;
|
||||||
class Job;
|
class Job;
|
||||||
class String;
|
class String;
|
||||||
|
@ -61,6 +62,7 @@ public:
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_API
|
# ifdef XMRIG_FEATURE_API
|
||||||
virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0;
|
virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0;
|
||||||
|
virtual void handleRequest(IApiRequest &request) = 0;
|
||||||
# endif
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,11 @@
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_API
|
||||||
|
# include "base/api/interfaces/IApiRequest.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,6 +122,38 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value hugePages(int version, rapidjson::Document &doc)
|
||||||
|
{
|
||||||
|
std::pair<unsigned, unsigned> pages(0, 0);
|
||||||
|
|
||||||
|
# ifdef XMRIG_ALGO_RANDOMX
|
||||||
|
if (algo.family() == Algorithm::RANDOM_X) {
|
||||||
|
pages = Rx::hugePages();
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
mutex.lock();
|
||||||
|
|
||||||
|
pages.first += status.hugePages;
|
||||||
|
pages.second += status.pages;
|
||||||
|
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
rapidjson::Value hugepages;
|
||||||
|
|
||||||
|
if (version > 1) {
|
||||||
|
hugepages.SetArray();
|
||||||
|
hugepages.PushBack(pages.first, doc.GetAllocator());
|
||||||
|
hugepages.PushBack(pages.second, doc.GetAllocator());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hugepages = pages.first == pages.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hugepages;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Algorithm algo;
|
Algorithm algo;
|
||||||
Controller *controller;
|
Controller *controller;
|
||||||
LaunchStatus status;
|
LaunchStatus status;
|
||||||
|
@ -143,25 +180,6 @@ xmrig::CpuBackend::~CpuBackend()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::pair<unsigned, unsigned> xmrig::CpuBackend::hugePages() const
|
|
||||||
{
|
|
||||||
std::pair<unsigned, unsigned> pages(0, 0);
|
|
||||||
|
|
||||||
# ifdef XMRIG_ALGO_RANDOMX
|
|
||||||
if (d_ptr->algo.family() == Algorithm::RANDOM_X) {
|
|
||||||
pages = Rx::hugePages();
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(d_ptr->mutex);
|
|
||||||
|
|
||||||
pages.first += d_ptr->status.hugePages;
|
|
||||||
pages.second += d_ptr->status.pages;
|
|
||||||
|
|
||||||
return pages;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool xmrig::CpuBackend::isEnabled() const
|
bool xmrig::CpuBackend::isEnabled() const
|
||||||
{
|
{
|
||||||
return d_ptr->controller->config()->cpu().isEnabled();
|
return d_ptr->controller->config()->cpu().isEnabled();
|
||||||
|
@ -319,13 +337,7 @@ rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const
|
||||||
out.AddMember("asm", false, allocator);
|
out.AddMember("asm", false, allocator);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
const auto pages = hugePages();
|
out.AddMember("hugepages", d_ptr->hugePages(2, doc), allocator);
|
||||||
|
|
||||||
rapidjson::Value hugepages(rapidjson::kArrayType);
|
|
||||||
hugepages.PushBack(pages.first, allocator);
|
|
||||||
hugepages.PushBack(pages.second, allocator);
|
|
||||||
|
|
||||||
out.AddMember("hugepages", hugepages, allocator);
|
|
||||||
out.AddMember("memory", static_cast<uint64_t>(d_ptr->algo.isValid() ? (d_ptr->ways() * d_ptr->algo.l3()) : 0), allocator);
|
out.AddMember("memory", static_cast<uint64_t>(d_ptr->algo.isValid() ? (d_ptr->ways() * d_ptr->algo.l3()) : 0), allocator);
|
||||||
|
|
||||||
if (d_ptr->threads.empty() || !hashrate()) {
|
if (d_ptr->threads.empty() || !hashrate()) {
|
||||||
|
@ -357,4 +369,12 @@ rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::CpuBackend::handleRequest(IApiRequest &request)
|
||||||
|
{
|
||||||
|
if (request.type() == IApiRequest::REQ_SUMMARY) {
|
||||||
|
request.reply().AddMember("hugepages", d_ptr->hugePages(request.version(), request.doc()), request.doc().GetAllocator());
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,8 +46,6 @@ public:
|
||||||
CpuBackend(Controller *controller);
|
CpuBackend(Controller *controller);
|
||||||
~CpuBackend() override;
|
~CpuBackend() override;
|
||||||
|
|
||||||
std::pair<unsigned, unsigned> hugePages() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool isEnabled() const override;
|
bool isEnabled() const override;
|
||||||
bool isEnabled(const Algorithm &algorithm) const override;
|
bool isEnabled(const Algorithm &algorithm) const override;
|
||||||
|
@ -63,6 +61,7 @@ protected:
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_API
|
# ifdef XMRIG_FEATURE_API
|
||||||
rapidjson::Value toJSON(rapidjson::Document &doc) const override;
|
rapidjson::Value toJSON(rapidjson::Document &doc) const override;
|
||||||
|
void handleRequest(IApiRequest &request) override;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -135,7 +135,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_API
|
# ifdef XMRIG_FEATURE_API
|
||||||
void getMiner(rapidjson::Value &reply, rapidjson::Document &doc, int version) const
|
void getMiner(rapidjson::Value &reply, rapidjson::Document &doc, int) const
|
||||||
{
|
{
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
@ -144,25 +144,6 @@ public:
|
||||||
reply.AddMember("kind", APP_KIND, allocator);
|
reply.AddMember("kind", APP_KIND, allocator);
|
||||||
reply.AddMember("ua", StringRef(Platform::userAgent()), allocator);
|
reply.AddMember("ua", StringRef(Platform::userAgent()), allocator);
|
||||||
reply.AddMember("cpu", Cpu::toJSON(doc), allocator);
|
reply.AddMember("cpu", Cpu::toJSON(doc), allocator);
|
||||||
|
|
||||||
Value hugepages;
|
|
||||||
|
|
||||||
if (!backends.empty() && backends.front()->type() == "cpu") {
|
|
||||||
const auto pages = static_cast<CpuBackend *>(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);
|
reply.AddMember("donate_level", controller->config()->pools().donateLevel(), allocator);
|
||||||
|
|
||||||
Value algo(kArrayType);
|
Value algo(kArrayType);
|
||||||
|
@ -489,5 +470,9 @@ void xmrig::Miner::onRequest(IApiRequest &request)
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (IBackend *backend : d_ptr->backends) {
|
||||||
|
backend->handleRequest(request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue