Added initial support for new style threads launch method.

This commit is contained in:
XMRig 2019-07-16 22:10:50 +07:00
parent dff59fabc2
commit 27f3008d79
32 changed files with 1429 additions and 505 deletions

View file

@ -0,0 +1,151 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "backend/common/Workers.h"
#include "backend/cpu/CpuBackend.h"
#include "base/net/stratum/Job.h"
#include "base/tools/String.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "base/io/log/Log.h"
namespace xmrig {
extern template class Threads<CpuThread>;
class CpuBackendPrivate
{
public:
inline CpuBackendPrivate(const Miner *miner, Controller *controller) :
miner(miner),
controller(controller)
{
}
inline ~CpuBackendPrivate()
{
}
inline bool isReady(const Algorithm &nextAlgo) const
{
if (!algo.isValid()) {
return false;
}
if (nextAlgo == algo) {
return true;
}
const CpuThreads &nextThreads = controller->config()->cpu().threads().get(nextAlgo);
return algo.memory() == nextAlgo.memory()
&& threads.size() == nextThreads.size()
&& std::equal(threads.begin(), threads.end(), nextThreads.begin());
}
Algorithm algo;
const Miner *miner;
Controller *controller;
CpuThreads threads;
String profileName;
Workers<CpuLaunchData> workers;
};
} // namespace xmrig
xmrig::CpuBackend::CpuBackend(const Miner *miner, Controller *controller) :
d_ptr(new CpuBackendPrivate(miner, controller))
{
}
xmrig::CpuBackend::~CpuBackend()
{
delete d_ptr;
}
const xmrig::String &xmrig::CpuBackend::profileName() const
{
return d_ptr->profileName;
}
void xmrig::CpuBackend::printHashrate(bool details)
{
}
void xmrig::CpuBackend::setJob(const Job &job)
{
LOG_WARN("PROFILE %s %zu", d_ptr->controller->config()->cpu().threads().profileName(job.algorithm()).data(), job.algorithm().memory());
if (d_ptr->isReady(job.algorithm())) {
return;
}
LOG_INFO(GREEN_BOLD_S "INIT");
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
const Threads<CpuThread> &threads = cpu.threads();
d_ptr->algo = job.algorithm();
d_ptr->profileName = threads.profileName(job.algorithm());
d_ptr->threads = threads.get(d_ptr->profileName);
LOG_INFO(BLUE_BG_S " %zu ", d_ptr->threads.size());
d_ptr->workers.stop();
for (const CpuThread &thread : d_ptr->threads) {
d_ptr->workers.add(CpuLaunchData(d_ptr->miner, d_ptr->algo, cpu, thread));
}
d_ptr->workers.start();
}
void xmrig::CpuBackend::stop()
{
d_ptr->workers.stop();
}
void xmrig::CpuBackend::tick(uint64_t ticks)
{
}

View file

@ -0,0 +1,61 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_CPUBACKEND_H
#define XMRIG_CPUBACKEND_H
#include "backend/common/interfaces/IBackend.h"
namespace xmrig {
class Controller;
class CpuBackendPrivate;
class Miner;
class CpuBackend : public IBackend
{
public:
CpuBackend(const Miner *miner, Controller *controller);
~CpuBackend() override;
protected:
const String &profileName() const override;
void printHashrate(bool details) override;
void setJob(const Job &job) override;
void stop() override;
void tick(uint64_t ticks) override;
private:
CpuBackendPrivate *d_ptr;
};
} /* namespace xmrig */
#endif /* XMRIG_CPUBACKEND_H */

View file

@ -0,0 +1,51 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "backend/cpu/CpuLaunchData.h"
#include "backend/cpu/CpuConfig.h"
xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread) :
algorithm(algorithm),
assembly(config.assembly()),
hugePages(config.isHugePages()),
hwAES(config.isHwAES()),
intensity(thread.intensity()),
priority(config.priority()),
affinity(thread.affinity()),
miner(miner)
{
}
xmrig::CnHash::AlgoVariant xmrig::CpuLaunchData::av() const
{
if (intensity <= 2) {
return static_cast<CnHash::AlgoVariant>(!hwAES ? (intensity + 2) : intensity);
}
return static_cast<CnHash::AlgoVariant>(!hwAES ? (intensity + 5) : (intensity + 2));
}

View file

@ -0,0 +1,67 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_CPULAUNCHDATA_H
#define XMRIG_CPULAUNCHDATA_H
#include "crypto/cn/CnHash.h"
#include "crypto/common/Algorithm.h"
#include "crypto/common/Assembly.h"
#include "crypto/common/Nonce.h"
namespace xmrig {
class CpuConfig;
class CpuThread;
class Miner;
class CpuLaunchData
{
public:
CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread);
CnHash::AlgoVariant av() const;
inline constexpr static Nonce::Backend backend() { return Nonce::CPU; }
const Algorithm algorithm;
const Assembly assembly;
const bool hugePages;
const bool hwAES;
const int intensity;
const int priority;
const int64_t affinity;
const Miner *miner;
};
} // namespace xmrig
#endif /* XMRIG_CPULAUNCHDATA_H */

View file

@ -38,19 +38,23 @@ namespace xmrig {
class CpuThread
{
public:
inline constexpr CpuThread(int intensity = 1, int affinity = -1) : m_affinity(affinity), m_intensity(intensity) {}
inline constexpr CpuThread(int intensity = 1, int64_t affinity = -1) : m_intensity(intensity), m_affinity(affinity) {}
CpuThread(const rapidjson::Value &value);
inline bool isValid() const { return m_intensity >= 1 && m_intensity <= 5; }
inline int affinity() const { return m_affinity; }
inline int intensity() const { return m_intensity; }
inline bool isEqual(const CpuThread &other) const { return other.m_affinity == m_affinity && other.m_intensity == m_intensity; }
inline bool isValid() const { return m_intensity >= 1 && m_intensity <= 5; }
inline int intensity() const { return m_intensity; }
inline int64_t affinity() const { return m_affinity; }
inline bool operator!=(const CpuThread &other) const { return !isEqual(other); }
inline bool operator==(const CpuThread &other) const { return isEqual(other); }
rapidjson::Value toJSON(rapidjson::Document &doc) const;
private:
int m_affinity = -1;
int m_intensity = -1;
int m_intensity = -1;
int64_t m_affinity = -1;
};

View file

@ -28,14 +28,17 @@
#include "backend/cpu/CpuWorker.h"
#include "core/Miner.h"
#include "crypto/cn/CryptoNight_test.h"
#include "crypto/common/Nonce.h"
#include "crypto/rx/Rx.h"
#include "crypto/rx/RxVm.h"
#include "net/JobResults.h"
#include "workers/CpuThreadLegacy.h"
#include "workers/ThreadHandle.h"
#include "workers/Workers.h"
#ifdef XMRIG_ALGO_RANDOMX
# include "crypto/randomx/randomx.h"
#endif
namespace xmrig {
@ -45,13 +48,18 @@ static constexpr uint32_t kReserveCount = 4096;
} // namespace xmrig
template<size_t N>
xmrig::CpuWorker<N>::CpuWorker(ThreadHandle *handle) :
Worker(handle->threadId(), handle->config()->affinity(), handle->config()->priority()),
m_thread(static_cast<xmrig::CpuThreadLegacy *>(handle->config()))
xmrig::CpuWorker<N>::CpuWorker(size_t index, const CpuLaunchData &data) :
Worker(index, data.affinity, data.priority),
m_algorithm(data.algorithm),
m_assembly(data.assembly),
m_hwAES(data.hwAES),
m_av(data.av()),
m_miner(data.miner)
{
if (m_thread->algorithm().family() != Algorithm::RANDOM_X) {
m_memory = Mem::create(m_ctx, m_thread->algorithm(), N);
if (m_algorithm.family() != Algorithm::RANDOM_X) {
m_memory = Mem::create(m_ctx, m_algorithm, N);
}
}
@ -73,7 +81,7 @@ void xmrig::CpuWorker<N>::allocateRandomX_VM()
{
if (!m_vm) {
RxDataset *dataset = Rx::dataset(m_job.currentJob().seedHash(), m_job.currentJob().algorithm());
m_vm = new RxVm(dataset, true, m_thread->isSoftAES());
m_vm = new RxVm(dataset, true, !m_hwAES);
}
}
#endif
@ -82,7 +90,7 @@ void xmrig::CpuWorker<N>::allocateRandomX_VM()
template<size_t N>
bool xmrig::CpuWorker<N>::selfTest()
{
if (m_thread->algorithm().family() == Algorithm::CN) {
if (m_algorithm.family() == Algorithm::CN) {
const bool rc = verify(Algorithm::CN_0, test_output_v0) &&
verify(Algorithm::CN_1, test_output_v1) &&
verify(Algorithm::CN_2, test_output_v2) &&
@ -108,14 +116,14 @@ bool xmrig::CpuWorker<N>::selfTest()
}
# ifdef XMRIG_ALGO_CN_LITE
if (m_thread->algorithm().family() == Algorithm::CN_LITE) {
if (m_algorithm.family() == Algorithm::CN_LITE) {
return verify(Algorithm::CN_LITE_0, test_output_v0_lite) &&
verify(Algorithm::CN_LITE_1, test_output_v1_lite);
}
# endif
# ifdef XMRIG_ALGO_CN_HEAVY
if (m_thread->algorithm().family() == Algorithm::CN_HEAVY) {
if (m_algorithm.family() == Algorithm::CN_HEAVY) {
return verify(Algorithm::CN_HEAVY_0, test_output_v0_heavy) &&
verify(Algorithm::CN_HEAVY_XHV, test_output_xhv_heavy) &&
verify(Algorithm::CN_HEAVY_TUBE, test_output_tube_heavy);
@ -123,13 +131,13 @@ bool xmrig::CpuWorker<N>::selfTest()
# endif
# ifdef XMRIG_ALGO_CN_PICO
if (m_thread->algorithm().family() == Algorithm::CN_PICO) {
if (m_algorithm.family() == Algorithm::CN_PICO) {
return verify(Algorithm::CN_PICO_0, test_output_pico_trtl);
}
# endif
# ifdef XMRIG_ALGO_RANDOMX
if (m_thread->algorithm().family() == Algorithm::RANDOM_X) {
if (m_algorithm.family() == Algorithm::RANDOM_X) {
return true;
}
# endif
@ -141,21 +149,21 @@ bool xmrig::CpuWorker<N>::selfTest()
template<size_t N>
void xmrig::CpuWorker<N>::start()
{
while (Nonce::sequence() > 0) {
if (Workers::isPaused()) {
while (Nonce::sequence(Nonce::CPU) > 0) {
if (Nonce::isPaused()) {
do {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
while (Workers::isPaused());
while (Nonce::isPaused());
if (Nonce::sequence() == 0) {
if (Nonce::sequence(Nonce::CPU) == 0) {
break;
}
consumeJob();
}
while (!Nonce::isOutdated(m_job.sequence())) {
while (!Nonce::isOutdated(Nonce::CPU, m_job.sequence())) {
if ((m_count & 0x7) == 0) {
storeStats();
}
@ -170,7 +178,7 @@ void xmrig::CpuWorker<N>::start()
else
# endif
{
m_thread->fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height());
fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height());
}
for (size_t i = 0; i < N; ++i) {
@ -193,7 +201,7 @@ void xmrig::CpuWorker<N>::start()
template<size_t N>
bool xmrig::CpuWorker<N>::verify(const Algorithm &algorithm, const uint8_t *referenceValue)
{
cn_hash_fun func = m_thread->fn(algorithm);
cn_hash_fun func = fn(algorithm);
if (!func) {
return false;
}
@ -206,7 +214,7 @@ bool xmrig::CpuWorker<N>::verify(const Algorithm &algorithm, const uint8_t *refe
template<size_t N>
bool xmrig::CpuWorker<N>::verify2(const Algorithm &algorithm, const uint8_t *referenceValue)
{
cn_hash_fun func = m_thread->fn(algorithm);
cn_hash_fun func = fn(algorithm);
if (!func) {
return false;
}
@ -235,7 +243,7 @@ namespace xmrig {
template<>
bool CpuWorker<1>::verify2(const Algorithm &algorithm, const uint8_t *referenceValue)
{
cn_hash_fun func = m_thread->fn(algorithm);
cn_hash_fun func = fn(algorithm);
if (!func) {
return false;
}
@ -257,7 +265,7 @@ bool CpuWorker<1>::verify2(const Algorithm &algorithm, const uint8_t *referenceV
template<size_t N>
void xmrig::CpuWorker<N>::consumeJob()
{
m_job.add(Workers::job(), Nonce::sequence(), kReserveCount);
m_job.add(m_miner->job(), Nonce::sequence(Nonce::CPU), kReserveCount);
}

View file

@ -27,20 +27,17 @@
#define XMRIG_CPUWORKER_H
#include "backend/common/Worker.h"
#include "backend/common/WorkerJob.h"
#include "backend/cpu/CpuLaunchData.h"
#include "base/net/stratum/Job.h"
#include "Mem.h"
#include "net/JobResult.h"
#include "backend/common/Worker.h"
class ThreadHandle;
namespace xmrig {
class CpuThreadLegacy;
class RxVm;
@ -48,7 +45,7 @@ template<size_t N>
class CpuWorker : public Worker
{
public:
CpuWorker(ThreadHandle *handle);
CpuWorker(size_t index, const CpuLaunchData &data);
~CpuWorker() override;
inline const MemInfo &memory() const { return m_memory; }
@ -58,6 +55,8 @@ protected:
void start() override;
private:
inline cn_hash_fun fn(const Algorithm &algorithm) const { return CnHash::fn(algorithm, m_av, m_assembly); }
# ifdef XMRIG_ALGO_RANDOMX
void allocateRandomX_VM();
# endif
@ -66,7 +65,11 @@ private:
bool verify2(const Algorithm &algorithm, const uint8_t *referenceValue);
void consumeJob();
CpuThreadLegacy *m_thread;
const Algorithm m_algorithm;
const Assembly m_assembly;
const bool m_hwAES;
const CnHash::AlgoVariant m_av;
const Miner *m_miner;
cryptonight_ctx *m_ctx[N];
MemInfo m_memory;
uint8_t m_hash[N * 32];

View file

@ -1,6 +1,8 @@
set(HEADERS_BACKEND_CPU
src/backend/cpu/Cpu.h
src/backend/cpu/CpuBackend.h
src/backend/cpu/CpuConfig.h
src/backend/cpu/CpuLaunchData.cpp
src/backend/cpu/CpuThread.h
src/backend/cpu/CpuWorker.h
src/backend/cpu/interfaces/ICpuInfo.h
@ -8,7 +10,9 @@ set(HEADERS_BACKEND_CPU
set(SOURCES_BACKEND_CPU
src/backend/cpu/Cpu.cpp
src/backend/cpu/CpuBackend.cpp
src/backend/cpu/CpuConfig.cpp
src/backend/cpu/CpuLaunchData.h
src/backend/cpu/CpuThread.cpp
src/backend/cpu/CpuWorker.cpp
)