summaryrefslogtreecommitdiffstats
path: root/xmrstak/backend/cpu
diff options
context:
space:
mode:
authorpsychocrypt <psychocryptHPC@gmail.com>2018-04-01 21:37:44 +0200
committerTimothy Pearson <tpearson@raptorengineering.com>2018-06-04 21:07:11 +0000
commit04d515a98a21d25e5a7c3fba13d0cd7207b99b9b (patch)
tree293b44674f90649f367397347713c92048ad52dc /xmrstak/backend/cpu
parentf3f300d19c37cb6e45795cb6f24a80b8e3a4beeb (diff)
downloadxmr-stak-04d515a98a21d25e5a7c3fba13d0cd7207b99b9b.zip
xmr-stak-04d515a98a21d25e5a7c3fba13d0cd7207b99b9b.tar.gz
refactor mining algo selection
- add `fork_height` to currency - refactor algorithm selection
Diffstat (limited to 'xmrstak/backend/cpu')
-rw-r--r--xmrstak/backend/cpu/minethd.cpp60
-rw-r--r--xmrstak/backend/cpu/minethd.hpp2
2 files changed, 36 insertions, 26 deletions
diff --git a/xmrstak/backend/cpu/minethd.cpp b/xmrstak/backend/cpu/minethd.cpp
index b25d91e..dd303b5 100644
--- a/xmrstak/backend/cpu/minethd.cpp
+++ b/xmrstak/backend/cpu/minethd.cpp
@@ -413,14 +413,15 @@ void minethd::work_main()
lck.release();
std::this_thread::yield();
- cn_hash_fun hash_fun;
cryptonight_ctx* ctx;
uint64_t iCount = 0;
uint64_t* piHashVal;
uint32_t* piNonce;
job_result result;
- hash_fun = func_selector(::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->GetMiningAlgo());
+ // start with root algorithm and switch later if fork version is reached
+ auto miner_algo = ::jconf::inst()->GetMiningAlgoRoot();
+ cn_hash_fun hash_fun = func_selector(::jconf::inst()->HaveHardwareAes(), bNoPrefetch, miner_algo);
ctx = minethd_alloc_ctx();
piHashVal = (uint64_t*)(result.bResult + 24);
@@ -428,6 +429,8 @@ void minethd::work_main()
globalStates::inst().inst().iConsumeCnt++;
result.iThreadId = iThreadNo;
+ uint8_t version = 0;
+
while (bQuit == 0)
{
if (oWork.bStall)
@@ -453,15 +456,16 @@ void minethd::work_main()
if(oWork.bNiceHash)
result.iNonce = *piNonce;
- auto miner_algo = ::jconf::inst()->GetMiningAlgo();
- const bool time_to_fork =
- ((miner_algo == cryptonight_monero || miner_algo == cryptonight_aeon) && oWork.bWorkBlob[0] >= 7) ||
- (miner_algo == cryptonight_heavy && oWork.bWorkBlob[0] >= 3);
-
- if(time_to_fork)
- hash_fun = func_selector(::jconf::inst()->HaveHardwareAes(), bNoPrefetch, miner_algo);
- else
- hash_fun = func_selector(::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->GetMiningAlgoRoot());
+ uint8_t new_version = oWork.getVersion();
+ if(new_version != version)
+ {
+ if(new_version >= ::jconf::inst()->GetMiningForkHeight())
+ {
+ miner_algo = ::jconf::inst()->GetMiningAlgo();
+ hash_fun = func_selector(::jconf::inst()->HaveHardwareAes(), bNoPrefetch, miner_algo);
+ }
+ version = new_version;
+ }
while(globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo)
{
@@ -619,22 +623,22 @@ 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()->GetMiningAlgo()));
+ multiway_work_main<2>();
}
void minethd::triple_work_main()
{
- multiway_work_main<3>(func_multi_selector(3, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->GetMiningAlgo()));
+ multiway_work_main<3>();
}
void minethd::quad_work_main()
{
- multiway_work_main<4>(func_multi_selector(4, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->GetMiningAlgo()));
+ multiway_work_main<4>();
}
void minethd::penta_work_main()
{
- multiway_work_main<5>(func_multi_selector(5, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->GetMiningAlgo()));
+ multiway_work_main<5>();
}
template<size_t N>
@@ -649,7 +653,7 @@ void minethd::prep_multiway_work(uint8_t *bWorkBlob, uint32_t **piNonce)
}
template<size_t N>
-void minethd::multiway_work_main(cn_hash_fun_multi hash_fun_multi)
+void minethd::multiway_work_main()
{
if(affinity >= 0) //-1 means no affinity
bindMemoryToNUMANode(affinity);
@@ -680,6 +684,11 @@ void minethd::multiway_work_main(cn_hash_fun_multi hash_fun_multi)
globalStates::inst().iConsumeCnt++;
+ // start with root algorithm and switch later if fork version is reached
+ auto miner_algo = ::jconf::inst()->GetMiningAlgoRoot();
+ cn_hash_fun_multi hash_fun_multi = func_multi_selector(N, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, miner_algo);
+ uint8_t version = 0;
+
while (bQuit == 0)
{
if (oWork.bStall)
@@ -704,15 +713,16 @@ void minethd::multiway_work_main(cn_hash_fun_multi hash_fun_multi)
if(oWork.bNiceHash)
iNonce = *piNonce[0];
- auto miner_algo = ::jconf::inst()->GetMiningAlgo();
- const bool time_to_fork =
- ((miner_algo == cryptonight_monero || miner_algo == cryptonight_aeon) && oWork.bWorkBlob[0] >= 7) ||
- (miner_algo == cryptonight_heavy && oWork.bWorkBlob[0] >= 3);
-
- if(time_to_fork)
- hash_fun_multi = func_multi_selector(N, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, miner_algo);
- else
- hash_fun_multi = func_multi_selector(N, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, ::jconf::inst()->GetMiningAlgoRoot());
+ uint8_t new_version = oWork.getVersion();
+ if(new_version != version)
+ {
+ if(new_version >= ::jconf::inst()->GetMiningForkHeight())
+ {
+ miner_algo = ::jconf::inst()->GetMiningAlgo();
+ hash_fun_multi = func_multi_selector(N, ::jconf::inst()->HaveHardwareAes(), bNoPrefetch, miner_algo);
+ }
+ version = new_version;
+ }
while (globalStates::inst().iGlobalJobNo.load(std::memory_order_relaxed) == iJobNo)
{
diff --git a/xmrstak/backend/cpu/minethd.hpp b/xmrstak/backend/cpu/minethd.hpp
index ef1bbd2..cd78343 100644
--- a/xmrstak/backend/cpu/minethd.hpp
+++ b/xmrstak/backend/cpu/minethd.hpp
@@ -36,7 +36,7 @@ private:
minethd(miner_work& pWork, size_t iNo, int iMultiway, bool no_prefetch, int64_t affinity);
template<size_t N>
- void multiway_work_main(cn_hash_fun_multi hash_fun_multi);
+ void multiway_work_main();
template<size_t N>
void prep_multiway_work(uint8_t *bWorkBlob, uint32_t **piNonce);
OpenPOWER on IntegriCloud