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

concurrent hash rate calculation #2393

Merged
merged 1 commit into from
Apr 23, 2019
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
10 changes: 6 additions & 4 deletions xmrstak/misc/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "telemetry.hpp"
#include "xmrstak/net/msgstruct.hpp"
#include "xmrstak/cpputil/read_write_lock.h"

#include <chrono>
#include <cmath>
Expand All @@ -36,7 +37,7 @@ telemetry::telemetry(size_t iThd)
ppHashCounts = new uint64_t*[iThd];
ppTimestamps = new uint64_t*[iThd];
iBucketTop = new uint32_t[iThd];
mtx = new std::mutex[iThd];
mtx = new ::cpputil::RWLock[iThd];

for(size_t i = 0; i < iThd; i++)
{
Expand All @@ -57,7 +58,7 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)
uint64_t iLatestHashCnt = 0;
bool bHaveFullSet = false;

std::unique_lock<std::mutex> lk(mtx[iThread]);
mtx[iThread].ReadLock();
uint64_t iTimeNow = get_timestamp_ms();

//Start at 1, buckettop points to next empty
Expand All @@ -83,7 +84,7 @@ double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)
iEarliestStamp = ppTimestamps[iThread][idx];
iEarliestHashCnt = ppHashCounts[iThread][idx];
}
lk.unlock();
mtx[iThread].UnLock();

if(!bHaveFullSet || iEarliestStamp == 0 || iLatestStamp == 0)
return nan("");
Expand All @@ -102,12 +103,13 @@ 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[iThd]);
mtx[iThd].WriteLock();
size_t iTop = iBucketTop[iThd];
ppHashCounts[iThd][iTop] = iHashCount;
ppTimestamps[iThd][iTop] = iTimestamp;

iBucketTop[iThd] = (iTop + 1) & iBucketMask;
mtx[iThd].UnLock();
}

} // namespace xmrstak
4 changes: 3 additions & 1 deletion xmrstak/misc/telemetry.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "xmrstak/cpputil/read_write_lock.h"

#include <cstdint>
#include <cstring>
#include <mutex>
Expand All @@ -15,7 +17,7 @@ class telemetry
double calc_telemetry_data(size_t iLastMillisec, size_t iThread);

private:
std::mutex* mtx;
::cpputil::RWLock* 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