diff --git a/src/backend/common/Worker.cpp b/src/backend/common/Worker.cpp
index f0457bbb1..98da61d41 100644
--- a/src/backend/common/Worker.cpp
+++ b/src/backend/common/Worker.cpp
@@ -23,36 +23,25 @@
* along with this program. If not, see .
*/
-#include
-
#include "backend/common/Worker.h"
-#include "backend/cpu/Cpu.h"
#include "base/kernel/Platform.h"
-#include "workers/CpuThreadLegacy.h"
-#include "workers/ThreadHandle.h"
+#include "base/tools/Chrono.h"
-Worker::Worker(ThreadHandle *handle) :
- m_id(handle->threadId()),
+xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
+ m_id(id),
m_hashCount(0),
m_timestamp(0),
- m_count(0),
- m_thread(static_cast(handle->config()))
+ m_count(0)
{
- if (xmrig::Cpu::info()->threads() > 1 && m_thread->affinity() != -1L) {
- Platform::setThreadAffinity(m_thread->affinity());
- }
-
- Platform::setThreadPriority(m_thread->priority());
+ Platform::trySetThreadAffinity(affinity);
+ Platform::setThreadPriority(priority);
}
-void Worker::storeStats()
+void xmrig::Worker::storeStats()
{
- using namespace std::chrono;
-
- const uint64_t timestamp = time_point_cast(high_resolution_clock::now()).time_since_epoch().count();
m_hashCount.store(m_count, std::memory_order_relaxed);
- m_timestamp.store(timestamp, std::memory_order_relaxed);
+ m_timestamp.store(Chrono::highResolutionMSecs(), std::memory_order_relaxed);
}
diff --git a/src/backend/common/Worker.h b/src/backend/common/Worker.h
index 3e1d202fd..3223a60c5 100644
--- a/src/backend/common/Worker.h
+++ b/src/backend/common/Worker.h
@@ -32,23 +32,16 @@
#include "backend/common/interfaces/IWorker.h"
-#include "Mem.h"
-
-
-class ThreadHandle;
namespace xmrig {
- class CpuThreadLegacy;
-}
class Worker : public IWorker
{
public:
- Worker(ThreadHandle *handle);
+ Worker(size_t id, int64_t affinity, int priority);
- inline const MemInfo &memory() const { return m_memory; }
inline size_t id() const override { return m_id; }
inline uint64_t hashCount() const override { return m_hashCount.load(std::memory_order_relaxed); }
inline uint64_t timestamp() const override { return m_timestamp.load(std::memory_order_relaxed); }
@@ -57,12 +50,13 @@ protected:
void storeStats();
const size_t m_id;
- MemInfo m_memory;
std::atomic m_hashCount;
std::atomic m_timestamp;
uint64_t m_count;
- xmrig::CpuThreadLegacy *m_thread;
};
+} // namespace xmrig
+
+
#endif /* XMRIG_WORKER_H */
diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp
index fc98048db..e8aa2e3e8 100644
--- a/src/backend/cpu/CpuWorker.cpp
+++ b/src/backend/cpu/CpuWorker.cpp
@@ -34,6 +34,7 @@
#include "crypto/rx/RxVm.h"
#include "net/JobResults.h"
#include "workers/CpuThreadLegacy.h"
+#include "workers/ThreadHandle.h"
#include "workers/Workers.h"
@@ -45,8 +46,9 @@ static constexpr uint32_t kReserveCount = 4096;
template
-xmrig::CpuWorker::CpuWorker(ThreadHandle *handle)
- : Worker(handle)
+xmrig::CpuWorker::CpuWorker(ThreadHandle *handle) :
+ Worker(handle->threadId(), handle->config()->affinity(), handle->config()->priority()),
+ m_thread(static_cast(handle->config()))
{
if (m_thread->algorithm().family() != Algorithm::RANDOM_X) {
m_memory = Mem::create(m_ctx, m_thread->algorithm(), N);
diff --git a/src/backend/cpu/CpuWorker.h b/src/backend/cpu/CpuWorker.h
index 7e878b54d..b9adf0f1e 100644
--- a/src/backend/cpu/CpuWorker.h
+++ b/src/backend/cpu/CpuWorker.h
@@ -34,9 +34,13 @@
#include "backend/common/Worker.h"
+class ThreadHandle;
+
+
namespace xmrig {
+class CpuThreadLegacy;
class RxVm;
@@ -47,6 +51,8 @@ public:
CpuWorker(ThreadHandle *handle);
~CpuWorker() override;
+ inline const MemInfo &memory() const { return m_memory; }
+
protected:
bool selfTest() override;
void start() override;
@@ -60,9 +66,10 @@ private:
bool verify2(const Algorithm &algorithm, const uint8_t *referenceValue);
void consumeJob();
+ CpuThreadLegacy *m_thread;
cryptonight_ctx *m_ctx[N];
+ MemInfo m_memory;
uint8_t m_hash[N * 32];
-
WorkerJob m_job;
# ifdef XMRIG_ALGO_RANDOMX
diff --git a/src/base/tools/Chrono.h b/src/base/tools/Chrono.h
index d3c146028..e464f3613 100644
--- a/src/base/tools/Chrono.h
+++ b/src/base/tools/Chrono.h
@@ -35,6 +35,14 @@ namespace xmrig {
class Chrono
{
public:
+ static inline uint64_t highResolutionMSecs()
+ {
+ using namespace std::chrono;
+
+ return static_cast(time_point_cast(high_resolution_clock::now()).time_since_epoch().count());
+ }
+
+
static inline uint64_t steadyMSecs()
{
using namespace std::chrono;
diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp
index 568817cd0..0a683caaa 100644
--- a/src/workers/Hashrate.cpp
+++ b/src/workers/Hashrate.cpp
@@ -24,13 +24,13 @@
#include
-#include
#include
#include
#include
#include "base/io/log/Log.h"
+#include "base/tools/Chrono.h"
#include "base/tools/Handle.h"
#include "core/config/Config.h"
#include "core/Controller.h"
@@ -98,9 +98,6 @@ double Hashrate::calc(size_t threadId, size_t ms) const
return nan("");
}
- using namespace std::chrono;
- const uint64_t now = time_point_cast(high_resolution_clock::now()).time_since_epoch().count();
-
uint64_t earliestHashCount = 0;
uint64_t earliestStamp = 0;
uint64_t lastestStamp = 0;
@@ -119,7 +116,7 @@ double Hashrate::calc(size_t threadId, size_t ms) const
lastestHashCnt = m_counts[threadId][idx];
}
- if (now - m_timestamps[threadId][idx] > ms) {
+ if (xmrig::Chrono::highResolutionMSecs() - m_timestamps[threadId][idx] > ms) {
haveFullSet = true;
break;
}
@@ -136,10 +133,8 @@ double Hashrate::calc(size_t threadId, size_t ms) const
return nan("");
}
- double hashes, time;
- hashes = (double) lastestHashCnt - earliestHashCount;
- time = (double) lastestStamp - earliestStamp;
- time /= 1000.0;
+ const double hashes = static_cast(lastestHashCnt - earliestHashCount);
+ const double time = static_cast(lastestStamp - earliestStamp) / 1000.0;
return hashes / time;
}
diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp
index b43546cd3..78954d8f6 100644
--- a/src/workers/Workers.cpp
+++ b/src/workers/Workers.cpp
@@ -299,12 +299,12 @@ void Workers::onTick(uv_timer_t *)
void Workers::start(IWorker *worker)
{
- const Worker *w = static_cast(worker);
+// const Worker *w = static_cast(worker);
uv_mutex_lock(&m_mutex);
m_status.started++;
- m_status.pages += w->memory().pages;
- m_status.hugePages += w->memory().hugePages;
+// m_status.pages += w->memory().pages;
+// m_status.hugePages += w->memory().hugePages;
if (m_status.started == m_status.threads) {
const double percent = (double) m_status.hugePages / m_status.pages * 100.0;