Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/perf: Fix cycles/instructions as PM_CYC/PM_INST_CMPL in power10

On power9 and earlier platforms, the default event used for cyles and
instructions is PM_CYC (0x0001e) and PM_INST_CMPL (0x00002)
respectively. These events use two programmable PMCs and by default will
count irrespective of the run latch state (idle state). But since they
use programmable PMCs, these events can lead to multiplexing with other
events, because there are only 4 programmable PMCs. Hence in power10,
performance monitoring unit (PMU) driver uses performance monitor
counter 5 (PMC5) and performance monitor counter6 (PMC6) for counting
instructions and cycles.

Currently on power10, the event used for cycles is PM_RUN_CYC (0x600F4)
and instructions uses PM_RUN_INST_CMPL (0x500fa). But counting of these
events in idle state is controlled by the CC56RUN bit setting in Monitor
Mode Control Register0 (MMCR0). If the CC56RUN bit is zero, PMC5/6 will
not count when CTRL[RUN] (run latch) is zero. This could lead to missing
some counts if a thread is in idle state during system wide profiling.

To fix it, set the CC56RUN bit in MMCR0 for power10, which makes PMC5
and PMC6 count instructions and cycles regardless of the run latch
state. Since this change make PMC5/6 count as PM_INST_CMPL/PM_CYC,
rename the event code 0x600f4 as PM_CYC instead of PM_RUN_CYC and event
code 0x500fa as PM_INST_CMPL instead of PM_RUN_INST_CMPL. The changes
are only for PMC5/6 event codes and will not affect the behaviour of
PM_RUN_CYC/PM_RUN_INST_CMPL if progammed in other PMC's.

Fixes: a64e697cef23 ("powerpc/perf: power10 Performance Monitoring support")
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.cm>
Reviewed-by: Madhavan Srinivasan <maddy@linux.ibm.com>
[mpe: Tweak change log wording for style and consistency]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211007075121.28497-1-atrajeev@linux.vnet.ibm.com

authored by

Athira Rajeev and committed by
Michael Ellerman
8f6aca0e b616230e

+35 -17
+4 -4
arch/powerpc/perf/power10-events-list.h
··· 9 9 /* 10 10 * Power10 event codes. 11 11 */ 12 - EVENT(PM_RUN_CYC, 0x600f4); 12 + EVENT(PM_CYC, 0x600f4); 13 13 EVENT(PM_DISP_STALL_CYC, 0x100f8); 14 14 EVENT(PM_EXEC_STALL, 0x30008); 15 - EVENT(PM_RUN_INST_CMPL, 0x500fa); 15 + EVENT(PM_INST_CMPL, 0x500fa); 16 16 EVENT(PM_BR_CMPL, 0x4d05e); 17 17 EVENT(PM_BR_MPRED_CMPL, 0x400f6); 18 18 EVENT(PM_BR_FIN, 0x2f04a); ··· 50 50 /* ITLB Reloaded */ 51 51 EVENT(PM_ITLB_MISS, 0x400fc); 52 52 53 - EVENT(PM_RUN_CYC_ALT, 0x0001e); 54 - EVENT(PM_RUN_INST_CMPL_ALT, 0x00002); 53 + EVENT(PM_CYC_ALT, 0x0001e); 54 + EVENT(PM_INST_CMPL_ALT, 0x00002); 55 55 56 56 /* 57 57 * Memory Access Events
+31 -13
arch/powerpc/perf/power10-pmu.c
··· 91 91 92 92 /* Table of alternatives, sorted by column 0 */ 93 93 static const unsigned int power10_event_alternatives[][MAX_ALT] = { 94 - { PM_RUN_CYC_ALT, PM_RUN_CYC }, 95 - { PM_RUN_INST_CMPL_ALT, PM_RUN_INST_CMPL }, 94 + { PM_CYC_ALT, PM_CYC }, 95 + { PM_INST_CMPL_ALT, PM_INST_CMPL }, 96 96 }; 97 97 98 98 static int power10_get_alternatives(u64 event, unsigned int flags, u64 alt[]) ··· 118 118 return 0; 119 119 } 120 120 121 - GENERIC_EVENT_ATTR(cpu-cycles, PM_RUN_CYC); 122 - GENERIC_EVENT_ATTR(instructions, PM_RUN_INST_CMPL); 121 + GENERIC_EVENT_ATTR(cpu-cycles, PM_CYC); 122 + GENERIC_EVENT_ATTR(instructions, PM_INST_CMPL); 123 123 GENERIC_EVENT_ATTR(branch-instructions, PM_BR_CMPL); 124 124 GENERIC_EVENT_ATTR(branch-misses, PM_BR_MPRED_CMPL); 125 125 GENERIC_EVENT_ATTR(cache-references, PM_LD_REF_L1); ··· 148 148 CACHE_EVENT_ATTR(iTLB-load-misses, PM_ITLB_MISS); 149 149 150 150 static struct attribute *power10_events_attr_dd1[] = { 151 - GENERIC_EVENT_PTR(PM_RUN_CYC), 152 - GENERIC_EVENT_PTR(PM_RUN_INST_CMPL), 151 + GENERIC_EVENT_PTR(PM_CYC), 152 + GENERIC_EVENT_PTR(PM_INST_CMPL), 153 153 GENERIC_EVENT_PTR(PM_BR_CMPL), 154 154 GENERIC_EVENT_PTR(PM_BR_MPRED_CMPL), 155 155 GENERIC_EVENT_PTR(PM_LD_REF_L1), ··· 173 173 }; 174 174 175 175 static struct attribute *power10_events_attr[] = { 176 - GENERIC_EVENT_PTR(PM_RUN_CYC), 177 - GENERIC_EVENT_PTR(PM_RUN_INST_CMPL), 176 + GENERIC_EVENT_PTR(PM_CYC), 177 + GENERIC_EVENT_PTR(PM_INST_CMPL), 178 178 GENERIC_EVENT_PTR(PM_BR_FIN), 179 179 GENERIC_EVENT_PTR(PM_MPRED_BR_FIN), 180 180 GENERIC_EVENT_PTR(PM_LD_REF_L1), ··· 271 271 }; 272 272 273 273 static int power10_generic_events_dd1[] = { 274 - [PERF_COUNT_HW_CPU_CYCLES] = PM_RUN_CYC, 275 - [PERF_COUNT_HW_INSTRUCTIONS] = PM_RUN_INST_CMPL, 274 + [PERF_COUNT_HW_CPU_CYCLES] = PM_CYC, 275 + [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL, 276 276 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BR_CMPL, 277 277 [PERF_COUNT_HW_BRANCH_MISSES] = PM_BR_MPRED_CMPL, 278 278 [PERF_COUNT_HW_CACHE_REFERENCES] = PM_LD_REF_L1, ··· 280 280 }; 281 281 282 282 static int power10_generic_events[] = { 283 - [PERF_COUNT_HW_CPU_CYCLES] = PM_RUN_CYC, 284 - [PERF_COUNT_HW_INSTRUCTIONS] = PM_RUN_INST_CMPL, 283 + [PERF_COUNT_HW_CPU_CYCLES] = PM_CYC, 284 + [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL, 285 285 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BR_FIN, 286 286 [PERF_COUNT_HW_BRANCH_MISSES] = PM_MPRED_BR_FIN, 287 287 [PERF_COUNT_HW_CACHE_REFERENCES] = PM_LD_REF_L1, ··· 548 548 549 549 #undef C 550 550 551 + /* 552 + * Set the MMCR0[CC56RUN] bit to enable counting for 553 + * PMC5 and PMC6 regardless of the state of CTRL[RUN], 554 + * so that we can use counters 5 and 6 as PM_INST_CMPL and 555 + * PM_CYC. 556 + */ 557 + static int power10_compute_mmcr(u64 event[], int n_ev, 558 + unsigned int hwc[], struct mmcr_regs *mmcr, 559 + struct perf_event *pevents[], u32 flags) 560 + { 561 + int ret; 562 + 563 + ret = isa207_compute_mmcr(event, n_ev, hwc, mmcr, pevents, flags); 564 + if (!ret) 565 + mmcr->mmcr0 |= MMCR0_C56RUN; 566 + return ret; 567 + } 568 + 551 569 static struct power_pmu power10_pmu = { 552 570 .name = "POWER10", 553 571 .n_counter = MAX_PMU_COUNTERS, ··· 573 555 .test_adder = ISA207_TEST_ADDER, 574 556 .group_constraint_mask = CNST_CACHE_PMC4_MASK, 575 557 .group_constraint_val = CNST_CACHE_PMC4_VAL, 576 - .compute_mmcr = isa207_compute_mmcr, 558 + .compute_mmcr = power10_compute_mmcr, 577 559 .config_bhrb = power10_config_bhrb, 578 560 .bhrb_filter_map = power10_bhrb_filter_map, 579 561 .get_constraint = isa207_get_constraint,