Browse Source

Fix synchronization bottleneck for high core machines

pull/4/head
Michael Toutonghi 6 years ago
parent
commit
6976734769
  1. 21
      src/metrics.cpp
  2. 4
      src/metrics.h
  3. 18
      src/miner.cpp

21
src/metrics.cpp

@ -25,6 +25,7 @@
#include <unistd.h>
extern int64_t ASSETCHAINS_TIMELOCKGTE;
extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH;
int64_t komodo_block_unlocktime(uint32_t nHeight);
void AtomicTimer::start()
@ -74,8 +75,21 @@ double AtomicTimer::rate(const AtomicCounter& count)
CCriticalSection cs_metrics;
double AtomicTimer::rate(const int64_t count)
{
std::unique_lock<std::mutex> lock(mtx);
LOCK(cs_metrics);
int64_t duration = total_time;
if (threads > 0) {
// Timer is running, so get the latest count
duration += GetTime() - start_time;
}
return duration > 0 ? (double)count / duration : 0;
}
boost::synchronized_value<int64_t> nNodeStartTime;
boost::synchronized_value<int64_t> nNextRefresh;
int64_t nHashCount;
AtomicCounter transactionsValidated;
AtomicCounter ehSolverRuns;
AtomicCounter solutionTargetChecks;
@ -109,7 +123,12 @@ int64_t GetUptime()
double GetLocalSolPS()
{
return miningTimer.rate(solutionTargetChecks);
if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH)
{
return miningTimer.rate(nHashCount);
}
else
return miningTimer.rate(solutionTargetChecks);
}
int EstimateNetHeightInner(int height, int64_t tipmediantime,

4
src/metrics.h

@ -8,6 +8,8 @@
#include <mutex>
#include <string>
extern int64_t nHashCount;
struct AtomicCounter {
std::atomic<uint64_t> value;
@ -52,6 +54,8 @@ public:
uint64_t threadCount();
double rate(const AtomicCounter& count);
double rate(const int64_t count);
};
extern AtomicCounter transactionsValidated;

18
src/miner.cpp

@ -107,6 +107,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
#include "komodo_defs.h"
extern CCriticalSection cs_metrics;
extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE;
extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED;
extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[];
@ -1154,18 +1155,12 @@ void static BitcoinMiner_noeq()
CVerusHash &vh = ss.GetState();
uint256 hashResult = uint256();
vh.ClearExtra();
int64_t count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1;
int64_t i, count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1;
int64_t hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO];
// for speed check 4 giga hash at a time
for (int64_t i = 0; i < count; i++)
// for speed check NONCEMASK at a time
for (i = 0; i < count; i++)
{
solutionTargetChecks.increment();
// Update nNonce
//ss.buf.charBuf[108] = *((unsigned char *)&(pblock->nNonce)) = i & 0xff;
//ss.buf.charBuf[109] = *(((unsigned char *)&(pblock->nNonce))+1) = (i >> 8) & 0xff;
//ss.buf.charBuf[110] = *(((unsigned char *)&(pblock->nNonce))+2) = (i >> 16) & 0xff;
*extraPtr = i;
vh.ExtraHash((unsigned char *)&hashResult);
@ -1218,6 +1213,11 @@ void static BitcoinMiner_noeq()
}
}
{
LOCK(cs_metrics);
nHashCount += i;
}
// Check for stop or if block needs to be rebuilt
boost::this_thread::interruption_point();

Loading…
Cancel
Save