From 9afdac17dcc8956fd795797bfc5b6e1c09285342 Mon Sep 17 00:00:00 2001 From: Gabriele Contini <contini.mailing@gmail.com> Date: 周日, 08 3月 2020 21:27:16 +0800 Subject: [PATCH] Issues #14 and #6 --- src/library/os/linux/cpu_info.cpp | 15 ++++----------- 1 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/library/os/linux/cpu_info.cpp b/src/library/os/linux/cpu_info.cpp index 4db4ba0..b052a03 100644 --- a/src/library/os/linux/cpu_info.cpp +++ b/src/library/os/linux/cpu_info.cpp @@ -11,11 +11,9 @@ #include "../cpu_info.hpp" namespace license { +namespace os { using namespace std; -const unordered_set<string> virtual_cpu_names = {"bhyve bhyve ", "KVMKVMKVM", "Microsoft Hv", - " lrpepyh vr", "prl hyperv ", "VMwareVMware", - "XenVMMXenVMM", "ACRNACRNACRN", "VBoxVBoxVBox"}; struct CPUVendorID { unsigned int ebx; unsigned int edx; @@ -31,20 +29,15 @@ * Detect Virtual machine using hypervisor bit. * @return true if the cpu hypervisor bit is set to 1 */ -bool CpuInfo::cpu_virtual() const { +bool CpuInfo::is_hypervisor_set() const { unsigned int level = 1, eax = 0, ebx = 0, ecx = 0, edx = 0; __get_cpuid(level, &eax, &ebx, &ecx, &edx); bool is_virtual = (((ecx >> 31) & 1) == 1); // hypervisor flag - if (!is_virtual) { - string cpu_vendor = vendor(); - auto it = virtual_cpu_names.find(cpu_vendor); - is_virtual = (it != virtual_cpu_names.end()); - } return is_virtual; } -uint32_t CpuInfo::model() { +uint32_t CpuInfo::model() const { unsigned int level = 1, eax = 0, ebx = 0, ecx = 0, edx = 0; __get_cpuid(level, &eax, &ebx, &ecx, &edx); // ax bits 0-3 stepping,4-7 model,8-11 family id,12-13 processor type @@ -60,5 +53,5 @@ CPUVendorID vendorID{.ebx = ebx, .edx = edx, .ecx = ecx}; return vendorID.toString(); } - +} // namespace os } /* namespace license */ -- Gitblit v1.9.1