<html><body><p><tt><font size="2">"Athira Rajeev" <atrajeev@linux.vnet.ibm.com> wrote on 27/05/2020 03:20:18 PM:<br><br>> From: "Athira Rajeev" <atrajeev@linux.vnet.ibm.com></font></tt><br><tt><font size="2">> To: linuxppc-dev@lists.ozlabs.org</font></tt><br><tt><font size="2">> Cc: linux-kernel@vger.kernel.org, ravi.bangoria@linux.ibm.com, <br>> maddy@linux.vnet.ibm.com, acme@kernel.org, anju@linux.vnet.ibm.com, <br>> jolsa@kernel.org, mpe@ellerman.id.au, atrajeev@linux.vnet.ibm.com</font></tt><br><tt><font size="2">> Date: 28/05/2020 02:46 PM</font></tt><br><tt><font size="2">> Subject: [PATCH V4 2/2] tools/perf: Add perf tools support for <br>> extended register capability in powerpc</font></tt><br><tt><font size="2">> <br>> From: Anju T Sudhakar <anju@linux.vnet.ibm.com><br>> <br>> Add extended regs to sample_reg_mask in the tool side to use<br>> with `-I?` option. Perf tools side uses extended mask to display<br>> the platform supported register names (with -I? option) to the user<br>> and also send this mask to the kernel to capture the extended registers<br>> in each sample. Hence decide the mask value based on the processor<br>> version.<br>> <br>> Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com><br>> [Decide extended mask at run time based on platform]<br>> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com><br>> Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com></font></tt><br><br><tt><font size="2">Tested-by: Nageswara R Sastry <nasastry@in.ibm.com></font></tt><br><tt><font size="2">Tested with 5.7.0-rc2</font></tt><br><tt><font size="2">Tested the following scenarios</font></tt><br><tt><font size="2">1. perf record -I<br>2. perf report -D # in output check for the registers<br>3. perf record -I<register name><br>4. perf record -I<non existing register name><br>5. perf record -I<non existing register name with special characters><br>6. perf record -I<register name> -e <different event names></font></tt><br><tt><font size="2"><br>> ---<br>> tools/arch/powerpc/include/uapi/asm/perf_regs.h | 14 ++++++-<br>> tools/perf/arch/powerpc/include/perf_regs.h | 5 ++-<br>> tools/perf/arch/powerpc/util/perf_regs.c | 55 ++++++++++++++<br>> +++++++++++<br>> 3 files changed, 72 insertions(+), 2 deletions(-)<br>> <br>> diff --git a/tools/arch/powerpc/include/uapi/asm/perf_regs.h b/<br>> tools/arch/powerpc/include/uapi/asm/perf_regs.h<br>> index f599064..485b1d5 100644<br>> --- a/tools/arch/powerpc/include/uapi/asm/perf_regs.h<br>> +++ b/tools/arch/powerpc/include/uapi/asm/perf_regs.h<br>> @@ -48,6 +48,18 @@ enum perf_event_powerpc_regs {<br>> PERF_REG_POWERPC_DSISR,<br>> PERF_REG_POWERPC_SIER,<br>> PERF_REG_POWERPC_MMCRA,<br>> - PERF_REG_POWERPC_MAX,<br>> + /* Extended registers */<br>> + PERF_REG_POWERPC_MMCR0,<br>> + PERF_REG_POWERPC_MMCR1,<br>> + PERF_REG_POWERPC_MMCR2,<br>> + /* Max regs without the extended regs */<br>> + PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,<br>> };<br>> +<br>> +#define PERF_REG_PMU_MASK ((1ULL << PERF_REG_POWERPC_MAX) - 1)<br>> +<br>> +/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */<br>> +#define PERF_REG_PMU_MASK_300 (((1ULL << (PERF_REG_POWERPC_MMCR2 <br>> + 1)) - 1) \<br>> + - PERF_REG_PMU_MASK)<br>> +<br>> #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */<br>> diff --git a/tools/perf/arch/powerpc/include/perf_regs.h b/tools/<br>> perf/arch/powerpc/include/perf_regs.h<br>> index e18a355..46ed00d 100644<br>> --- a/tools/perf/arch/powerpc/include/perf_regs.h<br>> +++ b/tools/perf/arch/powerpc/include/perf_regs.h<br>> @@ -64,7 +64,10 @@<br>> [PERF_REG_POWERPC_DAR] = "dar",<br>> [PERF_REG_POWERPC_DSISR] = "dsisr",<br>> [PERF_REG_POWERPC_SIER] = "sier",<br>> - [PERF_REG_POWERPC_MMCRA] = "mmcra"<br>> + [PERF_REG_POWERPC_MMCRA] = "mmcra",<br>> + [PERF_REG_POWERPC_MMCR0] = "mmcr0",<br>> + [PERF_REG_POWERPC_MMCR1] = "mmcr1",<br>> + [PERF_REG_POWERPC_MMCR2] = "mmcr2",<br>> };<br>> <br>> static inline const char *perf_reg_name(int id)<br>> diff --git a/tools/perf/arch/powerpc/util/perf_regs.c b/tools/perf/<br>> arch/powerpc/util/perf_regs.c<br>> index 0a52429..9179230 100644<br>> --- a/tools/perf/arch/powerpc/util/perf_regs.c<br>> +++ b/tools/perf/arch/powerpc/util/perf_regs.c<br>> @@ -6,9 +6,14 @@<br>> <br>> #include "../../../util/perf_regs.h"<br>> #include "../../../util/debug.h"<br>> +#include "../../../util/event.h"<br>> +#include "../../../util/header.h"<br>> +#include "../../../perf-sys.h"<br>> <br>> #include <linux/kernel.h><br>> <br>> +#define PVR_POWER9 0x004E<br>> +<br>> const struct sample_reg sample_reg_masks[] = {<br>> SMPL_REG(r0, PERF_REG_POWERPC_R0),<br>> SMPL_REG(r1, PERF_REG_POWERPC_R1),<br>> @@ -55,6 +60,9 @@<br>> SMPL_REG(dsisr, PERF_REG_POWERPC_DSISR),<br>> SMPL_REG(sier, PERF_REG_POWERPC_SIER),<br>> SMPL_REG(mmcra, PERF_REG_POWERPC_MMCRA),<br>> + SMPL_REG(mmcr0, PERF_REG_POWERPC_MMCR0),<br>> + SMPL_REG(mmcr1, PERF_REG_POWERPC_MMCR1),<br>> + SMPL_REG(mmcr2, PERF_REG_POWERPC_MMCR2),<br>> SMPL_REG_END<br>> };<br>> <br>> @@ -163,3 +171,50 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)<br>> <br>> return SDT_ARG_VALID;<br>> }<br>> +<br>> +uint64_t arch__intr_reg_mask(void)<br>> +{<br>> + struct perf_event_attr attr = {<br>> + .type = PERF_TYPE_HARDWARE,<br>> + .config = PERF_COUNT_HW_CPU_CYCLES,<br>> + .sample_type = PERF_SAMPLE_REGS_INTR,<br>> + .precise_ip = 1,<br>> + .disabled = 1,<br>> + .exclude_kernel = 1,<br>> + };<br>> + int fd, ret;<br>> + char buffer[64];<br>> + u32 version;<br>> + u64 extended_mask = 0;<br>> +<br>> + /* Get the PVR value to set the extended<br>> + * mask specific to platform<br>> + */<br>> + get_cpuid(buffer, sizeof(buffer));<br>> + ret = sscanf(buffer, "%u,", &version);<br>> +<br>> + if (ret != 1) {<br>> + pr_debug("Failed to get the processor version, unable to <br>> output extended registers\n");<br>> + return PERF_REGS_MASK;<br>> + }<br>> +<br>> + if (version == PVR_POWER9)<br>> + extended_mask = PERF_REG_PMU_MASK_300;<br>> + else<br>> + return PERF_REGS_MASK;<br>> +<br>> + attr.sample_regs_intr = extended_mask;<br>> + attr.sample_period = 1;<br>> + event_attr_init(&attr);<br>> +<br>> + /*<br>> + * check if the pmu supports perf extended regs, before<br>> + * returning the register mask to sample.<br>> + */<br>> + fd = sys_perf_event_open(&attr, 0, -1, -1, 0);<br>> + if (fd != -1) {<br>> + close(fd);<br>> + return (extended_mask | PERF_REGS_MASK);<br>> + }<br>> + return PERF_REGS_MASK;<br>> +}<br>> -- <br>> 1.8.3.1<br>> <br></font></tt><BR>
</body></html>