From 41a9bddd5937a9035eb874752a85e433ee90420f Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 6 Dec 2020 17:34:01 +0100 Subject: [PATCH] Added virtual machine detection --- src/Summary.cpp | 5 +++-- src/backend/cpu/interfaces/ICpuInfo.h | 2 ++ src/backend/cpu/platform/BasicCpuInfo.cpp | 6 ++++-- src/backend/cpu/platform/BasicCpuInfo.h | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Summary.cpp b/src/Summary.cpp index 02738044..0d3f409f 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -88,12 +88,13 @@ static void print_cpu(Config *) { const auto info = Cpu::info(); - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%zu)") " %sx64 %sAES", + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%zu)") " %sx64 %sAES%s", "CPU", info->brand(), info->packages(), info->isX64() ? GREEN_BOLD_S : RED_BOLD_S "-", - info->hasAES() ? GREEN_BOLD_S : RED_BOLD_S "-" + info->hasAES() ? GREEN_BOLD_S : RED_BOLD_S "-", + info->isVM() ? RED_BOLD_S " VM" : "" ); # if defined(XMRIG_FEATURE_HWLOC) Log::print(WHITE_BOLD(" %-13s") BLACK_BOLD("L2:") WHITE_BOLD("%.1f MB") BLACK_BOLD(" L3:") WHITE_BOLD("%.1f MB") diff --git a/src/backend/cpu/interfaces/ICpuInfo.h b/src/backend/cpu/interfaces/ICpuInfo.h index 7464781a..3b83aecc 100644 --- a/src/backend/cpu/interfaces/ICpuInfo.h +++ b/src/backend/cpu/interfaces/ICpuInfo.h @@ -64,6 +64,7 @@ public: FLAG_XOP, FLAG_POPCNT, FLAG_CAT_L3, + FLAG_VM, FLAG_MAX }; @@ -83,6 +84,7 @@ public: virtual bool hasBMI2() const = 0; virtual bool hasOneGbPages() const = 0; virtual bool hasCatL3() const = 0; + virtual bool isVM() const = 0; virtual const char *backend() const = 0; virtual const char *brand() const = 0; virtual CpuThreads threads(const Algorithm &algorithm, uint32_t limit) const = 0; diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index 7cf09f8c..1f1521ba 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -52,8 +52,8 @@ namespace xmrig { -constexpr size_t kCpuFlagsSize = 12; -static const std::array flagNames = { "aes", "avx2", "avx512f", "bmi2", "osxsave", "pdpe1gb", "sse2", "ssse3", "sse4.1", "xop", "popcnt", "cat_l3" }; +constexpr size_t kCpuFlagsSize = 13; +static const std::array flagNames = { "aes", "avx2", "avx512f", "bmi2", "osxsave", "pdpe1gb", "sse2", "ssse3", "sse4.1", "xop", "popcnt", "cat_l3", "vm" }; static_assert(kCpuFlagsSize == ICpuInfo::FLAG_MAX, "kCpuFlagsSize and FLAG_MAX mismatch"); @@ -148,6 +148,7 @@ static inline bool has_sse41() { return has_feature(PROCESSOR_INFO, static inline bool has_xop() { return has_feature(0x80000001, ECX_Reg, 1 << 11); } static inline bool has_popcnt() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 23); } static inline bool has_cat_l3() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 15) && has_feature(0x10, EBX_Reg, 1 << 1); } +static inline bool is_vm() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 31); } } // namespace xmrig @@ -185,6 +186,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : m_flags.set(FLAG_XOP, has_xop()); m_flags.set(FLAG_POPCNT, has_popcnt()); m_flags.set(FLAG_CAT_L3, has_cat_l3()); + m_flags.set(FLAG_VM, is_vm()); # ifdef XMRIG_FEATURE_ASM if (hasAES()) { diff --git a/src/backend/cpu/platform/BasicCpuInfo.h b/src/backend/cpu/platform/BasicCpuInfo.h index 85d2582d..7956ef1c 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.h +++ b/src/backend/cpu/platform/BasicCpuInfo.h @@ -52,6 +52,7 @@ protected: inline bool hasBMI2() const override { return has(FLAG_BMI2); } inline bool hasOneGbPages() const override { return has(FLAG_PDPE1GB); } inline bool hasCatL3() const override { return has(FLAG_CAT_L3); } + inline bool isVM() const override { return has(FLAG_VM); } inline const char *brand() const override { return m_brand; } inline MsrMod msrMod() const override { return m_msrMod; } inline size_t cores() const override { return 0; }