From dd4bcb3f35e45f1fb128dc7216585304a471d5d6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 29 Aug 2017 23:00:37 +0300 Subject: [PATCH] #7 Fixed crash when try see hashrate reports --- src/Options.cpp | 4 ++-- src/Summary.cpp | 2 +- src/workers/CudaWorker.cpp | 2 +- src/workers/GpuThread.cpp | 10 ++++++---- src/workers/GpuThread.h | 35 +++++++++++++++++++---------------- src/workers/Handle.cpp | 2 ++ src/workers/Hashrate.cpp | 4 ++-- src/workers/Hashrate.h | 2 +- src/workers/Workers.cpp | 26 +++++++++++++++++++------- 9 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/Options.cpp b/src/Options.cpp index 778ac609..c82b2f23 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -212,7 +212,7 @@ bool Options::save() json_t *threads = json_array(); for (const GpuThread *thread : m_threads) { json_t *obj = json_object(); - json_object_set(obj, "index", json_integer(thread->id())); + json_object_set(obj, "index", json_integer(thread->index())); json_object_set(obj, "threads", json_integer(thread->threads())); json_object_set(obj, "blocks", json_integer(thread->blocks())); json_object_set(obj, "bfactor", json_integer(thread->bfactor())); @@ -651,7 +651,7 @@ void Options::parseJSON(const struct option *option, json_t *object) void Options::parseThread(json_t *object) { GpuThread *thread = new GpuThread(); - thread->setId((int) json_integer_value(json_object_get(object, "index"))); + thread->setIndex((int) json_integer_value(json_object_get(object, "index"))); thread->setThreads((int) json_integer_value(json_object_get(object, "threads"))); thread->setBlocks((int) json_integer_value(json_object_get(object, "blocks"))); thread->setBFactor((int) json_integer_value(json_object_get(object, "bfactor"))); diff --git a/src/Summary.cpp b/src/Summary.cpp index f0f285b8..64a5f5f1 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -103,7 +103,7 @@ static void print_gpu() { for (const GpuThread *thread : Options::i()->threads()) { Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mGPU #%d: \x1B[22;32m%s @ %d/%d MHz \x1B[01;30m%dx%d %dx%d arch:%d%d SMX:%d" : " * GPU #%d: %s @ %d/%d MHz %dx%d %dx%d arch:%d%d SMX:%d", - thread->id(), + thread->index(), thread->name(), thread->clockRate() / 1000, thread->memoryClockRate() / 1000, diff --git a/src/workers/CudaWorker.cpp b/src/workers/CudaWorker.cpp index 7be11005..3f830797 100644 --- a/src/workers/CudaWorker.cpp +++ b/src/workers/CudaWorker.cpp @@ -43,7 +43,7 @@ CudaWorker::CudaWorker(Handle *handle) : { const GpuThread *thread = handle->gpuThread(); - m_ctx.device_id = thread->id(); + m_ctx.device_id = thread->index(); m_ctx.device_blocks = thread->blocks(); m_ctx.device_threads = thread->threads(); m_ctx.device_bfactor = thread->bfactor(); diff --git a/src/workers/GpuThread.cpp b/src/workers/GpuThread.cpp index 141041a8..d298e1e5 100644 --- a/src/workers/GpuThread.cpp +++ b/src/workers/GpuThread.cpp @@ -34,9 +34,10 @@ GpuThread::GpuThread() : m_blocks(0), m_bsleep(0), m_clockRate(0), - m_id(0), + m_index(0), m_memoryClockRate(0), m_smx(0), + m_threadId(0), m_threads(0) { memset(m_arch, 0, sizeof(m_arch)); @@ -49,9 +50,10 @@ GpuThread::GpuThread(const nvid_ctx &ctx) : m_blocks(ctx.device_blocks), m_bsleep(ctx.device_bsleep), m_clockRate(ctx.device_clockRate), - m_id(ctx.device_id), + m_index(ctx.device_id), m_memoryClockRate(ctx.device_memoryClockRate), m_smx(ctx.device_mpcount), + m_threadId(0), m_threads(ctx.device_threads) { memcpy(m_arch, ctx.device_arch, sizeof(m_arch)); @@ -66,7 +68,7 @@ GpuThread::~GpuThread() bool GpuThread::init() { - if (m_id < 0 || m_blocks < -1 || m_threads < -1 || m_bfactor < 0 || m_bsleep < 0) { + if (m_index < 0 || m_blocks < -1 || m_threads < -1 || m_bfactor < 0 || m_bsleep < 0) { return false; } @@ -75,7 +77,7 @@ bool GpuThread::init() } nvid_ctx ctx; - ctx.device_id = m_id; + ctx.device_id = m_index; ctx.device_blocks = m_blocks; ctx.device_threads = m_threads; ctx.device_bfactor = m_bfactor; diff --git a/src/workers/GpuThread.h b/src/workers/GpuThread.h index 64bb6751..04bb7510 100644 --- a/src/workers/GpuThread.h +++ b/src/workers/GpuThread.h @@ -42,22 +42,24 @@ class GpuThread static void autoConf(std::vector &threads, int bfactor, int bsleep); - inline const char *name() const { return m_name; } - inline const int *arch() const { return m_arch; } - inline int bfactor() const { return m_bfactor; } - inline int blocks() const { return m_blocks; } - inline int bsleep() const { return m_bsleep; } - inline int clockRate() const { return m_clockRate; } - inline int id() const { return m_id; } - inline int memoryClockRate() const { return m_memoryClockRate; } - inline int smx() const { return m_smx; } - inline int threads() const { return m_threads; } + inline const char *name() const { return m_name; } + inline const int *arch() const { return m_arch; } + inline int bfactor() const { return m_bfactor; } + inline int blocks() const { return m_blocks; } + inline int bsleep() const { return m_bsleep; } + inline int clockRate() const { return m_clockRate; } + inline int index() const { return m_index; } + inline int memoryClockRate() const { return m_memoryClockRate; } + inline int smx() const { return m_smx; } + inline int threadId() const { return m_threadId; } + inline int threads() const { return m_threads; } - inline void setBFactor(int bfactor) { if (bfactor >= 0 && bfactor <= 12) { m_bfactor = bfactor; } } - inline void setBlocks(int blocks) { m_blocks = blocks; } - inline void setBSleep(int bsleep) { m_bsleep = bsleep; } - inline void setId(int id) { m_id = id; } - inline void setThreads(int threads) { m_threads = threads; } + inline void setBFactor(int bfactor) { if (bfactor >= 0 && bfactor <= 12) { m_bfactor = bfactor; } } + inline void setBlocks(int blocks) { m_blocks = blocks; } + inline void setBSleep(int bsleep) { m_bsleep = bsleep; } + inline void setIndex(int index) { m_index = index; } + inline void setThreadId(int threadId) { m_threadId = threadId; } + inline void setThreads(int threads) { m_threads = threads; } private: bool m_affinity; @@ -67,9 +69,10 @@ class GpuThread int m_blocks; int m_bsleep; int m_clockRate; - int m_id; + int m_index; int m_memoryClockRate; int m_smx; + int m_threadId; int m_threads; }; diff --git a/src/workers/Handle.cpp b/src/workers/Handle.cpp index a2b26ce5..9470f348 100644 --- a/src/workers/Handle.cpp +++ b/src/workers/Handle.cpp @@ -23,6 +23,7 @@ #include "workers/Handle.h" +#include "workers/GpuThread.h" Handle::Handle(int threadId, GpuThread *thread, int threads, bool lite) : @@ -32,6 +33,7 @@ Handle::Handle(int threadId, GpuThread *thread, int threads, bool lite) : m_threads(threads), m_worker(nullptr) { + thread->setThreadId(threadId); } diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 5b60fd80..bde1552d 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -152,14 +152,14 @@ void Hashrate::print() } -void Hashrate::print(size_t threadId) +void Hashrate::print(size_t threadId, int gpuId) { char num1[8]; char num2[8]; char num3[8]; LOG_INFO(Options::i()->colors() ? "\x1B[01;37mGPU %d\x1B[0m 10s/60s/15m \x1B[01;36m%s\x1B[0m \x1B[22;36m%s %s \x1B[01;36mH/s" : "speed 10s/60s/15m %s %s %s H/s", - (int) threadId, + gpuId, format(calc(threadId, 10000), num1, sizeof(num1)), format(calc(threadId, 60000), num2, sizeof(num2)), format(calc(threadId, 900000), num3, sizeof(num3)) diff --git a/src/workers/Hashrate.h b/src/workers/Hashrate.h index c59bb72b..36fcebe4 100644 --- a/src/workers/Hashrate.h +++ b/src/workers/Hashrate.h @@ -36,7 +36,7 @@ class Hashrate double calc(size_t threadId, size_t ms) const; void add(size_t threadId, uint64_t count, uint64_t timestamp); void print(); - void print(size_t threadId); + void print(size_t threadId, int gpuId); void stop(); void updateHighest(); diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 810a6c49..173f132e 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -86,7 +86,7 @@ void Workers::printHashrate(bool detail) { if (detail) { for (const GpuThread *thread : Options::i()->threads()) { - m_hashrate->print(thread->id()); + m_hashrate->print(thread->threadId(), thread->index()); } } @@ -103,16 +103,28 @@ void Workers::printHealth() Health health; for (const GpuThread *thread : Options::i()->threads()) { - NvmlApi::health(thread->id(), health); + NvmlApi::health(thread->index(), health); - if (Options::i()->colors()) { - const uint32_t temp = health.temperature; + const uint32_t temp = health.temperature; + + if (health.clock && health.power) { + if (Options::i()->colors()) { + LOG_INFO("\x1B[00;35mGPU #%d: \x1B[01m%u\x1B[00;35m/\x1B[01m%u MHz\x1B[00;35m \x1B[01m%uW\x1B[00;35m %s%uC\x1B[00;35m FAN \x1B[01m%u%%", + thread->index(), health.clock, health.memClock, health.power / 1000, (temp < 45 ? "\x1B[01;32m" : (temp > 65 ? "\x1B[01;31m" : "\x1B[01;33m")), temp, health.fanSpeed); + } + else { + LOG_INFO(" * GPU #%d: %u/%u MHz %uW %uC FAN %u%%", thread->index(), health.clock, health.memClock, health.power / 1000, health.temperature, health.fanSpeed); + } - LOG_INFO("\x1B[00;35mGPU #%d: \x1B[01m%u\x1B[00;35m/\x1B[01m%u MHz\x1B[00;35m \x1B[01m%uW\x1B[00;35m %s%uC\x1B[00;35m FAN \x1B[01m%u%%", - thread->id(), health.clock, health.memClock, health.power / 1000, (temp < 45 ? "\x1B[01;32m" : (temp > 65 ? "\x1B[01;31m" : "\x1B[01;33m")), temp, health.fanSpeed); + continue; + } + + if (Options::i()->colors()) { + LOG_INFO("\x1B[00;35mGPU #%d: %s%uC\x1B[00;35m FAN \x1B[01m%u%%", + thread->index(), (temp < 45 ? "\x1B[01;32m" : (temp > 65 ? "\x1B[01;31m" : "\x1B[01;33m")), temp, health.fanSpeed); } else { - LOG_INFO(" * GPU #%d: %u/%u MHz %uW %uC FAN %u%%", thread->id(), health.clock, health.memClock, health.power / 1000, health.temperature, health.fanSpeed); + LOG_INFO(" * GPU #%d: %uC FAN %u%%", thread->index(), health.temperature, health.fanSpeed); } } }