All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test
@ 2025-05-29 21:01 Sean Christopherson
  2025-06-10  9:15 ` Mi, Dapeng
  2025-06-10 19:42 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Sean Christopherson @ 2025-05-29 21:01 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Sean Christopherson

Explicitly zero PERF_GLOBAL_CTRL at the start of the PMU test as the
architectural RESET value of PERF_GLOBAL_CTRL is to set all enable bits
for general purpose counters (for backwards compatibility with software
that was written for v1 PMUs).  Leaving PERF_GLOBAL_CTRL set can result in
false failures due to counters unexpectedly being left active.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 x86/pmu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/x86/pmu.c b/x86/pmu.c
index 8cf26b12..9bd0c186 100644
--- a/x86/pmu.c
+++ b/x86/pmu.c
@@ -905,9 +905,6 @@ static void set_ref_cycle_expectations(void)
 	if (!pmu.nr_gp_counters || !pmu_gp_counter_is_available(2))
 		return;
 
-	if (this_cpu_has_perf_global_ctrl())
-		wrmsr(pmu.msr_global_ctl, 0);
-
 	t0 = fenced_rdtsc();
 	start_event(&cnt);
 	t1 = fenced_rdtsc();
@@ -956,6 +953,9 @@ int main(int ac, char **av)
 	handle_irq(PMI_VECTOR, cnt_overflow);
 	buf = malloc(N*64);
 
+	if (this_cpu_has_perf_global_ctrl())
+		wrmsr(pmu.msr_global_ctl, 0);
+
 	check_invalid_rdpmc_gp();
 
 	if (pmu.is_intel) {

base-commit: 72d110d8286baf1b355301cc8c8bdb42be2663fb
-- 
2.49.0.1204.g71687c7c1d-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [kvm-unit-tests PATCH] x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test
  2025-05-29 21:01 [kvm-unit-tests PATCH] x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test Sean Christopherson
@ 2025-06-10  9:15 ` Mi, Dapeng
  2025-06-10 19:42 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Mi, Dapeng @ 2025-06-10  9:15 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm


On 5/30/2025 5:01 AM, Sean Christopherson wrote:
> Explicitly zero PERF_GLOBAL_CTRL at the start of the PMU test as the
> architectural RESET value of PERF_GLOBAL_CTRL is to set all enable bits
> for general purpose counters (for backwards compatibility with software
> that was written for v1 PMUs).  Leaving PERF_GLOBAL_CTRL set can result in
> false failures due to counters unexpectedly being left active.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>  x86/pmu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/x86/pmu.c b/x86/pmu.c
> index 8cf26b12..9bd0c186 100644
> --- a/x86/pmu.c
> +++ b/x86/pmu.c
> @@ -905,9 +905,6 @@ static void set_ref_cycle_expectations(void)
>  	if (!pmu.nr_gp_counters || !pmu_gp_counter_is_available(2))
>  		return;
>  
> -	if (this_cpu_has_perf_global_ctrl())
> -		wrmsr(pmu.msr_global_ctl, 0);
> -
>  	t0 = fenced_rdtsc();
>  	start_event(&cnt);
>  	t1 = fenced_rdtsc();
> @@ -956,6 +953,9 @@ int main(int ac, char **av)
>  	handle_irq(PMI_VECTOR, cnt_overflow);
>  	buf = malloc(N*64);
>  
> +	if (this_cpu_has_perf_global_ctrl())
> +		wrmsr(pmu.msr_global_ctl, 0);
> +
>  	check_invalid_rdpmc_gp();
>  
>  	if (pmu.is_intel) {
>
> base-commit: 72d110d8286baf1b355301cc8c8bdb42be2663fb

Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [kvm-unit-tests PATCH] x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test
  2025-05-29 21:01 [kvm-unit-tests PATCH] x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test Sean Christopherson
  2025-06-10  9:15 ` Mi, Dapeng
@ 2025-06-10 19:42 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2025-06-10 19:42 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm

On Thu, 29 May 2025 14:01:57 -0700, Sean Christopherson wrote:
> Explicitly zero PERF_GLOBAL_CTRL at the start of the PMU test as the
> architectural RESET value of PERF_GLOBAL_CTRL is to set all enable bits
> for general purpose counters (for backwards compatibility with software
> that was written for v1 PMUs).  Leaving PERF_GLOBAL_CTRL set can result in
> false failures due to counters unexpectedly being left active.
> 
> 
> [...]

Applied to kvm-x86 next, thanks!

[1/1] x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test
      https://github.com/kvm-x86/kvm-unit-tests/commit/0bd5a078d1d1

--
https://github.com/kvm-x86/kvm-unit-tests/tree/next

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-10 19:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-29 21:01 [kvm-unit-tests PATCH] x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test Sean Christopherson
2025-06-10  9:15 ` Mi, Dapeng
2025-06-10 19:42 ` Sean Christopherson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.