Skip to content
Snippets Groups Projects
Commit ca14c9df authored by psychocrypt's avatar psychocrypt
Browse files

reduce blocking during metric update

With #1845 a race condition during the telemetry update is solved.
The problem is that the used mutex is blocking all threads from updating the metrics during
the statistics are calculated.

- introduce a mutex per miner thread
parent 9fe30b2b
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,7 @@ telemetry::telemetry(size_t iThd) ...@@ -36,6 +36,7 @@ telemetry::telemetry(size_t iThd)
ppHashCounts = new uint64_t*[iThd]; ppHashCounts = new uint64_t*[iThd];
ppTimestamps = new uint64_t*[iThd]; ppTimestamps = new uint64_t*[iThd];
iBucketTop = new uint32_t[iThd]; iBucketTop = new uint32_t[iThd];
mtx = new std::mutex[iThd];
for (size_t i = 0; i < iThd; i++) for (size_t i = 0; i < iThd; i++)
{ {
...@@ -49,8 +50,7 @@ telemetry::telemetry(size_t iThd) ...@@ -49,8 +50,7 @@ telemetry::telemetry(size_t iThd)
double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread) double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)
{ {
std::unique_lock<std::mutex> lk(mtx);
uint64_t iTimeNow = get_timestamp_ms();
uint64_t iEarliestHashCnt = 0; uint64_t iEarliestHashCnt = 0;
uint64_t iEarliestStamp = 0; uint64_t iEarliestStamp = 0;
...@@ -58,6 +58,9 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread) ...@@ -58,6 +58,9 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)
uint64_t iLatestHashCnt = 0; uint64_t iLatestHashCnt = 0;
bool bHaveFullSet = false; bool bHaveFullSet = false;
std::unique_lock<std::mutex> lk(mtx[iThread]);
uint64_t iTimeNow = get_timestamp_ms();
//Start at 1, buckettop points to next empty //Start at 1, buckettop points to next empty
for (size_t i = 1; i < iBucketSize; i++) for (size_t i = 1; i < iBucketSize; i++)
{ {
...@@ -81,6 +84,7 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread) ...@@ -81,6 +84,7 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)
iEarliestStamp = ppTimestamps[iThread][idx]; iEarliestStamp = ppTimestamps[iThread][idx];
iEarliestHashCnt = ppHashCounts[iThread][idx]; iEarliestHashCnt = ppHashCounts[iThread][idx];
} }
lk.unlock();
if (!bHaveFullSet || iEarliestStamp == 0 || iLatestStamp == 0) if (!bHaveFullSet || iEarliestStamp == 0 || iLatestStamp == 0)
return nan(""); return nan("");
...@@ -99,7 +103,7 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread) ...@@ -99,7 +103,7 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)
void telemetry::push_perf_value(size_t iThd, uint64_t iHashCount, uint64_t iTimestamp) void telemetry::push_perf_value(size_t iThd, uint64_t iHashCount, uint64_t iTimestamp)
{ {
std::unique_lock<std::mutex> lk(mtx); std::unique_lock<std::mutex> lk(mtx[iThd]);
size_t iTop = iBucketTop[iThd]; size_t iTop = iBucketTop[iThd];
ppHashCounts[iThd][iTop] = iHashCount; ppHashCounts[iThd][iTop] = iHashCount;
ppTimestamps[iThd][iTop] = iTimestamp; ppTimestamps[iThd][iTop] = iTimestamp;
......
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
double calc_telemetry_data(size_t iLastMillisec, size_t iThread); double calc_telemetry_data(size_t iLastMillisec, size_t iThread);
private: private:
mutable std::mutex mtx; std::mutex* mtx;
constexpr static size_t iBucketSize = 2 << 11; //Power of 2 to simplify calculations constexpr static size_t iBucketSize = 2 << 11; //Power of 2 to simplify calculations
constexpr static size_t iBucketMask = iBucketSize - 1; constexpr static size_t iBucketMask = iBucketSize - 1;
uint32_t* iBucketTop; uint32_t* iBucketTop;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment