[PATCH] powerpc/64s/perf: Always use SIAR for kernel interrupts

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE1835d LANDED

Landed in mainline as cf9c615cde49 on 2021-08-04.

3 messages, 3 authors, 2021-08-18 · open the first message on its own page

[PATCH] powerpc/64s/perf: Always use SIAR for kernel interrupts

From: Nicholas Piggin <npiggin@gmail.com>
Date: 2021-07-20 14:15:46

If an interrupt is taken in kernel mode, always use SIAR for it rather than
looking at regs_sipr. This prevents samples piling up around interrupt
enable (hard enable or interrupt replay via soft enable) in PMUs / modes
where the PR sample indication is not in synch with SIAR.

This results in better sampling of interrupt entry and exit in particular.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/perf/core-book3s.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index bb0ee716de91..91203ed9d0ff 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -340,6 +340,13 @@ static inline void perf_read_regs(struct pt_regs *regs)
 	 * If the PMU doesn't update the SIAR for non marked events use
 	 * pt_regs.
 	 *
+	 * If regs is a kernel interrupt, always use SIAR. Some PMUs have an
+	 * issue with regs_sipr not being in synch with SIAR in interrupt entry
+	 * and return sequences, which can result in regs_sipr being true for
+	 * kernel interrupts and SIAR, which has the effect of causing samples
+	 * to pile up at mtmsrd MSR[EE] 0->1 or pending irq replay around
+	 * interrupt entry/exit.
+	 *
 	 * If the PMU has HV/PR flags then check to see if they
 	 * place the exception in userspace. If so, use pt_regs. In
 	 * continuous sampling mode the SIAR and the PMU exception are
@@ -356,6 +363,8 @@ static inline void perf_read_regs(struct pt_regs *regs)
 		use_siar = 1;
 	else if ((ppmu->flags & PPMU_NO_CONT_SAMPLING))
 		use_siar = 0;
+	else if (!user_mode(regs))
+		use_siar = 1;
 	else if (!(ppmu->flags & PPMU_NO_SIPR) && regs_sipr(regs))
 		use_siar = 0;
 	else
-- 
2.23.0

Re: [PATCH] powerpc/64s/perf: Always use SIAR for kernel interrupts

From: Athira Rajeev <hidden>
Date: 2021-07-21 05:39:08

quoted hunk
On 20-Jul-2021, at 7:45 PM, Nicholas Piggin [off-list ref] wrote:

If an interrupt is taken in kernel mode, always use SIAR for it rather than
looking at regs_sipr. This prevents samples piling up around interrupt
enable (hard enable or interrupt replay via soft enable) in PMUs / modes
where the PR sample indication is not in synch with SIAR.

This results in better sampling of interrupt entry and exit in particular.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/perf/core-book3s.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index bb0ee716de91..91203ed9d0ff 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -340,6 +340,13 @@ static inline void perf_read_regs(struct pt_regs *regs)
	 * If the PMU doesn't update the SIAR for non marked events use
	 * pt_regs.
	 *
+	 * If regs is a kernel interrupt, always use SIAR. Some PMUs have an
+	 * issue with regs_sipr not being in synch with SIAR in interrupt entry
+	 * and return sequences, which can result in regs_sipr being true for
+	 * kernel interrupts and SIAR, which has the effect of causing samples
+	 * to pile up at mtmsrd MSR[EE] 0->1 or pending irq replay around
+	 * interrupt entry/exit.
+	 *
	 * If the PMU has HV/PR flags then check to see if they
	 * place the exception in userspace. If so, use pt_regs. In
	 * continuous sampling mode the SIAR and the PMU exception are
@@ -356,6 +363,8 @@ static inline void perf_read_regs(struct pt_regs *regs)
		use_siar = 1;
	else if ((ppmu->flags & PPMU_NO_CONT_SAMPLING))
		use_siar = 0;
+	else if (!user_mode(regs))
+		use_siar = 1;

Tested the change.

Workload used: Testcase that runs a loop of “scv” syscalls

Before the patch:
# perf record <test>
# perf report|grep replay
     3.90%  scvonly  [kernel.vmlinux]            [k] replay_soft_interrupts

Samples were present around interrupt replay code.

After the fix, perf report didn’t had samples pointing to replay code.

Tested-by: Athira Rajeev <redacted>

Thanks
Athira
	else if (!(ppmu->flags & PPMU_NO_SIPR) && regs_sipr(regs))
		use_siar = 0;
	else
-- 
2.23.0

Re: [PATCH] powerpc/64s/perf: Always use SIAR for kernel interrupts

From: Michael Ellerman <hidden>
Date: 2021-08-18 13:53:58

On Wed, 21 Jul 2021 00:15:04 +1000, Nicholas Piggin wrote:
If an interrupt is taken in kernel mode, always use SIAR for it rather than
looking at regs_sipr. This prevents samples piling up around interrupt
enable (hard enable or interrupt replay via soft enable) in PMUs / modes
where the PR sample indication is not in synch with SIAR.

This results in better sampling of interrupt entry and exit in particular.
Applied to powerpc/next.

[1/1] powerpc/64s/perf: Always use SIAR for kernel interrupts
      https://git.kernel.org/powerpc/c/cf9c615cde49fb5d2480549c8c955a0a387798d3

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help