Skip to contentSkip to conversation

x86/pmu: Disable inlining of measure()

PATCH Applied Bill Wendling 5 participants 8 messages Jun 1, 2022 – Nov 2, 2022 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/pmu: Disable inlining of measure()

From: Bill Wendling <[email protected]>

Clang can be more aggressive at inlining than GCC and will fully inline calls to measure(). This can mess with the counter overflow check. To set up the PMC overflow, check_counter_overflow() first records the number of instructions retired in an invocation of measure() and checks to see that subsequent calls to measure() retire the same number of instructions. If inlining occurs, those numbers can be different and the overflow test fails.

FAIL: overflow: cntr-0
PASS: overflow: status-0
PASS: overflow: status clear-0
PASS: overflow: irq-0
FAIL: overflow: cntr-1
PASS: overflow: status-1
PASS: overflow: status clear-1
PASS: overflow: irq-1
FAIL: overflow: cntr-2
PASS: overflow: status-2
PASS: overflow: status clear-2
PASS: overflow: irq-2
FAIL: overflow: cntr-3
PASS: overflow: status-3
PASS: overflow: status clear-3
PASS: overflow: irq-3

Disabling inlining of measure() keeps the assumption that all calls to measure() retire the same number of instructions.

---
 x86/pmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/pmu.c +1 -1
index a46bdbf4788c..bbfd268aafa4 100644
@@ -211,7 +211,7 @@ static void stop_event(pmu_counter_t *evt)
 	evt->count = rdmsr(evt->ctr);
 }
 
-static void measure(pmu_counter_t *evt, int count)
+static noinline void measure(pmu_counter_t *evt, int count)
 {
 	int i;
 	for (i = 0; i < count; i++)
Signature · 1 line
2.36.1.255.ge46751e96f-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Bill Wendling

From: Bill Wendling <[email protected]>

Clang can be more aggressive at inlining than GCC and will fully inline calls to measure(). This can mess with the counter overflow check. To set up the PMC overflow, check_counter_overflow() first records the number of instructions retired in an invocation of measure() and checks to see that subsequent calls to measure() retire the same number of instructions. If inlining occurs, those numbers can be different and the overflow test fails.

FAIL: overflow: cntr-0
PASS: overflow: status-0
PASS: overflow: status clear-0
PASS: overflow: irq-0
FAIL: overflow: cntr-1
PASS: overflow: status-1
PASS: overflow: status clear-1
PASS: overflow: irq-1
FAIL: overflow: cntr-2
PASS: overflow: status-2
PASS: overflow: status clear-2
PASS: overflow: irq-2
FAIL: overflow: cntr-3
PASS: overflow: status-3
PASS: overflow: status clear-3
PASS: overflow: irq-3

Quoted 5 lines

Disabling inlining of measure() keeps the assumption that all calls to measure() retire the same number of instructions.

#2 lore raw
Quoted 30 lines · Jim Mattson
Quoted 28 lines · Bill Wendling

From: Bill Wendling <[email protected]>

Clang can be more aggressive at inlining than GCC and will fully inline calls to measure(). This can mess with the counter overflow check. To set up the PMC overflow, check_counter_overflow() first records the number of instructions retired in an invocation of measure() and checks to see that subsequent calls to measure() retire the same number of instructions. If inlining occurs, those numbers can be different and the overflow test fails.

FAIL: overflow: cntr-0
PASS: overflow: status-0
PASS: overflow: status clear-0
PASS: overflow: irq-0
FAIL: overflow: cntr-1
PASS: overflow: status-1
PASS: overflow: status clear-1
PASS: overflow: irq-1
FAIL: overflow: cntr-2
PASS: overflow: status-2
PASS: overflow: status clear-2
PASS: overflow: irq-2
FAIL: overflow: cntr-3
PASS: overflow: status-3
PASS: overflow: status clear-3
PASS: overflow: irq-3

Quoted 6 lines
Quoted 5 lines

Disabling inlining of measure() keeps the assumption that all calls to measure() retire the same number of instructions.

Bumping for visibility.

-bw

#3 lore raw
Quoted 31 lines · Bill Wendling
Quoted 30 lines · Jim Mattson
Quoted 28 lines · Bill Wendling

From: Bill Wendling <[email protected]>

Clang can be more aggressive at inlining than GCC and will fully inline calls to measure(). This can mess with the counter overflow check. To set up the PMC overflow, check_counter_overflow() first records the number of instructions retired in an invocation of measure() and checks to see that subsequent calls to measure() retire the same number of instructions. If inlining occurs, those numbers can be different and the overflow test fails.

FAIL: overflow: cntr-0
PASS: overflow: status-0
PASS: overflow: status clear-0
PASS: overflow: irq-0
FAIL: overflow: cntr-1
PASS: overflow: status-1
PASS: overflow: status clear-1
PASS: overflow: irq-1
FAIL: overflow: cntr-2
PASS: overflow: status-2
PASS: overflow: status clear-2
PASS: overflow: irq-2
FAIL: overflow: cntr-3
PASS: overflow: status-3
PASS: overflow: status clear-3
PASS: overflow: irq-3

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Disabling inlining of measure() keeps the assumption that all calls to measure() retire the same number of instructions.

Bumping for visibility.

Heh, make sure kvm-unit-tests is in the subject, i.e. [kvm-unit-tests PATCH]. This slipped by on my end because I didn't realize at a quick glance that it was touching KVM-unit-tests and not kernel code.

#4 lore raw

PATCH 1/1 x86/pmu: Disable inlining of measure()

Quoted 38 lines · Sean Christopherson
Quoted 36 lines · Bill Wendling
Quoted 35 lines · Jim Mattson
Quoted 33 lines · Bill Wendling

From: Bill Wendling <[email protected]>

Clang can be more aggressive at inlining than GCC and will fully inline calls to measure(). This can mess with the counter overflow check. To set up the PMC overflow, check_counter_overflow() first records the number of instructions retired in an invocation of measure() and checks to see that subsequent calls to measure() retire the same number of instructions. If inlining occurs, those numbers can be different and the overflow test fails.

FAIL: overflow: cntr-0
PASS: overflow: status-0
PASS: overflow: status clear-0
PASS: overflow: irq-0
FAIL: overflow: cntr-1
PASS: overflow: status-1
PASS: overflow: status clear-1
PASS: overflow: irq-1
FAIL: overflow: cntr-2
PASS: overflow: status-2
PASS: overflow: status clear-2
PASS: overflow: irq-2
FAIL: overflow: cntr-3
PASS: overflow: status-3
PASS: overflow: status clear-3
PASS: overflow: irq-3

Disabling inlining of measure() keeps the assumption that all calls to measure() retire the same number of instructions.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Bumping for visibility.

Heh, make sure kvm-unit-tests is in the subject, i.e. [kvm-unit-tests PATCH]. This slipped by on my end because I didn't realize at a quick glance that it was touching KVM-unit-tests and not kernel code.

Doh! I'm not sure why I forgot that. Added. Thanks. :)

-bw

#5 lore raw
Quoted 8 lines · Bill Wendling
Quoted 7 lines · Sean Christopherson
Quoted 5 lines · Bill Wendling
Quoted 4 lines · Jim Mattson
Quoted 2 lines · Bill Wendling

From: Bill Wendling <[email protected]>

This "From:" should not exist. It causes your @gmail.com account be to credited as the author, whereas your SOB suggests you intended this to be credited to your @google.com address.

Let me know if this should indeed list [email protected] as the author, I can fix it up when applying.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
#6 lore raw
Quoted 9 lines · Sean Christopherson
Quoted 7 lines · Bill Wendling
Quoted 6 lines · Sean Christopherson
Quoted 4 lines · Bill Wendling
Quoted 3 lines · Jim Mattson
Quoted 1 line · Bill Wendling
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

From: Bill Wendling <[email protected]>

This "From:" should not exist. It causes your @gmail.com account be to credited as the author, whereas your SOB suggests you intended this to be credited to your @google.com address.

Let me know if this should indeed list [email protected] as the author, I can fix it up when applying.

Please use [email protected]. Sorry about this mixup.

-bw

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
maintainer Applied
#7 lore raw
In reply to Bill Wendling
Quoted 41 lines · Bill Wendling

From: Bill Wendling <[email protected]>

Clang can be more aggressive at inlining than GCC and will fully inline calls to measure(). This can mess with the counter overflow check. To set up the PMC overflow, check_counter_overflow() first records the number of instructions retired in an invocation of measure() and checks to see that subsequent calls to measure() retire the same number of instructions. If inlining occurs, those numbers can be different and the overflow test fails.

FAIL: overflow: cntr-0
PASS: overflow: status-0
PASS: overflow: status clear-0
PASS: overflow: irq-0
FAIL: overflow: cntr-1
PASS: overflow: status-1
PASS: overflow: status clear-1
PASS: overflow: irq-1
FAIL: overflow: cntr-2
PASS: overflow: status-2
PASS: overflow: status clear-2
PASS: overflow: irq-2
FAIL: overflow: cntr-3
PASS: overflow: status-3
PASS: overflow: status clear-3
PASS: overflow: irq-3

Disabling inlining of measure() keeps the assumption that all calls to measure() retire the same number of instructions.

---
  x86/pmu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
x86/pmu.c +0 -0
index a46bdbf4788c..bbfd268aafa4 100644

x86/pmu.c static void stop_event(pmu_counter_t *evt) · line 217

Quoted 8 lines
x86/pmu.c +1 -1
@@ -211,7 +211,7 @@ static void stop_event(pmu_counter_t *evt)
  	evt->count = rdmsr(evt->ctr);
  }
 
-static void measure(pmu_counter_t *evt, int count)
+static noinline void measure(pmu_counter_t *evt, int count)
  {
  	int i;
  	for (i = 0; i < count; i++)

Queued, thanks.

Paolo