Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telemetry: Add mutex to avoid push during recalc and other races #1845

Merged
merged 1 commit into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions xmrstak/misc/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ telemetry::telemetry(size_t iThd)

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;
Expand Down Expand Up @@ -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)
{
std::unique_lock<std::mutex> lk(mtx);
size_t iTop = iBucketTop[iThd];
ppHashCounts[iThd][iTop] = iHashCount;
ppTimestamps[iThd][iTop] = iTimestamp;
Expand Down
2 changes: 2 additions & 0 deletions xmrstak/misc/telemetry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <cstring>
#include <mutex>

namespace xmrstak
{
Expand All @@ -14,6 +15,7 @@ class telemetry
double calc_telemetry_data(size_t iLastMillisec, size_t iThread);

private:
mutable std::mutex mtx;
constexpr static size_t iBucketSize = 2 << 11; //Power of 2 to simplify calculations
constexpr static size_t iBucketMask = iBucketSize - 1;
uint32_t* iBucketTop;
Expand Down