More precise hashrate calculation
- Use only steady timestamp counters to guarantee correctness - CPU backend: directly measure total hashrate using raw hash counters from each thread; update data more often on ARM CPUs because they're slower - GPU backends: directly measure total hashrate too, but use interpolator with 4 second lag to fix variance from batches of hashes Total hashrate is now measured directly (realtime for CPU, 4 seconds lag for GPU), so it might differ a bit from the sum of all thread hashrates because data points are taken at different moments in time. Overhead is reduced a lot since it doesn't have to go through all threads to calculate max total hashrate on every timer tick (2 times a second).
This commit is contained in:
parent
0a2fe5caa7
commit
3fbf2ac3d4
17 changed files with 192 additions and 39 deletions
|
@ -48,13 +48,13 @@ inline static const char *format(double h, char *buf, size_t size)
|
|||
|
||||
|
||||
xmrig::Hashrate::Hashrate(size_t threads) :
|
||||
m_threads(threads)
|
||||
m_threads(threads + 1)
|
||||
{
|
||||
m_counts = new uint64_t*[threads];
|
||||
m_timestamps = new uint64_t*[threads];
|
||||
m_top = new uint32_t[threads];
|
||||
m_counts = new uint64_t*[m_threads];
|
||||
m_timestamps = new uint64_t*[m_threads];
|
||||
m_top = new uint32_t[m_threads];
|
||||
|
||||
for (size_t i = 0; i < threads; i++) {
|
||||
for (size_t i = 0; i < m_threads; i++) {
|
||||
m_counts[i] = new uint64_t[kBucketSize]();
|
||||
m_timestamps[i] = new uint64_t[kBucketSize]();
|
||||
m_top[i] = 0;
|
||||
|
@ -77,17 +77,8 @@ xmrig::Hashrate::~Hashrate()
|
|||
|
||||
double xmrig::Hashrate::calc(size_t ms) const
|
||||
{
|
||||
double result = 0.0;
|
||||
double data;
|
||||
|
||||
for (size_t i = 0; i < m_threads; ++i) {
|
||||
data = calc(i, ms);
|
||||
if (std::isnormal(data)) {
|
||||
result += data;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
const double data = calc(0, ms);
|
||||
return std::isnormal(data) ? data : 0.0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,7 +93,7 @@ double xmrig::Hashrate::calc(size_t threadId, size_t ms) const
|
|||
uint64_t earliestStamp = 0;
|
||||
bool haveFullSet = false;
|
||||
|
||||
const uint64_t timeStampLimit = xmrig::Chrono::highResolutionMSecs() - ms;
|
||||
const uint64_t timeStampLimit = xmrig::Chrono::steadyMSecs() - ms;
|
||||
uint64_t* timestamps = m_timestamps[threadId];
|
||||
uint64_t* counts = m_counts[threadId];
|
||||
|
||||
|
@ -183,9 +174,9 @@ rapidjson::Value xmrig::Hashrate::toJSON(size_t threadId, rapidjson::Document &d
|
|||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
Value out(kArrayType);
|
||||
out.PushBack(normalize(calc(threadId, ShortInterval)), allocator);
|
||||
out.PushBack(normalize(calc(threadId, MediumInterval)), allocator);
|
||||
out.PushBack(normalize(calc(threadId, LargeInterval)), allocator);
|
||||
out.PushBack(normalize(calc(threadId + 1, ShortInterval)), allocator);
|
||||
out.PushBack(normalize(calc(threadId + 1, MediumInterval)), allocator);
|
||||
out.PushBack(normalize(calc(threadId + 1, LargeInterval)), allocator);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue