Skip to content
Snippets Groups Projects
Unverified Commit 952d2446 authored by psychocrypt's avatar psychocrypt Committed by GitHub
Browse files

Merge pull request #1845 from Spudz76/dev-telemetry

telemetry: Add mutex to avoid push during recalc and other races
parents bf225a23 f03319c3
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,7 @@ telemetry::telemetry(size_t iThd) ...@@ -49,6 +49,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 iTimeNow = get_timestamp_ms();
uint64_t iEarliestHashCnt = 0; uint64_t iEarliestHashCnt = 0;
...@@ -98,6 +99,7 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread) ...@@ -98,6 +99,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);
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;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <mutex>
namespace xmrstak namespace xmrstak
{ {
...@@ -14,6 +15,7 @@ public: ...@@ -14,6 +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;
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