From: Yang Weijiang <weijiang.yang@intel.com>
To: seanjc@google.com, pbonzini@redhat.com, kvm@vger.kernel.org
Cc: Yang Weijiang <weijiang.yang@intel.com>
Subject: [kvm-unit-tests PATCH 4/4] x86: Check platform pmu capabilities before run lbr tests
Date: Mon, 11 Jul 2022 00:18:41 -0400 [thread overview]
Message-ID: <20220711041841.126648-5-weijiang.yang@intel.com> (raw)
In-Reply-To: <20220711041841.126648-1-weijiang.yang@intel.com>
Use new helper to check whether pmu is available and Perfmon/Debug
capbilities are supported before read MSR_IA32_PERF_CAPABILITIES to
avoid test failure. The issue can be captured when enable_pmu=0.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
---
lib/x86/processor.h | 1 +
x86/pmu_lbr.c | 33 +++++++++++++--------------------
2 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index b772cf3..c192a25 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -146,6 +146,7 @@ static inline bool is_intel(void)
*/
#define X86_FEATURE_MWAIT (CPUID(0x1, 0, ECX, 3))
#define X86_FEATURE_VMX (CPUID(0x1, 0, ECX, 5))
+#define X86_FEATURE_PDCM (CPUID(0x1, 0, ECX, 15))
#define X86_FEATURE_PCID (CPUID(0x1, 0, ECX, 17))
#define X86_FEATURE_MOVBE (CPUID(0x1, 0, ECX, 22))
#define X86_FEATURE_TSC_DEADLINE_TIMER (CPUID(0x1, 0, ECX, 24))
diff --git a/x86/pmu_lbr.c b/x86/pmu_lbr.c
index 688634d..22c8c69 100644
--- a/x86/pmu_lbr.c
+++ b/x86/pmu_lbr.c
@@ -15,6 +15,7 @@
#define MSR_LBR_SELECT 0x000001c8
volatile int count;
+u32 lbr_from, lbr_to;
static noinline int compute_flag(int i)
{
@@ -38,18 +39,6 @@ static noinline int lbr_test(void)
return 0;
}
-union cpuid10_eax {
- struct {
- unsigned int version_id:8;
- unsigned int num_counters:8;
- unsigned int bit_width:8;
- unsigned int mask_length:8;
- } split;
- unsigned int full;
-} eax;
-
-u32 lbr_from, lbr_to;
-
static void init_lbr(void *index)
{
wrmsr(lbr_from + *(int *) index, 0);
@@ -63,7 +52,6 @@ static bool test_init_lbr_from_exception(u64 index)
int main(int ac, char **av)
{
- struct cpuid id = cpuid(10);
u64 perf_cap;
int max, i;
@@ -74,19 +62,24 @@ int main(int ac, char **av)
return 0;
}
- perf_cap = rdmsr(MSR_IA32_PERF_CAPABILITIES);
- eax.full = id.a;
+ if (!cpu_has_pmu()) {
+ report_skip("No pmu is detected!");
+ return report_summary();
+ }
- if (!eax.split.version_id) {
- printf("No pmu is detected!\n");
+ if (!this_cpu_has(X86_FEATURE_PDCM)) {
+ report_skip("Perfmon/Debug Capabilities MSR isn't supported.");
return report_summary();
}
+
+ perf_cap = rdmsr(MSR_IA32_PERF_CAPABILITIES);
+
if (!(perf_cap & PMU_CAP_LBR_FMT)) {
- printf("No LBR is detected!\n");
+ report_skip("(Architectural) LBR is not supported.");
return report_summary();
}
- printf("PMU version: %d\n", eax.split.version_id);
+ printf("PMU version: %d\n", pmu_version());
printf("LBR version: %ld\n", perf_cap & PMU_CAP_LBR_FMT);
/* Look for LBR from and to MSRs */
@@ -98,7 +91,7 @@ int main(int ac, char **av)
}
if (test_init_lbr_from_exception(0)) {
- printf("LBR on this platform is not supported!\n");
+ report_skip("LBR on this platform is not supported!");
return report_summary();
}
--
2.31.1
prev parent reply other threads:[~2022-07-11 7:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 4:18 [kvm-unit-tests PATCH 0/4] Fixup and cleanup to pmu test applications Yang Weijiang
2022-07-11 4:18 ` [kvm-unit-tests PATCH 1/4] x86: Use report_skip to print messages when tests are skipped Yang Weijiang
2022-07-11 4:18 ` [kvm-unit-tests PATCH 2/4] x86: Use helpers to fetch supported perf capabilities Yang Weijiang
2022-07-21 21:21 ` Sean Christopherson
2022-07-22 0:58 ` Yang, Weijiang
2022-07-11 4:18 ` [kvm-unit-tests PATCH 3/4] x86: Skip perf related tests when platform cannot support Yang Weijiang
2022-07-11 4:18 ` Yang Weijiang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220711041841.126648-5-weijiang.yang@intel.com \
--to=weijiang.yang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox