powerpc/perf: Factor of event_alternative function
PATCH v2 1/6 powerpc/perf: Factor of event_alternative function
Factor out the power8 event_alternative function to share the code with power9.
---
Changelog v1:
No changes to this patch, just a rebase
arch/powerpc/perf/isa207-common.c | 36 ++++++++++++++++++++++++++++++++++++ arch/powerpc/perf/isa207-common.h | 3 +++ arch/powerpc/perf/power8-pmu.c | 35 ++--------------------------------- 3 files changed, 41 insertions(+), 33 deletions(-)
arch/powerpc/perf/isa207-common.c +36 -0
@@ -338,3 +338,39 @@ void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[])if (pmc <=3 ) mmcr[1 ] &= ~(0xffUL <<MMCR1_PMCSEL_SHIFT (pmc +1 )); } + +static int find_alternative (u64 event,const unsigned int ev_alt[][MAX_ALT ],int size) +{ +int i, j; + +for (i =0 ; i < size; ++i) { +if (event < ev_alt[i][0 ]) +break ; + +for (j =0 ; j <MAX_ALT && ev_alt[i][j]; ++j) +if (event == ev_alt[i][j]) +return i; + } + +return -1 ; +} + +int isa207_get_alternatives (u64 event,u64 alt[], +const unsigned int ev_alt[][MAX_ALT ],int size) +{ +int i, j, num_alt =0 ; +u64 alt_event; + + alt[num_alt++] = event; + i =find_alternative (event, ev_alt, size); +if (i >=0 ) { +/* Filter out the original event, it's already in alt[0] */ +for (j =0 ; j <MAX_ALT ; ++j) { + alt_event = ev_alt[i][j]; +if (alt_event && alt_event != event) + alt[num_alt++] = alt_event; + } + } + +return num_alt; +}
arch/powerpc/perf/isa207-common.h +3 -0
@@ -260,5 +260,8 @@ int isa207_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[]);void isa207_disable_pmc (unsigned int pmc,unsigned long mmcr[]); +int isa207_get_alternatives (u64 event,u64 alt[], +const unsigned int ev_alt[][MAX_ALT ],int size); +#endif
arch/powerpc/perf/power8-pmu.c +2 -33
@@ -48,43 +48,12 @@ static const unsigned int event_alternatives[][MAX_ALT] = { { PM_RUN_INST_CMPL_ALT, PM_RUN_INST_CMPL }, }; -/* -* Scan the alternatives table for a match and return the -* index into the alternatives table if found, else -1. -*/ -static int find_alternative (u64 event) -{ -int i, j; - -for (i =0 ; i <ARRAY_SIZE (event_alternatives); ++i) { -if (event < event_alternatives[i][0 ]) -break ; - -for (j =0 ; j <MAX_ALT && event_alternatives[i][j]; ++j) -if (event == event_alternatives[i][j]) -return i; - } - -return -1 ; -} -static int power8_get_alternatives (u64 event,unsigned int flags,u64 alt[]) {int i, j, num_alt =0 ; -u64 alt_event; - - alt[num_alt++] = event; - - i =find_alternative (event); -if (i >=0 ) { -/* Filter out the original event, it's already in alt[0] */ -for (j =0 ; j <MAX_ALT ; ++j) { - alt_event = event_alternatives[i][j]; -if (alt_event && alt_event != event) - alt[num_alt++] = alt_event; - } - } + num_alt =isa207_get_alternatives (event, alt, event_alternatives, + (int )ARRAY_SIZE (event_alternatives));if (flags &PPMU_ONLY_COUNT_RUN ) {/* * We're only counting in RUN state, so PM_CYC is equivalent to
Signature · 1 line
2.7.4
PATCH v2 2/6 powerpc/perf: Add PM_INST_DISP event to Power9 event list
---
Changelog v1:
Fix the event code.
arch/powerpc/perf/power9-events-list.h | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/perf/power9-events-list.h +3 -0
@@ -53,3 +53,6 @@ EVENT(PM_ITLB_MISS, 0x400fc)EVENT (PM_RUN_INST_CMPL ,0x500fa ) /* Run_cycles */EVENT (PM_RUN_CYC ,0x600f4 ) +/* Instruction Dispatched */ +EVENT(PM_INST_DISP, 0x200f2) +EVENT (PM_INST_DISP_ALT ,0x300f2 )
Signature · 1 line
2.7.4
PATCH v2 3/6 powerpc/perf: Add alternative event table and function for power9
In reply to Madhavan Srinivasan---
Change v1:
No changes, just a rebase
arch/powerpc/perf/power9-pmu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/powerpc/perf/power9-pmu.c +17 -0
@@ -106,6 +106,21 @@ enum {/* PowerISA v2.07 format attribute structure*/ extern struct attribute_group isa207_pmu_format_group; +/* Table of alternatives, sorted by column 0 */ +static const unsigned int power9_event_alternatives[][MAX_ALT ] = { + {PM_INST_DISP ,PM_INST_DISP_ALT }, +}; + +static int power9_get_alternatives (u64 event,unsigned int flags,u64 alt[]) +{ +int num_alt =0 ; + + num_alt =isa207_get_alternatives (event, alt, power9_event_alternatives, + (int )ARRAY_SIZE (power9_event_alternatives)); + +return num_alt; +} +GENERIC_EVENT_ATTR (cpu-cycles,PM_CYC );GENERIC_EVENT_ATTR (stalled-cycles-frontend,PM_ICT_NOSLOT_CYC );GENERIC_EVENT_ATTR (stalled-cycles-backend,PM_CMPLU_STALL );
@@ -383,6 +398,7 @@ static struct power_pmu power9_isa207_pmu = { .config_bhrb = power9_config_bhrb, .bhrb_filter_map = power9_bhrb_filter_map, .get_constraint = isa207_get_constraint, + .get_alternatives = power9_get_alternatives, .disable_pmc = isa207_disable_pmc, .flags = PPMU_NO_SIAR | PPMU_ARCH_207S, .n_generic = ARRAY_SIZE(power9_generic_events),
@@ -401,6 +417,7 @@ static struct power_pmu power9_pmu = { .config_bhrb = power9_config_bhrb, .bhrb_filter_map = power9_bhrb_filter_map, .get_constraint = isa207_get_constraint, + .get_alternatives = power9_get_alternatives, .disable_pmc = isa207_disable_pmc, .flags = PPMU_HAS_SIER | PPMU_ARCH_207S, .n_generic = ARRAY_SIZE(power9_generic_events),
Signature · 1 line
2.7.4
PATCH v2 4/6 powerpc/perf: Use PM_INST_DISP for generic instructions sample
In reply to Madhavan SrinivasanSince PM_INST_CMPL may not provide right counts in all sampling scenarios in power9 DD1, instead use PM_INST_DISP. Patch also update generic instruction sampling with the same.
---
Changelog v1:
Based on DD1 check, modified the event code to use for "instructions"
arch/powerpc/perf/power9-pmu.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
arch/powerpc/perf/power9-pmu.c +18 -2
@@ -228,6 +228,17 @@ static const struct attribute_group *power9_pmu_attr_groups[] = { NULL, }; +static int power9_generic_events_dd1[] = { + [PERF_COUNT_HW_CPU_CYCLES ] =PM_CYC , + [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND ] =PM_ICT_NOSLOT_CYC , + [PERF_COUNT_HW_STALLED_CYCLES_BACKEND ] =PM_CMPLU_STALL , + [PERF_COUNT_HW_INSTRUCTIONS ] =PM_INST_DISP , + [PERF_COUNT_HW_BRANCH_INSTRUCTIONS ] =PM_BRU_CMPL , + [PERF_COUNT_HW_BRANCH_MISSES ] =PM_BR_MPRED_CMPL , + [PERF_COUNT_HW_CACHE_REFERENCES ] =PM_LD_REF_L1 , + [PERF_COUNT_HW_CACHE_MISSES ] =PM_LD_MISS_L1_FIN , +}; +static int power9_generic_events[] = { [PERF_COUNT_HW_CPU_CYCLES ] =PM_CYC , [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND ] =PM_ICT_NOSLOT_CYC ,
@@ -401,8 +412,8 @@ static struct power_pmu power9_isa207_pmu = { .get_alternatives = power9_get_alternatives, .disable_pmc = isa207_disable_pmc, .flags = PPMU_NO_SIAR | PPMU_ARCH_207S, - .n_generic = ARRAY_SIZE(power9_generic_events), - .generic_events = power9_generic_events, + .n_generic = ARRAY_SIZE(power9_generic_events_dd1), + .generic_events = power9_generic_events_dd1, .cache_events = &power9_cache_events, .attr_groups = power9_isa207_pmu_attr_groups, .bhrb_nr = 32,
@@ -437,6 +448,11 @@ static int __init init_power9_pmu(void)return -ENODEV ;if (cpu_has_feature (CPU_FTR_POWER9_DD1 )) { +/* +* Since PM_INST_CMPL may not provide right counts in all +* sampling scenarios in power9 DD1, instead use PM_INST_DISP. +*/ +EVENT_VAR (PM_INST_CMPL , _g).id =PM_INST_DISP ; rc =register_power_pmu (&power9_isa207_pmu); }else { rc =register_power_pmu (&power9_pmu);
Signature · 1 line
2.7.4
PATCH v2 5/6 powerpc/perf: Use Instruction Counter value
In reply to Madhavan SrinivasanSince PM_INST_DISP include speculative instruction, based on the workload the dispatch count could vary considerably. Hence as an alternative, for completed instruction counting, program the PM_INST_DISP event to the MMCR* but use Instruction Counter register value.
---
Changelog v1:
1)Removed the #ifdef and added changes for EBB count updates
arch/powerpc/perf/core-book3s.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
arch/powerpc/perf/core-book3s.c +36 -0
@@ -57,6 +57,7 @@ struct cpu_hw_events {void *bhrb_context;struct perf_branch_stack bhrb_stack;struct perf_branch_entry bhrb_entries[BHRB_MAX_ENTRIES ]; +u64 ic_init; }; static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events);
@@ -127,6 +128,10 @@ static inline void power_pmu_bhrb_disable(struct perf_event *event) {}static void power_pmu_sched_task (struct perf_event_context *ctx,bool sched_in) {}static inline void power_pmu_bhrb_read (struct cpu_hw_events *cpuhw) {}static void pmao_restore_workaround (bool ebb) { } +static bool use_ic (u64 event) +{ +return false; +}#endif /* CONFIG_PPC32 */ static bool regs_use_siar (struct pt_regs *regs)
@@ -688,6 +693,15 @@ static void pmao_restore_workaround(bool ebb)mtspr (SPRN_PMC5 , pmcs[4 ]); mtspr(SPRN_PMC6, pmcs[5]); } + +static bool use_ic (u64 event) +{ +if (cpu_has_feature (CPU_FTR_POWER9_DD1 ) && + (event ==0x200f2 || event ==0x300f2 )) +return true; + +return false; +}#endif /* CONFIG_PPC64 */ static void perf_event_interrupt (struct pt_regs *regs);
@@ -1007,6 +1021,7 @@ static u64 check_and_compute_delta(u64 prev, u64 val)static void power_pmu_read (struct perf_event *event) {s64 val, delta, prev; +struct cpu_hw_events *cpuhw =this_cpu_ptr (&cpu_hw_events);if (event->hw.state &PERF_HES_STOPPED )return ;
@@ -1016,6 +1031,13 @@ static void power_pmu_read(struct perf_event *event)if (is_ebb_event (event)) { val =read_pmc (event->hw.idx); +if (use_ic (event->attr.config)) { + val =mfspr (SPRN_IC ); +if (val > cpuhw->ic_init) + val = val - cpuhw->ic_init; +else + val = val + (0 - cpuhw->ic_init); + }local64_set (&event->hw.prev_count, val);return ; }
@@ -1029,6 +1051,13 @@ static void power_pmu_read(struct perf_event *event) prev =local64_read (&event->hw.prev_count);barrier (); val =read_pmc (event->hw.idx); +if (use_ic (event->attr.config)) { + val =mfspr (SPRN_IC ); +if (val > cpuhw->ic_init) + val = val - cpuhw->ic_init; +else + val = val + (0 - cpuhw->ic_init); + } delta =check_and_compute_delta (prev, val);if (!delta)return ;
@@ -1466,6 +1495,13 @@ static int power_pmu_add(struct perf_event *event, int ef_flags) event->attr.branch_sample_type); } +/* +* Workaround for POWER9 DD1 to use the Instruction Counter +* register value for instruction counting +*/ +if (use_ic (event->attr.config)) + cpuhw->ic_init =mfspr (SPRN_IC ); +perf_pmu_enable (event->pmu);local_irq_restore (flags);return ret;
Signature · 1 line
2.7.4
PATCH v2 6/6 powerpc/perf: Add restrictions to PMC5 in power9 DD1
In reply to Madhavan SrinivasanPMC5 on POWER9 DD1 may not provide right counts in all sampling scenarios, hence use PM_INST_DISP event instead in PMC2 or PMC3 in preference.
---
Changelog v1:
No changes, just a rebase
arch/powerpc/perf/isa207-common.h | 4 ++++ arch/powerpc/perf/power9-pmu.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
arch/powerpc/perf/isa207-common.h +4 -0
@@ -222,6 +222,10 @@CNST_PMC_VAL (1 ) |CNST_PMC_VAL (2 ) |CNST_PMC_VAL (3 ) | \CNST_PMC_VAL (4 ) |CNST_PMC_VAL (5 ) |CNST_PMC_VAL (6 ) |CNST_NC_VAL +/* +* Lets restrict use of PMC5 for instruction counting. + */ +#define P9_DD1_TEST_ADDER (ISA207_TEST_ADDER | CNST_PMC_VAL(5))/* Bits in MMCR1 for PowerISA v2.07 */ #define MMCR1_UNIT_SHIFT (pmc) (60 - (4 * ((pmc) - 1)))
arch/powerpc/perf/power9-pmu.c +1 -1
@@ -423,7 +423,7 @@ static struct power_pmu power9_pmu = { .name = "POWER9", .n_counter = MAX_PMU_COUNTERS, .add_fields = ISA207_ADD_FIELDS, - .test_adder = ISA207_TEST_ADDER, + .test_adder = P9_DD1_TEST_ADDER, .compute_mmcr = isa207_compute_mmcr, .config_bhrb = power9_config_bhrb, .bhrb_filter_map = power9_bhrb_filter_map,
Signature · 1 line
2.7.4
Quoted 4 lines · Madhavan Srinivasan
Factor out the power8
event_alternativefunction to share the code with power9.Signed-off-by Madhavan Srinivasan <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/efe881afdd9996ccbcd2a09c93b724
cheers