Skip to contentSkip to conversation

x86/vpmu: Simplify is_pmc_quirk

PATCH In review Andrew Cooper 2 participants 3 messages Jun 20, 2023 – Jun 21, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/vpmu: Simplify is_pmc_quirk

This should be static, and there's no need for a separate (non-init, even) function to perform a simple equality test. Drop the is_ prefix which is gramatically questionable, and make it __ro_after_init.

Leave a TODO, because the behaviour is definitely wrong to be applied to ~all modern Intel CPUs, and has been raised on xen-devel previously without conclusion.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/cpu/vpmu_intel.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
xen/arch/x86/cpu/vpmu_intel.c +6 -12
index 35e350578b84..0291481da22e 100644
@@ -91,22 +91,14 @@ static const unsigned int regs_off =
  * 1 (or another value != 0) into it.
  * There exist no errata and the real cause of this behaviour is unknown.
  */
-bool_t __read_mostly is_pmc_quirk;
-
-static void check_pmc_quirk(void)
-{
-    if ( current_cpu_data.x86 == 6 )
-        is_pmc_quirk = 1;
-    else
-        is_pmc_quirk = 0;    
-}
+static bool __ro_after_init pmc_quirk;
 
 static void handle_pmc_quirk(u64 msr_content)
 {
     int i;
     u64 val;
 
-    if ( !is_pmc_quirk )
+    if ( !pmc_quirk )
         return;
 
     val = msr_content;
@@ -791,8 +783,9 @@ static int cf_check core2_vpmu_do_interrupt(struct cpu_user_regs *regs)
     rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, msr_content);
     if ( msr_content )
     {
-        if ( is_pmc_quirk )
+        if ( pmc_quirk )
             handle_pmc_quirk(msr_content);
+
         core2_vpmu_cxt->global_status |= msr_content;
         msr_content &= ~global_ovf_ctrl_mask;
         wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, msr_content);
@@ -967,7 +960,8 @@ const struct arch_vpmu_ops *__init core2_vpmu_init(void)
               sizeof(uint64_t) * fixed_pmc_cnt +
               sizeof(struct xen_pmu_cntr_pair) * arch_pmc_cnt;
 
-    check_pmc_quirk();
+    /* TODO: This is surely wrong. */
+    pmc_quirk = current_cpu_data.x86 == 6;
 
     if ( sizeof(struct xen_pmu_data) + sizeof(uint64_t) * fixed_pmc_cnt +
          sizeof(struct xen_pmu_cntr_pair) * arch_pmc_cnt > PAGE_SIZE )
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andrew Cooper

This should be static, and there's no need for a separate (non-init, even) function to perform a simple equality test. Drop the is_ prefix which is gramatically questionable, and make it __ro_after_init.

Leave a TODO, because the behaviour is definitely wrong to be applied to ~all modern Intel CPUs, and has been raised on xen-devel previously without conclusion.

No functional change.

with one request:

xen/arch/x86/cpu/vpmu_intel.c const struct arch_vpmu_ops *__init core2_vpmu_init(void) · line 964

Quoted 7 lines
xen/arch/x86/cpu/vpmu_intel.c +2 -1
@@ -967,7 +960,8 @@ const struct arch_vpmu_ops *__init core2_vpmu_init(void)
               sizeof(uint64_t) * fixed_pmc_cnt +
               sizeof(struct xen_pmu_cntr_pair) * arch_pmc_cnt;
 
-    check_pmc_quirk();
+    /* TODO: This is surely wrong. */
+    pmc_quirk = current_cpu_data.x86 == 6;

In the description you say "~all modern Intel CPUs", which suggests it might be correct for old enough ones. Would you mind weakening the comment to "This surely isn't universally correct" or some such?

Jan

#2 lore raw
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Andrew Cooper

This should be static, and there's no need for a separate (non-init, even) function to perform a simple equality test. Drop the is_ prefix which is gramatically questionable, and make it __ro_after_init.

Quoted 8 lines
Quoted 7 lines

Leave a TODO, because the behaviour is definitely wrong to be applied to ~all modern Intel CPUs, and has been raised on xen-devel previously without conclusion.

No functional change.

Thanks.

Quoted 6 lines

with one request:

Quoted 4 lines
xen/arch/x86/cpu/vpmu_intel.c +0 -0
@@ -967,7 +960,8 @@ const struct arch_vpmu_ops *__init core2_vpmu_init(void)
               sizeof(uint64_t) * fixed_pmc_cnt +
               sizeof(struct xen_pmu_cntr_pair) * arch_pmc_cnt;
 
Quoted 6 lines

xen/arch/x86/cpu/vpmu_intel.c const struct arch_vpmu_ops *__init core2_vpmu_init(void) · line 964

Quoted 3 lines
xen/arch/x86/cpu/vpmu_intel.c +2 -1
-    check_pmc_quirk();
+    /* TODO: This is surely wrong. */
+    pmc_quirk = current_cpu_data.x86 == 6;

In the description you say "~all modern Intel CPUs", which suggests it might be correct for old enough ones. Would you mind weakening the comment to "This surely isn't universally correct" or some such?

I'm happy to tweak the wording as appropriate, but Kyle (who is a regular contributor to perf in Linux) questioned that there was an issue.

There's insufficient information to figure out why it was introduced in the first place, and IIRC he wasn't aware of any errata that manifested in this way.

It's possible it's entirely bogus, or it may be a misunderstood errata. It needs looking into by someone with some copious free time.

~Andrew