summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknown <fireice-uk@users.noreply.github.com>2017-12-07 19:08:09 +0000
committerUnknown <fireice-uk@users.noreply.github.com>2017-12-07 19:08:09 +0000
commitfe6d5b7ecc7f01ee2dc0664772b789c754c18762 (patch)
treea21f855aced10c1a7995f73d050065af2c5516cd
parentaa6a6040e34c0c081a7359cee890e23bf7ff383e (diff)
downloadxmr-stak-fe6d5b7ecc7f01ee2dc0664772b789c754c18762.zip
xmr-stak-fe6d5b7ecc7f01ee2dc0664772b789c754c18762.tar.gz
Fix nonce allocation
-rw-r--r--xmrstak/backend/cpu/minethd.cpp38
-rw-r--r--xmrstak/backend/cpu/minethd.hpp7
2 files changed, 28 insertions, 17 deletions
diff --git a/xmrstak/backend/cpu/minethd.cpp b/xmrstak/backend/cpu/minethd.cpp
index b10f0ca..1c0e491 100644
--- a/xmrstak/backend/cpu/minethd.cpp
+++ b/xmrstak/backend/cpu/minethd.cpp
@@ -169,7 +169,7 @@ cryptonight_ctx* minethd::minethd_alloc_ctx()
return nullptr; //Should never happen
}
-static const size_t MAX_N = 5;
+static constexpr size_t MAX_N = 5;
bool minethd::self_test()
{
alloc_msg msg = { 0 };
@@ -525,25 +525,26 @@ minethd::cn_hash_fun_multi minethd::func_multi_selector(size_t N, bool bHaveAes,
void minethd::double_work_main()
{
- multiway_work_main(2, func_multi_selector(2, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->IsCurrencyMonero()));
+ multiway_work_main<2>(func_multi_selector(2, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->IsCurrencyMonero()));
}
void minethd::triple_work_main()
{
- multiway_work_main(3, func_multi_selector(3, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->IsCurrencyMonero()));
+ multiway_work_main<3>(func_multi_selector(3, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->IsCurrencyMonero()));
}
void minethd::quad_work_main()
{
- multiway_work_main(4, func_multi_selector(4, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->IsCurrencyMonero()));
+ multiway_work_main<4>(func_multi_selector(4, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->IsCurrencyMonero()));
}
void minethd::penta_work_main()
{
- multiway_work_main(5, func_multi_selector(5, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->IsCurrencyMonero()));
+ multiway_work_main<5>(func_multi_selector(5, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->IsCurrencyMonero()));
}
-void minethd::prep_multiway_work(size_t N, uint8_t *bWorkBlob, uint32_t **piNonce)
+template<size_t N>
+void minethd::prep_multiway_work(uint8_t *bWorkBlob, uint32_t **piNonce)
{
for (size_t i = 0; i < N; i++)
{
@@ -553,7 +554,8 @@ void minethd::prep_multiway_work(size_t N, uint8_t *bWorkBlob, uint32_t **piNonc
}
}
-void minethd::multiway_work_main(size_t N, cn_hash_fun_multi hash_fun_multi)
+template<size_t N>
+void minethd::multiway_work_main(cn_hash_fun_multi hash_fun_multi)
{
if(affinity >= 0) //-1 means no affinity
bindMemoryToNUMANode(affinity);
@@ -580,9 +582,9 @@ void minethd::multiway_work_main(size_t N, cn_hash_fun_multi hash_fun_multi)
}
if(!oWork.bStall)
- prep_multiway_work(N, bWorkBlob, piNonce);
+ prep_multiway_work<N>(bWorkBlob, piNonce);
- globalStates::inst().inst().iConsumeCnt++;
+ globalStates::inst().iConsumeCnt++;
while (bQuit == 0)
{
@@ -596,12 +598,12 @@ void minethd::multiway_work_main(size_t N, cn_hash_fun_multi hash_fun_multi)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
consume_work();
- prep_multiway_work(N, bWorkBlob, piNonce);
+ prep_multiway_work<N>(bWorkBlob, piNonce);
continue;
}
- size_t nonce_ctr = 0;
- constexpr size_t nonce_chunk = 4096; //Needs to be a power of 2
+ constexpr uint32_t nonce_chunk = 4096;
+ int64_t nonce_ctr = 0;
assert(sizeof(job_result::sJobID) == sizeof(pool_job::sJobID));
@@ -618,9 +620,11 @@ void minethd::multiway_work_main(size_t N, cn_hash_fun_multi hash_fun_multi)
iTimestamp.store(iStamp, std::memory_order_relaxed);
}
- if((nonce_ctr++ & (nonce_chunk/2 - 1)) == 0)
+ nonce_ctr -= N;
+ if(nonce_ctr <= 0)
{
- globalStates::inst().calc_start_nonce(iNonce, oWork.bNiceHash, (nonce_chunk/2) * N);
+ globalStates::inst().calc_start_nonce(iNonce, oWork.bNiceHash, nonce_chunk);
+ nonce_ctr = nonce_chunk;
}
for (size_t i = 0; i < N; i++)
@@ -629,14 +633,18 @@ void minethd::multiway_work_main(size_t N, cn_hash_fun_multi hash_fun_multi)
hash_fun_multi(bWorkBlob, oWork.iWorkSize, bHashOut, ctx);
for (size_t i = 0; i < N; i++)
+ {
if (*piHashVal[i] < oWork.iTarget)
+ {
executor::inst()->push_event(ex_event(job_result(oWork.sJobID, iNonce - N + 1 + i, bHashOut + 32 * i, iThreadNo), oWork.iPoolId));
+ }
+ }
std::this_thread::yield();
}
consume_work();
- prep_multiway_work(N, bWorkBlob, piNonce);
+ prep_multiway_work<N>(bWorkBlob, piNonce);
}
for (int i = 0; i < N; i++)
diff --git a/xmrstak/backend/cpu/minethd.hpp b/xmrstak/backend/cpu/minethd.hpp
index b8819d3..0433d0d 100644
--- a/xmrstak/backend/cpu/minethd.hpp
+++ b/xmrstak/backend/cpu/minethd.hpp
@@ -34,7 +34,11 @@ private:
minethd(miner_work& pWork, size_t iNo, int iMultiway, bool no_prefetch, int64_t affinity);
- void multiway_work_main(size_t N, cn_hash_fun_multi hash_fun_multi);
+ template<size_t N>
+ void multiway_work_main(cn_hash_fun_multi hash_fun_multi);
+
+ template<size_t N>
+ void prep_multiway_work(uint8_t *bWorkBlob, uint32_t **piNonce);
void work_main();
void double_work_main();
@@ -43,7 +47,6 @@ private:
void penta_work_main();
void consume_work();
- void prep_multiway_work(size_t N, uint8_t *bWorkBlob, uint32_t **piNonce);
uint64_t iJobNo;
OpenPOWER on IntegriCloud