From d353d15be41c77483b908b450d5a81a3341cc3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Gr=C3=A4f?= Date: Wed, 28 Mar 2018 12:40:33 +0200 Subject: [PATCH] Added possibility to set variant by proxy (#79) Added fix for wrong cpu cache detection --- src/Cpu_cpuid.cpp | 8 +++++++- src/Options.cpp | 5 +++++ src/Options.h | 2 ++ src/net/Client.cpp | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Cpu_cpuid.cpp b/src/Cpu_cpuid.cpp index 96619e30..6251a97e 100644 --- a/src/Cpu_cpuid.cpp +++ b/src/Cpu_cpuid.cpp @@ -59,7 +59,13 @@ void CpuImpl::initCommon() m_l2_cache = data.l2_cache * (m_totalCores / 2) * m_sockets; m_l2_exclusive = true; } - else { + // Workaround for Intel Pentium Dual-Core, Core Duo, Core 2 Duo, Core 2 Quad and their Xeon homologue + // These processors have L2 cache shared by 2 cores. + else if (data.vendor == VENDOR_INTEL && data.ext_family == 0x06 && (data.ext_model == 0x0E || data.ext_model == 0x0F || data.ext_model == 0x17)) { + int l2_count_per_socket = m_totalCores > 1 ? m_totalCores / 2 : 1; + m_l2_cache = data.l2_cache > 0 ? data.l2_cache * l2_count_per_socket * m_sockets : 0; + } + else{ m_l2_cache = data.l2_cache > 0 ? data.l2_cache * m_totalCores * m_sockets : 0; } diff --git a/src/Options.cpp b/src/Options.cpp index 2ef55f7a..dd8c8f34 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -1005,4 +1005,9 @@ bool Options::parseCCUrl(const char* url) return true; } +void Options::setForcePowVersion(Options::PowVersion powVersion) +{ + m_forcePowVersion = powVersion; +} + diff --git a/src/Options.h b/src/Options.h index bd4c8140..2e0a8b12 100644 --- a/src/Options.h +++ b/src/Options.h @@ -112,6 +112,8 @@ public: const char *algoName() const; + void setForcePowVersion(PowVersion version); + private: constexpr static uint16_t kDefaultCCPort = 3344; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index c11dece0..e73b474f 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "interfaces/IClientListener.h" #include "log/Log.h" @@ -200,6 +201,26 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } + if (params.HasMember("variant")) { + int variantFromProxy = params["variant"].GetInt(); + + if (Options::i()->forcePowVersion() == Options::POW_AUTODETECT) { + switch (variantFromProxy) { + case -1: + Options::i()->setForcePowVersion(Options::POW_AUTODETECT); + break; + case 0: + Options::i()->setForcePowVersion(Options::POW_V1); + break; + case 1: + Options::i()->setForcePowVersion(Options::POW_V2); + break; + default: + break; + } + } + } + if (m_job == job) { if (!m_quiet) { LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());