linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Perf: Some fixes for Alder Lake and Sapphire Rapids
@ 2021-06-18 15:12 kan.liang
  2021-06-18 15:12 ` [RESEND PATCH 1/3] perf/x86/intel: Fix fixed counter check warning for some Alder Lake kan.liang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: kan.liang @ 2021-06-18 15:12 UTC (permalink / raw)
  To: peterz, mingo, linux-kernel; +Cc: acme, jolsa, namhyung, ak, Kan Liang

From: Kan Liang <kan.liang@linux.intel.com>

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(-)

-- 
2.7.4


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

* [RESEND PATCH 1/3] perf/x86/intel: Fix fixed counter check warning for some Alder Lake
  2021-06-18 15:12 [PATCH 0/3] Perf: Some fixes for Alder Lake and Sapphire Rapids kan.liang
@ 2021-06-18 15:12 ` kan.liang
  2021-06-24  7:09   ` [tip: perf/core] " tip-bot2 for Kan Liang
  2021-06-18 15:12 ` [PATCH 2/3] perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids kan.liang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: kan.liang @ 2021-06-18 15:12 UTC (permalink / raw)
  To: peterz, mingo, linux-kernel; +Cc: acme, jolsa, namhyung, ak, Kan Liang, stable

From: Kan Liang <kan.liang@linux.intel.com>

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")
Reported-by: Jin Yao <yao.jin@linux.intel.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Cc: stable@vger.kernel.org
---

The original post can be found at
https://lkml.kernel.org/r/1623413662-18373-1-git-send-email-kan.liang@linux.intel.com

 arch/x86/events/intel/core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 2521d03..d39991b 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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,
-- 
2.7.4


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

* [PATCH 2/3] perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids
  2021-06-18 15:12 [PATCH 0/3] Perf: Some fixes for Alder Lake and Sapphire Rapids kan.liang
  2021-06-18 15:12 ` [RESEND PATCH 1/3] perf/x86/intel: Fix fixed counter check warning for some Alder Lake kan.liang
@ 2021-06-18 15:12 ` kan.liang
  2021-06-24  7:09   ` [tip: perf/core] " tip-bot2 for Kan Liang
  2021-06-18 15:12 ` [PATCH 3/3] perf/x86/intel: Fix instructions:ppp support in " kan.liang
  2021-06-25  8:27 ` [PATCH 0/3] Perf: Some fixes for Alder Lake and " You-Sheng Yang
  3 siblings, 1 reply; 8+ messages in thread
From: kan.liang @ 2021-06-18 15:12 UTC (permalink / raw)
  To: peterz, mingo, linux-kernel; +Cc: acme, jolsa, namhyung, ak, Kan Liang, stable

From: Kan Liang <kan.liang@linux.intel.com>

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")
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Cc: stable@vger.kernel.org
---
 arch/x86/events/intel/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index d39991b..e442b55 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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
 };
 
-- 
2.7.4


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

* [PATCH 3/3] perf/x86/intel: Fix instructions:ppp support in Sapphire Rapids
  2021-06-18 15:12 [PATCH 0/3] Perf: Some fixes for Alder Lake and Sapphire Rapids kan.liang
  2021-06-18 15:12 ` [RESEND PATCH 1/3] perf/x86/intel: Fix fixed counter check warning for some Alder Lake kan.liang
  2021-06-18 15:12 ` [PATCH 2/3] perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids kan.liang
@ 2021-06-18 15:12 ` kan.liang
  2021-06-24  7:09   ` [tip: perf/core] " tip-bot2 for Kan Liang
  2021-06-25  8:27 ` [PATCH 0/3] Perf: Some fixes for Alder Lake and " You-Sheng Yang
  3 siblings, 1 reply; 8+ messages in thread
From: kan.liang @ 2021-06-18 15:12 UTC (permalink / raw)
  To: peterz, mingo, linux-kernel; +Cc: acme, jolsa, namhyung, ak, Kan Liang, stable

From: Kan Liang <kan.liang@linux.intel.com>

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")
Reported-by: Yasin, Ahmad <ahmad.yasin@intel.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Cc: stable@vger.kernel.org
---
 arch/x86/events/intel/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index e442b55..e355db5 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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;
 
-- 
2.7.4


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

* [tip: perf/core] perf/x86/intel: Fix instructions:ppp support in Sapphire Rapids
  2021-06-18 15:12 ` [PATCH 3/3] perf/x86/intel: Fix instructions:ppp support in " kan.liang
@ 2021-06-24  7:09   ` tip-bot2 for Kan Liang
  0 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Kan Liang @ 2021-06-24  7:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Yasin, Ahmad, Kan Liang, Peter Zijlstra (Intel),
	stable, x86, linux-kernel

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 <kan.liang@linux.intel.com>
AuthorDate:    Fri, 18 Jun 2021 08:12:54 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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")
Reported-by: Yasin, Ahmad <ahmad.yasin@intel.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/1624029174-122219-4-git-send-email-kan.liang@linux.intel.com
---
 arch/x86/events/intel/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index e442b55..e355db5 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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;
 

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

* [tip: perf/core] perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids
  2021-06-18 15:12 ` [PATCH 2/3] perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids kan.liang
@ 2021-06-24  7:09   ` tip-bot2 for Kan Liang
  0 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Kan Liang @ 2021-06-24  7:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kan Liang, Peter Zijlstra (Intel), stable, x86, linux-kernel

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 <kan.liang@linux.intel.com>
AuthorDate:    Fri, 18 Jun 2021 08:12:53 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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")
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/1624029174-122219-3-git-send-email-kan.liang@linux.intel.com
---
 arch/x86/events/intel/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index d39991b..e442b55 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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
 };
 

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

* [tip: perf/core] perf/x86/intel: Fix fixed counter check warning for some Alder Lake
  2021-06-18 15:12 ` [RESEND PATCH 1/3] perf/x86/intel: Fix fixed counter check warning for some Alder Lake kan.liang
@ 2021-06-24  7:09   ` tip-bot2 for Kan Liang
  0 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Kan Liang @ 2021-06-24  7:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Jin Yao, Kan Liang, Peter Zijlstra (Intel), stable, x86, linux-kernel

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 <kan.liang@linux.intel.com>
AuthorDate:    Fri, 18 Jun 2021 08:12:52 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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")
Reported-by: Jin Yao <yao.jin@linux.intel.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/1624029174-122219-2-git-send-email-kan.liang@linux.intel.com
---
 arch/x86/events/intel/core.c |  9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 2521d03..d39991b 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -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,

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

* Re: [PATCH 0/3] Perf: Some fixes for Alder Lake and Sapphire Rapids
  2021-06-18 15:12 [PATCH 0/3] Perf: Some fixes for Alder Lake and Sapphire Rapids kan.liang
                   ` (2 preceding siblings ...)
  2021-06-18 15:12 ` [PATCH 3/3] perf/x86/intel: Fix instructions:ppp support in " kan.liang
@ 2021-06-25  8:27 ` You-Sheng Yang
  3 siblings, 0 replies; 8+ messages in thread
From: You-Sheng Yang @ 2021-06-25  8:27 UTC (permalink / raw)
  To: kan.liang; +Cc: acme, jolsa, namhyung, ak, linux-kernel, mingo, peterz

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

On 6/18/21 11:12 PM, kan.liang@linux.intel.com wrote:
> From: Kan Liang <kan.liang@linux.intel.com>
> 
> 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(-)
> 

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

end of thread, other threads:[~2021-06-25  8:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 15:12 [PATCH 0/3] Perf: Some fixes for Alder Lake and Sapphire Rapids kan.liang
2021-06-18 15:12 ` [RESEND PATCH 1/3] perf/x86/intel: Fix fixed counter check warning for some Alder Lake kan.liang
2021-06-24  7:09   ` [tip: perf/core] " tip-bot2 for Kan Liang
2021-06-18 15:12 ` [PATCH 2/3] perf/x86/intel: Add more events requires FRONTEND MSR on Sapphire Rapids kan.liang
2021-06-24  7:09   ` [tip: perf/core] " tip-bot2 for Kan Liang
2021-06-18 15:12 ` [PATCH 3/3] perf/x86/intel: Fix instructions:ppp support in " kan.liang
2021-06-24  7:09   ` [tip: perf/core] " tip-bot2 for Kan Liang
2021-06-25  8:27 ` [PATCH 0/3] Perf: Some fixes for Alder Lake and " You-Sheng Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).