From 232c0c3523c9321cdcb258c2114ae21c8436efdc Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Tue, 18 Jul 2017 23:24:48 +0100 Subject: [PATCH 1/2] Fix cacheHashes calc --- autoAdjustHwloc.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoAdjustHwloc.hpp b/autoAdjustHwloc.hpp index f6711fb3..92a668a5 100644 --- a/autoAdjustHwloc.hpp +++ b/autoAdjustHwloc.hpp @@ -156,7 +156,7 @@ class autoAdjust cores.reserve(16); findChildrenByType(obj, HWLOC_OBJ_CORE, [&cores](hwloc_obj_t found) { cores.emplace_back(found); } ); - size_t cacheHashes = (cacheSize + hashSize/2u - 1) / hashSize; + size_t cacheHashes = (cacheSize + hashSize/2) / hashSize; //Firstly allocate PU 0 of every CORE, then PU 1 etc. size_t pu_id = 0; From 06402d739a522dbaa7093cc5e912c4b8a8abeb29 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Tue, 18 Jul 2017 23:34:16 +0100 Subject: [PATCH 2/2] Fix atttempt at NUMA aff reset on Windows --- minethd.cpp | 28 +++++++++++++++------------- minethd.h | 7 ++++--- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/minethd.cpp b/minethd.cpp index fd83e82a..5c7871d2 100644 --- a/minethd.cpp +++ b/minethd.cpp @@ -150,7 +150,7 @@ void telemetry::push_perf_value(size_t iThd, uint64_t iHashCount, uint64_t iTime iBucketTop[iThd] = (iTop + 1) & iBucketMask; } -minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch, int affinity) +minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch, int64_t affinity) { oWork = pWork; bQuit = 0; @@ -307,15 +307,6 @@ std::vector* minethd::thread_starter(miner_work& pWork) jconf::inst()->GetThreadConfig(i, cfg); minethd* thd = new minethd(pWork, i, cfg.bDoubleMode, cfg.bNoPrefetch, cfg.iCpuAff); - - if(cfg.iCpuAff >= 0) - { -#if defined(__APPLE__) - printer::inst()->print_msg(L1, "WARNING on MacOS thread affinity is only advisory."); -#endif - thd_setaffinity(thd->oWorkThd.native_handle(), cfg.iCpuAff); - } - pvThreads->push_back(thd); if(cfg.iCpuAff >= 0) @@ -370,11 +361,22 @@ minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch) return func_table[digit.to_ulong()]; } -void minethd::work_main() +void minethd::pin_thd_affinity() { // pin memory to NUMA node bindMemoryToNUMANode(affinity); +#if defined(__APPLE__) + printer::inst()->print_msg(L1, "WARNING on MacOS thread affinity is only advisory."); +#endif + thd_setaffinity(oWorkThd.native_handle(), affinity); +} + +void minethd::work_main() +{ + if(affinity >= 0) //-1 means no affinity + pin_thd_affinity(); + cn_hash_fun hash_fun; cryptonight_ctx* ctx; uint64_t iCount = 0; @@ -462,8 +464,8 @@ minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefe void minethd::double_work_main() { - // pin memory to NUMA node - bindMemoryToNUMANode(affinity); + if(affinity >= 0) //-1 means no affinity + pin_thd_affinity(); cn_hash_fun_dbl hash_fun; cryptonight_ctx* ctx0; diff --git a/minethd.h b/minethd.h index 3543b85f..3c88c267 100644 --- a/minethd.h +++ b/minethd.h @@ -97,13 +97,11 @@ class minethd std::atomic iHashCount; std::atomic iTimestamp; - int affinity; - private: typedef void (*cn_hash_fun)(const void*, size_t, void*, cryptonight_ctx*); typedef void (*cn_hash_fun_dbl)(const void*, size_t, void*, cryptonight_ctx* __restrict, cryptonight_ctx* __restrict); - minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch, int affinity); + minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch, int64_t affinity); // We use the top 10 bits of the nonce for thread and resume // This allows us to resume up to 128 threads 4 times before @@ -131,8 +129,11 @@ class minethd static miner_work oGlobalWork; miner_work oWork; + void pin_thd_affinity(); + std::thread oWorkThd; uint8_t iThreadNo; + int64_t affinity; bool bQuit; bool bNoPrefetch;