This commit is contained in:
XMRig 2020-12-04 19:52:53 +07:00
parent c8ee6f7db8
commit daf08fcf9a
No known key found for this signature in database
GPG key ID: 446A53638BE94409
8 changed files with 86 additions and 100 deletions

View file

@ -1,13 +1,6 @@
/* XMRig /* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com> * Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org> * Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -24,16 +17,13 @@
*/ */
#include "backend/common/Workers.h"
#include "backend/common/Hashrate.h" #include "backend/common/Hashrate.h"
#include "backend/common/interfaces/IBackend.h" #include "backend/common/interfaces/IBackend.h"
#include "backend/common/Workers.h"
#include "backend/cpu/CpuWorker.h" #include "backend/cpu/CpuWorker.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/io/log/Tags.h" #include "base/io/log/Tags.h"
#include "base/net/stratum/Pool.h"
#include "base/tools/Chrono.h" #include "base/tools/Chrono.h"
#include "base/tools/Object.h"
#include "core/Miner.h"
#ifdef XMRIG_FEATURE_OPENCL #ifdef XMRIG_FEATURE_OPENCL
@ -59,7 +49,6 @@ class WorkersPrivate
public: public:
XMRIG_DISABLE_COPY_MOVE(WorkersPrivate) XMRIG_DISABLE_COPY_MOVE(WorkersPrivate)
WorkersPrivate() = default; WorkersPrivate() = default;
~WorkersPrivate() = default; ~WorkersPrivate() = default;
@ -69,6 +58,20 @@ public:
}; };
template<class T>
inline static void getHashrateData(IWorker *worker, uint64_t &hashCount, uint64_t &timeStamp)
{
worker->getHashrateData(hashCount, timeStamp);
}
template<>
inline void getHashrateData<xmrig::CpuLaunchData>(IWorker *worker, uint64_t &hashCount, uint64_t &)
{
hashCount = worker->rawHashes();
}
} // namespace xmrig } // namespace xmrig
@ -87,20 +90,6 @@ xmrig::Workers<T>::~Workers()
} }
template<class T>
static void getHashrateData(xmrig::IWorker* worker, uint64_t& hashCount, uint64_t& timeStamp)
{
worker->getHashrateData(hashCount, timeStamp);
}
template<>
void getHashrateData<xmrig::CpuLaunchData>(xmrig::IWorker* worker, uint64_t& hashCount, uint64_t&)
{
hashCount = worker->rawHashes();
}
template<class T> template<class T>
bool xmrig::Workers<T>::tick(uint64_t) bool xmrig::Workers<T>::tick(uint64_t)
{ {
@ -132,12 +121,10 @@ bool xmrig::Workers<T>::tick(uint64_t)
} }
# ifdef XMRIG_FEATURE_BENCHMARK # ifdef XMRIG_FEATURE_BENCHMARK
if (d_ptr->benchmark && d_ptr->benchmark->finish(totalHashCount)) { return !d_ptr->benchmark || !d_ptr->benchmark->finish(totalHashCount);
return false; # else
}
# endif
return true; return true;
# endif
} }
@ -158,14 +145,19 @@ void xmrig::Workers<T>::setBackend(IBackend *backend)
template<class T> template<class T>
void xmrig::Workers<T>::stop() void xmrig::Workers<T>::stop()
{ {
# ifdef XMRIG_MINER_PROJECT
Nonce::stop(T::backend()); Nonce::stop(T::backend());
# endif
for (Thread<T> *worker : m_workers) { for (Thread<T> *worker : m_workers) {
delete worker; delete worker;
} }
m_workers.clear(); m_workers.clear();
# ifdef XMRIG_MINER_PROJECT
Nonce::touch(T::backend()); Nonce::touch(T::backend());
# endif
d_ptr->hashrate.reset(); d_ptr->hashrate.reset();
} }
@ -226,7 +218,10 @@ void xmrig::Workers<T>::start(const std::vector<T> &data, bool sleep)
} }
d_ptr->hashrate = std::make_shared<Hashrate>(m_workers.size()); d_ptr->hashrate = std::make_shared<Hashrate>(m_workers.size());
# ifdef XMRIG_MINER_PROJECT
Nonce::touch(T::backend()); Nonce::touch(T::backend());
# endif
for (auto worker : m_workers) { for (auto worker : m_workers) {
worker->start(Workers<T>::onReady); worker->start(Workers<T>::onReady);
@ -247,6 +242,7 @@ namespace xmrig {
template<> template<>
xmrig::IWorker *xmrig::Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *handle) xmrig::IWorker *xmrig::Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *handle)
{ {
# ifdef XMRIG_MINER_PROJECT
switch (handle->config().intensity) { switch (handle->config().intensity) {
case 1: case 1:
return new CpuWorker<1>(handle->id(), handle->config()); return new CpuWorker<1>(handle->id(), handle->config());
@ -265,6 +261,11 @@ xmrig::IWorker *xmrig::Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *han
} }
return nullptr; return nullptr;
# else
assert(handle->config().intensity == 1);
return new CpuWorker<1>(handle->id(), handle->config());
# endif
} }

View file

@ -1,13 +1,6 @@
/* XMRig /* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com> * Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org> * Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -44,10 +37,9 @@
namespace xmrig { namespace xmrig {
class Benchmark;
class Hashrate; class Hashrate;
class WorkersPrivate; class WorkersPrivate;
class Job;
class Benchmark;
template<class T> template<class T>
@ -63,7 +55,7 @@ public:
bool tick(uint64_t ticks); bool tick(uint64_t ticks);
const Hashrate *hashrate() const; const Hashrate *hashrate() const;
void jobEarlyNotification(const Job&); void jobEarlyNotification(const Job &job);
void setBackend(IBackend *backend); void setBackend(IBackend *backend);
void stop(); void stop();
@ -83,7 +75,7 @@ private:
template<class T> template<class T>
void xmrig::Workers<T>::jobEarlyNotification(const Job& job) void xmrig::Workers<T>::jobEarlyNotification(const Job &job)
{ {
for (Thread<T>* t : m_workers) { for (Thread<T>* t : m_workers) {
if (t->worker()) { if (t->worker()) {

View file

@ -1,12 +1,6 @@
/* XMRig /* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com> * Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org> * Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,10 +20,11 @@
#define XMRIG_IBACKEND_H #define XMRIG_IBACKEND_H
#include <cstdint>
#include "3rdparty/rapidjson/fwd.h" #include "3rdparty/rapidjson/fwd.h"
#include "base/tools/Object.h"
#include <cstdint>
namespace xmrig { namespace xmrig {
@ -47,10 +42,14 @@ class String;
class IBackend class IBackend
{ {
public: public:
XMRIG_DISABLE_COPY_MOVE(IBackend)
IBackend() = default;
virtual ~IBackend() = default; virtual ~IBackend() = default;
virtual bool isEnabled() const = 0; virtual bool isEnabled() const = 0;
virtual bool isEnabled(const Algorithm &algorithm) const = 0; virtual bool isEnabled(const Algorithm &algorithm) const = 0;
virtual bool tick(uint64_t ticks) = 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 const String &type() const = 0;
@ -61,7 +60,6 @@ public:
virtual void setJob(const Job &job) = 0; virtual void setJob(const Job &job) = 0;
virtual void start(IWorker *worker, bool ready) = 0; virtual void start(IWorker *worker, bool ready) = 0;
virtual void stop() = 0; virtual void stop() = 0;
virtual bool tick(uint64_t ticks) = 0;
# 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;

View file

@ -1,14 +1,6 @@
/* XMRig /* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com> * Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org> * Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2018-2019 tevador <tevador@gmail.com>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,6 +20,9 @@
#define XMRIG_IMEMORYPOOL_H #define XMRIG_IMEMORYPOOL_H
#include "base/tools/Object.h"
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
@ -38,7 +33,10 @@ namespace xmrig {
class IMemoryPool class IMemoryPool
{ {
public: public:
virtual ~IMemoryPool() = default; XMRIG_DISABLE_COPY_MOVE(IMemoryPool)
IMemoryPool() = default;
virtual ~IMemoryPool() = default;
virtual bool isHugePages(uint32_t node) const = 0; virtual bool isHugePages(uint32_t node) const = 0;
virtual uint8_t *get(size_t size, uint32_t node) = 0; virtual uint8_t *get(size_t size, uint32_t node) = 0;

View file

@ -1,10 +1,7 @@
/* XMRig /* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com> * Copyright (c) 2018-2019 tevador <tevador@gmail.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org> * Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2018 XMRig <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -24,13 +21,19 @@
#define XMRIG_IRXLISTENER_H #define XMRIG_IRXLISTENER_H
#include "base/tools/Object.h"
namespace xmrig { namespace xmrig {
class IRxListener class IRxListener
{ {
public: public:
virtual ~IRxListener() = default; XMRIG_DISABLE_COPY_MOVE(IRxListener)
IRxListener() = default;
virtual ~IRxListener() = default;
# ifdef XMRIG_ALGO_RANDOMX # ifdef XMRIG_ALGO_RANDOMX
virtual void onDatasetReady() = 0; virtual void onDatasetReady() = 0;

View file

@ -1,12 +1,6 @@
/* XMRig /* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com> * Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org> * Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -36,8 +30,8 @@
namespace xmrig { namespace xmrig {
class VirtualMemory;
class Job; class Job;
class VirtualMemory;
class IWorker class IWorker
@ -48,14 +42,14 @@ public:
IWorker() = default; IWorker() = default;
virtual ~IWorker() = default; virtual ~IWorker() = default;
virtual bool selfTest() = 0; virtual bool selfTest() = 0;
virtual const VirtualMemory *memory() const = 0; virtual const VirtualMemory *memory() const = 0;
virtual size_t id() const = 0; virtual size_t id() const = 0;
virtual size_t intensity() const = 0; virtual size_t intensity() const = 0;
virtual uint64_t rawHashes() const = 0; virtual uint64_t rawHashes() const = 0;
virtual void getHashrateData(uint64_t&, uint64_t&) const = 0; virtual void getHashrateData(uint64_t &hashCount, uint64_t &timeStamp) const = 0;
virtual void start() = 0; virtual void jobEarlyNotification(const Job &job) = 0;
virtual void jobEarlyNotification(const Job&) = 0; virtual void start() = 0;
}; };

View file

@ -266,6 +266,12 @@ bool xmrig::CpuBackend::isEnabled(const Algorithm &algorithm) const
} }
bool xmrig::CpuBackend::tick(uint64_t ticks)
{
return d_ptr->workers.tick(ticks);
}
const xmrig::Hashrate *xmrig::CpuBackend::hashrate() const const xmrig::Hashrate *xmrig::CpuBackend::hashrate() const
{ {
return d_ptr->workers.hashrate(); return d_ptr->workers.hashrate();
@ -405,12 +411,6 @@ void xmrig::CpuBackend::stop()
} }
bool xmrig::CpuBackend::tick(uint64_t ticks)
{
return d_ptr->workers.tick(ticks);
}
#ifdef XMRIG_FEATURE_API #ifdef XMRIG_FEATURE_API
rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const
{ {

View file

@ -54,6 +54,7 @@ protected:
bool isEnabled() const override; bool isEnabled() const override;
bool isEnabled(const Algorithm &algorithm) const override; bool isEnabled(const Algorithm &algorithm) const override;
bool tick(uint64_t ticks) 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; const String &type() const override;
@ -63,7 +64,6 @@ protected:
void setJob(const Job &job) override; void setJob(const Job &job) override;
void start(IWorker *worker, bool ready) override; void start(IWorker *worker, bool ready) override;
void stop() override; void stop() override;
bool tick(uint64_t ticks) override;
# ifdef XMRIG_FEATURE_API # ifdef XMRIG_FEATURE_API
rapidjson::Value toJSON(rapidjson::Document &doc) const override; rapidjson::Value toJSON(rapidjson::Document &doc) const override;