From 35d9c755e076f87203f114ceb2b581246986869d Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 26 Jul 2019 16:22:44 +0700 Subject: [PATCH] Special case for Intel CPUs with 1 MB L2 cache per core. --- src/backend/cpu/platform/HwlocCpuInfo.cpp | 45 ++++++++++++++++------- src/crypto/rx/Rx.cpp | 2 +- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/backend/cpu/platform/HwlocCpuInfo.cpp b/src/backend/cpu/platform/HwlocCpuInfo.cpp index 253d51085..4e48f65e2 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.cpp +++ b/src/backend/cpu/platform/HwlocCpuInfo.cpp @@ -189,28 +189,47 @@ xmrig::CpuThreads xmrig::HwlocCpuInfo::threads(const Algorithm &algorithm) const void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorithm &algorithm, CpuThreads &threads) const { + constexpr size_t oneMiB = 1024u * 1024u; + size_t PUs = countByType(cache, HWLOC_OBJ_PU); if (PUs == 0) { return; } - size_t size = cache->attr->cache.size; - const size_t scratchpad = algorithm.memory(); - - if (cache->attr->cache.depth == 3 && isCacheExclusive(cache)) { - for (size_t i = 0; i < cache->arity; ++i) { - hwloc_obj_t l2 = cache->children[i]; - if (isCacheObject(l2) && l2->attr != nullptr && l2->attr->cache.size >= scratchpad) { - size += scratchpad; - } - } - } - std::vector cores; cores.reserve(m_cores); findByType(cache, HWLOC_OBJ_CORE, [&cores](hwloc_obj_t found) { cores.emplace_back(found); }); - size_t cacheHashes = (size + (scratchpad / 2)) / scratchpad; + size_t L3 = cache->attr->cache.size; + size_t L2 = 0; + int L2_associativity = 0; + size_t extra = 0; + const size_t scratchpad = algorithm.memory(); + + if (cache->attr->cache.depth == 3 && isCacheExclusive(cache)) { + for (size_t i = 0; i < cache->arity; ++i) { + hwloc_obj_t l2 = cache->children[i]; + if (!isCacheObject(l2) || l2->attr == nullptr) { + continue; + } + + L2 += l2->attr->cache.size; + L2_associativity = l2->attr->cache.associativity; + + if (l2->attr->cache.size >= scratchpad) { + extra += scratchpad; + } + } + } + + if (scratchpad == 2 * oneMiB) { + if (L2 && (cores.size() * oneMiB) == L2 && L2_associativity == 16 && L3 >= L2) { + L3 = L2; + extra = L2; + } + } + + size_t cacheHashes = ((L3 + extra) + (scratchpad / 2)) / scratchpad; # ifdef XMRIG_ALGO_CN_GPU if (algorithm == Algorithm::CN_GPU) { diff --git a/src/crypto/rx/Rx.cpp b/src/crypto/rx/Rx.cpp index d6d49c656..fe4202e6b 100644 --- a/src/crypto/rx/Rx.cpp +++ b/src/crypto/rx/Rx.cpp @@ -147,7 +147,7 @@ void xmrig::Rx::initDataset(size_t index, const uint8_t *seed, const Algorithm & if (!d_ptr->datasets[index]) { const uint64_t ts = Chrono::steadyMSecs(); - LOG_INFO("%s" MAGENTA_BOLD(" allocate") CYAN_BOLD(" %zu MiB") BLACK_BOLD(" (%zu+%zu) for RandomX dataset & cache"), + LOG_INFO("%s" MAGENTA_BOLD(" allocate") CYAN_BOLD(" %zu MB") BLACK_BOLD(" (%zu+%zu) for RandomX dataset & cache"), tag, (RxDataset::size() + RxCache::size()) / 1024 / 1024, RxDataset::size() / 1024 / 1024,