From: Tanushree Shah <tshah@linux.ibm.com>
To: Matt Turner <mattst88@gmail.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
Paul Mackerras <paulus@ozlabs.org>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 7/8] powerpc/perf: Use SIAR for sample addresses on 32-bit
Date: Wed, 18 Nov 2026 18:50:22 +0530 [thread overview]
Message-ID: <53a68daf-e694-4c88-b99e-fb8a4c17c1a7@linux.ibm.com> (raw)
In-Reply-To: <20261117-ppc32-perf-v2-7-2072e9b90009@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4267 bytes --]
On 11/17/26 11:13 PM, Matt Turner wrote:
> On 32-bit, perf_read_regs() sets regs->result to 0, so regs_use_siar()
> is always false and every sample is attributed to the interrupted PC.
>
> The MPC7450 family's SIAR holds the address of the last instruction to
> complete before the performance monitor exception is generated
> (MPC7450UM Rev. 5, section 11.3.7). The exception can be generated
> with MSR[EE] = 0 and is taken once EE is set again (section 11.2), so
> when interrupts are disabled the interrupted PC is wherever they are
> re-enabled, while SIAR still points into the disabled region.
>
> On a 7448, sampling cycles system-wide with --intr-regs=nip during dd,
> perf bench sched pipe and find, 46% of the kernel samples have SIAR and
> the interrupted PC in different functions. 13270 samples have their PC
> on the instruction after the mtmsr that restores interrupts in
> ata_scsi_queuecmd(), and 11661 of those have SIAR in udelay().
>
> With interrupts enabled SIAR helps less. Sampling a 32-instruction
> loop with one store and one branch with -c 10007, 99.8% of the samples
> land at:
>
> event interrupted PC SIAR
> r122 (branches) br + 13 br + 9
> r014 (stores) stw + 21 stw + 17
>
> Because the exception is held off, it can also be taken on the other
> side of a user/kernel transition from the instruction in SIAR, e.g.
> just after the rfi at the end of a system call. SIAR also holds a real
> address while translation is off, such as 0xc00 in the system call
> vector. Recording a loop that alternates user work with getppid() with
> perf record -g -c 1000000, 3022 of 16953 samples had SIAR in a
> different mode from the interrupted PC. The callchain is walked from
> regs, so taking its first entry from SIAR there starts a user
> callchain with a kernel address, or reports a kernel sample as a user
> sample at 0xc00.
>
> siar_valid() already returns true on 32-bit. Use SIAR for PMU
> exceptions when it is in the same mode as the interrupted context, and
> the interrupted PC otherwise. With that, the same test has no samples
> with mixed modes.
>
> Signed-off-by: Matt Turner<mattst88@gmail.com>
Hi Matt,
Thanks, v2 looks right. One concern: the rule infers user vs kernel
from SIAR's address, but a real-mode address (translation off) is also
low, so it can look like a user address. The 0xc00 samples in the
results come out
right only because the regs are kernel there. If a real-mode SIAR ever
pairs with user regs, the rule would trust a bogus address.
This rule avoids it and still fixes the interrupts-off case:
regs->result = siar && !user_mode(regs) && is_kernel_addr(siar);
User samples then use regs->nip, which loses little (SIAR was only ~4
instructions closer in your table).
Thanks,
Tanushree Shah
> ---
> arch/powerpc/perf/core-book3s.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
> index 10ded865583c..4c9c9ff1073e 100644
> --- a/arch/powerpc/perf/core-book3s.c
> +++ b/arch/powerpc/perf/core-book3s.c
> @@ -112,9 +112,25 @@ static inline u32 perf_get_misc_flags(struct pt_regs *regs)
> {
> return 0;
> }
> +
> +/*
> + * The MPC7450 family's SIAR holds the address of the last instruction to
> + * complete before the performance monitor exception was generated, so for
> + * a PMU exception it is closer to the event than the interrupted PC.
> + *
> + * The exception is held off while MSR[EE] is clear, so it can be taken on
> + * the other side of a user/kernel transition from the instruction in SIAR,
> + * e.g. just after the rfi at the end of a system call. SIAR also holds a
> + * real address for code running with translation off, such as the start
> + * of an exception vector. Use SIAR only when it is in the same mode as
> + * the interrupted context, so the sample's mode and the callchain built
> + * from regs stay consistent with it.
> + */
> static inline void perf_read_regs(struct pt_regs *regs)
> {
> - regs->result = 0;
> + unsigned long siar = mfspr(SPRN_SIAR);
> +
> + regs->result = siar && is_kernel_addr(siar) == !user_mode(regs);
> }
>
> static inline int siar_valid(struct pt_regs *regs)
>
[-- Attachment #2: Type: text/html, Size: 6242 bytes --]
next prev parent reply other threads:[~2026-11-18 13:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 17:43 [PATCH v2 0/8] powerpc/perf: mpc7450: Event fixes, SIAR sampling and sysfs event names Matt Turner
2026-11-17 17:43 ` [PATCH v2 1/8] powerpc/perf: mpc7450: Event 0x30d does not use the threshold Matt Turner
2026-11-17 17:43 ` [PATCH v2 2/8] powerpc/perf: mpc7450: Event 0x634 counts L2 prefetches, not L1I Matt Turner
2026-11-17 17:43 ` [PATCH v2 3/8] powerpc/perf: mpc7450: Remove the snoop retry alternatives Matt Turner
2026-11-17 17:43 ` [PATCH v2 4/8] powerpc/perf: mpc7450: Fill in the L1 data cache events Matt Turner
2026-11-17 17:43 ` [PATCH v2 5/8] powerpc/perf: mpc7450: Add the PMC6 L3 events to the alternatives table Matt Turner
2026-11-17 17:43 ` [PATCH v2 6/8] powerpc/perf: mpc7450: Export the event format in sysfs Matt Turner
2026-11-17 17:43 ` [PATCH v2 7/8] powerpc/perf: Use SIAR for sample addresses on 32-bit Matt Turner
2026-11-18 13:20 ` Tanushree Shah [this message]
2026-11-18 16:01 ` Matt Turner
2026-11-18 16:17 ` [PATCH v3 7/8] powerpc/perf: Use SIAR for kernel " Matt Turner
2026-11-19 7:28 ` Tanushree Shah
2026-11-17 17:43 ` [PATCH v2 8/8] powerpc/perf: mpc7450: Export event names in sysfs Matt Turner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53a68daf-e694-4c88-b99e-fb8a4c17c1a7@linux.ibm.com \
--to=tshah@linux.ibm.com \
--cc=chleroy@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mattst88@gmail.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=paulus@ozlabs.org \
--cc=ritesh.list@gmail.com \
--cc=sshegde@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox