On 7/8/2022 4:26 AM, Sean Christopherson wrote:
On Tue, Jun 28, 2022, Yang Weijiang wrote:
Add helpers to check whether MSR_CORE_PERF_GLOBAL_CTRL and rdpmc
are supported in KVM. When pmu is disabled with enable_pmu=0,
reading MSR_CORE_PERF_GLOBAL_CTRL or executing rdpmc leads to #GP,
so skip related tests in this case to avoid test failure.
Opportunistically replace some "printf" with "report_skip" to make
the output log clean.
Ooof, these end up dominating the patch. Can you split them to a separate prep
patch? Thanks!
Welcome back!
Will do it, thanks!
Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Signed-off-by: Yang Weijiang <weijiang.yang@xxxxxxxxx>
v4:
- Use supported_fn() to make the code nicer. [Sean]
- Replace some of the printf with report_skip to make the results clean. [Sean]
Put the versioning info below the three dashes so that it doesn't show up in the
final changelog.
---
<version info goes here>
OK.
lib/x86/processor.h | 10 ++++++++++
x86/vmx_tests.c | 40 +++++++++++++++++++++++++++-------------
2 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index 9a0dad6..7b6ee92 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -690,4 +690,14 @@ static inline bool cpuid_osxsave(void)
return cpuid(1).c & (1 << (X86_FEATURE_OSXSAVE % 32));
}
+static inline u8 pmu_version(void)
+{
+ return cpuid(10).a & 0xff;
+}
+
+static inline bool cpu_has_perf_global_ctrl(void)
+{
+ return pmu_version() > 1;
+}
+
#endif
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 4d581e7..3a14cb2 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -852,6 +852,10 @@ static bool monitor_supported(void)
return this_cpu_has(X86_FEATURE_MWAIT);
}
+static inline bool pmu_supported(void) {
Curly brace goes on a new line.
Sorry for the typo.
+ return !!pmu_version();
+}
Why not put this in processor.h? And maybe call it cpu_has_pmu()?
Good suggestion, then it can serve other apps. Thank you!