From 2f27d5d108113ac0e9a6e0da69fbdd22d995d953 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 14 Feb 2020 01:11:53 +0700 Subject: [PATCH] Added printHealth to IBackend interface. --- src/backend/common/interfaces/IBackend.h | 5 ++-- src/backend/cpu/CpuBackend.cpp | 9 +++++-- src/backend/cpu/CpuBackend.h | 5 ++-- src/backend/cuda/CudaBackend.cpp | 31 ++++++++++-------------- src/backend/cuda/CudaBackend.h | 5 ++-- src/backend/opencl/OclBackend.cpp | 24 +++++++----------- src/backend/opencl/OclBackend.h | 1 + src/core/Miner.cpp | 18 +++++++++++--- 8 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/backend/common/interfaces/IBackend.h b/src/backend/common/interfaces/IBackend.h index c6e05bcfb..bdaf54635 100644 --- a/src/backend/common/interfaces/IBackend.h +++ b/src/backend/common/interfaces/IBackend.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -56,6 +56,7 @@ public: virtual void execCommand(char command) = 0; virtual void prepare(const Job &nextJob) = 0; virtual void printHashrate(bool details) = 0; + virtual void printHealth() = 0; virtual void setJob(const Job &job) = 0; virtual void start(IWorker *worker, bool ready) = 0; virtual void stop() = 0; diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index ac4594975..9ada16376 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -319,6 +319,11 @@ void xmrig::CpuBackend::printHashrate(bool details) } +void xmrig::CpuBackend::printHealth() +{ +} + + void xmrig::CpuBackend::setJob(const Job &job) { if (!isEnabled()) { diff --git a/src/backend/cpu/CpuBackend.h b/src/backend/cpu/CpuBackend.h index d0e2267a2..1046ec359 100644 --- a/src/backend/cpu/CpuBackend.h +++ b/src/backend/cpu/CpuBackend.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -59,6 +59,7 @@ protected: const String &type() const override; void prepare(const Job &nextJob) override; void printHashrate(bool details) override; + void printHealth() override; void setJob(const Job &job) override; void start(IWorker *worker, bool ready) override; void stop() override; diff --git a/src/backend/cuda/CudaBackend.cpp b/src/backend/cuda/CudaBackend.cpp index 5bb1cbdd8..b68784083 100644 --- a/src/backend/cuda/CudaBackend.cpp +++ b/src/backend/cuda/CudaBackend.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -254,7 +254,8 @@ public: } } - LOG_INFO(CYAN_BOLD("#%u") YELLOW(" %s") MAGENTA_BOLD("%4uW") CSI "1;%um %2uC" CLEAR WHITE_BOLD("%s") "%s", + LOG_INFO("%s" CYAN_BOLD(" #%u") YELLOW(" %s") MAGENTA_BOLD("%4uW") CSI "1;%um %2uC" CLEAR WHITE_BOLD("%s") "%s", + tag, device.index(), device.topology().toString().data(), health.power, @@ -338,13 +339,8 @@ const xmrig::String &xmrig::CudaBackend::type() const } -void xmrig::CudaBackend::execCommand(char command) +void xmrig::CudaBackend::execCommand(char) { -# ifdef XMRIG_FEATURE_NVML - if (command == 'e' || command == 'E') { - d_ptr->printHealth(); - } -# endif } @@ -387,6 +383,14 @@ void xmrig::CudaBackend::printHashrate(bool details) } +void xmrig::CudaBackend::printHealth() +{ +# ifdef XMRIG_FEATURE_NVML + d_ptr->printHealth(); +# endif +} + + void xmrig::CudaBackend::setJob(const Job &job) { const auto &cuda = d_ptr->controller->config()->cuda(); @@ -455,15 +459,6 @@ void xmrig::CudaBackend::stop() void xmrig::CudaBackend::tick(uint64_t ticks) { d_ptr->workers.tick(ticks); - -# ifdef XMRIG_FEATURE_NVML - if (isEnabled()) { - auto seconds = d_ptr->controller->config()->healthPrintTime(); - if (seconds && ticks && (ticks % (seconds * 2)) == 0) { - d_ptr->printHealth(); - } - } -# endif } diff --git a/src/backend/cuda/CudaBackend.h b/src/backend/cuda/CudaBackend.h index cf0bb6217..2e82c589a 100644 --- a/src/backend/cuda/CudaBackend.h +++ b/src/backend/cuda/CudaBackend.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -59,6 +59,7 @@ protected: void execCommand(char command) override; void prepare(const Job &nextJob) override; void printHashrate(bool details) override; + void printHealth() override; void setJob(const Job &job) override; void start(IWorker *worker, bool ready) override; void stop() override; diff --git a/src/backend/opencl/OclBackend.cpp b/src/backend/opencl/OclBackend.cpp index 0943076b7..5cbf57b70 100644 --- a/src/backend/opencl/OclBackend.cpp +++ b/src/backend/opencl/OclBackend.cpp @@ -324,13 +324,8 @@ const xmrig::String &xmrig::OclBackend::type() const } -void xmrig::OclBackend::execCommand(char command) +void xmrig::OclBackend::execCommand(char) { -# ifdef XMRIG_FEATURE_ADL - if (command == 'e' || command == 'E') { - d_ptr->printHealth(); - } -# endif } @@ -373,6 +368,14 @@ void xmrig::OclBackend::printHashrate(bool details) } +void xmrig::OclBackend::printHealth() +{ +# ifdef XMRIG_FEATURE_ADL + d_ptr->printHealth(); +# endif +} + + void xmrig::OclBackend::setJob(const Job &job) { const auto &cl = d_ptr->controller->config()->cl(); @@ -449,15 +452,6 @@ void xmrig::OclBackend::stop() void xmrig::OclBackend::tick(uint64_t ticks) { d_ptr->workers.tick(ticks); - -# ifdef XMRIG_FEATURE_ADL - if (isEnabled()) { - auto seconds = d_ptr->controller->config()->healthPrintTime(); - if (seconds && ticks && (ticks % (seconds * 2)) == 0) { - d_ptr->printHealth(); - } - } -# endif } diff --git a/src/backend/opencl/OclBackend.h b/src/backend/opencl/OclBackend.h index 3813804ae..0ed7b8eb0 100644 --- a/src/backend/opencl/OclBackend.h +++ b/src/backend/opencl/OclBackend.h @@ -59,6 +59,7 @@ protected: void execCommand(char command) override; void prepare(const Job &nextJob) override; void printHashrate(bool details) override; + void printHealth() override; void setJob(const Job &job) override; void start(IWorker *worker, bool ready) override; void stop() override; diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 1dc4716dc..55a448e2a 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -353,6 +353,13 @@ void xmrig::Miner::execCommand(char command) setEnabled(true); break; + case 'e': + case 'E': + for (auto backend : d_ptr->backends) { + backend->printHealth(); + } + break; + default: break; } @@ -489,11 +496,16 @@ void xmrig::Miner::onConfigChanged(Config *config, Config *previousConfig) void xmrig::Miner::onTimer(const Timer *) { - double maxHashrate = 0.0; + double maxHashrate = 0.0; + const auto healthPrintTime = d_ptr->controller->config()->healthPrintTime(); for (IBackend *backend : d_ptr->backends) { backend->tick(d_ptr->ticks); + if (healthPrintTime && d_ptr->ticks && (d_ptr->ticks % (healthPrintTime * 2)) == 0 && backend->isEnabled()) { + backend->printHealth(); + } + if (backend->hashrate()) { maxHashrate += backend->hashrate()->calc(Hashrate::ShortInterval); } @@ -501,8 +513,8 @@ void xmrig::Miner::onTimer(const Timer *) d_ptr->maxHashrate[d_ptr->algorithm] = std::max(d_ptr->maxHashrate[d_ptr->algorithm], maxHashrate); - auto seconds = d_ptr->controller->config()->printTime(); - if (seconds && (d_ptr->ticks % (seconds * 2)) == 0) { + const auto printTime = d_ptr->controller->config()->printTime(); + if (printTime && d_ptr->ticks && (d_ptr->ticks % (printTime * 2)) == 0) { printHashrate(false); }