Merge pull request #79 from VerusCoin/dev

Fix synchronization bottleneck for high core machines
This commit is contained in:
Asher Dawes
2018-06-27 13:18:24 -07:00
committed by GitHub
3 changed files with 33 additions and 10 deletions

View File

@@ -25,6 +25,7 @@
#include <unistd.h> #include <unistd.h>
extern int64_t ASSETCHAINS_TIMELOCKGTE; extern int64_t ASSETCHAINS_TIMELOCKGTE;
extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH;
int64_t komodo_block_unlocktime(uint32_t nHeight); int64_t komodo_block_unlocktime(uint32_t nHeight);
void AtomicTimer::start() void AtomicTimer::start()
@@ -74,8 +75,21 @@ double AtomicTimer::rate(const AtomicCounter& count)
CCriticalSection cs_metrics; 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> nNodeStartTime;
boost::synchronized_value<int64_t> nNextRefresh; boost::synchronized_value<int64_t> nNextRefresh;
int64_t nHashCount;
AtomicCounter transactionsValidated; AtomicCounter transactionsValidated;
AtomicCounter ehSolverRuns; AtomicCounter ehSolverRuns;
AtomicCounter solutionTargetChecks; AtomicCounter solutionTargetChecks;
@@ -109,7 +123,12 @@ int64_t GetUptime()
double GetLocalSolPS() 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, int EstimateNetHeightInner(int height, int64_t tipmediantime,

View File

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

View File

@@ -107,6 +107,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
#include "komodo_defs.h" #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 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_COMMISSION, ASSETCHAINS_STAKED;
extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[];
@@ -1154,18 +1155,12 @@ void static BitcoinMiner_noeq()
CVerusHash &vh = ss.GetState(); CVerusHash &vh = ss.GetState();
uint256 hashResult = uint256(); uint256 hashResult = uint256();
vh.ClearExtra(); 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]; int64_t hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO];
// for speed check 4 giga hash at a time // for speed check NONCEMASK at a time
for (int64_t i = 0; i < count; i++) 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; *extraPtr = i;
vh.ExtraHash((unsigned char *)&hashResult); 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 // Check for stop or if block needs to be rebuilt
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();