diff options
author | fireice-uk <fireice-uk@users.noreply.github.com> | 2017-10-23 19:14:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 19:14:20 +0100 |
commit | 7030f1b3ab2ff9670c5251919d00387095cf71f2 (patch) | |
tree | 40c19dd7735f372aa194f1399aed4a30d81a1c24 /xmrstak/backend/cpu/minethd.cpp | |
parent | a7116b999efae0b303cd2474bbea3c918a4fe8b3 (diff) | |
parent | 14ceeaca2ea501d1c4ad9ba90655cc3204cd27c3 (diff) | |
download | xmr-stak-7030f1b3ab2ff9670c5251919d00387095cf71f2.zip xmr-stak-7030f1b3ab2ff9670c5251919d00387095cf71f2.tar.gz |
Merge pull request #45 from fireice-uk/topic-nonce-alloc
Implement pool-controlled nonce allocation
Diffstat (limited to 'xmrstak/backend/cpu/minethd.cpp')
-rw-r--r-- | xmrstak/backend/cpu/minethd.cpp | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/xmrstak/backend/cpu/minethd.cpp b/xmrstak/backend/cpu/minethd.cpp index 625fbe4..ac80cc2 100644 --- a/xmrstak/backend/cpu/minethd.cpp +++ b/xmrstak/backend/cpu/minethd.cpp @@ -335,31 +335,36 @@ void minethd::work_main() either because of network latency, or a socket problem. Since we are raison d'etre of this software it us sensible to just wait until we have something*/ - while (globalStates::inst().inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) + while (globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) std::this_thread::sleep_for(std::chrono::milliseconds(100)); consume_work(); continue; } - if(oWork.bNiceHash) - result.iNonce = calc_nicehash_nonce(*piNonce, oWork.iResumeCnt); - else - result.iNonce = calc_start_nonce(oWork.iResumeCnt); + size_t nonce_ctr = 0; + constexpr size_t nonce_chunk = 4096; // Needs to be a power of 2 assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID)); memcpy(result.sJobID, oWork.sJobID, sizeof(job_result::sJobID)); - while(globalStates::inst().inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) + if(oWork.bNiceHash) + result.iNonce = *piNonce; + + while(globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) { - if ((iCount & 0xF) == 0) //Store stats every 16 hashes + if ((iCount++ & 0xF) == 0) //Store stats every 16 hashes { using namespace std::chrono; uint64_t iStamp = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count(); iHashCount.store(iCount, std::memory_order_relaxed); iTimestamp.store(iStamp, std::memory_order_relaxed); } - iCount++; + + if((nonce_ctr++ & (nonce_chunk-1)) == 0) + { + globalStates::inst().calc_start_nonce(result.iNonce, oWork.bNiceHash, nonce_chunk); + } *piNonce = ++result.iNonce; @@ -446,7 +451,7 @@ void minethd::double_work_main() either because of network latency, or a socket problem. Since we are raison d'etre of this software it us sensible to just wait until we have something*/ - while (globalStates::inst().inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) + while (globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) std::this_thread::sleep_for(std::chrono::milliseconds(100)); consume_work(); @@ -456,14 +461,15 @@ void minethd::double_work_main() continue; } - if(oWork.bNiceHash) - iNonce = calc_nicehash_nonce(*piNonce0, oWork.iResumeCnt); - else - iNonce = calc_start_nonce(oWork.iResumeCnt); + size_t nonce_ctr = 0; + constexpr size_t nonce_chunk = 4096; //Needs to be a power of 2 assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID)); - while (globalStates::inst().inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) + if(oWork.bNiceHash) + iNonce = *piNonce0; + + while (globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo) { if ((iCount & 0x7) == 0) //Store stats every 16 hashes { @@ -472,8 +478,14 @@ void minethd::double_work_main() iHashCount.store(iCount, std::memory_order_relaxed); iTimestamp.store(iStamp, std::memory_order_relaxed); } - iCount += 2; + + + if((nonce_ctr++ & (nonce_chunk/2 - 1)) == 0) + { + globalStates::inst().calc_start_nonce(iNonce, oWork.bNiceHash, nonce_chunk); + } + *piNonce0 = ++iNonce; *piNonce1 = ++iNonce; |