Skip to content

Commit 77ca395

Browse files
anjutsudhakarmpe
authored andcommitted
powerpc/perf: Add kernel support for new MSR[HV PR] bits in trace-imc
IMC trace-mode record has MSR[HV PR] bits added in the third DW. These bits can be used to set the cpumode for the instruction pointer captured in each sample. Add support in kernel to use these bits to set the cpumode for each sample. Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20200713144623.508695-1-maddy@linux.ibm.com
1 parent 9a3e3dc commit 77ca395

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

arch/powerpc/include/asm/imc-pmu.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ struct trace_imc_data {
9999
*/
100100
#define IMC_TRACE_RECORD_TB1_MASK 0x3ffffffffffULL
101101

102+
/*
103+
* Bit 0:1 in third DW of IMC trace record
104+
* specifies the MSR[HV PR] values.
105+
*/
106+
#define IMC_TRACE_RECORD_VAL_HVPR(x) ((x) >> 62)
102107

103108
/*
104109
* Device tree parser code detects IMC pmu support and

arch/powerpc/perf/imc-pmu.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,11 +1288,30 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem,
12881288
header->size = sizeof(*header) + event->header_size;
12891289
header->misc = 0;
12901290

1291-
if (is_kernel_addr(data->ip))
1292-
header->misc |= PERF_RECORD_MISC_KERNEL;
1293-
else
1294-
header->misc |= PERF_RECORD_MISC_USER;
1295-
1291+
if (cpu_has_feature(CPU_FTR_ARCH_31)) {
1292+
switch (IMC_TRACE_RECORD_VAL_HVPR(mem->val)) {
1293+
case 0:/* when MSR HV and PR not set in the trace-record */
1294+
header->misc |= PERF_RECORD_MISC_GUEST_KERNEL;
1295+
break;
1296+
case 1: /* MSR HV is 0 and PR is 1 */
1297+
header->misc |= PERF_RECORD_MISC_GUEST_USER;
1298+
break;
1299+
case 2: /* MSR HV is 1 and PR is 0 */
1300+
header->misc |= PERF_RECORD_MISC_HYPERVISOR;
1301+
break;
1302+
case 3: /* MSR HV is 1 and PR is 1 */
1303+
header->misc |= PERF_RECORD_MISC_USER;
1304+
break;
1305+
default:
1306+
pr_info("IMC: Unable to set the flag based on MSR bits\n");
1307+
break;
1308+
}
1309+
} else {
1310+
if (is_kernel_addr(data->ip))
1311+
header->misc |= PERF_RECORD_MISC_KERNEL;
1312+
else
1313+
header->misc |= PERF_RECORD_MISC_USER;
1314+
}
12961315
perf_event_header__init_id(header, data, event);
12971316

12981317
return 0;

0 commit comments

Comments
 (0)