powerpc/perf: Adds support for programming of Thresholding in P10
PATCH v2 1/1 powerpc/perf: Adds support for programming of Thresholding in P10
Thresholding, a performance monitoring unit feature, can be used to identify marked instructions which take more than expected cycles between start event and end event. Threshold compare (thresh_cmp) bits are programmed in MMCRA register. In Power9, thresh_cmp bits were part of the event code. But in case of P10, thresh_cmp are not part of event code due to inclusion of MMCR3 bits.
Patch here adds an option to use attr.config1 variable to be used to pass thresh_cmp value to be programmed in MMCRA register. A new ppmu flag called PPMU_HAS_ATTR_CONFIG1 has been added and this flag is used to notify the use of attr.config1 variable.
Patch has extended the parameter list of 'compute_mmcr', to include power_pmu's 'flags' element and parameter list of get_constraint to include attr.config1 value.
As stated by commit ef0e3b650f8d ("powerpc/perf: Fix Threshold Event Counter Multiplier width for P10"), constraint bits for thresh_cmp is also needed to be increased to 11 bits, which is handled as part of this patch. We added bit number 53 as part of constraint bits of thresh_cmp for power10 to make it an 11 bit field.
Updated layout for p10:
/*
* Layout of constraint bits:
*
* 60 56 52 48 44 40 36 32
* | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
* [ fab_match ] [ thresh_cmp ] [ thresh_ctl ] [ ]
* | |
* [ thresh_cmp bits for p10] thresh_sel -*
*
* 28 24 20 16 12 8 4 0
* | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
* [ ] | [ ] | [ sample ] [ ] [6] [5] [4] [3] [2] [1] * | | | | | * BHRB IFM -* | | |*radix_scope | Count of events for each PMC.
* EBB -* | | p1, p2, p3, p4, p5, p6.
* L1 I/D qualifier -* |
* nc - number of counters -*
*
* The PMC fields P1..P6, and NC, are adder fields. As we accumulate constraints
* we want the low bit of each field to be added to any existing value. *
* Everything else is a value field.
*/
Result:
command#: cat /sys/devices/cpu/format/thresh_cmp
config1:0-17
ex. usage:
command#: perf record -I --weight -d -e
cpu/event=0x67340101EC,thresh_cmp=500/ ./ebizzy -S 2 -t 1 -s 4096 1826636 records/s real 2.00 s user 2.00 s sys 0.00 s
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.038 MB perf.data (61 samples) ]
--- arch/powerpc/include/asm/perf_event_server.h | 5 +- arch/powerpc/perf/core-book3s.c | 24 +++++-- arch/powerpc/perf/isa207-common.c | 71 +++++++++++++++++--- arch/powerpc/perf/isa207-common.h | 15 +++-- arch/powerpc/perf/mpc7450-pmu.c | 5 +- arch/powerpc/perf/power10-pmu.c | 4 +- arch/powerpc/perf/power5+-pmu.c | 5 +- arch/powerpc/perf/power5-pmu.c | 5 +- arch/powerpc/perf/power6-pmu.c | 5 +- arch/powerpc/perf/power7-pmu.c | 5 +- arch/powerpc/perf/ppc970-pmu.c | 5 +- 11 files changed, 116 insertions(+), 33 deletions(-)
---
Changelog
v1 -> v2
- Add new function 'p10_thresh_cmp_val' to evaluate thresh_cmp value.
- Extended the parameter list of get_constraint function to include attr.config1 value.
- Added bit number 53 as part of constraint bits of thresh_cmp to make it a 11 bit field for power10.
- Updated PPMU_HAS_ATTR_CONFIG1 value to 0x00000800
- Add new field 'events_config1' in struct cpu_hw_events and also update this field in all required functions accordingly.
---
arch/powerpc/include/asm/perf_event_server.h +3 -2
@@ -36,9 +36,9 @@ struct power_pmu {unsigned long test_adder;int (*compute_mmcr)(u64 events[],int n_ev,unsigned int hwc[],struct mmcr_regs *mmcr, -struct perf_event *pevents[]); +struct perf_event *pevents[],u32 flags);int (*get_constraint)(u64 event_id,unsigned long *mskp, -unsigned long *valp); +unsigned long *valp,u64 event_config1);int (*get_alternatives)(u64 event_id,unsigned int flags,u64 alt[]); void (*get_mem_data_src)(union perf_mem_data_src *dsrc,
@@ -83,6 +83,7 @@ struct power_pmu {#define PPMU_NO_SIAR 0x00000100/* Do not use SIAR */ #define PPMU_ARCH_31 0x00000200/* Has MMCR3, SIER2 and SIER3 */ #define PPMU_P10_DD1 0x00000400/* Is power10 DD1 processor version */ +#define PPMU_HAS_ATTR_CONFIG1 0x00000800/* Using config1 attribute */ /* * Values for flags to get_alternatives()
arch/powerpc/perf/core-book3s.c +18 -6
@@ -36,6 +36,7 @@ struct cpu_hw_events {u8 pmcs_enabled;struct perf_event *event[MAX_HWEVENTS ];u64 events[MAX_HWEVENTS ]; +u64 events_config1[MAX_HWEVENTS ];unsigned int flags[MAX_HWEVENTS ];struct mmcr_regs mmcr;struct perf_event *limited_counter[MAX_LIMITED_HWCOUNTERS ];
@@ -938,7 +939,7 @@ static int power_check_constraints(struct cpu_hw_events *cpuhw, event_id[i] = cpuhw->alternatives[i][0 ]; }if (ppmu->get_constraint (event_id[i], &cpuhw->amasks[i][0 ], - &cpuhw->avalues[i][0 ])) + &cpuhw->avalues[i][0 ], cpuhw->events_config1[i]))return -1 ; } value = mask =0 ;
@@ -973,7 +974,8 @@ static int power_check_constraints(struct cpu_hw_events *cpuhw,for (j =1 ; j < n_alt[i]; ++j) ppmu->get_constraint (cpuhw->alternatives[i][j], &cpuhw->amasks[i][j], - &cpuhw->avalues[i][j]); + &cpuhw->avalues[i][j], + cpuhw->events_config1[i]); }/* enumerate all possibilities and see if any will work */
@@ -1391,7 +1393,7 @@ static void power_pmu_enable(struct pmu *pmu)memset (&cpuhw->mmcr,0 ,sizeof (cpuhw->mmcr));if (ppmu->compute_mmcr (cpuhw->events, cpuhw->n_events, hwc_index, - &cpuhw->mmcr, cpuhw->event)) { + &cpuhw->mmcr, cpuhw->event, ppmu->flags)) {/* shouldn't ever get here */ printk (KERN_ERR "oops compute_mmcr failed\n" ); goto out;
@@ -1505,7 +1507,7 @@ static void power_pmu_enable(struct pmu *pmu)static int collect_events (struct perf_event *group,int max_count,struct perf_event *ctrs[],u64 *events, -unsigned int *flags) +unsigned int *flags,u64 *events_config1) {int n =0 ;struct perf_event *event;
@@ -1515,6 +1517,7 @@ static int collect_events(struct perf_event *group, int max_count,return -1 ; ctrs[n] = group; flags[n] = group->hw.event_base; + events_config1[n] = group->hw.extra_reg.config; events[n++] = group->hw.config; }for_each_sibling_event (event, group) {
@@ -1524,6 +1527,7 @@ static int collect_events(struct perf_event *group, int max_count,return -1 ; ctrs[n] = event; flags[n] = event->hw.event_base; + events_config1[n] = event->hw.extra_reg.config; events[n++] = event->hw.config; } }
@@ -1556,6 +1560,7 @@ static int power_pmu_add(struct perf_event *event, int ef_flags) goto out; cpuhw->event[n0] = event; cpuhw->events[n0] = event->hw.config; + cpuhw->events_config1[n0] = event->hw.extra_reg.config; cpuhw->flags[n0] = event->hw.event_base;/*
@@ -1582,6 +1587,7 @@ static int power_pmu_add(struct perf_event *event, int ef_flags)if (power_check_constraints (cpuhw, cpuhw->events, cpuhw->flags, n0 +1 )) goto out; event->hw.config = cpuhw->events[n0]; + event->hw.extra_reg.config = cpuhw->events_config1[n0]; nocheck:ebb_event_add (event);
@@ -1629,6 +1635,7 @@ static void power_pmu_del(struct perf_event *event, int ef_flags)while (++i < cpuhw->n_events) { cpuhw->event[i-1 ] = cpuhw->event[i]; cpuhw->events[i-1 ] = cpuhw->events[i]; + cpuhw->events_config1[i -1 ] = cpuhw->events_config1[i]; cpuhw->flags[i-1 ] = cpuhw->flags[i]; } --cpuhw->n_events;
@@ -1793,8 +1800,10 @@ static int power_pmu_commit_txn(struct pmu *pmu)if (i <0 )return -EAGAIN ; -for (i = cpuhw->n_txn_start; i < n; ++i) +for (i = cpuhw->n_txn_start; i < n; ++i) { cpuhw->event[i]->hw.config = cpuhw->events[i]; + cpuhw->event[i]->hw.extra_reg.config = cpuhw->events_config1[i]; + } cpuhw->txn_flags =0 ;perf_pmu_enable (pmu);
@@ -1919,6 +1928,7 @@ static int power_pmu_event_init(struct perf_event *event)unsigned long flags, irq_flags;struct perf_event *ctrs[MAX_HWEVENTS ];u64 events[MAX_HWEVENTS ]; +u64 events_config1[MAX_HWEVENTS ];unsigned int cflags[MAX_HWEVENTS ];int n;int err;
@@ -2014,11 +2024,12 @@ static int power_pmu_event_init(struct perf_event *event) n =0 ;if (event->group_leader != event) { n =collect_events (event->group_leader, ppmu->n_counter -1 , - ctrs, events, cflags); + ctrs, events, cflags, events_config1);if (n <0 )return -EINVAL ; } events[n] = ev; + events_config1[n] = event->attr.config1; ctrs[n] = event; cflags[n] = flags;if (check_excludes (ctrs, cflags, n,1 ))
@@ -2048,6 +2059,7 @@ static int power_pmu_event_init(struct perf_event *event)return -EINVAL ; event->hw.config = events[n]; + event->hw.extra_reg.config = events_config1[n]; event->hw.event_base = cflags[n]; event->hw.last_period = event->hw.sample_period;local64_set (&event->hw.period_left, event->hw.last_period);
arch/powerpc/perf/isa207-common.c +63 -8
117 lines not on this page · raw message
arch/powerpc/perf/isa207-common.h +11 -4
@@ -105,6 +105,10 @@#define p10_EVENT_RADIX_SCOPE_QUAL_MASK 0x1#define p10_MMCR1_RADIX_SCOPE_QUAL_SHIFT 45 +/* Event Threshold Compare bit constant for power10 in config1 attribute */ +#define p10_EVENT_THR_CMP_SHIFT 0 +#define p10_EVENT_THR_CMP_MASK 0x3FFFFull +#define p10_EVENT_VALID_MASK \ ((p10_SDAR_MODE_MASK << p10_SDAR_MODE_SHIFT | \ (p10_EVENT_THRESH_MASK << EVENT_THRESH_SHIFT) | \
@@ -124,8 +128,8 @@* 60 56 52 48 44 40 36 32 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | * [ fab_match ] [ thresh_cmp ] [ thresh_ctl ] [ ] -* | -* thresh_sel -* +* | | +* [ thresh_cmp bits for p10] thresh_sel -* * * 28 24 20 16 12 8 4 0 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
@@ -152,6 +156,9 @@#define CNST_THRESH_CTL_SEL_VAL (v) (((v) & 0x7ffull) << 32)#define CNST_THRESH_CTL_SEL_MASK CNST_THRESH_CTL_SEL_VAL(0x7ff) +#define p10_CNST_THRESH_CMP_VAL (v) (((v) & 0x7ffull) << 43) +#define p10_CNST_THRESH_CMP_MASK p10_CNST_THRESH_CMP_VAL(0x7ff) +#define CNST_EBB_VAL (v) (((v) & EVENT_EBB_MASK) << 24)#define CNST_EBB_MASK CNST_EBB_VAL(EVENT_EBB_MASK)
@@ -262,10 +269,10 @@#define PH (a, b) (P(LVL, HIT) | P(a, b))#define PM (a, b) (P(LVL, MISS) | P(a, b)) -int isa207_get_constraint (u64 event,unsigned long *maskp,unsigned long *valp); +int isa207_get_constraint (u64 event,unsigned long *maskp,unsigned long *valp,u64 event_config1);int isa207_compute_mmcr (u64 event[],int n_ev,unsigned int hwc[],struct mmcr_regs *mmcr, -struct perf_event *pevents[]); +struct perf_event *pevents[],u32 flags);void isa207_disable_pmc (unsigned int pmc,struct mmcr_regs *mmcr);int isa207_get_alternatives (u64 event,u64 alt[],int size,unsigned int flags,const unsigned int ev_alt[][MAX_ALT ]);
arch/powerpc/perf/mpc7450-pmu.c +3 -2
@@ -148,7 +148,7 @@ static u32 classbits[N_CLASSES - 1][2] = { };static int mpc7450_get_constraint (u64 event,unsigned long *maskp, -unsigned long *valp) +unsigned long *valp,u64 event_config1__maybe_unused ) {int pmc, class;u32 mask, value;
@@ -258,7 +258,8 @@ static const u32 pmcsel_mask[N_COUNTER] = {*/ static int mpc7450_compute_mmcr (u64 event[],int n_ev,unsigned int hwc[],struct mmcr_regs *mmcr, -struct perf_event *pevents[]) +struct perf_event *pevents[], +u32 flags__maybe_unused ) {u8 event_index[N_CLASSES ][N_COUNTER ];int n_classevent[N_CLASSES ];
arch/powerpc/perf/power10-pmu.c +3 -1
@@ -216,6 +216,7 @@ PMU_FORMAT_ATTR(invert_bit, "config:47");PMU_FORMAT_ATTR (src_mask,"config:48-53" );PMU_FORMAT_ATTR (src_match,"config:54-59" );PMU_FORMAT_ATTR (radix_scope,"config:9" ); +PMU_FORMAT_ATTR (thresh_cmp,"config1:0-17" );static struct attribute *power10_pmu_format_attr[] = { &format_attr_event.attr,
@@ -236,6 +237,7 @@ static struct attribute *power10_pmu_format_attr[] = { &format_attr_src_mask.attr, &format_attr_src_match.attr, &format_attr_radix_scope.attr, + &format_attr_thresh_cmp.attr, NULL, };
@@ -550,7 +552,7 @@ static struct power_pmu power10_pmu = { .get_mem_weight = isa207_get_mem_weight, .disable_pmc = isa207_disable_pmc, .flags =PPMU_HAS_SIER |PPMU_ARCH_207S | - PPMU_ARCH_31, + PPMU_ARCH_31 | PPMU_HAS_ATTR_CONFIG1, .n_generic = ARRAY_SIZE(power10_generic_events), .generic_events = power10_generic_events, .cache_events = &power10_cache_events,
arch/powerpc/perf/power5+-pmu.c +3 -2
@@ -132,7 +132,7 @@ static unsigned long unit_cons[PM_LASTUNIT+1][2] = { };static int power5p_get_constraint (u64 event,unsigned long *maskp, -unsigned long *valp) +unsigned long *valp,u64 event_config1__maybe_unused ) {int pmc, byte, unit, sh;int bit, fmask;
@@ -451,7 +451,8 @@ static int power5p_marked_instr_event(u64 event)static int power5p_compute_mmcr (u64 event[],int n_ev,unsigned int hwc[],struct mmcr_regs *mmcr, -struct perf_event *pevents[]) +struct perf_event *pevents[], +u32 flags__maybe_unused ) {unsigned long mmcr1 =0 ;unsigned long mmcra =0 ;
arch/powerpc/perf/power5-pmu.c +3 -2
@@ -136,7 +136,7 @@ static unsigned long unit_cons[PM_LASTUNIT+1][2] = { };static int power5_get_constraint (u64 event,unsigned long *maskp, -unsigned long *valp) +unsigned long *valp,u64 event_config1__maybe_unused ) {int pmc, byte, unit, sh;int bit, fmask;
@@ -382,7 +382,8 @@ static int power5_marked_instr_event(u64 event)static int power5_compute_mmcr (u64 event[],int n_ev,unsigned int hwc[],struct mmcr_regs *mmcr, -struct perf_event *pevents[]) +struct perf_event *pevents[], +u32 flags__maybe_unused ) {unsigned long mmcr1 =0 ;unsigned long mmcra =MMCRA_SDAR_DCACHE_MISS |MMCRA_SDAR_ERAT_MISS ;
arch/powerpc/perf/power6-pmu.c +3 -2
@@ -173,7 +173,8 @@ static int power6_marked_instr_event(u64 event)* Assign PMC numbers and compute MMCR1 value for a set of events */ static int p6_compute_mmcr (u64 event[],int n_ev, -unsigned int hwc[],struct mmcr_regs *mmcr,struct perf_event *pevents[]) +unsigned int hwc[],struct mmcr_regs *mmcr,struct perf_event *pevents[], +u32 flags__maybe_unused ) {unsigned long mmcr1 =0 ;unsigned long mmcra =MMCRA_SDAR_DCACHE_MISS |MMCRA_SDAR_ERAT_MISS ;
@@ -266,7 +267,7 @@ static int p6_compute_mmcr(u64 event[], int n_ev,* 32-34 select field: nest (subunit) event selector */ static int p6_get_constraint (u64 event,unsigned long *maskp, -unsigned long *valp) +unsigned long *valp,u64 event_config1__maybe_unused ) {int pmc, byte, sh, subunit;unsigned long mask =0 , value =0 ;
arch/powerpc/perf/power7-pmu.c +3 -2
@@ -81,7 +81,7 @@ enum {*/ static int power7_get_constraint (u64 event,unsigned long *maskp, -unsigned long *valp) +unsigned long *valp,u64 event_config1__maybe_unused ) {int pmc, sh, unit;unsigned long mask =0 , value =0 ;
@@ -245,7 +245,8 @@ static int power7_marked_instr_event(u64 event)static int power7_compute_mmcr (u64 event[],int n_ev,unsigned int hwc[],struct mmcr_regs *mmcr, -struct perf_event *pevents[]) +struct perf_event *pevents[], +u32 flags__maybe_unused ) {unsigned long mmcr1 =0 ;unsigned long mmcra =MMCRA_SDAR_DCACHE_MISS |MMCRA_SDAR_ERAT_MISS ;
arch/powerpc/perf/ppc970-pmu.c +3 -2
@@ -190,7 +190,7 @@ static unsigned long unit_cons[PM_LASTUNIT+1][2] = { };static int p970_get_constraint (u64 event,unsigned long *maskp, -unsigned long *valp) +unsigned long *valp,u64 event_config1__maybe_unused ) {int pmc, byte, unit, sh, spcsel;unsigned long mask =0 , value =0 ;
@@ -256,7 +256,8 @@ static int p970_get_alternatives(u64 event, unsigned int flags, u64 alt[])static int p970_compute_mmcr (u64 event[],int n_ev,unsigned int hwc[],struct mmcr_regs *mmcr, -struct perf_event *pevents[]) +struct perf_event *pevents[], +u32 flags__maybe_unused ) {unsigned long mmcr0 =0 , mmcr1 =0 , mmcra =0 ;unsigned int pmc, unit, byte, psel;
Signature · 1 line
2.27.0