Added GpuWorker class.
This commit is contained in:
parent
daf08fcf9a
commit
bd82b3c852
15 changed files with 193 additions and 202 deletions
52
src/backend/common/GpuWorker.cpp
Normal file
52
src/backend/common/GpuWorker.cpp
Normal 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];
|
||||
}
|
58
src/backend/common/GpuWorker.h
Normal file
58
src/backend/common/GpuWorker.h
Normal 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 */
|
|
@ -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>
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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] = {};
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -58,20 +58,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
inline static void getHashrateData(IWorker *worker, uint64_t &hashCount, uint64_t &timeStamp)
|
||||
{
|
||||
worker->getHashrateData(hashCount, timeStamp);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
inline void getHashrateData<xmrig::CpuLaunchData>(IWorker *worker, uint64_t &hashCount, uint64_t &)
|
||||
{
|
||||
hashCount = worker->rawHashes();
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -100,19 +86,20 @@ 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);
|
||||
worker->hashrateData(hashCount, ts, rawHashes);
|
||||
d_ptr->hashrate->add(handle->id() + 1, hashCount, ts);
|
||||
|
||||
const uint64_t n = worker->rawHashes();
|
||||
if (n == 0) {
|
||||
if (rawHashes == 0) {
|
||||
totalAvailable = false;
|
||||
}
|
||||
totalHashCount += n;
|
||||
|
||||
totalHashCount += rawHashes;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -42,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 &hashCount, uint64_t &timeStamp) const = 0;
|
||||
virtual void jobEarlyNotification(const Job &job) = 0;
|
||||
virtual void start() = 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;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue