Merge xmrig v6.7.0 into master

This commit is contained in:
MoneroOcean 2020-12-23 06:03:02 +00:00
commit 1719879f7e
249 changed files with 6814 additions and 6134 deletions

View file

@ -1,7 +1,7 @@
include (src/backend/cpu/cpu.cmake)
include (src/backend/opencl/opencl.cmake)
include (src/backend/cuda/cuda.cmake)
include (src/backend/common/common.cmake)
include(src/backend/cpu/cpu.cmake)
include(src/backend/opencl/opencl.cmake)
include(src/backend/cuda/cuda.cmake)
include(src/backend/common/common.cmake)
set(HEADERS_BACKEND

View file

@ -0,0 +1,52 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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/GpuWorker.h"
#include "base/tools/Chrono.h"
xmrig::GpuWorker::GpuWorker(size_t id, int64_t affinity, int priority, uint32_t deviceIndex) : Worker(id, affinity, priority),
m_deviceIndex(deviceIndex)
{
}
void xmrig::GpuWorker::storeStats()
{
// Get index which is unused now
const uint32_t index = m_index.load(std::memory_order_relaxed) ^ 1;
// Fill in the data for that index
m_hashCount[index] = m_count;
m_timestamp[index] = Chrono::steadyMSecs();
// Switch to that index
// All data will be in memory by the time it completes thanks to std::memory_order_seq_cst
m_index.fetch_xor(1, std::memory_order_seq_cst);
}
void xmrig::GpuWorker::hashrateData(uint64_t &hashCount, uint64_t &timeStamp, uint64_t &rawHashes) const
{
const uint32_t index = m_index.load(std::memory_order_relaxed);
rawHashes = m_hashrateData.interpolate(timeStamp);
hashCount = m_hashCount[index];
timeStamp = m_timestamp[index];
}

View file

@ -0,0 +1,58 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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_GPUWORKER_H
#define XMRIG_GPUWORKER_H
#include <atomic>
#include "backend/common/HashrateInterpolator.h"
#include "backend/common/Worker.h"
namespace xmrig {
class GpuWorker : public Worker
{
public:
GpuWorker(size_t id, int64_t affinity, int priority, uint32_t m_deviceIndex);
protected:
inline const VirtualMemory *memory() const override { return nullptr; }
inline uint32_t deviceIndex() const { return m_deviceIndex; }
void hashrateData(uint64_t &hashCount, uint64_t &timeStamp, uint64_t &rawHashes) const override;
protected:
void storeStats();
const uint32_t m_deviceIndex;
HashrateInterpolator m_hashrateData;
std::atomic<uint32_t> m_index = {};
uint64_t m_hashCount[2] = {};
uint64_t m_timestamp[2] = {};
};
} // namespace xmrig
#endif /* XMRIG_GPUWORKER_H */

View file

@ -1,12 +1,7 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -24,7 +19,6 @@
#include <cassert>
#include <cmath>
#include <memory.h>
#include <cstdio>
@ -75,72 +69,6 @@ xmrig::Hashrate::~Hashrate()
}
double xmrig::Hashrate::calc(size_t ms) const
{
const double data = calc(0, ms);
return std::isnormal(data) ? data : 0.0;
}
double xmrig::Hashrate::calc(size_t threadId, size_t ms) const
{
assert(threadId < m_threads);
if (threadId >= m_threads) {
return nan("");
}
uint64_t earliestHashCount = 0;
uint64_t earliestStamp = 0;
bool haveFullSet = false;
const uint64_t timeStampLimit = xmrig::Chrono::steadyMSecs() - ms;
uint64_t* timestamps = m_timestamps[threadId];
uint64_t* counts = m_counts[threadId];
const size_t idx_start = (m_top[threadId] - 1) & kBucketMask;
size_t idx = idx_start;
uint64_t lastestStamp = timestamps[idx];
uint64_t lastestHashCnt = counts[idx];
do {
if (timestamps[idx] < timeStampLimit) {
haveFullSet = (timestamps[idx] != 0);
if (idx != idx_start) {
idx = (idx + 1) & kBucketMask;
earliestStamp = timestamps[idx];
earliestHashCount = counts[idx];
}
break;
}
idx = (idx - 1) & kBucketMask;
} while (idx != idx_start);
if (!haveFullSet || earliestStamp == 0 || lastestStamp == 0) {
return nan("");
}
if (lastestStamp - earliestStamp == 0) {
return nan("");
}
const auto hashes = static_cast<double>(lastestHashCnt - earliestHashCount);
const auto time = static_cast<double>(lastestStamp - earliestStamp) / 1000.0;
return hashes / time;
}
void xmrig::Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp)
{
const size_t top = m_top[threadId];
m_counts[threadId][top] = count;
m_timestamps[threadId][top] = timestamp;
m_top[threadId] = (top + 1) & kBucketMask;
}
const char *xmrig::Hashrate::format(double h, char *buf, size_t size)
{
return ::format(h, buf, size);
@ -174,10 +102,69 @@ rapidjson::Value xmrig::Hashrate::toJSON(size_t threadId, rapidjson::Document &d
auto &allocator = doc.GetAllocator();
Value out(kArrayType);
out.PushBack(normalize(calc(threadId + 1, ShortInterval)), allocator);
out.PushBack(normalize(calc(threadId + 1, MediumInterval)), allocator);
out.PushBack(normalize(calc(threadId + 1, LargeInterval)), allocator);
out.PushBack(normalize(calc(threadId, ShortInterval)), allocator);
out.PushBack(normalize(calc(threadId, MediumInterval)), allocator);
out.PushBack(normalize(calc(threadId, LargeInterval)), allocator);
return out;
}
#endif
double xmrig::Hashrate::hashrate(size_t index, size_t ms) const
{
assert(index < m_threads);
if (index >= m_threads) {
return nan("");
}
uint64_t earliestHashCount = 0;
uint64_t earliestStamp = 0;
bool haveFullSet = false;
const uint64_t timeStampLimit = xmrig::Chrono::steadyMSecs() - ms;
uint64_t* timestamps = m_timestamps[index];
uint64_t* counts = m_counts[index];
const size_t idx_start = (m_top[index] - 1) & kBucketMask;
size_t idx = idx_start;
uint64_t lastestStamp = timestamps[idx];
uint64_t lastestHashCnt = counts[idx];
do {
if (timestamps[idx] < timeStampLimit) {
haveFullSet = (timestamps[idx] != 0);
if (idx != idx_start) {
idx = (idx + 1) & kBucketMask;
earliestStamp = timestamps[idx];
earliestHashCount = counts[idx];
}
break;
}
idx = (idx - 1) & kBucketMask;
} while (idx != idx_start);
if (!haveFullSet || earliestStamp == 0 || lastestStamp == 0) {
return nan("");
}
if (lastestStamp - earliestStamp == 0) {
return nan("");
}
const auto hashes = static_cast<double>(lastestHashCnt - earliestHashCount);
const auto time = static_cast<double>(lastestStamp - earliestStamp) / 1000.0;
return hashes / time;
}
void xmrig::Hashrate::addData(size_t index, uint64_t count, uint64_t timestamp)
{
const size_t top = m_top[index];
m_counts[index][top] = count;
m_timestamps[index][top] = timestamp;
m_top[index] = (top + 1) & kBucketMask;
}

View file

@ -1,12 +1,7 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -26,6 +21,7 @@
#define XMRIG_HASHRATE_H
#include <cmath>
#include <cstddef>
#include <cstdint>
@ -42,7 +38,7 @@ class Hashrate
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Hashrate)
enum Intervals {
enum Intervals : size_t {
ShortInterval = 10000,
MediumInterval = 60000,
LargeInterval = 900000
@ -50,11 +46,12 @@ public:
Hashrate(size_t threads);
~Hashrate();
double calc(size_t ms) const;
double calc(size_t threadId, size_t ms) const;
void add(size_t threadId, uint64_t count, uint64_t timestamp);
inline size_t threads() const { return m_threads; }
inline double calc(size_t ms) const { const double data = hashrate(0U, ms); return std::isnormal(data) ? data : 0.0; }
inline double calc(size_t threadId, size_t ms) const { return hashrate(threadId + 1, ms); }
inline size_t threads() const { return m_threads > 0U ? m_threads - 1U : 0U; }
inline void add(size_t threadId, uint64_t count, uint64_t timestamp) { addData(threadId + 1U, count, timestamp); }
inline void add(uint64_t count, uint64_t timestamp) { addData(0U, count, timestamp); }
static const char *format(double h, char *buf, size_t size);
static rapidjson::Value normalize(double d);
@ -65,6 +62,9 @@ public:
# endif
private:
double hashrate(size_t index, size_t ms) const;
void addData(size_t index, uint64_t count, uint64_t timestamp);
constexpr static size_t kBucketSize = 2 << 11;
constexpr static size_t kBucketMask = kBucketSize - 1;

View file

@ -1,10 +1,4 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*

View file

@ -1,10 +1,4 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
@ -47,7 +41,7 @@ public:
private:
// Buffer of hashrate counters, used for linear interpolation of past data
mutable std::mutex m_lock;
std::deque<std::pair<uint64_t, uint64_t>> m_data;
std::deque<std::pair<uint64_t, uint64_t> > m_data;
};

View file

@ -1,12 +1,6 @@
/* 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>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -27,12 +21,17 @@
#include "backend/common/interfaces/IWorker.h"
#include "base/tools/Object.h"
#include <thread>
#ifdef XMRIG_OS_APPLE
# include <pthread.h>
# include <mach/thread_act.h>
#endif
namespace xmrig {
@ -46,21 +45,48 @@ public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Thread)
inline Thread(IBackend *backend, size_t id, const T &config) : m_id(id), m_config(config), m_backend(backend) {}
# ifdef XMRIG_OS_APPLE
inline ~Thread() { pthread_join(m_thread, nullptr); delete m_worker; }
inline void start(void *(*callback)(void *))
{
if (m_config.affinity >= 0) {
pthread_create_suspended_np(&m_thread, nullptr, callback, this);
mach_port_t mach_thread = pthread_mach_thread_np(m_thread);
thread_affinity_policy_data_t policy = { static_cast<integer_t>(m_config.affinity + 1) };
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, reinterpret_cast<thread_policy_t>(&policy), THREAD_AFFINITY_POLICY_COUNT);
thread_resume(mach_thread);
}
else {
pthread_create(&m_thread, nullptr, callback, this);
}
}
# else
inline ~Thread() { m_thread.join(); delete m_worker; }
inline void start(void *(*callback)(void *)) { m_thread = std::thread(callback, this); }
# endif
inline const T &config() const { return m_config; }
inline IBackend *backend() const { return m_backend; }
inline IWorker *worker() const { return m_worker; }
inline size_t id() const { return m_id; }
inline void setWorker(IWorker *worker) { m_worker = worker; }
inline void start(void (*callback) (void *)) { m_thread = std::thread(callback, this); }
private:
const size_t m_id = 0;
const T m_config;
IBackend *m_backend;
IWorker *m_worker = nullptr;
#ifdef XMRIG_OS_APPLE
pthread_t m_thread{};
# else
std::thread m_thread;
# endif
};

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -26,7 +19,6 @@
#include "backend/common/Worker.h"
#include "base/kernel/Platform.h"
#include "base/tools/Chrono.h"
#include "crypto/common/VirtualMemory.h"
@ -39,27 +31,3 @@ xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
Platform::trySetThreadAffinity(affinity);
Platform::setThreadPriority(priority);
}
void xmrig::Worker::storeStats()
{
// Get index which is unused now
const uint32_t index = m_index.load(std::memory_order_relaxed) ^ 1;
// Fill in the data for that index
m_hashCount[index] = m_count;
m_timestamp[index] = Chrono::steadyMSecs();
// Switch to that index
// All data will be in memory by the time it completes thanks to std::memory_order_seq_cst
m_index.fetch_xor(1, std::memory_order_seq_cst);
}
void xmrig::Worker::getHashrateData(uint64_t& hashCount, uint64_t& timeStamp) const
{
const uint32_t index = m_index.load(std::memory_order_relaxed);
hashCount = m_hashCount[index];
timeStamp = m_timestamp[index];
}

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -27,9 +20,6 @@
#define XMRIG_WORKER_H
#include <atomic>
#include "backend/common/interfaces/IWorker.h"
@ -41,23 +31,17 @@ class Worker : public IWorker
public:
Worker(size_t id, int64_t affinity, int priority);
inline const VirtualMemory *memory() const override { return nullptr; }
inline size_t id() const override { return m_id; }
inline uint64_t rawHashes() const override { return m_count; }
inline void jobEarlyNotification(const Job&) override {}
void getHashrateData(uint64_t& hashCount, uint64_t& timeStamp) const override;
protected:
void storeStats();
inline int64_t affinity() const { return m_affinity; }
inline size_t id() const override { return m_id; }
inline uint32_t node() const { return m_node; }
uint64_t m_count = 0;
private:
const int64_t m_affinity;
const size_t m_id;
std::atomic<uint32_t> m_index = {};
uint32_t m_node = 0;
uint64_t m_count = 0;
uint64_t m_hashCount[2] = {};
uint64_t m_timestamp[2] = {};
};

View file

@ -110,7 +110,7 @@ private:
alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N]{};
Job m_jobs[2];
uint32_t m_rounds[2] = { 0, 0 };
uint64_t m_nonce_mask[2];
uint64_t m_nonce_mask[2] = { 0, 0 };
uint64_t m_sequence = 0;
uint8_t m_index = 0;
};

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -24,16 +17,13 @@
*/
#include "backend/common/Workers.h"
#include "backend/common/Hashrate.h"
#include "backend/common/interfaces/IBackend.h"
#include "backend/common/Workers.h"
#include "backend/cpu/CpuWorker.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/net/stratum/Pool.h"
#include "base/tools/Chrono.h"
#include "base/tools/Object.h"
#include "core/Miner.h"
#ifdef XMRIG_FEATURE_OPENCL
@ -59,7 +49,6 @@ class WorkersPrivate
public:
XMRIG_DISABLE_COPY_MOVE(WorkersPrivate)
WorkersPrivate() = default;
~WorkersPrivate() = default;
@ -87,20 +76,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>
bool xmrig::Workers<T>::tick(uint64_t)
{
@ -111,33 +86,32 @@ bool xmrig::Workers<T>::tick(uint64_t)
uint64_t ts = Chrono::steadyMSecs();
bool totalAvailable = true;
uint64_t totalHashCount = 0;
uint64_t hashCount = 0;
uint64_t rawHashes = 0;
for (Thread<T> *handle : m_workers) {
IWorker *worker = handle->worker();
if (worker) {
uint64_t hashCount;
getHashrateData<T>(worker, hashCount, ts);
d_ptr->hashrate->add(handle->id() + 1, hashCount, ts);
worker->hashrateData(hashCount, ts, rawHashes);
d_ptr->hashrate->add(handle->id(), hashCount, ts);
const uint64_t n = worker->rawHashes();
if (n == 0) {
if (rawHashes == 0) {
totalAvailable = false;
}
totalHashCount += n;
totalHashCount += rawHashes;
}
}
if (totalAvailable) {
d_ptr->hashrate->add(0, totalHashCount, Chrono::steadyMSecs());
d_ptr->hashrate->add(totalHashCount, Chrono::steadyMSecs());
}
# ifdef XMRIG_FEATURE_BENCHMARK
if (d_ptr->benchmark && d_ptr->benchmark->finish(totalHashCount)) {
return false;
}
# endif
return !d_ptr->benchmark || !d_ptr->benchmark->finish(totalHashCount);
# else
return true;
# endif
}
@ -158,14 +132,19 @@ void xmrig::Workers<T>::setBackend(IBackend *backend)
template<class T>
void xmrig::Workers<T>::stop()
{
# ifdef XMRIG_MINER_PROJECT
Nonce::stop(T::backend());
# endif
for (Thread<T> *worker : m_workers) {
delete worker;
}
m_workers.clear();
# ifdef XMRIG_MINER_PROJECT
Nonce::touch(T::backend());
# endif
d_ptr->hashrate.reset();
}
@ -195,7 +174,7 @@ xmrig::IWorker *xmrig::Workers<T>::create(Thread<T> *)
template<class T>
void xmrig::Workers<T>::onReady(void *arg)
void *xmrig::Workers<T>::onReady(void *arg)
{
auto handle = static_cast<Thread<T>* >(arg);
@ -208,13 +187,15 @@ void xmrig::Workers<T>::onReady(void *arg)
handle->backend()->start(worker, false);
delete worker;
return;
return nullptr;
}
assert(handle->backend() != nullptr);
handle->setWorker(worker);
handle->backend()->start(worker, true);
return nullptr;
}
@ -226,17 +207,13 @@ void xmrig::Workers<T>::start(const std::vector<T> &data, bool sleep)
}
d_ptr->hashrate = std::make_shared<Hashrate>(m_workers.size());
# ifdef XMRIG_MINER_PROJECT
Nonce::touch(T::backend());
# endif
for (auto worker : m_workers) {
worker->start(Workers<T>::onReady);
// This sleep is important for optimal caching!
// Threads must allocate scratchpads in order so that adjacent cores will use adjacent scratchpads
// Sub-optimal caching can result in up to 0.5% hashrate penalty
if (sleep) {
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
}
}
@ -247,6 +224,7 @@ namespace xmrig {
template<>
xmrig::IWorker *xmrig::Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *handle)
{
# ifdef XMRIG_MINER_PROJECT
switch (handle->config().intensity) {
case 1:
return new CpuWorker<1>(handle->id(), handle->config());
@ -265,6 +243,11 @@ xmrig::IWorker *xmrig::Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *han
}
return nullptr;
# else
assert(handle->config().intensity == 1);
return new CpuWorker<1>(handle->id(), handle->config());
# endif
}

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -44,10 +37,9 @@
namespace xmrig {
class Benchmark;
class Hashrate;
class WorkersPrivate;
class Job;
class Benchmark;
template<class T>
@ -63,7 +55,7 @@ public:
bool tick(uint64_t ticks);
const Hashrate *hashrate() const;
void jobEarlyNotification(const Job&);
void jobEarlyNotification(const Job &job);
void setBackend(IBackend *backend);
void stop();
@ -73,7 +65,7 @@ public:
private:
static IWorker *create(Thread<T> *handle);
static void onReady(void *arg);
static void *onReady(void *arg);
void start(const std::vector<T> &data, bool sleep);
@ -83,7 +75,7 @@ private:
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) {
if (t->worker()) {

View file

@ -1,6 +1,5 @@
set(HEADERS_BACKEND_COMMON
src/backend/common/Hashrate.h
src/backend/common/HashrateInterpolator.h
src/backend/common/Tags.h
src/backend/common/interfaces/IBackend.h
src/backend/common/interfaces/IRxListener.h
@ -16,7 +15,6 @@ set(HEADERS_BACKEND_COMMON
set(SOURCES_BACKEND_COMMON
src/backend/common/Hashrate.cpp
src/backend/common/HashrateInterpolator.cpp
src/backend/common/Threads.cpp
src/backend/common/Worker.cpp
src/backend/common/Workers.cpp
@ -35,3 +33,16 @@ if (WITH_RANDOMX AND WITH_BENCHMARK)
src/backend/common/benchmark/BenchState.cpp
)
endif()
if (WITH_OPENCL OR WITH_CUDA)
list(APPEND HEADERS_BACKEND_COMMON
src/backend/common/HashrateInterpolator.h
src/backend/common/GpuWorker.h
)
list(APPEND SOURCES_BACKEND_COMMON
src/backend/common/HashrateInterpolator.cpp
src/backend/common/GpuWorker.cpp
)
endif()

View file

@ -1,12 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -26,10 +20,11 @@
#define XMRIG_IBACKEND_H
#include <cstdint>
#include "3rdparty/rapidjson/fwd.h"
#include "base/tools/Object.h"
#include <cstdint>
namespace xmrig {
@ -47,10 +42,14 @@ class String;
class IBackend
{
public:
XMRIG_DISABLE_COPY_MOVE(IBackend)
IBackend() = default;
virtual ~IBackend() = default;
virtual bool isEnabled() 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 String &profileName() const = 0;
virtual const String &type() const = 0;
@ -61,7 +60,6 @@ public:
virtual void setJob(const Job &job) = 0;
virtual void start(IWorker *worker, bool ready) = 0;
virtual void stop() = 0;
virtual bool tick(uint64_t ticks) = 0;
# ifdef XMRIG_FEATURE_API
virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0;

View file

@ -1,14 +1,6 @@
/* 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 2018-2019 tevador <tevador@gmail.com>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -28,6 +20,9 @@
#define XMRIG_IMEMORYPOOL_H
#include "base/tools/Object.h"
#include <cstddef>
#include <cstdint>
@ -38,7 +33,10 @@ namespace xmrig {
class IMemoryPool
{
public:
virtual ~IMemoryPool() = default;
XMRIG_DISABLE_COPY_MOVE(IMemoryPool)
IMemoryPool() = default;
virtual ~IMemoryPool() = default;
virtual bool isHugePages(uint32_t node) const = 0;
virtual uint8_t *get(size_t size, uint32_t node) = 0;

View file

@ -1,10 +1,7 @@
/* 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 2016-2018 XMRig <support@xmrig.com>
* Copyright (c) 2018-2019 tevador <tevador@gmail.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -24,13 +21,19 @@
#define XMRIG_IRXLISTENER_H
#include "base/tools/Object.h"
namespace xmrig {
class IRxListener
{
public:
virtual ~IRxListener() = default;
XMRIG_DISABLE_COPY_MOVE(IRxListener)
IRxListener() = default;
virtual ~IRxListener() = default;
# ifdef XMRIG_ALGO_RANDOMX
virtual void onDatasetReady() = 0;

View file

@ -1,10 +1,7 @@
/* 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 2016-2018 XMRig <support@xmrig.com>
* Copyright (c) 2018-2019 tevador <tevador@gmail.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -24,8 +21,9 @@
#define XMRIG_IRXSTORAGE_H
#include "crypto/rx/RxConfig.h"
#include "base/tools/Object.h"
#include "crypto/common/HugePagesInfo.h"
#include "crypto/rx/RxConfig.h"
#include <cstdint>
@ -43,7 +41,10 @@ class RxSeed;
class IRxStorage
{
public:
virtual ~IRxStorage() = default;
XMRIG_DISABLE_COPY_MOVE(IRxStorage)
IRxStorage() = default;
virtual ~IRxStorage() = default;
virtual bool isAllocated() const = 0;
virtual HugePagesInfo hugePages() const = 0;

View file

@ -1,12 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -36,8 +30,8 @@
namespace xmrig {
class VirtualMemory;
class Job;
class VirtualMemory;
class IWorker
@ -48,14 +42,13 @@ public:
IWorker() = default;
virtual ~IWorker() = default;
virtual bool selfTest() = 0;
virtual const VirtualMemory *memory() const = 0;
virtual size_t id() const = 0;
virtual size_t intensity() const = 0;
virtual uint64_t rawHashes() const = 0;
virtual void getHashrateData(uint64_t&, uint64_t&) const = 0;
virtual void start() = 0;
virtual void jobEarlyNotification(const Job&) = 0;
virtual bool selfTest() = 0;
virtual const VirtualMemory *memory() const = 0;
virtual size_t id() const = 0;
virtual size_t intensity() const = 0;
virtual void hashrateData(uint64_t &hashCount, uint64_t &timeStamp, uint64_t &rawHashes) const = 0;
virtual void jobEarlyNotification(const Job &job) = 0;
virtual void start() = 0;
};

View file

@ -1,12 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -32,8 +26,6 @@
#if defined(XMRIG_FEATURE_HWLOC)
# include "backend/cpu/platform/HwlocCpuInfo.h"
#elif defined(XMRIG_FEATURE_LIBCPUID)
# include "backend/cpu/platform/AdvancedCpuInfo.h"
#else
# include "backend/cpu/platform/BasicCpuInfo.h"
#endif
@ -47,8 +39,6 @@ xmrig::ICpuInfo *xmrig::Cpu::info()
if (cpuInfo == nullptr) {
# if defined(XMRIG_FEATURE_HWLOC)
cpuInfo = new HwlocCpuInfo();
# elif defined(XMRIG_FEATURE_LIBCPUID)
cpuInfo = new AdvancedCpuInfo();
# else
cpuInfo = new BasicCpuInfo();
# endif

View file

@ -1,12 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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

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
{
return d_ptr->workers.hashrate();
@ -316,9 +322,9 @@ void xmrig::CpuBackend::printHashrate(bool details)
Log::print("| %8zu | %8" PRId64 " | %7s | %7s | %7s |",
i,
data.affinity,
Hashrate::format(hashrate()->calc(i + 1, Hashrate::ShortInterval), num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::MediumInterval), num + 8, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3)
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval), num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval), num + 8, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3)
);
i++;
@ -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
rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const
{

View file

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

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -80,7 +73,7 @@ xmrig::CpuWorker<N>::CpuWorker(size_t id, const CpuLaunchData &data) :
m_threads(data.threads),
m_ctx()
{
m_memory = new VirtualMemory(m_algorithm.l3() * N, data.hugePages, false, true, m_node);
m_memory = new VirtualMemory(m_algorithm.l3() * N, data.hugePages, false, true, node());
}
@ -100,7 +93,7 @@ xmrig::CpuWorker<N>::~CpuWorker()
template<size_t N>
void xmrig::CpuWorker<N>::allocateRandomX_VM()
{
RxDataset *dataset = Rx::dataset(m_job.currentJob(), m_node);
RxDataset *dataset = Rx::dataset(m_job.currentJob(), node());
while (dataset == nullptr) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
@ -109,13 +102,13 @@ void xmrig::CpuWorker<N>::allocateRandomX_VM()
return;
}
dataset = Rx::dataset(m_job.currentJob(), m_node);
dataset = Rx::dataset(m_job.currentJob(), node());
}
if (!m_vm) {
// Try to allocate scratchpad from dataset's 1 GB huge pages, if normal huge pages are not available
uint8_t* scratchpad = m_memory->isHugePages() ? m_memory->scratchpad() : dataset->tryAllocateScrathpad();
m_vm = RxVm::create(dataset, scratchpad ? scratchpad : m_memory->scratchpad(), !m_hwAES, m_assembly, m_node);
m_vm = RxVm::create(dataset, scratchpad ? scratchpad : m_memory->scratchpad(), !m_hwAES, m_assembly, node());
}
}
#endif
@ -200,6 +193,14 @@ bool xmrig::CpuWorker<N>::selfTest()
}
template<size_t N>
void xmrig::CpuWorker<N>::hashrateData(uint64_t &hashCount, uint64_t &, uint64_t &rawHashes) const
{
hashCount = m_count;
rawHashes = m_count;
}
template<size_t N>
void xmrig::CpuWorker<N>::start()
{

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -56,10 +49,12 @@ public:
protected:
bool selfTest() override;
void hashrateData(uint64_t &hashCount, uint64_t &timeStamp, uint64_t &rawHashes) const override;
void start() override;
inline const VirtualMemory *memory() const override { return m_memory; }
inline size_t intensity() const override { return N; }
inline const VirtualMemory *memory() const override { return m_memory; }
inline size_t intensity() const override { return N; }
inline void jobEarlyNotification(const Job&) override {}
private:
inline cn_hash_fun fn(const Algorithm &algorithm) const { return CnHash::fn(algorithm, m_av, m_assembly); }

View file

@ -1,13 +1,14 @@
set(HEADERS_BACKEND_CPU
src/backend/cpu/Cpu.h
src/backend/cpu/CpuBackend.h
src/backend/cpu/CpuConfig.h
src/backend/cpu/CpuConfig_gen.h
src/backend/cpu/CpuConfig.h
src/backend/cpu/CpuLaunchData.cpp
src/backend/cpu/CpuThread.h
src/backend/cpu/CpuThreads.h
src/backend/cpu/CpuWorker.h
src/backend/cpu/interfaces/ICpuInfo.h
src/backend/cpu/platform/BasicCpuInfo.h
)
set(SOURCES_BACKEND_CPU
@ -20,7 +21,6 @@ set(SOURCES_BACKEND_CPU
src/backend/cpu/CpuWorker.cpp
)
if (WITH_HWLOC)
if (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
add_subdirectory(src/3rdparty/hwloc)
@ -32,51 +32,26 @@ if (WITH_HWLOC)
set(CPUID_LIB ${HWLOC_LIBRARY})
endif()
set(WITH_LIBCPUID OFF)
remove_definitions(/DXMRIG_FEATURE_LIBCPUID)
add_definitions(/DXMRIG_FEATURE_HWLOC)
if (HWLOC_DEBUG)
add_definitions(/DXMRIG_HWLOC_DEBUG)
endif()
set(SOURCES_CPUID
src/backend/cpu/platform/BasicCpuInfo.h
src/backend/cpu/platform/HwlocCpuInfo.cpp
src/backend/cpu/platform/HwlocCpuInfo.h
)
elseif (WITH_LIBCPUID)
message(WARNING, "libcpuid support is deprecated and will be removed in future versions.")
set(WITH_HWLOC OFF)
add_subdirectory(src/3rdparty/libcpuid)
include_directories(src/3rdparty/libcpuid)
add_definitions(/DXMRIG_FEATURE_LIBCPUID)
remove_definitions(/DXMRIG_FEATURE_HWLOC)
set(CPUID_LIB cpuid)
set(SOURCES_CPUID
src/backend/cpu/platform/AdvancedCpuInfo.cpp
src/backend/cpu/platform/AdvancedCpuInfo.h
)
list(APPEND HEADERS_BACKEND_CPU src/backend/cpu/platform/HwlocCpuInfo.h)
list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/HwlocCpuInfo.cpp)
else()
remove_definitions(/DXMRIG_FEATURE_LIBCPUID)
remove_definitions(/DXMRIG_FEATURE_HWLOC)
set(CPUID_LIB "")
set(SOURCES_CPUID
src/backend/cpu/platform/BasicCpuInfo.h
)
endif()
if (XMRIG_ARM)
list(APPEND SOURCES_CPUID src/backend/cpu/platform/BasicCpuInfo_arm.cpp)
list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/BasicCpuInfo_arm.cpp)
if (XMRIG_OS_UNIX)
list(APPEND SOURCES_CPUID src/backend/cpu/platform/lscpu_arm.cpp)
list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/lscpu_arm.cpp)
endif()
else()
list(APPEND SOURCES_CPUID src/backend/cpu/platform/BasicCpuInfo.cpp)
list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/BasicCpuInfo.cpp)
endif()

View file

@ -1,12 +1,6 @@
/* 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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -46,6 +40,14 @@ public:
VENDOR_AMD
};
enum Arch : uint32_t {
ARCH_UNKNOWN,
ARCH_ZEN,
ARCH_ZEN_PLUS,
ARCH_ZEN2,
ARCH_ZEN3
};
enum MsrMod : uint32_t {
MSR_MOD_NONE,
MSR_MOD_RYZEN_17H,
@ -59,6 +61,7 @@ public:
enum Flag : uint32_t {
FLAG_AES,
FLAG_AVX,
FLAG_AVX2,
FLAG_AVX512F,
FLAG_BMI2,
@ -70,6 +73,7 @@ public:
FLAG_XOP,
FLAG_POPCNT,
FLAG_CAT_L3,
FLAG_VM,
FLAG_MAX
};
@ -77,18 +81,21 @@ public:
virtual ~ICpuInfo() = default;
# if defined(__x86_64__) || defined(_M_AMD64) || defined (__arm64__) || defined (__aarch64__)
inline constexpr static bool isX64() { return true; }
inline constexpr static bool is64bit() { return true; }
# else
inline constexpr static bool isX64() { return false; }
inline constexpr static bool is64bit() { return false; }
# endif
virtual Assembly::Id assembly() const = 0;
virtual bool has(Flag feature) const = 0;
virtual bool hasAES() const = 0;
virtual bool hasAVX() const = 0;
virtual bool hasAVX2() const = 0;
virtual bool hasBMI2() const = 0;
virtual bool hasOneGbPages() const = 0;
virtual bool hasXOP() const = 0;
virtual bool hasCatL3() const = 0;
virtual bool isVM() const = 0;
virtual const char *backend() const = 0;
virtual const char *brand() const = 0;
virtual CpuThreads threads(const Algorithm &algorithm, uint32_t limit) const = 0;
@ -101,6 +108,7 @@ public:
virtual size_t packages() const = 0;
virtual size_t threads() const = 0;
virtual Vendor vendor() const = 0;
virtual Arch arch() const = 0;
virtual bool jccErratum() const = 0;
};

View file

@ -1,136 +0,0 @@
/* 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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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/platform/AdvancedCpuInfo.h"
#include "3rdparty/libcpuid/libcpuid.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
xmrig::AdvancedCpuInfo::AdvancedCpuInfo()
{
struct cpu_raw_data_t raw = {};
struct cpu_id_t data = {};
cpuid_get_raw_data(&raw);
cpu_identify(&raw, &data);
snprintf(m_backend, sizeof m_backend, "libcpuid/%s", cpuid_lib_version());
m_threads = static_cast<size_t>(data.total_logical_cpus);
m_packages = std::max<size_t>(m_threads / static_cast<size_t>(data.num_logical_cpus), 1);
m_cores = static_cast<size_t>(data.num_cores) * m_packages;
m_L3 = data.l3_cache > 0 ? static_cast<size_t>(data.l3_cache) * m_packages : 0;
const auto l2 = static_cast<size_t>(data.l2_cache);
// Workaround for AMD CPUs https://github.com/anrieff/libcpuid/issues/97
if (m_vendor == VENDOR_AMD && data.ext_family >= 0x15 && data.ext_family < 0x17) {
m_L2 = l2 * (cores() / 2) * m_packages;
m_L2_exclusive = true;
}
// Workaround for Intel Pentium Dual-Core, Core Duo, Core 2 Duo, Core 2 Quad and their Xeon homologue
// These processors have L2 cache shared by 2 cores.
else if (m_vendor == VENDOR_INTEL && data.ext_family == 0x06 && (data.ext_model == 0x0E || data.ext_model == 0x0F || data.ext_model == 0x17)) {
size_t l2_count_per_socket = cores() > 1 ? cores() / 2 : 1;
m_L2 = data.l2_cache > 0 ? l2 * l2_count_per_socket * m_packages : 0;
}
else{
m_L2 = data.l2_cache > 0 ? l2 * cores() * m_packages : 0;
}
m_L2 *= 1024;
m_L3 *= 1024;
}
xmrig::CpuThreads xmrig::AdvancedCpuInfo::threads(const Algorithm &algorithm, uint32_t limit) const
{
if (threads() == 1) {
return 1;
}
# ifdef XMRIG_ALGO_CN_GPU
if (algorithm == Algorithm::CN_GPU) {
return CpuThreads(threads());
}
# endif
size_t cache = 0;
size_t count = 0;
# ifdef XMRIG_ALGO_ASTROBWT
if (algorithm == Algorithm::ASTROBWT_DERO) {
CpuThreads t;
count = threads();
for (size_t i = 0; i < count; ++i) {
t.add(i, 0);
}
return t;
}
# endif
if (m_L3) {
cache = m_L2_exclusive ? (m_L2 + m_L3) : m_L3;
}
else {
cache = m_L2;
}
if (cache) {
const size_t memory = algorithm.l3();
assert(memory > 0);
count = cache / memory;
if (cache % memory >= memory / 2) {
count++;
}
}
else {
count = threads() / 2;
}
uint32_t intensity = algorithm.maxIntensity() == 1 ? 0 : 1;
# ifdef XMRIG_ALGO_CN_PICO
if (algorithm == Algorithm::CN_PICO_0 && (count / cores()) >= 2) {
intensity = 2;
}
# endif
if (limit > 0 && limit < 100) {
count = std::min(count, static_cast<size_t>(round(threads() * (limit / 100.0))));
}
else {
count = std::min(count, threads());
}
return CpuThreads(std::max<size_t>(count, 1), intensity);
}

View file

@ -1,63 +0,0 @@
/* 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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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_ADVANCEDCPUINFO_H
#define XMRIG_ADVANCEDCPUINFO_H
#include "backend/cpu/platform/BasicCpuInfo.h"
namespace xmrig {
class AdvancedCpuInfo : public BasicCpuInfo
{
public:
AdvancedCpuInfo();
protected:
CpuThreads threads(const Algorithm &algorithm, uint32_t limit) const override;
inline const char *backend() const override { return m_backend; }
inline size_t cores() const override { return m_cores; }
inline size_t L2() const override { return m_L2; }
inline size_t L3() const override { return m_L3; }
inline size_t packages() const override { return m_packages; }
inline size_t threads() const override { return m_threads; }
private:
bool m_L2_exclusive = false;
char m_backend[32]{};
size_t m_cores = 0;
size_t m_L2 = 0;
size_t m_L3 = 0;
size_t m_packages = 1;
};
} /* namespace xmrig */
#endif /* XMRIG_ADVANCEDCPUINFO_H */

View file

@ -52,8 +52,8 @@
namespace xmrig {
constexpr size_t kCpuFlagsSize = 12;
static const std::array<const char *, kCpuFlagsSize> flagNames = { "aes", "avx2", "avx512f", "bmi2", "osxsave", "pdpe1gb", "sse2", "ssse3", "sse4.1", "xop", "popcnt", "cat_l3" };
constexpr size_t kCpuFlagsSize = 14;
static const std::array<const char *, kCpuFlagsSize> flagNames = { "aes", "avx", "avx2", "avx512f", "bmi2", "osxsave", "pdpe1gb", "sse2", "ssse3", "sse4.1", "xop", "popcnt", "cat_l3", "vm" };
static_assert(kCpuFlagsSize == ICpuInfo::FLAG_MAX, "kCpuFlagsSize and FLAG_MAX mismatch");
@ -134,11 +134,12 @@ static inline uint64_t xgetbv()
#endif
}
static inline bool has_xcr_avx2() { return (xgetbv() & 0x06) == 0x06; }
static inline bool has_xcr_avx() { return (xgetbv() & 0x06) == 0x06; }
static inline bool has_xcr_avx512() { return (xgetbv() & 0xE6) == 0xE6; }
static inline bool has_osxsave() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 27); }
static inline bool has_aes_ni() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 25); }
static inline bool has_avx2() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 5) && has_osxsave() && has_xcr_avx2(); }
static inline bool has_avx() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 28) && has_osxsave() && has_xcr_avx(); }
static inline bool has_avx2() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 5) && has_osxsave() && has_xcr_avx(); }
static inline bool has_avx512f() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 16) && has_osxsave() && has_xcr_avx512(); }
static inline bool has_bmi2() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 8); }
static inline bool has_pdpe1gb() { return has_feature(PROCESSOR_EXT_INFO, EDX_Reg, 1 << 26); }
@ -148,6 +149,7 @@ static inline bool has_sse41() { return has_feature(PROCESSOR_INFO,
static inline bool has_xop() { return has_feature(0x80000001, ECX_Reg, 1 << 11); }
static inline bool has_popcnt() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 23); }
static inline bool has_cat_l3() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 15) && has_feature(0x10, EBX_Reg, 1 << 1); }
static inline bool is_vm() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 31); }
} // namespace xmrig
@ -174,6 +176,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
cpu_brand_string(m_brand);
m_flags.set(FLAG_AES, has_aes_ni());
m_flags.set(FLAG_AVX, has_avx());
m_flags.set(FLAG_AVX2, has_avx2());
m_flags.set(FLAG_AVX512F, has_avx512f());
m_flags.set(FLAG_BMI2, has_bmi2());
@ -185,6 +188,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
m_flags.set(FLAG_XOP, has_xop());
m_flags.set(FLAG_POPCNT, has_popcnt());
m_flags.set(FLAG_CAT_L3, has_cat_l3());
m_flags.set(FLAG_VM, is_vm());
# ifdef XMRIG_FEATURE_ASM
if (hasAES()) {
@ -213,9 +217,27 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
switch (m_family) {
case 0x17:
m_msrMod = MSR_MOD_RYZEN_17H;
switch (m_model) {
case 1:
case 17:
case 32:
m_arch = ARCH_ZEN;
break;
case 8:
case 24:
m_arch = ARCH_ZEN_PLUS;
break;
case 49:
case 96:
case 113:
case 144:
m_arch = ARCH_ZEN2;
break;
}
break;
case 0x19:
m_arch = ARCH_ZEN3;
m_msrMod = MSR_MOD_RYZEN_19H;
break;
@ -353,7 +375,8 @@ rapidjson::Value xmrig::BasicCpuInfo::toJSON(rapidjson::Document &doc) const
out.AddMember("proc_info", m_procInfo, allocator);
out.AddMember("aes", hasAES(), allocator);
out.AddMember("avx2", hasAVX2(), allocator);
out.AddMember("x64", isX64(), allocator);
out.AddMember("x64", is64bit(), allocator); // DEPRECATED will be removed in the next major release.
out.AddMember("64_bit", is64bit(), allocator);
out.AddMember("l2", static_cast<uint64_t>(L2()), allocator);
out.AddMember("l3", static_cast<uint64_t>(L3()), allocator);
out.AddMember("cores", static_cast<uint64_t>(cores()), allocator);

View file

@ -48,10 +48,13 @@ protected:
inline Assembly::Id assembly() const override { return m_assembly; }
inline bool has(Flag flag) const override { return m_flags.test(flag); }
inline bool hasAES() const override { return has(FLAG_AES); }
inline bool hasAVX() const override { return has(FLAG_AVX); }
inline bool hasAVX2() const override { return has(FLAG_AVX2); }
inline bool hasBMI2() const override { return has(FLAG_BMI2); }
inline bool hasOneGbPages() const override { return has(FLAG_PDPE1GB); }
inline bool hasXOP() const override { return has(FLAG_XOP); }
inline bool hasCatL3() const override { return has(FLAG_CAT_L3); }
inline bool isVM() const override { return has(FLAG_VM); }
inline const char *brand() const override { return m_brand; }
inline MsrMod msrMod() const override { return m_msrMod; }
inline size_t cores() const override { return 0; }
@ -61,19 +64,24 @@ protected:
inline size_t packages() const override { return 1; }
inline size_t threads() const override { return m_threads; }
inline Vendor vendor() const override { return m_vendor; }
inline Arch arch() const override { return m_arch; }
inline bool jccErratum() const override { return m_jccErratum; }
protected:
char m_brand[64 + 6]{};
size_t m_threads;
Vendor m_vendor = VENDOR_UNKNOWN;
Arch m_arch = ARCH_UNKNOWN;
bool m_jccErratum = false;
private:
# ifndef XMRIG_ARM
uint32_t m_procInfo = 0;
uint32_t m_family = 0;
uint32_t m_model = 0;
uint32_t m_stepping = 0;
# endif
Assembly m_assembly = Assembly::NONE;
MsrMod m_msrMod = MSR_MOD_NONE;
std::bitset<FLAG_MAX> m_flags;

View file

@ -36,12 +36,14 @@
#include "3rdparty/rapidjson/document.h"
#ifdef XMRIG_OS_UNIX
#if defined(XMRIG_OS_UNIX)
namespace xmrig {
extern String cpu_name_arm();
} // namespace xmrig
#elif defined(XMRIG_OS_MACOS)
# include <sys/sysctl.h>
#endif
@ -62,13 +64,16 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
# endif
# endif
# ifdef XMRIG_OS_UNIX
# if defined(XMRIG_OS_UNIX)
auto name = cpu_name_arm();
if (!name.isNull()) {
strncpy(m_brand, name, sizeof(m_brand) - 1);
}
m_flags.set(FLAG_PDPE1GB, std::ifstream("/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages").good());
# elif defined(XMRIG_OS_MACOS)
size_t buflen = sizeof(m_brand);
sysctlbyname("machdep.cpu.brand_string", &m_brand, &buflen, nullptr, 0);
# endif
}
@ -95,7 +100,8 @@ rapidjson::Value xmrig::BasicCpuInfo::toJSON(rapidjson::Document &doc) const
out.AddMember("brand", StringRef(brand()), allocator);
out.AddMember("aes", hasAES(), allocator);
out.AddMember("avx2", false, allocator);
out.AddMember("x64", isX64(), allocator);
out.AddMember("x64", is64bit(), allocator); // DEPRECATED will be removed in the next major release.
out.AddMember("64_bit", is64bit(), allocator);
out.AddMember("l2", static_cast<uint64_t>(L2()), allocator);
out.AddMember("l3", static_cast<uint64_t>(L3()), allocator);
out.AddMember("cores", static_cast<uint64_t>(cores()), allocator);

View file

@ -1,12 +1,6 @@
/* 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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -91,6 +85,15 @@ static inline void findByType(hwloc_obj_t obj, hwloc_obj_type_t type, func lambd
}
static inline size_t countByType(hwloc_topology_t topology, hwloc_obj_type_t type)
{
const int count = hwloc_get_nbobjs_by_type(topology, type);
return count > 0 ? static_cast<size_t>(count) : 0;
}
#ifndef XMRIG_ARM
static inline std::vector<hwloc_obj_t> findByType(hwloc_obj_t obj, hwloc_obj_type_t type)
{
std::vector<hwloc_obj_t> out;
@ -100,14 +103,6 @@ static inline std::vector<hwloc_obj_t> findByType(hwloc_obj_t obj, hwloc_obj_typ
}
static inline size_t countByType(hwloc_topology_t topology, hwloc_obj_type_t type)
{
const int count = hwloc_get_nbobjs_by_type(topology, type);
return count > 0 ? static_cast<size_t>(count) : 0;
}
static inline size_t countByType(hwloc_obj_t obj, hwloc_obj_type_t type)
{
size_t count = 0;
@ -122,6 +117,7 @@ static inline bool isCacheExclusive(hwloc_obj_t obj)
const char *value = hwloc_obj_get_info_by_name(obj, "Inclusive");
return value == nullptr || value[0] != '1';
}
#endif
} // namespace xmrig
@ -191,6 +187,12 @@ xmrig::HwlocCpuInfo::HwlocCpuInfo()
m_nodeset.emplace_back(node->os_index);
}
}
# if defined(XMRIG_OS_MACOS) && defined(XMRIG_ARM)
if (L2() == 33554432U && m_cores == 8 && m_cores == m_threads) {
m_cache[2] = 16777216U;
}
# endif
}

View file

@ -1,12 +1,6 @@
/* 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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -52,7 +46,7 @@ public:
HwlocCpuInfo();
~HwlocCpuInfo() override;
static inline bool has(Feature feature) { return m_features & feature; }
static inline bool hasFeature(Feature feature) { return m_features & feature; }
inline const std::vector<uint32_t> &nodeset() const { return m_nodeset; }
inline hwloc_topology_t topology() const { return m_topology; }

View file

@ -409,9 +409,9 @@ void xmrig::CudaBackend::printHashrate(bool details)
Log::print("| %8zu | %8" PRId64 " | %8s | %8s | %8s |" CYAN_BOLD(" #%u") YELLOW(" %s") GREEN(" %s"),
i,
data.thread.affinity(),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
data.device.index(),
data.device.topology().toString().data(),
data.device.name().data()

View file

@ -1,13 +1,6 @@
/* 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>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -32,6 +25,7 @@ xmrig::CudaLaunchData::CudaLaunchData(const Miner *miner, const Algorithm &algor
algorithm(algorithm),
device(device),
thread(thread),
affinity(thread.affinity()),
miner(miner)
{
}

View file

@ -1,13 +1,6 @@
/* 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>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -56,6 +49,7 @@ public:
const Algorithm algorithm;
const CudaDevice &device;
const CudaThread thread;
const int64_t affinity;
const Miner *miner;
const uint32_t benchSize = 0;
};

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -57,11 +50,10 @@
namespace xmrig {
static constexpr uint32_t kReserveCount = 32768;
std::atomic<bool> CudaWorker::ready;
static inline bool isReady() { return !Nonce::isPaused() && CudaWorker::ready; }
static inline bool isReady() { return !Nonce::isPaused() && CudaWorker::ready; }
} // namespace xmrig
@ -69,10 +61,9 @@ static inline bool isReady() { return !Nonce::isPaused()
xmrig::CudaWorker::CudaWorker(size_t id, const CudaLaunchData &data) :
Worker(id, data.thread.affinity(), -1),
GpuWorker(id, data.thread.affinity(), -1, data.device.index()),
m_algorithm(data.algorithm),
m_miner(data.miner),
m_deviceIndex(data.device.index())
m_miner(data.miner)
{
switch (m_algorithm.family()) {
case Algorithm::RANDOM_X:
@ -119,13 +110,7 @@ xmrig::CudaWorker::~CudaWorker()
}
uint64_t xmrig::CudaWorker::rawHashes() const
{
return m_hashrateData.interpolate(Chrono::steadyMSecs());
}
void xmrig::CudaWorker::jobEarlyNotification(const Job& job)
void xmrig::CudaWorker::jobEarlyNotification(const Job &job)
{
if (m_runner) {
m_runner->jobEarlyNotification(job);
@ -213,5 +198,5 @@ void xmrig::CudaWorker::storeStats()
const uint64_t timeStamp = Chrono::steadyMSecs();
m_hashrateData.addDataPoint(m_count, timeStamp);
Worker::storeStats();
GpuWorker::storeStats();
}

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -27,8 +20,7 @@
#define XMRIG_CUDAWORKER_H
#include "backend/common/HashrateInterpolator.h"
#include "backend/common/Worker.h"
#include "backend/common/GpuWorker.h"
#include "backend/common/WorkerJob.h"
#include "backend/cuda/CudaLaunchData.h"
#include "base/tools/Object.h"
@ -41,7 +33,7 @@ namespace xmrig {
class ICudaRunner;
class CudaWorker : public Worker
class CudaWorker : public GpuWorker
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(CudaWorker)
@ -50,8 +42,7 @@ public:
~CudaWorker() override;
uint64_t rawHashes() const override;
void jobEarlyNotification(const Job&) override;
void jobEarlyNotification(const Job &job) override;
static std::atomic<bool> ready;
@ -68,9 +59,6 @@ private:
const Miner *m_miner;
ICudaRunner *m_runner = nullptr;
WorkerJob<1> m_job;
uint32_t m_deviceIndex;
HashrateInterpolator m_hashrateData;
};

View file

@ -385,9 +385,9 @@ void xmrig::OclBackend::printHashrate(bool details)
Log::print("| %8zu | %8" PRId64 " | %8s | %8s | %8s |" CYAN_BOLD(" #%u") YELLOW(" %s") " %s",
i,
data.affinity,
Hashrate::format(hashrate()->calc(i + 1, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
data.device.index(),
data.device.topology().toString().data(),
data.device.printableName().data()

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -63,7 +56,7 @@ namespace xmrig {
std::atomic<bool> OclWorker::ready;
static inline bool isReady() { return !Nonce::isPaused() && OclWorker::ready; }
static inline bool isReady() { return !Nonce::isPaused() && OclWorker::ready; }
static inline void printError(size_t id, const char *error)
@ -77,11 +70,10 @@ static inline void printError(size_t id, const char *error)
xmrig::OclWorker::OclWorker(size_t id, const OclLaunchData &data) :
Worker(id, data.affinity, -1),
GpuWorker(id, data.affinity, -1, data.device.index()),
m_algorithm(data.algorithm),
m_miner(data.miner),
m_sharedData(OclSharedState::get(data.device.index())),
m_deviceIndex(data.device.index())
m_sharedData(OclSharedState::get(data.device.index()))
{
switch (m_algorithm.family()) {
case Algorithm::RANDOM_X:
@ -149,13 +141,7 @@ xmrig::OclWorker::~OclWorker()
}
uint64_t xmrig::OclWorker::rawHashes() const
{
return m_hashrateData.interpolate(Chrono::steadyMSecs());
}
void xmrig::OclWorker::jobEarlyNotification(const Job& job)
void xmrig::OclWorker::jobEarlyNotification(const Job &job)
{
if (m_runner) {
m_runner->jobEarlyNotification(job);
@ -192,7 +178,7 @@ void xmrig::OclWorker::start()
break;
}
m_sharedData.resumeDelay(m_id);
m_sharedData.resumeDelay(id());
if (!consumeJob()) {
return;
@ -200,7 +186,7 @@ void xmrig::OclWorker::start()
}
while (!Nonce::isOutdated(Nonce::OPENCL, m_job.sequence())) {
m_sharedData.adjustDelay(m_id);
m_sharedData.adjustDelay(id());
const uint64_t t = Chrono::steadyMSecs();
@ -266,5 +252,5 @@ void xmrig::OclWorker::storeStats(uint64_t t)
m_sharedData.setRunTime(timeStamp - t);
Worker::storeStats();
GpuWorker::storeStats();
}

View file

@ -1,13 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@ -27,8 +20,7 @@
#define XMRIG_OCLWORKER_H
#include "backend/common/HashrateInterpolator.h"
#include "backend/common/Worker.h"
#include "backend/common/GpuWorker.h"
#include "backend/common/WorkerJob.h"
#include "backend/opencl/OclLaunchData.h"
#include "base/tools/Object.h"
@ -42,7 +34,7 @@ class IOclRunner;
class Job;
class OclWorker : public Worker
class OclWorker : public GpuWorker
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(OclWorker)
@ -51,8 +43,7 @@ public:
~OclWorker() override;
uint64_t rawHashes() const override;
void jobEarlyNotification(const Job&) override;
void jobEarlyNotification(const Job &job) override;
static std::atomic<bool> ready;
@ -70,9 +61,6 @@ private:
IOclRunner *m_runner = nullptr;
OclSharedData &m_sharedData;
WorkerJob<1> m_job;
uint32_t m_deviceIndex;
HashrateInterpolator m_hashrateData;
};

View file

@ -93,7 +93,7 @@ xmrig::OclAstroBWTRunner::~OclAstroBWTRunner()
OclLib::release(m_tmp_indices);
OclLib::release(m_filtered_hashes);
delete m_bwt_data_sizes_host;
delete [] m_bwt_data_sizes_host;
}

View file

@ -43,6 +43,9 @@
namespace xmrig {
constexpr size_t BLOB_SIZE = 40;
OclKawPowRunner::OclKawPowRunner(size_t index, const OclLaunchData &data) : OclBaseRunner(index, data)
{
switch (data.thread.worksize())
@ -82,7 +85,7 @@ void OclKawPowRunner::run(uint32_t nonce, uint32_t *hashOutput)
const size_t global_work_offset = nonce;
const size_t global_work_size = m_intensity - (m_intensity % m_workGroupSize);
enqueueWriteBuffer(m_input, CL_FALSE, 0, 40, m_blob);
enqueueWriteBuffer(m_input, CL_FALSE, 0, BLOB_SIZE, m_blob);
const uint32_t zero[2] = {};
enqueueWriteBuffer(m_output, CL_FALSE, 0, sizeof(uint32_t), zero);
@ -177,7 +180,7 @@ void OclKawPowRunner::set(const Job &job, uint8_t *blob)
OclLib::setKernelArg(m_searchKernel, 5, sizeof(m_stop), &m_stop);
m_blob = blob;
enqueueWriteBuffer(m_input, CL_TRUE, 0, sizeof(m_blob), m_blob);
enqueueWriteBuffer(m_input, CL_TRUE, 0, BLOB_SIZE, m_blob);
}

View file

@ -306,7 +306,7 @@ private:
}
static std::string merge(std::string a, std::string b, uint32_t r)
static std::string merge(const std::string& a, const std::string& b, uint32_t r)
{
switch (r % 4)
{
@ -323,7 +323,7 @@ private:
}
static std::string math(std::string d, std::string a, std::string b, uint32_t r)
static std::string math(const std::string& d, const std::string& a, const std::string& b, uint32_t r)
{
switch (r % 11)
{

View file

@ -836,7 +836,13 @@ xmrig::String xmrig::OclLib::getProgramBuildLog(cl_program program, cl_device_id
return String();
}
char *log = new char[size + 1]();
char* log = nullptr;
try {
log = new char[size + 1]();
}
catch (...) {
return String();
}
if (getProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, size, log, nullptr) != CL_SUCCESS) {
delete [] log;