Commit 565701f9 authored by Suraj Sharma's avatar Suraj Sharma Committed by Commit Bot

Treat Microsoft Hyper-V as having an invariant time stamp counter

This CL replicates the logic in chromium.src to support timestampcounter.
Based on:
https://chromium-review.googlesource.com/c/chromium/src/+/1413055

Change-Id: I3a64d53f64d3850831ac3ff983daa8ebef1cb29c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2789013Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Suraj Sharma <surshar@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#73751}
parent b6520eda
......@@ -443,6 +443,7 @@ CPU::CPU()
has_jscvt_(false),
is_fp64_mode_(false),
has_non_stop_time_stamp_counter_(false),
is_running_in_vm_(false),
has_msa_(false) {
base::Memcpy(vendor_, "Unknown", 8);
......@@ -497,6 +498,12 @@ CPU::CPU()
has_avx_ = (cpu_info[2] & 0x10000000) != 0;
has_avx2_ = (cpu_info7[1] & 0x00000020) != 0;
has_fma3_ = (cpu_info[2] & 0x00001000) != 0;
// "Hypervisor Present Bit: Bit 31 of ECX of CPUID leaf 0x1."
// See https://lwn.net/Articles/301888/
// This is checking for any hypervisor. Hypervisors may choose not to
// announce themselves. Hypervisors trap CPUID and sometimes return
// different results to underlying hardware.
is_running_in_vm_ = (cpu_info[2] & 0x80000000) != 0;
if (family_ == 0x6) {
switch (model_) {
......@@ -541,6 +548,23 @@ CPU::CPU()
has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0;
}
// This logic is replicated from cpu.cc present in chromium.src
if (!has_non_stop_time_stamp_counter_ && is_running_in_vm_) {
int cpu_info_hv[4] = {};
__cpuid(cpu_info_hv, 0x40000000);
if (cpu_info_hv[1] == 0x7263694D && // Micr
cpu_info_hv[2] == 0x666F736F && // osof
cpu_info_hv[3] == 0x76482074) { // t Hv
// If CPUID says we have a variant TSC and a hypervisor has identified
// itself and the hypervisor says it is Microsoft Hyper-V, then treat
// TSC as invariant.
//
// Microsoft Hyper-V hypervisor reports variant TSC as there are some
// scenarios (eg. VM live migration) where the TSC is variant, but for
// our purposes we can treat it as invariant.
has_non_stop_time_stamp_counter_ = true;
}
}
#elif V8_HOST_ARCH_ARM
#if V8_OS_LINUX
......
......@@ -103,6 +103,7 @@ class V8_BASE_EXPORT CPU final {
bool has_non_stop_time_stamp_counter() const {
return has_non_stop_time_stamp_counter_;
}
bool is_running_in_vm() const { return is_running_in_vm_; }
// arm features
bool has_idiva() const { return has_idiva_; }
......@@ -159,6 +160,7 @@ class V8_BASE_EXPORT CPU final {
bool has_jscvt_;
bool is_fp64_mode_;
bool has_non_stop_time_stamp_counter_;
bool is_running_in_vm_;
bool has_msa_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment