mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 10:01:06 +00:00
"GET /1/threads" replaced to "GET /2/backends".
This commit is contained in:
parent
fa2c9df075
commit
1d78e7d60d
10 changed files with 159 additions and 58 deletions
|
@ -52,11 +52,7 @@ xmrig::ApiRouter::~ApiRouter()
|
||||||
void xmrig::ApiRouter::onRequest(IApiRequest &request)
|
void xmrig::ApiRouter::onRequest(IApiRequest &request)
|
||||||
{
|
{
|
||||||
if (request.method() == IApiRequest::METHOD_GET) {
|
if (request.method() == IApiRequest::METHOD_GET) {
|
||||||
if (request.url() == "/1/threads") {
|
if (request.url() == "/1/config") {
|
||||||
request.accept();
|
|
||||||
getThreads(request.reply(), request.doc());
|
|
||||||
}
|
|
||||||
else if (request.url() == "/1/config") {
|
|
||||||
if (request.isRestricted()) {
|
if (request.isRestricted()) {
|
||||||
return request.done(403);
|
return request.done(403);
|
||||||
}
|
}
|
||||||
|
@ -77,33 +73,3 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::ApiRouter::getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const
|
|
||||||
{
|
|
||||||
// using namespace rapidjson;
|
|
||||||
// auto &allocator = doc.GetAllocator();
|
|
||||||
// const Hashrate *hr = WorkersLegacy::hashrate();
|
|
||||||
|
|
||||||
// WorkersLegacy::threadsSummary(doc);
|
|
||||||
|
|
||||||
// const std::vector<IThread *> &threads = m_base->config()->threads();
|
|
||||||
// Value list(kArrayType);
|
|
||||||
|
|
||||||
// size_t i = 0;
|
|
||||||
// for (const xmrig::IThread *thread : threads) {
|
|
||||||
// Value value = thread->toAPI(doc);
|
|
||||||
|
|
||||||
// Value hashrate(kArrayType);
|
|
||||||
// hashrate.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
|
|
||||||
// hashrate.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
|
|
||||||
// hashrate.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
|
|
||||||
|
|
||||||
// i++;
|
|
||||||
|
|
||||||
// value.AddMember("hashrate", hashrate, allocator);
|
|
||||||
// list.PushBack(value, allocator);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// reply.AddMember("threads", list, allocator);
|
|
||||||
}
|
|
||||||
|
|
|
@ -49,8 +49,6 @@ protected:
|
||||||
void onRequest(IApiRequest &request) override;
|
void onRequest(IApiRequest &request) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
|
||||||
|
|
||||||
Base *m_base;
|
Base *m_base;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,11 +51,16 @@ public:
|
||||||
virtual bool isEnabled(const Algorithm &algorithm) const = 0;
|
virtual bool isEnabled(const Algorithm &algorithm) const = 0;
|
||||||
virtual const Hashrate *hashrate() const = 0;
|
virtual const Hashrate *hashrate() const = 0;
|
||||||
virtual const String &profileName() const = 0;
|
virtual const String &profileName() const = 0;
|
||||||
|
virtual const String &type() const = 0;
|
||||||
virtual void printHashrate(bool details) = 0;
|
virtual void printHashrate(bool details) = 0;
|
||||||
virtual void setJob(const Job &job) = 0;
|
virtual void setJob(const Job &job) = 0;
|
||||||
virtual void start(IWorker *worker) = 0;
|
virtual void start(IWorker *worker) = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
virtual void tick(uint64_t ticks) = 0;
|
virtual void tick(uint64_t ticks) = 0;
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_API
|
||||||
|
virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0;
|
||||||
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
static ICpuInfo *info();
|
static ICpuInfo *info();
|
||||||
static void init();
|
static void init();
|
||||||
static void release();
|
static void release();
|
||||||
|
|
||||||
|
inline static Assembly::Id assembly(Assembly::Id hint) { return hint == Assembly::AUTO ? Cpu::info()->assembly() : hint; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "backend/common/Hashrate.h"
|
#include "backend/common/Hashrate.h"
|
||||||
#include "backend/common/interfaces/IWorker.h"
|
#include "backend/common/interfaces/IWorker.h"
|
||||||
#include "backend/common/Workers.h"
|
#include "backend/common/Workers.h"
|
||||||
|
#include "backend/cpu/Cpu.h"
|
||||||
#include "backend/cpu/CpuBackend.h"
|
#include "backend/cpu/CpuBackend.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/stratum/Job.h"
|
#include "base/net/stratum/Job.h"
|
||||||
|
@ -37,6 +38,9 @@
|
||||||
#include "core/config/Config.h"
|
#include "core/config/Config.h"
|
||||||
#include "core/Controller.h"
|
#include "core/Controller.h"
|
||||||
#include "crypto/common/VirtualMemory.h"
|
#include "crypto/common/VirtualMemory.h"
|
||||||
|
#include "crypto/rx/Rx.h"
|
||||||
|
#include "crypto/rx/RxDataset.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -45,6 +49,9 @@ namespace xmrig {
|
||||||
extern template class Threads<CpuThread>;
|
extern template class Threads<CpuThread>;
|
||||||
|
|
||||||
|
|
||||||
|
static const String kType = "cpu";
|
||||||
|
|
||||||
|
|
||||||
struct LaunchStatus
|
struct LaunchStatus
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -59,13 +66,13 @@ public:
|
||||||
ts = Chrono::steadyMSecs();
|
ts = Chrono::steadyMSecs();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t hugePages;
|
size_t hugePages = 0;
|
||||||
size_t memory;
|
size_t memory = 0;
|
||||||
size_t pages;
|
size_t pages = 0;
|
||||||
size_t started;
|
size_t started = 0;
|
||||||
size_t threads;
|
size_t threads = 0;
|
||||||
size_t ways;
|
size_t ways = 0;
|
||||||
uint64_t ts;
|
uint64_t ts = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,6 +164,12 @@ const xmrig::String &xmrig::CpuBackend::profileName() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const xmrig::String &xmrig::CpuBackend::type() const
|
||||||
|
{
|
||||||
|
return kType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::CpuBackend::printHashrate(bool details)
|
void xmrig::CpuBackend::printHashrate(bool details)
|
||||||
{
|
{
|
||||||
if (!details || !hashrate()) {
|
if (!details || !hashrate()) {
|
||||||
|
@ -251,3 +264,80 @@ void xmrig::CpuBackend::tick(uint64_t ticks)
|
||||||
{
|
{
|
||||||
d_ptr->workers.tick(ticks);
|
d_ptr->workers.tick(ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_API
|
||||||
|
rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
|
||||||
|
|
||||||
|
Value out(kObjectType);
|
||||||
|
out.AddMember("type", type().toJSON(), allocator);
|
||||||
|
out.AddMember("enabled", isEnabled(), allocator);
|
||||||
|
out.AddMember("algo", d_ptr->algo.toJSON(), allocator);
|
||||||
|
out.AddMember("profile", profileName().toJSON(), allocator);
|
||||||
|
out.AddMember("hw-aes", cpu.isHwAES(), allocator);
|
||||||
|
out.AddMember("priority", cpu.priority(), allocator);
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_ASM
|
||||||
|
const Assembly assembly = Cpu::assembly(cpu.assembly());
|
||||||
|
out.AddMember("asm", assembly.toJSON(), allocator);
|
||||||
|
# else
|
||||||
|
out.AddMember("asm", false, allocator);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
uv_mutex_lock(&d_ptr->mutex);
|
||||||
|
uint64_t pages[2] = { d_ptr->status.hugePages, d_ptr->status.pages };
|
||||||
|
const size_t ways = d_ptr->status.ways;
|
||||||
|
uv_mutex_unlock(&d_ptr->mutex);
|
||||||
|
|
||||||
|
# ifdef XMRIG_ALGO_RANDOMX
|
||||||
|
if (d_ptr->algo.family() == Algorithm::RANDOM_X) {
|
||||||
|
RxDataset *dataset = Rx::dataset();
|
||||||
|
if (dataset) {
|
||||||
|
const auto rxPages = dataset->hugePages();
|
||||||
|
pages[0] += rxPages.first;
|
||||||
|
pages[1] += rxPages.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
rapidjson::Value hugepages(rapidjson::kArrayType);
|
||||||
|
hugepages.PushBack(pages[0], allocator);
|
||||||
|
hugepages.PushBack(pages[1], allocator);
|
||||||
|
|
||||||
|
out.AddMember("hugepages", hugepages, allocator);
|
||||||
|
out.AddMember("memory", d_ptr->algo.isValid() ? (ways * d_ptr->algo.memory()) : 0, allocator);
|
||||||
|
|
||||||
|
if (d_ptr->threads.empty() || !hashrate()) {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
Value threads(kArrayType);
|
||||||
|
const Hashrate *hr = hashrate();
|
||||||
|
|
||||||
|
size_t i = 0;
|
||||||
|
for (const CpuLaunchData &data : d_ptr->threads) {
|
||||||
|
Value thread(kObjectType);
|
||||||
|
thread.AddMember("intensity", data.intensity, allocator);
|
||||||
|
thread.AddMember("affinity", data.affinity, allocator);
|
||||||
|
thread.AddMember("av", data.av(), allocator);
|
||||||
|
|
||||||
|
Value hashrate(kArrayType);
|
||||||
|
hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
|
||||||
|
hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
|
||||||
|
hashrate.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
thread.AddMember("hashrate", hashrate, allocator);
|
||||||
|
threads.PushBack(thread, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
out.AddMember("threads", threads, allocator);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -48,12 +48,17 @@ protected:
|
||||||
bool isEnabled(const Algorithm &algorithm) const override;
|
bool isEnabled(const Algorithm &algorithm) const override;
|
||||||
const Hashrate *hashrate() const override;
|
const Hashrate *hashrate() const override;
|
||||||
const String &profileName() const override;
|
const String &profileName() const override;
|
||||||
|
const String &type() const override;
|
||||||
void printHashrate(bool details) override;
|
void printHashrate(bool details) override;
|
||||||
void setJob(const Job &job) override;
|
void setJob(const Job &job) override;
|
||||||
void start(IWorker *worker) override;
|
void start(IWorker *worker) override;
|
||||||
void stop() override;
|
void stop() override;
|
||||||
void tick(uint64_t ticks) override;
|
void tick(uint64_t ticks) override;
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_API
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const override;
|
||||||
|
# endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CpuBackendPrivate *d_ptr;
|
CpuBackendPrivate *d_ptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -205,6 +205,19 @@ public:
|
||||||
|
|
||||||
reply.AddMember("hashrate", hashrate, allocator);
|
reply.AddMember("hashrate", hashrate, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void getBackends(rapidjson::Value &reply, rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
reply.SetArray();
|
||||||
|
|
||||||
|
for (IBackend *backend : backends) {
|
||||||
|
reply.PushBack(backend->toJSON(doc), allocator);
|
||||||
|
}
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -412,11 +425,18 @@ void xmrig::Miner::onTimer(const Timer *)
|
||||||
#ifdef XMRIG_FEATURE_API
|
#ifdef XMRIG_FEATURE_API
|
||||||
void xmrig::Miner::onRequest(IApiRequest &request)
|
void xmrig::Miner::onRequest(IApiRequest &request)
|
||||||
{
|
{
|
||||||
|
if (request.method() == IApiRequest::METHOD_GET) {
|
||||||
if (request.type() == IApiRequest::REQ_SUMMARY) {
|
if (request.type() == IApiRequest::REQ_SUMMARY) {
|
||||||
request.accept();
|
request.accept();
|
||||||
|
|
||||||
d_ptr->getMiner(request.reply(), request.doc(), request.version());
|
d_ptr->getMiner(request.reply(), request.doc(), request.version());
|
||||||
d_ptr->getHashrate(request.reply(), request.doc(), request.version());
|
d_ptr->getHashrate(request.reply(), request.doc(), request.version());
|
||||||
}
|
}
|
||||||
|
else if (request.url() == "/2/backends") {
|
||||||
|
request.accept();
|
||||||
|
|
||||||
|
d_ptr->getBackends(request.reply(), request.doc());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -262,7 +262,7 @@ xmrig::cn_hash_fun xmrig::CnHash::fn(const Algorithm &algorithm, AlgoVariant av,
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_ASM
|
# ifdef XMRIG_FEATURE_ASM
|
||||||
cn_hash_fun fun = cnHash.m_map[algorithm][av][assembly == Assembly::AUTO ? Cpu::info()->assembly() : assembly];
|
cn_hash_fun fun = cnHash.m_map[algorithm][av][Cpu::assembly(assembly)];
|
||||||
if (fun) {
|
if (fun) {
|
||||||
return fun;
|
return fun;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,17 @@ static const char *tag = BLUE_BG(" rx ");
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::RxDataset *xmrig::Rx::dataset()
|
||||||
|
{
|
||||||
|
d_ptr->lock();
|
||||||
|
RxDataset *dataset = d_ptr->dataset;
|
||||||
|
d_ptr->unlock();
|
||||||
|
|
||||||
|
return dataset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
xmrig::RxDataset *xmrig::Rx::dataset(const uint8_t *seed, const Algorithm &algorithm, bool hugePages)
|
xmrig::RxDataset *xmrig::Rx::dataset(const uint8_t *seed, const Algorithm &algorithm, bool hugePages)
|
||||||
{
|
{
|
||||||
d_ptr->lock();
|
d_ptr->lock();
|
||||||
|
|
|
@ -42,6 +42,7 @@ class RxDataset;
|
||||||
class Rx
|
class Rx
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static RxDataset *dataset();
|
||||||
static RxDataset *dataset(const uint8_t *seed, const Algorithm &algorithm, bool hugePages = true);
|
static RxDataset *dataset(const uint8_t *seed, const Algorithm &algorithm, bool hugePages = true);
|
||||||
static void stop();
|
static void stop();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue