mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 12:09:22 +00:00
Optimized hashrate calculation
This commit is contained in:
parent
c235145121
commit
426bc8f0c4
3 changed files with 19 additions and 34 deletions
|
@ -47,7 +47,6 @@ inline static const char *format(double h, char *buf, size_t size)
|
||||||
|
|
||||||
|
|
||||||
xmrig::Hashrate::Hashrate(size_t threads) :
|
xmrig::Hashrate::Hashrate(size_t threads) :
|
||||||
m_highest(0.0),
|
|
||||||
m_threads(threads)
|
m_threads(threads)
|
||||||
{
|
{
|
||||||
m_counts = new uint64_t*[threads];
|
m_counts = new uint64_t*[threads];
|
||||||
|
@ -100,30 +99,30 @@ double xmrig::Hashrate::calc(size_t threadId, size_t ms) const
|
||||||
|
|
||||||
uint64_t earliestHashCount = 0;
|
uint64_t earliestHashCount = 0;
|
||||||
uint64_t earliestStamp = 0;
|
uint64_t earliestStamp = 0;
|
||||||
uint64_t lastestStamp = 0;
|
|
||||||
uint64_t lastestHashCnt = 0;
|
|
||||||
bool haveFullSet = false;
|
bool haveFullSet = false;
|
||||||
|
|
||||||
for (size_t i = 1; i < kBucketSize; i++) {
|
const uint64_t timeStampLimit = xmrig::Chrono::highResolutionMSecs() - ms;
|
||||||
const size_t idx = (m_top[threadId] - i) & kBucketMask;
|
uint64_t* timestamps = m_timestamps[threadId];
|
||||||
|
uint64_t* counts = m_counts[threadId];
|
||||||
|
|
||||||
if (m_timestamps[threadId][idx] == 0) {
|
const size_t idx_start = (m_top[threadId] - 1) & kBucketMask;
|
||||||
|
size_t idx = idx_start;
|
||||||
|
|
||||||
|
uint64_t lastestStamp = timestamps[idx];
|
||||||
|
uint64_t lastestHashCnt = counts[idx];
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (timestamps[idx] < timeStampLimit) {
|
||||||
|
haveFullSet = (timestamps[idx] != 0);
|
||||||
|
if (idx != idx_start) {
|
||||||
|
idx = (idx + 1) & kBucketMask;
|
||||||
|
earliestStamp = timestamps[idx];
|
||||||
|
earliestHashCount = counts[idx];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
idx = (idx - 1) & kBucketMask;
|
||||||
if (lastestStamp == 0) {
|
} while (idx != idx_start);
|
||||||
lastestStamp = m_timestamps[threadId][idx];
|
|
||||||
lastestHashCnt = m_counts[threadId][idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xmrig::Chrono::highResolutionMSecs() - m_timestamps[threadId][idx] > ms) {
|
|
||||||
haveFullSet = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
earliestStamp = m_timestamps[threadId][idx];
|
|
||||||
earliestHashCount = m_counts[threadId][idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!haveFullSet || earliestStamp == 0 || lastestStamp == 0) {
|
if (!haveFullSet || earliestStamp == 0 || lastestStamp == 0) {
|
||||||
return nan("");
|
return nan("");
|
||||||
|
@ -150,15 +149,6 @@ void xmrig::Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Hashrate::updateHighest()
|
|
||||||
{
|
|
||||||
double highest = calc(ShortInterval);
|
|
||||||
if (std::isnormal(highest) && highest > m_highest) {
|
|
||||||
m_highest = highest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char *xmrig::Hashrate::format(double h, char *buf, size_t size)
|
const char *xmrig::Hashrate::format(double h, char *buf, size_t size)
|
||||||
{
|
{
|
||||||
return ::format(h, buf, size);
|
return ::format(h, buf, size);
|
||||||
|
|
|
@ -53,9 +53,7 @@ public:
|
||||||
double calc(size_t ms) const;
|
double calc(size_t ms) const;
|
||||||
double calc(size_t threadId, size_t ms) const;
|
double calc(size_t threadId, size_t ms) const;
|
||||||
void add(size_t threadId, uint64_t count, uint64_t timestamp);
|
void add(size_t threadId, uint64_t count, uint64_t timestamp);
|
||||||
void updateHighest();
|
|
||||||
|
|
||||||
inline double highest() const { return m_highest; }
|
|
||||||
inline size_t threads() const { return m_threads; }
|
inline size_t threads() const { return m_threads; }
|
||||||
|
|
||||||
static const char *format(double h, char *buf, size_t size);
|
static const char *format(double h, char *buf, size_t size);
|
||||||
|
@ -70,7 +68,6 @@ private:
|
||||||
constexpr static size_t kBucketSize = 2 << 11;
|
constexpr static size_t kBucketSize = 2 << 11;
|
||||||
constexpr static size_t kBucketMask = kBucketSize - 1;
|
constexpr static size_t kBucketMask = kBucketSize - 1;
|
||||||
|
|
||||||
double m_highest;
|
|
||||||
size_t m_threads;
|
size_t m_threads;
|
||||||
uint32_t* m_top;
|
uint32_t* m_top;
|
||||||
uint64_t** m_counts;
|
uint64_t** m_counts;
|
||||||
|
|
|
@ -144,8 +144,6 @@ void xmrig::Workers<T>::tick(uint64_t)
|
||||||
|
|
||||||
d_ptr->hashrate->add(handle->id(), handle->worker()->hashCount(), handle->worker()->timestamp());
|
d_ptr->hashrate->add(handle->id(), handle->worker()->hashCount(), handle->worker()->timestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
d_ptr->hashrate->updateHighest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue