Skip to contentSkip to conversation

Perf: Some fixes for Alder Lake and Sapphire Rapids

PATCH Applied [email protected] 3 participants 8 messages Jun 18, 2021 – Jun 25, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Perf: Some fixes for Alder Lake and Sapphire Rapids

From: Kan Liang <[email protected]>

The patchset includes several fixes for a special configuration and specific events on Alder Lake and Sapphire Rapids.

A single fix patch is easily buried in the numerous LKML emails. So I put them together to attract more attention.

They are independent small fixes and can be reviewed/merged separately.

Kan Liang (3):
perf/x86/intel: Fix fixed counter check warning for some Alder Lake perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids perf/x86/intel: Fix instructions:ppp support in Sapphire Rapids

 arch/x86/events/intel/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH RESEND 1/3 perf/x86/intel: Fix fixed counter check warning for some Alder Lake

From: Kan Liang <[email protected]>

For some Alder Lake machine, the below fixed counter check warning may be triggered.

[    2.010766] hw perf events fixed 5 > max(4), clipping!

Current perf unconditionally increases the number of the GP counters and the fixed counters for a big core PMU on an Alder Lake system, because the number enumerated in the CPUID only reflects the common counters. The big core may has more counters. However, Alder Lake may have an alternative configuration. With that configuration,
the X86_FEATURE_HYBRID_CPU is not set. The number of the GP counters and fixed counters enumerated in the CPUID is accurate. Perf mistakenly increases the number of counters. The warning is triggered.

Directly use the enumerated value on the system with the alternative configuration.

Fixes f83d2f91d259 ("perf/x86/intel: Add Alder Lake Hybrid support")

---

The original post can be found at
https://lkml.kernel.org/r/[email protected]

 arch/x86/events/intel/core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/events/intel/core.c +7 -2
index 2521d03..d39991b 100644
@@ -6157,8 +6157,13 @@ __init int intel_pmu_init(void)
 		pmu = &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_CORE_IDX];
 		pmu->name = "cpu_core";
 		pmu->cpu_type = hybrid_big;
-		pmu->num_counters = x86_pmu.num_counters + 2;
-		pmu->num_counters_fixed = x86_pmu.num_counters_fixed + 1;
+		if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU)) {
+			pmu->num_counters = x86_pmu.num_counters + 2;
+			pmu->num_counters_fixed = x86_pmu.num_counters_fixed + 1;
+		} else {
+			pmu->num_counters = x86_pmu.num_counters;
+			pmu->num_counters_fixed = x86_pmu.num_counters_fixed;
+		}
 		pmu->max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, pmu->num_counters);
 		pmu->unconstrained = (struct event_constraint)
 					__EVENT_CONSTRAINT(0, (1ULL << pmu->num_counters) - 1,
Signature · 1 line
2.7.4
merge bot Applied
#2 lore raw

[tip: perf/core] perf/x86/intel: Fix fixed counter check warning for some Alder Lake

The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     ee72a94ea4a6d8fa304a506859cd07ecdc0cf5c4
Gitweb:        https://git.kernel.org/tip/ee72a94ea4a6d8fa304a506859cd07ecdc0cf5c4
Author:        Kan Liang <[email protected]>
AuthorDate:    Fri, 18 Jun 2021 08:12:52 -07:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 23 Jun 2021 18:30:53 +02:00

perf/x86/intel: Fix fixed counter check warning for some Alder Lake

For some Alder Lake machine, the below fixed counter check warning may be triggered.

[    2.010766] hw perf events fixed 5 > max(4), clipping!

Current perf unconditionally increases the number of the GP counters and the fixed counters for a big core PMU on an Alder Lake system, because the number enumerated in the CPUID only reflects the common counters. The big core may has more counters. However, Alder Lake may have an alternative configuration. With that configuration,
the X86_FEATURE_HYBRID_CPU is not set. The number of the GP counters and fixed counters enumerated in the CPUID is accurate. Perf mistakenly increases the number of counters. The warning is triggered.

Directly use the enumerated value on the system with the alternative configuration.

Fixes f83d2f91d259 ("perf/x86/intel: Add Alder Lake Hybrid support")
---
 arch/x86/events/intel/core.c |  9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/x86/events/intel/core.c +7 -2
index 2521d03..d39991b 100644
@@ -6157,8 +6157,13 @@ __init int intel_pmu_init(void)
 		pmu = &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_CORE_IDX];
 		pmu->name = "cpu_core";
 		pmu->cpu_type = hybrid_big;
-		pmu->num_counters = x86_pmu.num_counters + 2;
-		pmu->num_counters_fixed = x86_pmu.num_counters_fixed + 1;
+		if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU)) {
+			pmu->num_counters = x86_pmu.num_counters + 2;
+			pmu->num_counters_fixed = x86_pmu.num_counters_fixed + 1;
+		} else {
+			pmu->num_counters = x86_pmu.num_counters;
+			pmu->num_counters_fixed = x86_pmu.num_counters_fixed;
+		}
 		pmu->max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, pmu->num_counters);
 		pmu->unconstrained = (struct event_constraint)
 					__EVENT_CONSTRAINT(0, (1ULL << pmu->num_counters) - 1,
#3 lore raw

PATCH 2/3 perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids

In reply to [email protected]

From: Kan Liang <[email protected]>

On Sapphire Rapids, there are two more events 0x40ad and 0x04c2 which rely on the FRONTEND MSR. If the FRONTEND MSR is not set correctly, the count value is not correct.

Update intel_spr_extra_regs[] to support them.

Fixes 61b985e3e775 ("perf/x86/intel: Add perf core PMU support for Sapphire Rapids")
---
 arch/x86/events/intel/core.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/events/intel/core.c +2 -0
index d39991b..e442b55 100644
@@ -280,6 +280,8 @@ static struct extra_reg intel_spr_extra_regs[] __read_mostly = {
 	INTEL_UEVENT_EXTRA_REG(0x012b, MSR_OFFCORE_RSP_1, 0x3fffffffffull, RSP_1),
 	INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x01cd),
 	INTEL_UEVENT_EXTRA_REG(0x01c6, MSR_PEBS_FRONTEND, 0x7fff17, FE),
+	INTEL_UEVENT_EXTRA_REG(0x40ad, MSR_PEBS_FRONTEND, 0x7, FE),
+	INTEL_UEVENT_EXTRA_REG(0x04c2, MSR_PEBS_FRONTEND, 0x8, FE),
 	EVENT_EXTRA_END
 };
 
Signature · 1 line
2.7.4
merge bot Applied
#4 lore raw

[tip: perf/core] perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids

The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     d18216fafecf2a3a7c2b97086892269d6ab3cd5e
Gitweb:        https://git.kernel.org/tip/d18216fafecf2a3a7c2b97086892269d6ab3cd5e
Author:        Kan Liang <[email protected]>
AuthorDate:    Fri, 18 Jun 2021 08:12:53 -07:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 23 Jun 2021 18:30:55 +02:00

perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids

On Sapphire Rapids, there are two more events 0x40ad and 0x04c2 which rely on the FRONTEND MSR. If the FRONTEND MSR is not set correctly, the count value is not correct.

Update intel_spr_extra_regs[] to support them.

Fixes 61b985e3e775 ("perf/x86/intel: Add perf core PMU support for Sapphire Rapids")
---
 arch/x86/events/intel/core.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/events/intel/core.c +2 -0
index d39991b..e442b55 100644
@@ -280,6 +280,8 @@ static struct extra_reg intel_spr_extra_regs[] __read_mostly = {
 	INTEL_UEVENT_EXTRA_REG(0x012b, MSR_OFFCORE_RSP_1, 0x3fffffffffull, RSP_1),
 	INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x01cd),
 	INTEL_UEVENT_EXTRA_REG(0x01c6, MSR_PEBS_FRONTEND, 0x7fff17, FE),
+	INTEL_UEVENT_EXTRA_REG(0x40ad, MSR_PEBS_FRONTEND, 0x7, FE),
+	INTEL_UEVENT_EXTRA_REG(0x04c2, MSR_PEBS_FRONTEND, 0x8, FE),
 	EVENT_EXTRA_END
 };
 
#5 lore raw

PATCH 3/3 perf/x86/intel: Fix instructions:ppp support in Sapphire Rapids

In reply to [email protected]

From: Kan Liang <[email protected]>

Perf errors out when sampling instructions:ppp.

$ perf record -e instructions:ppp -- true
Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument)
for event (instructions:ppp).

The instruction PDIR is only available on the fixed counter 0. The event constraint has been updated to fixed0_constraint in icl_get_event_constraints(). The Sapphire Rapids codes unconditionally error out for the event which is not available on the GP counter 0.

Make the instructions:ppp an exception.

Fixes 61b985e3e775 ("perf/x86/intel: Add perf core PMU support for Sapphire Rapids")
---
 arch/x86/events/intel/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/events/intel/core.c +3 -1
index e442b55..e355db5 100644
@@ -4032,8 +4032,10 @@ spr_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
 	 * The :ppp indicates the Precise Distribution (PDist) facility, which
 	 * is only supported on the GP counter 0. If a :ppp event which is not
 	 * available on the GP counter 0, error out.
+	 * Exception: Instruction PDIR is only available on the fixed counter 0.
 	 */
-	if (event->attr.precise_ip == 3) {
+	if ((event->attr.precise_ip == 3) &&
+	    !constraint_match(&fixed0_constraint, event->hw.config)) {
 		if (c->idxmsk64 & BIT_ULL(0))
 			return &counter0_constraint;
 
Signature · 1 line
2.7.4
merge bot Applied
#6 lore raw

[tip: perf/core] perf/x86/intel: Fix instructions:ppp support in Sapphire Rapids

The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     1d5c7880992a06679585e7e568cc679c0c5fd4f2
Gitweb:        https://git.kernel.org/tip/1d5c7880992a06679585e7e568cc679c0c5fd4f2
Author:        Kan Liang <[email protected]>
AuthorDate:    Fri, 18 Jun 2021 08:12:54 -07:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Wed, 23 Jun 2021 18:30:55 +02:00

perf/x86/intel: Fix instructions:ppp support in Sapphire Rapids

Perf errors out when sampling instructions:ppp.

$ perf record -e instructions:ppp -- true
Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument)
for event (instructions:ppp).

The instruction PDIR is only available on the fixed counter 0. The event constraint has been updated to fixed0_constraint in icl_get_event_constraints(). The Sapphire Rapids codes unconditionally error out for the event which is not available on the GP counter 0.

Make the instructions:ppp an exception.

Fixes 61b985e3e775 ("perf/x86/intel: Add perf core PMU support for Sapphire Rapids")
---
 arch/x86/events/intel/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/events/intel/core.c +3 -1
index e442b55..e355db5 100644
@@ -4032,8 +4032,10 @@ spr_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
 	 * The :ppp indicates the Precise Distribution (PDist) facility, which
 	 * is only supported on the GP counter 0. If a :ppp event which is not
 	 * available on the GP counter 0, error out.
+	 * Exception: Instruction PDIR is only available on the fixed counter 0.
 	 */
-	if (event->attr.precise_ip == 3) {
+	if ((event->attr.precise_ip == 3) &&
+	    !constraint_match(&fixed0_constraint, event->hw.config)) {
 		if (c->idxmsk64 & BIT_ULL(0))
 			return &counter0_constraint;
 
#7 lore raw
In reply to [email protected]

Hi,

I've tried to apply this on Ubuntu's 5.13 OEM kernel[1], and yet it still doesn't fix reported issue[2][3].

Vicamo

[1]: https://launchpad.net/~vicamo/+archive/ubuntu/ppa-1933617
[2]: https://bugs.launchpad.net/bugs/1933617
[3]: https://bugzilla.kernel.org/show_bug.cgi?id=213443

Quoted 18 lines · On 6/18/21 11:12 PM, [email protected] wrote:

From: Kan Liang <[email protected]>

The patchset includes several fixes for a special configuration and specific events on Alder Lake and Sapphire Rapids.

A single fix patch is easily buried in the numerous LKML emails. So I put them together to attract more attention.

They are independent small fixes and can be reviewed/merged separately.

Kan Liang (3):
perf/x86/intel: Fix fixed counter check warning for some Alder Lake perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids perf/x86/intel: Fix instructions:ppp support in Sapphire Rapids

 arch/x86/events/intel/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)