Skip to contentSkip to conversation

perf, x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

PATCH In review Andi Kleen 6 participants 22 messages Dec 1, 2015 – Jan 6, 2016

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/2 perf, x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

From: Andi Kleen <[email protected]>

I added UOPS_RETIRED.ALL by mistake to the Skylake PEBS event list for cycles:pp. But the event is not documented for Skylake, and has some issues.

The recommended replacement for cycles:pp is to use INST_RETIRED.ANY+pebs as a base, similar to what CPUs before Sandy Bridge did. This new event is called INST_RETIRED.TOTAL_CYCLES_PS. The event is not really new, but has been already used by perf before Sandy Bridge for the original cycles:p

Note the SDM doesn't document that event either, but it's being documented in the latest version of the event list on
https://download.01.org/perfmon/SKL

This patch does:

- Remove UOPS_RETIRED.ALL from the Skylake PEBS event list
- Add INST_RETIRED.ANY to the Skylake PEBS event list, and an table entry to allow cmask=16,inv=1 for cycles:pp
- We don't need an extra entry for the base INST_RETIRED event, because it is already covered by the catch-all PEBS table entry.
- Switch Skylake to use the Core2 PEBS alias (which is INST_RETIRED.TOTAL_CYCLES_PS)

---
 arch/x86/kernel/cpu/perf_event_intel.c    | 2 +-
 arch/x86/kernel/cpu/perf_event_intel_ds.c | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/perf_event_intel.c +1 -1
index 297960a..09f4399 100644
@@ -3521,7 +3521,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.event_constraints = intel_skl_event_constraints;
 		x86_pmu.pebs_constraints = intel_skl_pebs_event_constraints;
 		x86_pmu.extra_regs = intel_skl_extra_regs;
-		x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
+		x86_pmu.pebs_aliases = intel_pebs_aliases_core2;
 		/* all extra regs are per-cpu when HT is on */
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
arch/x86/kernel/cpu/perf_event_intel_ds.c +2 -3
index 5db1c77..dcab005 100644
@@ -718,9 +718,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 
 struct event_constraint intel_skl_pebs_event_constraints[] = {
 	INTEL_FLAGS_UEVENT_CONSTRAINT(0x1c0, 0x2),	/* INST_RETIRED.PREC_DIST */
-	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_NA(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
-	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
-	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.TOTAL_CYCLES_PS (inv=1, cmask=16) (cycles:p). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108000c0, 0x01),
 	INTEL_PLD_CONSTRAINT(0x1cd, 0xf),		      /* MEM_TRANS_RETIRED.* */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD(0x11d0, 0xf), /* MEM_INST_RETIRED.STLB_MISS_LOADS */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST(0x12d0, 0xf), /* MEM_INST_RETIRED.STLB_MISS_STORES */
Signature · 1 line
2.4.3
author
#1 lore raw

PATCH 2/2 x86, perf: Use INST_RETIRED.PREC_DIST for cycles:ppp

From: Andi Kleen <[email protected]>

Add a new 'three-p' precise level, that uses INST_RETIRED.PREC_DIST as base. The basic mechanism of abusing the inverse cmask to get all cycles works the same as before.

PREC_DIST is available on Sandy Bridge or later. It had some problems on Sandy Bridge, so we only use it on IvyBridge and later. I tested it on Broadwell and Skylake.

PREC_DIST has special support for avoiding shadow effects, which can give better results compare to UOPS_RETIRED. The drawback is that PREC_DIST can only schedule on counter 1, but that is ok for cycle sampling, as there is normally no need to do multiple cycle sampling runs in parallel. It is still possible to run perf top in parallel, as that doesn't use precise mode. Also of course the multiplexing can still allow parallel operation.

:pp stays with the previous event.

Example:

Sample a loop with 10 sqrt with old cycles:pp

  0.14 │10:   sqrtps %xmm1,%xmm0     <--------------
  9.13 │      sqrtps %xmm1,%xmm0
 11.58 │      sqrtps %xmm1,%xmm0
 11.51 │      sqrtps %xmm1,%xmm0
  6.27 │      sqrtps %xmm1,%xmm0
 10.38 │      sqrtps %xmm1,%xmm0
 12.20 │      sqrtps %xmm1,%xmm0
 12.74 │      sqrtps %xmm1,%xmm0
  5.40 │      sqrtps %xmm1,%xmm0
 10.14 │      sqrtps %xmm1,%xmm0
 10.51 │    ↑ jmp    10

We expect all 10 sqrt to get roughly the sample number of samples.

But you can see that the instruction directly after the jmp is systematically underestimated in the result, due to sampling shadow effects.

With the new PREC_DIST based sampling this problem is gone and all instructions show up roughly evenly:

  9.51 │10:   sqrtps %xmm1,%xmm0
 11.74 │      sqrtps %xmm1,%xmm0
 11.84 │      sqrtps %xmm1,%xmm0
  6.05 │      sqrtps %xmm1,%xmm0
 10.46 │      sqrtps %xmm1,%xmm0
 12.25 │      sqrtps %xmm1,%xmm0
 12.18 │      sqrtps %xmm1,%xmm0
  5.26 │      sqrtps %xmm1,%xmm0
 10.13 │      sqrtps %xmm1,%xmm0
 10.43 │      sqrtps %xmm1,%xmm0
  0.16 │    ↑ jmp    10

Even with PREC_DIST there is still sampling skid and the result is not completely even, but systematic shadow effects are significantly reduced.

The improvements are mainly expected to make a difference in high IPC code. With low IPC it should be similar.

v2:
Change to use precise_ip == 3 for the new cycles event Split original patch into two.
Use from Ivy Bridge and up.

---
 arch/x86/kernel/cpu/perf_event.c          |  3 ++
 arch/x86/kernel/cpu/perf_event_intel.c    | 46 ++++++++++++++++++++++++++++---
 arch/x86/kernel/cpu/perf_event_intel_ds.c |  6 ++++
 3 files changed, 51 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/perf_event.c +3 -0
index 9dfbba5..ba41899 100644
@@ -482,6 +482,9 @@ int x86_pmu_hw_config(struct perf_event *event)
 			/* Support for IP fixup */
 			if (x86_pmu.lbr_nr || x86_pmu.intel_cap.pebs_format >= 2)
 				precise++;
+
+			if (x86_pmu.pebs_aliases)
+				precise++;
 		}
 
 		if (event->attr.precise_ip > precise)
arch/x86/kernel/cpu/perf_event_intel.c +42 -4

76 lines not on this page · raw message

arch/x86/kernel/cpu/perf_event_intel_ds.c +6 -0
index dcab005..7f11784 100644
@@ -686,6 +686,8 @@ struct event_constraint intel_ivb_pebs_event_constraints[] = {
 	INTEL_PST_CONSTRAINT(0x02cd, 0x8),    /* MEM_TRANS_RETIRED.PRECISE_STORES */
 	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	INTEL_EXCLEVT_CONSTRAINT(0xd0, 0xf),    /* MEM_UOP_RETIRED.* */
 	INTEL_EXCLEVT_CONSTRAINT(0xd1, 0xf),    /* MEM_LOAD_UOPS_RETIRED.* */
 	INTEL_EXCLEVT_CONSTRAINT(0xd2, 0xf),    /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
@@ -700,6 +702,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 	INTEL_PLD_CONSTRAINT(0x01cd, 0xf),    /* MEM_TRANS_RETIRED.* */
 	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_NA(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XLD(0x11d0, 0xf), /* MEM_UOPS_RETIRED.STLB_MISS_LOADS */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XLD(0x21d0, 0xf), /* MEM_UOPS_RETIRED.LOCK_LOADS */
@@ -718,6 +722,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 
 struct event_constraint intel_skl_pebs_event_constraints[] = {
 	INTEL_FLAGS_UEVENT_CONSTRAINT(0x1c0, 0x2),	/* INST_RETIRED.PREC_DIST */
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	/* INST_RETIRED.TOTAL_CYCLES_PS (inv=1, cmask=16) (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108000c0, 0x01),
 	INTEL_PLD_CONSTRAINT(0x1cd, 0xf),		      /* MEM_TRANS_RETIRED.* */
Signature · 1 line
2.4.3
maintainer
#2 lore raw

Re: [PATCH 2/2] x86, perf: Use INST_RETIRED.PREC_DIST for cycles:ppp

arch/x86/kernel/cpu/perf_event.c int x86_pmu_hw_config(struct perf_event *event) · line 487

Quoted 11 lines · Andi Kleen
arch/x86/kernel/cpu/perf_event.c +3 -0
index 9dfbba5..ba41899 100644
@@ -482,6 +482,9 @@ int x86_pmu_hw_config(struct perf_event *event)
 			/* Support for IP fixup */
 			if (x86_pmu.lbr_nr || x86_pmu.intel_cap.pebs_format >= 2)
 				precise++;
+
+			if (x86_pmu.pebs_aliases)
+				precise++;

This is not accurate, it would allow :ppp for core2 for example, which does not at all support PREC_DIST events.

Something like so on top?

arch/x86/kernel/cpu/perf_event.c +1 -1
@@ -483,7 +483,7 @@ int x86_pmu_hw_config(struct perf_event
 			if (x86_pmu.lbr_nr || x86_pmu.intel_cap.pebs_format >= 2)
 				precise++;
 
-			if (x86_pmu.pebs_aliases)
+			if (x86_pmu.pebs_prec_dist)
 				precise++;
 		}
 
arch/x86/kernel/cpu/perf_event.h +2 -1
@@ -593,7 +593,8 @@ struct x86_pmu {
 			bts_active	:1,
 			pebs		:1,
 			pebs_active	:1,
-			pebs_broken	:1;
+			pebs_broken	:1,
+			pebs_prec_dist	:1;
 	int		pebs_record_size;
 	void		(*drain_pebs)(struct pt_regs *regs);
 	struct event_constraint *pebs_constraints;
arch/x86/kernel/cpu/perf_event_intel.c +4 -0
@@ -3470,6 +3470,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.event_constraints = intel_ivb_event_constraints;
 		x86_pmu.pebs_constraints = intel_ivb_pebs_event_constraints;
 		x86_pmu.pebs_aliases = intel_pebs_aliases_ivb;
+		x86_pmu.pebs_prec_dist = true;
 		if (boot_cpu_data.x86_model == 62)
 			x86_pmu.extra_regs = intel_snbep_extra_regs;
 		else
@@ -3503,6 +3504,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints;
 		x86_pmu.extra_regs = intel_snbep_extra_regs;
 		x86_pmu.pebs_aliases = intel_pebs_aliases_ivb;
+		x86_pmu.pebs_prec_dist = true;
 		/* all extra regs are per-cpu when HT is on */
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
@@ -3538,6 +3540,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints;
 		x86_pmu.extra_regs = intel_snbep_extra_regs;
 		x86_pmu.pebs_aliases = intel_pebs_aliases_ivb;
+		x86_pmu.pebs_prec_dist = true;
 		/* all extra regs are per-cpu when HT is on */
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
@@ -3560,6 +3563,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.pebs_constraints = intel_skl_pebs_event_constraints;
 		x86_pmu.extra_regs = intel_skl_extra_regs;
 		x86_pmu.pebs_aliases = intel_pebs_aliases_skl;
+		x86_pmu.pebs_prec_dist = true;
 		/* all extra regs are per-cpu when HT is on */
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
#3 lore raw

Re: [PATCH 2/2] x86, perf: Use INST_RETIRED.PREC_DIST for cycles:ppp

Quoted 16 lines · Peter Zijlstra

arch/x86/kernel/cpu/perf_event.c int x86_pmu_hw_config(struct perf_event *event) · line 487

Quoted 11 lines · Andi Kleen
arch/x86/kernel/cpu/perf_event.c +3 -0
index 9dfbba5..ba41899 100644
@@ -482,6 +482,9 @@ int x86_pmu_hw_config(struct perf_event *event)
 			/* Support for IP fixup */
 			if (x86_pmu.lbr_nr || x86_pmu.intel_cap.pebs_format >= 2)
 				precise++;
+
+			if (x86_pmu.pebs_aliases)
+				precise++;

This is not accurate, it would allow :ppp for core2 for example, which does not at all support PREC_DIST events.

Quoted 1 line

Something like so on top?

Yes that's fine. Thanks.

Are you just applying it with that change, or should I resend a combined patch?

-Andi

maintainer
#4 lore raw

Re: [PATCH 2/2] x86, perf: Use INST_RETIRED.PREC_DIST for cycles:ppp

Quoted 17 lines · Andi Kleen
Quoted 16 lines · Peter Zijlstra

arch/x86/kernel/cpu/perf_event.c int x86_pmu_hw_config(struct perf_event *event) · line 487

Quoted 11 lines · Andi Kleen
arch/x86/kernel/cpu/perf_event.c +3 -0
index 9dfbba5..ba41899 100644
@@ -482,6 +482,9 @@ int x86_pmu_hw_config(struct perf_event *event)
 			/* Support for IP fixup */
 			if (x86_pmu.lbr_nr || x86_pmu.intel_cap.pebs_format >= 2)
 				precise++;
+
+			if (x86_pmu.pebs_aliases)
+				precise++;

This is not accurate, it would allow :ppp for core2 for example, which does not at all support PREC_DIST events.

Quoted 5 lines
Quoted 1 line

Something like so on top?

Yes that's fine. Thanks.

Are you just applying it with that change, or should I resend a combined patch?

Yep, got it in. Thanks.

#5 lore raw

[tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

In reply to Andi Kleen
perf/x86: Use INST_RETIRED.PREC_DIST for cycles:ppp
Commit-ID:  4576ceaa56a86bd0c041c204d51c3f3ca582a49c
Gitweb:     http://git.kernel.org/tip/4576ceaa56a86bd0c041c204d51c3f3ca582a49c
Author:     Andi Kleen <[email protected]>
AuthorDate: Mon, 30 Nov 2015 16:28:09 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Dec 2015 10:08:04 +0100

perf/x86: Use INST_RETIRED.PREC_DIST for cycles:ppp

Add a new 'three-p' precise level, that uses INST_RETIRED.PREC_DIST as base. The basic mechanism of abusing the inverse cmask to get all cycles works the same as before.

PREC_DIST is available on Sandy Bridge or later. It had some problems on Sandy Bridge, so we only use it on IvyBridge and later. I tested it on Broadwell and Skylake.

PREC_DIST has special support for avoiding shadow effects, which can give better results compare to UOPS_RETIRED. The drawback is that PREC_DIST can only schedule on counter 1, but that is ok for cycle sampling, as there is normally no need to do multiple cycle sampling runs in parallel. It is still possible to run perf top in parallel, as that doesn't use precise mode. Also of course the multiplexing can still allow parallel operation.

:pp stays with the previous event.

Example:

Sample a loop with 10 sqrt with old cycles:pp

	  0.14 │10:   sqrtps %xmm1,%xmm0     <--------------
	  9.13 │      sqrtps %xmm1,%xmm0
	 11.58 │      sqrtps %xmm1,%xmm0
	 11.51 │      sqrtps %xmm1,%xmm0
	  6.27 │      sqrtps %xmm1,%xmm0
	 10.38 │      sqrtps %xmm1,%xmm0
	 12.20 │      sqrtps %xmm1,%xmm0
	 12.74 │      sqrtps %xmm1,%xmm0
	  5.40 │      sqrtps %xmm1,%xmm0
	 10.14 │      sqrtps %xmm1,%xmm0
	 10.51 │    ↑ jmp    10

We expect all 10 sqrt to get roughly the sample number of samples.

But you can see that the instruction directly after the JMP is systematically underestimated in the result, due to sampling shadow effects.

With the new PREC_DIST based sampling this problem is gone and all instructions show up roughly evenly:

	  9.51 │10:   sqrtps %xmm1,%xmm0
	 11.74 │      sqrtps %xmm1,%xmm0
	 11.84 │      sqrtps %xmm1,%xmm0
	  6.05 │      sqrtps %xmm1,%xmm0
	 10.46 │      sqrtps %xmm1,%xmm0
	 12.25 │      sqrtps %xmm1,%xmm0
	 12.18 │      sqrtps %xmm1,%xmm0
	  5.26 │      sqrtps %xmm1,%xmm0
	 10.13 │      sqrtps %xmm1,%xmm0
	 10.43 │      sqrtps %xmm1,%xmm0
	  0.16 │    ↑ jmp    10

Even with PREC_DIST there is still sampling skid and the result is not completely even, but systematic shadow effects are significantly reduced.

The improvements are mainly expected to make a difference in high IPC code. With low IPC it should be similar.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
---
 arch/x86/kernel/cpu/perf_event.c          |  3 ++
 arch/x86/kernel/cpu/perf_event.h          |  3 +-
 arch/x86/kernel/cpu/perf_event_intel.c    | 50 ++++++++++++++++++++++++++++---
 arch/x86/kernel/cpu/perf_event_intel_ds.c |  6 ++++
 4 files changed, 57 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/perf_event.c +3 -0
index 2bf79d7..ec2cbe5 100644
@@ -482,6 +482,9 @@ int x86_pmu_hw_config(struct perf_event *event)
 			/* Support for IP fixup */
 			if (x86_pmu.lbr_nr || x86_pmu.intel_cap.pebs_format >= 2)
 				precise++;
+
+			if (x86_pmu.pebs_prec_dist)
+				precise++;
 		}
 
 		if (event->attr.precise_ip > precise)
arch/x86/kernel/cpu/perf_event.h +2 -1
index ab18b8a..ce0ce26 100644
@@ -589,7 +589,8 @@ struct x86_pmu {
 			bts_active	:1,
 			pebs		:1,
 			pebs_active	:1,
-			pebs_broken	:1;
+			pebs_broken	:1,
+			pebs_prec_dist	:1;
 	int		pebs_record_size;
 	void		(*drain_pebs)(struct pt_regs *regs);
 	struct event_constraint *pebs_constraints;
arch/x86/kernel/cpu/perf_event_intel.c +46 -4

80 lines not on this page · raw message

arch/x86/kernel/cpu/perf_event_intel_ds.c +6 -0
index dcab005..7f11784 100644
@@ -686,6 +686,8 @@ struct event_constraint intel_ivb_pebs_event_constraints[] = {
 	INTEL_PST_CONSTRAINT(0x02cd, 0x8),    /* MEM_TRANS_RETIRED.PRECISE_STORES */
 	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	INTEL_EXCLEVT_CONSTRAINT(0xd0, 0xf),    /* MEM_UOP_RETIRED.* */
 	INTEL_EXCLEVT_CONSTRAINT(0xd1, 0xf),    /* MEM_LOAD_UOPS_RETIRED.* */
 	INTEL_EXCLEVT_CONSTRAINT(0xd2, 0xf),    /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
@@ -700,6 +702,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 	INTEL_PLD_CONSTRAINT(0x01cd, 0xf),    /* MEM_TRANS_RETIRED.* */
 	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_NA(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XLD(0x11d0, 0xf), /* MEM_UOPS_RETIRED.STLB_MISS_LOADS */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XLD(0x21d0, 0xf), /* MEM_UOPS_RETIRED.LOCK_LOADS */
@@ -718,6 +722,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 
 struct event_constraint intel_skl_pebs_event_constraints[] = {
 	INTEL_FLAGS_UEVENT_CONSTRAINT(0x1c0, 0x2),	/* INST_RETIRED.PREC_DIST */
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	/* INST_RETIRED.TOTAL_CYCLES_PS (inv=1, cmask=16) (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108000c0, 0x01),
 	INTEL_PLD_CONSTRAINT(0x1cd, 0xf),		      /* MEM_TRANS_RETIRED.* */
#6 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 7 lines · tip-bot for Andi Kleen
Commit-ID:  4576ceaa56a86bd0c041c204d51c3f3ca582a49c
Gitweb:     http://git.kernel.org/tip/4576ceaa56a86bd0c041c204d51c3f3ca582a49c
Author:     Andi Kleen <[email protected]>
AuthorDate: Mon, 30 Nov 2015 16:28:09 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Dec 2015 10:08:04 +0100
Quoted 5 lines

perf/x86: Use INST_RETIRED.PREC_DIST for cycles:ppp

Add a new 'three-p' precise level, that uses INST_RETIRED.PREC_DIST as base. The basic mechanism of abusing the inverse cmask to get all cycles works the same as before.

So this commit regressed on the follwing Intel Nehalem box:

 processor       : 15
 vendor_id       : GenuineIntel
 cpu family      : 6
 model           : 26
 model name      : Intel(R) Xeon(R) CPU           X55600 @ 2.80GHz
 stepping        : 5
 cpu MHz         : 2793.000
 cache size      : 8192 KB

it has this perf bootup signature:

0.272504] Performance Events: PEBS fmt1+, 16-deep LBR, Nehalem events, Intel PMU driver. 0.281356] perf_event_intel: CPU erratum AAJ80 worked around

the symptom is that latest 'perf top' and 'perf record' produces no samples.

So I've removed this commit and the related Skylake commit from -tip:

4576ceaa56a8 perf/x86: Use INST_RETIRED.PREC_DIST for cycles:ppp ac1e1d30cf90 perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

you need to do better testing next time around. Note: if you resubmit the patches, please also pick up the updates commit changelogs from the tip-bot emails, don't use your original changelogs.

Also, I'm not convinced we need a new 'ppp' qualifier for any of this, why not just replace 'pp' with this event - 'pp' is meant to be our most precise event.

Thanks,

Ingo

maintainer
#7 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 2 lines · Ingo Molnar

Also, I'm not convinced we need a new 'ppp' qualifier for any of this, why not just replace 'pp' with this event - 'pp' is meant to be our most precise event.

I requested this because the PREC_DIST events can only be scheduled on a single counter, whereas the existing :pp events can be had on all 4.

This mean you can have 2 concurrent :pp users (without RR), but not :ppp.

#8 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 10 lines · Peter Zijlstra
Quoted 3 lines · Ingo Molnar

Also, I'm not convinced we need a new 'ppp' qualifier for any of this, why not just replace 'pp' with this event - 'pp' is meant to be our most precise event.

I requested this because the PREC_DIST events can only be scheduled on a single counter, whereas the existing :pp events can be had on all 4.

This mean you can have 2 concurrent :pp users (without RR), but not :ppp.

Ok. Will tooling do the right thing? I.e. will the first user of 'perf top' get :ppp automatically, while the second one falls back to :pp?

Thanks,

Ingo

maintainer
#9 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Ingo Molnar

Also, I'm not convinced we need a new 'ppp' qualifier for any of this, why not just replace 'pp' with this event - 'pp' is meant to be our most precise event.

Quoted 7 lines
Quoted 4 lines

I requested this because the PREC_DIST events can only be scheduled on a single counter, whereas the existing :pp events can be had on all 4.

This mean you can have 2 concurrent :pp users (without RR), but not :ppp.

Ok. Will tooling do the right thing? I.e. will the first user of 'perf top' get :ppp automatically, while the second one falls back to :pp?

if not I'll make it so.

#10 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

In reply to Ingo Molnar

Em Mon, Dec 07, 2015 at 07:48:41AM +0100, Ingo Molnar escreveu:

Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Ingo Molnar
Quoted 3 lines

Also, I'm not convinced we need a new 'ppp' qualifier for any of this, why not just replace 'pp' with this event - 'pp' is meant to be our most precise event.

Quoted 7 lines
Quoted 4 lines

I requested this because the PREC_DIST events can only be scheduled on a single counter, whereas the existing :pp events can be had on all 4.

This mean you can have 2 concurrent :pp users (without RR), but not :ppp.

Ok. Will tooling do the right thing? I.e. will the first user of 'perf top' get :ppp automatically, while the second one falls back to :pp?

I guess so:

void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr)

{
        attr->precise_ip = 3;

<SNIP>

- Arnaldo

maintainer
#11 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 12 lines · Arnaldo Carvalho de Melo

Em Mon, Dec 07, 2015 at 07:48:41AM +0100, Ingo Molnar escreveu:

Quoted 10 lines · Peter Zijlstra
Quoted 9 lines · Ingo Molnar
Quoted 3 lines

Also, I'm not convinced we need a new 'ppp' qualifier for any of this, why not just replace 'pp' with this event - 'pp' is meant to be our most precise event.

I requested this because the PREC_DIST events can only be scheduled on a single counter, whereas the existing :pp events can be had on all 4.

This mean you can have 2 concurrent :pp users (without RR), but not :ppp.

Quoted 8 lines
Quoted 2 lines

Ok. Will tooling do the right thing? I.e. will the first user of 'perf top' get :ppp automatically, while the second one falls back to :pp?

I guess so:

void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr)

{
        attr->precise_ip = 3;

Indeed so, I've since confirmed it does also works in practise.

maintainer
#12 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar

the symptom is that latest 'perf top' and 'perf record' produces no samples.

So I've removed this commit and the related Skylake commit from -tip:

4576ceaa56a8 perf/x86: Use INST_RETIRED.PREC_DIST for cycles:ppp ac1e1d30cf90 perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

you need to do better testing next time around. Note: if you resubmit the patches, please also pick up the updates commit changelogs from the tip-bot emails, don't use your original changelogs.

OK, so I need:

lkml.kernel.org/r/[email protected] lkml.kernel.org/r/[email protected]

On my IVB because that keeps triggering that case with :ppp, other than that this seems to work fine on IVB.

I've also tried on SNB (which does not support the new :ppp thing) and that too works.

Sadly I do not have older hardware anymore :/

Also, perf tools DTRT and will use :ppp by default if available.

#13 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 21 lines · Peter Zijlstra
Quoted 10 lines · Ingo Molnar

the symptom is that latest 'perf top' and 'perf record' produces no samples.

So I've removed this commit and the related Skylake commit from -tip:

4576ceaa56a8 perf/x86: Use INST_RETIRED.PREC_DIST for cycles:ppp ac1e1d30cf90 perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

you need to do better testing next time around. Note: if you resubmit the patches, please also pick up the updates commit changelogs from the tip-bot emails, don't use your original changelogs.

OK, so I need:

lkml.kernel.org/r/[email protected] lkml.kernel.org/r/[email protected]

On my IVB because that keeps triggering that case with :ppp, other than that this seems to work fine on IVB.

Quoted 7 lines

I've also tried on SNB (which does not support the new :ppp thing) and that too works.

Sadly I do not have older hardware anymore :/

Also, perf tools DTRT and will use :ppp by default if available.

So I checked my NHM box with your latest queue and it now works correctly. Do you have any idea what the difference is/was?

Thanks,

Ingo

maintainer
#14 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 2 lines · Ingo Molnar

So I checked my NHM box with your latest queue and it now works correctly. Do you have any idea what the difference is/was?

Sadly, no clue :/

I went over those patches and cannot find anything that should affect NHM (or <=SNB in fact).

maintainer
#15 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 9 lines · Peter Zijlstra
Quoted 2 lines · Ingo Molnar

So I checked my NHM box with your latest queue and it now works correctly. Do you have any idea what the difference is/was?

Sadly, no clue :/

I went over those patches and cannot find anything that should affect NHM (or <=SNB in fact).

Oh wait, I spoke too soon, the two new patches affect everything with PEBS. And esp. the latter one:

lkml.kernel.org/r/[email protected]

But note that this is a pre-existing issue and should not be changed by the skl-:pp and :ppp patches.

maintainer
#16 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Ingo Molnar

So I checked my NHM box with your latest queue and it now works correctly. Do you have any idea what the difference is/was?

Sadly, no clue :/

Quoted 8 lines
Quoted 2 lines

I went over those patches and cannot find anything that should affect NHM (or <=SNB in fact).

Oh wait, I spoke too soon, the two new patches affect everything with PEBS. And esp. the latter one:

lkml.kernel.org/r/[email protected]

If that is the patch that makes your NHM go again, then running 2 concurrent perf-top sessions should make it all go dark again.

#17 lore raw

Re: [tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Quoted 12 lines · Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Quoted 2 lines · Ingo Molnar

So I checked my NHM box with your latest queue and it now works correctly. Do you have any idea what the difference is/was?

Sadly, no clue :/

I went over those patches and cannot find anything that should affect NHM (or <=SNB in fact).

Quoted 8 lines
Quoted 5 lines

Oh wait, I spoke too soon, the two new patches affect everything with PEBS. And esp. the latter one:

lkml.kernel.org/r/[email protected]

If that is the patch that makes your NHM go again, then running 2 concurrent perf-top sessions should make it all go dark again.

Hm, so I tried again your latest perf/urgent (1221fc3b3e3a) merged into tip:master (c9586e904a68), and booted it on the NHM, but 'perf top' refuses to break.

One thing that was special about my first NHM test was that it conducted an about 24 hours perf stress. OTOH 'cycles:p' did work, it was only 'cycles:pp' that was producing no events whatsoever - so it wasn't a total breakage, only :pp related.

Weird ...

Thanks,

Ingo

#18 lore raw

[tip:perf/core] perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

In reply to Andi Kleen
perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp
Commit-ID:  724697648eec540b2a7561089b1c87cb33e6a0eb
Gitweb:     http://git.kernel.org/tip/724697648eec540b2a7561089b1c87cb33e6a0eb
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 4 Dec 2015 03:50:52 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 6 Jan 2016 11:15:32 +0100

perf/x86: Use INST_RETIRED.PREC_DIST for cycles: ppp

Add a new 'three-p' precise level, that uses INST_RETIRED.PREC_DIST as base. The basic mechanism of abusing the inverse cmask to get all cycles works the same as before.

PREC_DIST is available on Sandy Bridge or later. It had some problems on Sandy Bridge, so we only use it on IvyBridge and later. I tested it on Broadwell and Skylake.

PREC_DIST has special support for avoiding shadow effects, which can give better results compare to UOPS_RETIRED. The drawback is that PREC_DIST can only schedule on counter 1, but that is ok for cycle sampling, as there is normally no need to do multiple cycle sampling runs in parallel. It is still possible to run perf top in parallel, as that doesn't use precise mode. Also of course the multiplexing can still allow parallel operation.

:pp stays with the previous event.

Example:

Sample a loop with 10 sqrt with old cycles:pp

	  0.14 │10:   sqrtps %xmm1,%xmm0     <--------------
	  9.13 │      sqrtps %xmm1,%xmm0
	 11.58 │      sqrtps %xmm1,%xmm0
	 11.51 │      sqrtps %xmm1,%xmm0
	  6.27 │      sqrtps %xmm1,%xmm0
	 10.38 │      sqrtps %xmm1,%xmm0
	 12.20 │      sqrtps %xmm1,%xmm0
	 12.74 │      sqrtps %xmm1,%xmm0
	  5.40 │      sqrtps %xmm1,%xmm0
	 10.14 │      sqrtps %xmm1,%xmm0
	 10.51 │    ↑ jmp    10

We expect all 10 sqrt to get roughly the sample number of samples.

But you can see that the instruction directly after the JMP is systematically underestimated in the result, due to sampling shadow effects.

With the new PREC_DIST based sampling this problem is gone and all instructions show up roughly evenly:

	  9.51 │10:   sqrtps %xmm1,%xmm0
	 11.74 │      sqrtps %xmm1,%xmm0
	 11.84 │      sqrtps %xmm1,%xmm0
	  6.05 │      sqrtps %xmm1,%xmm0
	 10.46 │      sqrtps %xmm1,%xmm0
	 12.25 │      sqrtps %xmm1,%xmm0
	 12.18 │      sqrtps %xmm1,%xmm0
	  5.26 │      sqrtps %xmm1,%xmm0
	 10.13 │      sqrtps %xmm1,%xmm0
	 10.43 │      sqrtps %xmm1,%xmm0
	  0.16 │    ↑ jmp    10

Even with PREC_DIST there is still sampling skid and the result is not completely even, but systematic shadow effects are significantly reduced.

The improvements are mainly expected to make a difference in high IPC code. With low IPC it should be similar.

---
 arch/x86/kernel/cpu/perf_event.c          |  3 ++
 arch/x86/kernel/cpu/perf_event.h          |  3 +-
 arch/x86/kernel/cpu/perf_event_intel.c    | 50 ++++++++++++++++++++++++++++---
 arch/x86/kernel/cpu/perf_event_intel_ds.c |  6 ++++
 4 files changed, 57 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/perf_event.c +3 -0
index 9dfbba5..e7e63a9 100644
@@ -482,6 +482,9 @@ int x86_pmu_hw_config(struct perf_event *event)
 			/* Support for IP fixup */
 			if (x86_pmu.lbr_nr || x86_pmu.intel_cap.pebs_format >= 2)
 				precise++;
+
+			if (x86_pmu.pebs_prec_dist)
+				precise++;
 		}
 
 		if (event->attr.precise_ip > precise)
arch/x86/kernel/cpu/perf_event.h +2 -1
index 799e6bd..ce8768f 100644
@@ -583,7 +583,8 @@ struct x86_pmu {
 			bts_active	:1,
 			pebs		:1,
 			pebs_active	:1,
-			pebs_broken	:1;
+			pebs_broken	:1,
+			pebs_prec_dist	:1;
 	int		pebs_record_size;
 	void		(*drain_pebs)(struct pt_regs *regs);
 	struct event_constraint *pebs_constraints;
arch/x86/kernel/cpu/perf_event_intel.c +46 -4

80 lines not on this page · raw message

arch/x86/kernel/cpu/perf_event_intel_ds.c +6 -0
index 56b5015..9c0f8d4 100644
@@ -686,6 +686,8 @@ struct event_constraint intel_ivb_pebs_event_constraints[] = {
 	INTEL_PST_CONSTRAINT(0x02cd, 0x8),    /* MEM_TRANS_RETIRED.PRECISE_STORES */
 	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	INTEL_EXCLEVT_CONSTRAINT(0xd0, 0xf),    /* MEM_UOP_RETIRED.* */
 	INTEL_EXCLEVT_CONSTRAINT(0xd1, 0xf),    /* MEM_LOAD_UOPS_RETIRED.* */
 	INTEL_EXCLEVT_CONSTRAINT(0xd2, 0xf),    /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
@@ -700,6 +702,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 	INTEL_PLD_CONSTRAINT(0x01cd, 0xf),    /* MEM_TRANS_RETIRED.* */
 	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_NA(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XLD(0x11d0, 0xf), /* MEM_UOPS_RETIRED.STLB_MISS_LOADS */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XLD(0x21d0, 0xf), /* MEM_UOPS_RETIRED.LOCK_LOADS */
@@ -718,6 +722,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 
 struct event_constraint intel_skl_pebs_event_constraints[] = {
 	INTEL_FLAGS_UEVENT_CONSTRAINT(0x1c0, 0x2),	/* INST_RETIRED.PREC_DIST */
+	/* INST_RETIRED.PREC_DIST, inv=1, cmask=16 (cycles:ppp). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c0, 0x2),
 	/* INST_RETIRED.TOTAL_CYCLES_PS (inv=1, cmask=16) (cycles:p). */
 	INTEL_FLAGS_EVENT_CONSTRAINT(0x108000c0, 0x0f),
 	INTEL_PLD_CONSTRAINT(0x1cd, 0xf),		      /* MEM_TRANS_RETIRED.* */
maintainer
#19 lore raw
In reply to Andi Kleen

arch/x86/kernel/cpu/perf_event_intel_ds.c struct event_constraint intel_hsw_pebs_event_constraints[] = { · line 722

Quoted 2 lines · Andi Kleen
arch/x86/kernel/cpu/perf_event_intel_ds.c +2 -0
+	/* INST_RETIRED.TOTAL_CYCLES_PS (inv=1, cmask=16) (cycles:p). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108000c0, 0x01),

Hmm, so this event is still limited to a single counter. Better than nothing I suppose.

Thanks!

#20 lore raw

[tip:perf/core] perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

In reply to Andi Kleen
perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake
Commit-ID:  ac1e1d30cf90fdc7716150a9c130bdd7d7b9fdd9
Gitweb:     http://git.kernel.org/tip/ac1e1d30cf90fdc7716150a9c130bdd7d7b9fdd9
Author:     Andi Kleen <[email protected]>
AuthorDate: Mon, 30 Nov 2015 16:28:08 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Dec 2015 10:08:04 +0100

perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

I added UOPS_RETIRED.ALL by mistake to the Skylake PEBS event list for cycles:pp. But the event is not documented for Skylake, and has some issues.

The recommended replacement for cycles:pp is to use INST_RETIRED.ANY+pebs as a base, similar to what CPUs before Sandy Bridge did. This new event is called INST_RETIRED.TOTAL_CYCLES_PS. The event is not really new, but has been already used by perf before Sandy Bridge for the original cycles:p

Note the SDM doesn't document that event either, but it's being documented in the latest version of the event list on:

https://download.01.org/perfmon/SKL

This patch does:

- Remove UOPS_RETIRED.ALL from the Skylake PEBS event list

- Add INST_RETIRED.ANY to the Skylake PEBS event list, and an table entry to allow cmask=16,inv=1 for cycles:pp

- We don't need an extra entry for the base INST_RETIRED event, because it is already covered by the catch-all PEBS table entry.

- Switch Skylake to use the Core2 PEBS alias (which is INST_RETIRED.TOTAL_CYCLES_PS)

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
---
 arch/x86/kernel/cpu/perf_event_intel.c    | 2 +-
 arch/x86/kernel/cpu/perf_event_intel_ds.c | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/perf_event_intel.c +1 -1
index f63360b..e7daab3 100644
@@ -3521,7 +3521,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.event_constraints = intel_skl_event_constraints;
 		x86_pmu.pebs_constraints = intel_skl_pebs_event_constraints;
 		x86_pmu.extra_regs = intel_skl_extra_regs;
-		x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
+		x86_pmu.pebs_aliases = intel_pebs_aliases_core2;
 		/* all extra regs are per-cpu when HT is on */
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
arch/x86/kernel/cpu/perf_event_intel_ds.c +2 -3
index 5db1c77..dcab005 100644
@@ -718,9 +718,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 
 struct event_constraint intel_skl_pebs_event_constraints[] = {
 	INTEL_FLAGS_UEVENT_CONSTRAINT(0x1c0, 0x2),	/* INST_RETIRED.PREC_DIST */
-	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_NA(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
-	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
-	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.TOTAL_CYCLES_PS (inv=1, cmask=16) (cycles:p). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108000c0, 0x01),
 	INTEL_PLD_CONSTRAINT(0x1cd, 0xf),		      /* MEM_TRANS_RETIRED.* */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD(0x11d0, 0xf), /* MEM_INST_RETIRED.STLB_MISS_LOADS */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST(0x12d0, 0xf), /* MEM_INST_RETIRED.STLB_MISS_STORES */
#21 lore raw

[tip:perf/core] perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

In reply to Andi Kleen
perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake
Commit-ID:  442f5c74cbeaf54939980397ece59360c0a824e9
Gitweb:     http://git.kernel.org/tip/442f5c74cbeaf54939980397ece59360c0a824e9
Author:     Andi Kleen <[email protected]>
AuthorDate: Fri, 4 Dec 2015 03:50:32 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 6 Jan 2016 11:15:32 +0100

perf/x86: Use INST_RETIRED.TOTAL_CYCLES_PS for cycles:pp for Skylake

I added UOPS_RETIRED.ALL by mistake to the Skylake PEBS event list for cycles:pp. But the event is not documented for Skylake, and has some issues.

The recommended replacement for cycles:pp is to use INST_RETIRED.ANY+pebs as a base, similar to what CPUs before Sandy Bridge did. This new event is called INST_RETIRED.TOTAL_CYCLES_PS. The event is not really new, but has been already used by perf before Sandy Bridge for the original cycles:p

Note the SDM doesn't document that event either, but it's being documented in the latest version of the event list on:

https://download.01.org/perfmon/SKL

This patch does:

- Remove UOPS_RETIRED.ALL from the Skylake PEBS event list

- Add INST_RETIRED.ANY to the Skylake PEBS event list, and an table entry to allow cmask=16,inv=1 for cycles:pp

- We don't need an extra entry for the base INST_RETIRED event, because it is already covered by the catch-all PEBS table entry.

- Switch Skylake to use the Core2 PEBS alias (which is INST_RETIRED.TOTAL_CYCLES_PS)

---
 arch/x86/kernel/cpu/perf_event_intel.c    | 2 +-
 arch/x86/kernel/cpu/perf_event_intel_ds.c | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/perf_event_intel.c +1 -1
index 33b4b67..5ed6e0d 100644
@@ -3521,7 +3521,7 @@ __init int intel_pmu_init(void)
 		x86_pmu.event_constraints = intel_skl_event_constraints;
 		x86_pmu.pebs_constraints = intel_skl_pebs_event_constraints;
 		x86_pmu.extra_regs = intel_skl_extra_regs;
-		x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
+		x86_pmu.pebs_aliases = intel_pebs_aliases_core2;
 		/* all extra regs are per-cpu when HT is on */
 		x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 		x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
arch/x86/kernel/cpu/perf_event_intel_ds.c +2 -3
index cd1993e..56b5015 100644
@@ -718,9 +718,8 @@ struct event_constraint intel_hsw_pebs_event_constraints[] = {
 
 struct event_constraint intel_skl_pebs_event_constraints[] = {
 	INTEL_FLAGS_UEVENT_CONSTRAINT(0x1c0, 0x2),	/* INST_RETIRED.PREC_DIST */
-	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_NA(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
-	/* UOPS_RETIRED.ALL, inv=1, cmask=16 (cycles:p). */
-	INTEL_FLAGS_EVENT_CONSTRAINT(0x108001c2, 0xf),
+	/* INST_RETIRED.TOTAL_CYCLES_PS (inv=1, cmask=16) (cycles:p). */
+	INTEL_FLAGS_EVENT_CONSTRAINT(0x108000c0, 0x0f),
 	INTEL_PLD_CONSTRAINT(0x1cd, 0xf),		      /* MEM_TRANS_RETIRED.* */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD(0x11d0, 0xf), /* MEM_INST_RETIRED.STLB_MISS_LOADS */
 	INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST(0x12d0, 0xf), /* MEM_INST_RETIRED.STLB_MISS_STORES */