From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Liam Merwick <liam.merwick@oracle.com>
Subject: Re: [kvm-unit-tests PATCH v2 06/14] x86/pmu: Mark all arch events as available on AMD, and rename fields
Date: Wed, 11 Jun 2025 09:32:34 +0800 [thread overview]
Message-ID: <a6465f46-4ab8-418e-b10d-d85e288562a7@linux.intel.com> (raw)
In-Reply-To: <20250610195415.115404-7-seanjc@google.com>
On 6/11/2025 3:54 AM, Sean Christopherson wrote:
> Mark all arch events as available on AMD, as AMD PMUs don't provide the
> "not available" CPUID field, and the number of GP counters has nothing to
> do with which architectural events are available/supported.
>
> Rename gp_counter_mask_length to arch_event_mask_length, and
> pmu_gp_counter_is_available() to pmu_arch_event_is_available(), to
> reflect what the field and helper actually track.
>
> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
> Fixes: b883751a ("x86/pmu: Update testcases to cover AMD PMU")
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> lib/x86/pmu.c | 10 +++++-----
> lib/x86/pmu.h | 8 ++++----
> x86/pmu.c | 8 ++++----
> 3 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/lib/x86/pmu.c b/lib/x86/pmu.c
> index d06e9455..d37c874c 100644
> --- a/lib/x86/pmu.c
> +++ b/lib/x86/pmu.c
> @@ -18,10 +18,10 @@ void pmu_init(void)
>
> pmu.nr_gp_counters = (cpuid_10.a >> 8) & 0xff;
> pmu.gp_counter_width = (cpuid_10.a >> 16) & 0xff;
> - pmu.gp_counter_mask_length = (cpuid_10.a >> 24) & 0xff;
> + pmu.arch_event_mask_length = (cpuid_10.a >> 24) & 0xff;
>
> - /* CPUID.0xA.EBX bit is '1' if a counter is NOT available. */
> - pmu.gp_counter_available = ~cpuid_10.b;
> + /* CPUID.0xA.EBX bit is '1' if an arch event is NOT available. */
> + pmu.arch_event_available = ~cpuid_10.b;
>
> if (this_cpu_has(X86_FEATURE_PDCM))
> pmu.perf_cap = rdmsr(MSR_IA32_PERF_CAPABILITIES);
> @@ -50,8 +50,8 @@ void pmu_init(void)
> pmu.msr_gp_event_select_base = MSR_K7_EVNTSEL0;
> }
> pmu.gp_counter_width = PMC_DEFAULT_WIDTH;
> - pmu.gp_counter_mask_length = pmu.nr_gp_counters;
> - pmu.gp_counter_available = (1u << pmu.nr_gp_counters) - 1;
> + pmu.arch_event_mask_length = 32;
> + pmu.arch_event_available = -1u;
>
> if (this_cpu_has_perf_global_status()) {
> pmu.msr_global_status = MSR_AMD64_PERF_CNTR_GLOBAL_STATUS;
> diff --git a/lib/x86/pmu.h b/lib/x86/pmu.h
> index f07fbd93..c7dc68c1 100644
> --- a/lib/x86/pmu.h
> +++ b/lib/x86/pmu.h
> @@ -63,8 +63,8 @@ struct pmu_caps {
> u8 fixed_counter_width;
> u8 nr_gp_counters;
> u8 gp_counter_width;
> - u8 gp_counter_mask_length;
> - u32 gp_counter_available;
> + u8 arch_event_mask_length;
> + u32 arch_event_available;
> u32 msr_gp_counter_base;
> u32 msr_gp_event_select_base;
>
> @@ -110,9 +110,9 @@ static inline bool this_cpu_has_perf_global_status(void)
> return pmu.version > 1;
> }
>
> -static inline bool pmu_gp_counter_is_available(int i)
> +static inline bool pmu_arch_event_is_available(int i)
> {
> - return pmu.gp_counter_available & BIT(i);
> + return pmu.arch_event_available & BIT(i);
> }
>
> static inline u64 pmu_lbr_version(void)
> diff --git a/x86/pmu.c b/x86/pmu.c
> index 45c6db3c..e79122ed 100644
> --- a/x86/pmu.c
> +++ b/x86/pmu.c
> @@ -436,7 +436,7 @@ static void check_gp_counters(void)
> int i;
>
> for (i = 0; i < gp_events_size; i++)
> - if (pmu_gp_counter_is_available(i))
> + if (pmu_arch_event_is_available(i))
> check_gp_counter(&gp_events[i]);
> else
> printf("GP event '%s' is disabled\n",
> @@ -463,7 +463,7 @@ static void check_counters_many(void)
> int i, n;
>
> for (i = 0, n = 0; n < pmu.nr_gp_counters; i++) {
> - if (!pmu_gp_counter_is_available(i))
> + if (!pmu_arch_event_is_available(i))
> continue;
>
> cnt[n].ctr = MSR_GP_COUNTERx(n);
> @@ -902,7 +902,7 @@ static void set_ref_cycle_expectations(void)
> uint64_t t0, t1, t2, t3;
>
> /* Bit 2 enumerates the availability of reference cycles events. */
> - if (!pmu.nr_gp_counters || !pmu_gp_counter_is_available(2))
> + if (!pmu.nr_gp_counters || !pmu_arch_event_is_available(2))
> return;
>
> t0 = fenced_rdtsc();
> @@ -992,7 +992,7 @@ int main(int ac, char **av)
> printf("PMU version: %d\n", pmu.version);
> printf("GP counters: %d\n", pmu.nr_gp_counters);
> printf("GP counter width: %d\n", pmu.gp_counter_width);
> - printf("Mask length: %d\n", pmu.gp_counter_mask_length);
> + printf("Event Mask length: %d\n", pmu.arch_event_mask_length);
> printf("Fixed counters: %d\n", pmu.nr_fixed_counters);
> printf("Fixed counter width: %d\n", pmu.fixed_counter_width);
>
Tested this patch on Intel platform (Sapphire Rapids). No issue found.
Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
next prev parent reply other threads:[~2025-06-11 1:32 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 19:54 [kvm-unit-tests PATCH v2 00/14] x86: Add CPUID properties, clean up related code Sean Christopherson
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 01/14] x86: Encode X86_FEATURE_* definitions using a structure Sean Christopherson
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 02/14] x86: Add X86_PROPERTY_* framework to retrieve CPUID values Sean Christopherson
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 03/14] x86: Use X86_PROPERTY_MAX_VIRT_ADDR in is_canonical() Sean Christopherson
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 04/14] x86: Implement get_supported_xcr0() using X86_PROPERTY_SUPPORTED_XCR0_{LO,HI} Sean Christopherson
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 05/14] x86: Add and use X86_PROPERTY_INTEL_PT_NR_RANGES Sean Christopherson
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 06/14] x86/pmu: Mark all arch events as available on AMD, and rename fields Sean Christopherson
2025-06-11 1:32 ` Mi, Dapeng [this message]
2025-06-11 12:02 ` Liam Merwick
2025-06-13 6:24 ` Sandipan Das
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 07/14] x86/pmu: Mark Intel architectural event available iff X <= CPUID.0xA.EAX[31:24] Sean Christopherson
2025-06-11 1:35 ` Mi, Dapeng
2025-06-11 12:10 ` Liam Merwick
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 08/14] x86/pmu: Use X86_PROPERTY_PMU_* macros to retrieve PMU information Sean Christopherson
2025-06-13 6:25 ` Sandipan Das
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 09/14] x86/sev: Use VC_VECTOR from processor.h Sean Christopherson
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 10/14] x86/sev: Skip the AMD SEV test if SEV is unsupported/disabled Sean Christopherson
2025-06-11 12:28 ` Liam Merwick
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 11/14] x86/sev: Define and use X86_FEATURE_* flags for CPUID 0x8000001F Sean Christopherson
2025-06-11 12:38 ` Liam Merwick
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 12/14] x86/sev: Use X86_PROPERTY_SEV_C_BIT to get the AMD SEV C-bit location Sean Christopherson
2025-06-11 12:58 ` Liam Merwick
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 13/14] x86/sev: Use amd_sev_es_enabled() to detect if SEV-ES is enabled Sean Christopherson
2025-06-10 19:54 ` [kvm-unit-tests PATCH v2 14/14] x86: Move SEV MSR definitions to msr.h Sean Christopherson
2025-06-11 15:41 ` Liam Merwick
2025-06-25 22:25 ` [kvm-unit-tests PATCH v2 00/14] x86: Add CPUID properties, clean up related code Sean Christopherson
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=a6465f46-4ab8-418e-b10d-d85e288562a7@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=liam.merwick@oracle.com \
--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