From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794931928; b=Jen6GNJXdadrEtEmpB5c+RY60/b3ca63Ds/T2eKPe2svQuqa7RsjBtCMKA17IZNZ0fVY b1DtHiJnTOmDEi2zkIbNSgdL/2huIJ6Tb/aSJO4226dSetq/ACKs5YdnIMQGwRDLLPZa9 sK0/hI4dTsWb/FwNeV5fxrFrv+P276DtilZhaYCkPpC99BbmJv/bNQAyWHsmTC7xpxTS2 hr0racSetdTk/GdFIrMThAxMhlbPe4kLpHFC9q6xLiqRm0ywqaIYY3AS6WWilW4cQ6L6I iWy5yRfiiUKTCCklZtHpmqNdZdPWEVp+Pd5Bfr3ZP+XkSD8vLxjNSeMyKNXjWrKqd2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794931928; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-TM-AS-GCONF: X-Proofpoint-Reinject:X-Proofpoint-Spam-Info:X-Proofpoint-GUID: X-Authority-Analysis:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=/T+V9VuJK47vxfoZ9qkABQahXL/mlkWoR6A/viVYIj4=; b=VBgMCtW/8LVi8fmVMFCuF9GpSN5sfgmjXkHqDSfa/NjPlWDCB6WJ+FLfB4mSuEIs56k0 m4fJHhLkoLwEG/vZB8i/Q0NzZutg2BF5DUvDh/KaWVze4FQeIlLsvksY5QOZtY3Jw91KC HdfX86UhF/X5EBFTdLFtXyr570zztYfHdvCijG2euFKB0X5S62dj2NjcRW/hK/bn0R5Kl dOZBF5aTDjdWX5Axh4XZOjQZwj8x32MXfnoiISeFVRD4TTwebbaehHdhCXMsMNUgP3AQ9 pr87l5XsU7d3KwhFjLPbbGZ/syAv4C6EdhkWAxl7yOipNROjtBGANngCtE83tOJbIGg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=IzDLiAef; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCEE5606A32A for ; Tue, 17 Nov 2026 16:12:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BCEE5606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=IzDLiAef Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AHFQbtn2892636; Tue, 17 Nov 2026 16:11:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=/T+V9V uJK47vxfoZ9qkABQahXL/mlkWoR6A/viVYIj4=; b=IzDLiAefztDpiA77q6hVSV 5fwntlqIKV5bcM+rjm/RKJLdM+uvfYAq4Yc72RwsaTrAfM7W2Z6a0nAEfUgOjmxC USx7w2P6ZCNYxITDcEmwlHxu80FPzV4z/aWlHnmZABYo2IE9AOL5NxFfzrafI5YL WzcsRjQIessyOaBX8ZVHFETWKJK4mO2PPGR6pYiTEuXjZGiWNPMUtF1YKF5qyZt9 cYnqSCNGA1oBD0XPEP+9wTwccUCEuufWmIiSgYzmEyLPsk5e+MoaSNi+5AtoJyHt Ar8jRJ2wcmRAlGgazhMRRWlOUxjengFmF7CJmIGOHdT58VjUX4AKmZ5XP0vc+nIQ == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4hxf56c84w-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 17 Nov 2026 16:11:46 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6AHFZ2ch657734; Tue, 17 Nov 2026 16:11:45 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j00nse9w2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Nov 2026 16:11:45 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6AHGBisH21168650 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Nov 2026 16:11:44 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 700635805E; Tue, 17 Nov 2026 16:11:44 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2FD45805C; Tue, 17 Nov 2026 16:11:40 +0000 (GMT) Received: from [9.39.20.228] (unknown [9.39.20.228]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Tue, 17 Nov 2026 16:11:40 +0000 (GMT) Message-ID: <3950cc84-93bf-4830-8a37-57f9739a84b0@linux.ibm.com> Date: Tue, 17 Nov 2026 21:41:39 +0530 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 7/8] powerpc/perf: Use SIAR for sample addresses on 32-bit To: Matt Turner , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , "Ritesh Harjani (IBM)" , Shrikanth Hegde , Paul Mackerras Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20261109-ppc32-perf-v1-0-a6e8a55b3b48@gmail.com> <20261109-ppc32-perf-v1-7-a6e8a55b3b48@gmail.com> Content-Language: en-US From: Tanushree Shah In-Reply-To: <20261109-ppc32-perf-v1-7-a6e8a55b3b48@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTE3MDA2MyBTYWx0ZWRfX0lunCtT3eOri fdX8omIi+0rb4acEgKVm371pWud+wft9csAGW5pWUv4wQBVvdbuEuwHmaukk87VHf7oDbVYzVQ0 GyEI5/G8XgXnfaYBMnumPuVULuh/O58= X-Proofpoint-GUID: jn3L4S6PVGY7oNWqjq80fObrvk_-mpvH X-Authority-Analysis: v=2.4 cv=ROImjIi+ c=1 sm=1 tr=0 ts=6afc7cc2 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=pGLkceISAAAA:8 a=aGFjUxq13BNP2VoxV7wA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: jWg993CcMFpxH0i6vvgTMO2A676UmzaE X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTE3MDA2MyBTYWx0ZWRfX+s6sDGolXBST cS/Kb7/tasX7r9DWIKx6MdlPlQ0jZaYrCyIqJe5GsVeEqXpfwdx+w0HMsVEum4o2grNA+qHk23L /M37uzvZwoxDQtrEgFNTthBGKcqUQnEPGkk1t/sIMuU0mIaIdc93mf/DX4w02XgxEHyeNqIYVp1 eE3Rfz6rXn+GJRGlgY68rNoINGb6e88SyTU1rjPulqz1ewhgwdla/XEeLGNXq/7/aMw8qhmcZbI npQkr62Q7IkQ8jqQvoLRtB3RAqNavV4Q4Pp1iqBJLSKK2LRVGJyTPNbCk/hyO7bOJ33p5TpLQuk liVCV4CNv7nuKp6LWDcXytaIohXbIeLFPjZ2REmDQJcyczkqaXiHlxNALsv4FgoCYfMQu5ofdYX sQOnYBQMoklVsHoljEL9FIFNqipEuX9pnHbfoI6VRbK31ukYZWVYcT7Xr+guYfC+AuGXJxqEtda QSqnkWAIZ9p1r6V39gw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-17_03,2026-11-16_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611170063 On 11/10/26 7:17 AM, 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 > > siar_valid() already returns true on 32-bit. Use SIAR for PMU > exceptions, and take the user/kernel flags from it too. Move > regs_use_siar() above the 32-bit block so that perf_get_misc_flags() > can call it. > > Signed-off-by: Matt Turner Hi Matt, I checked the manual references (11.3.7 for SIAR and 11.2 for the exception being taken only once EE is set), and they match the commit message. Infrastructure-wise this looks good to me. One question: the callchain still walks from regs (gpr[1], link), but its first entry now comes from SIAR. Can SIAR and the interrupted PC end up on opposite sides of user/kernel? If so, would the callchain be affected? Something like perf record -g on a workload that switches between user and kernel often might show it. Thanks Tanushree Shah > --- > arch/powerpc/perf/core-book3s.c | 55 +++++++++++++++++++++++++++-------------- > 1 file changed, 36 insertions(+), 19 deletions(-) > > diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c > index 10ded865583c..e4c8ecddccbd 100644 > --- a/arch/powerpc/perf/core-book3s.c > +++ b/arch/powerpc/perf/core-book3s.c > @@ -75,6 +75,20 @@ static struct power_pmu *ppmu; > */ > static unsigned int freeze_events_kernel = MMCR0_FCS; > > +static bool regs_use_siar(struct pt_regs *regs) > +{ > + /* > + * When we take a performance monitor exception the regs are setup > + * using perf_read_regs() which overloads some fields, in particular > + * regs->result to tell us whether to use SIAR. > + * > + * However if the regs are from another exception, eg. a syscall, then > + * they have not been setup using perf_read_regs() and so regs->result > + * is something random. > + */ > + return ((TRAP(regs) == INTERRUPT_PERFMON) && regs->result); > +} > + > /* > * 32-bit doesn't have MMCRA but does have an MMCR2, > * and a few other names are different. > @@ -108,13 +122,30 @@ static inline unsigned long perf_ip_adjust(struct pt_regs *regs) > return 0; > } > static inline void perf_get_data_addr(struct perf_event *event, struct pt_regs *regs, u64 *addrp) { } > -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. > + */ > static inline void perf_read_regs(struct pt_regs *regs) > { > - regs->result = 0; > + regs->result = 1; > +} > + > +static inline u32 perf_get_misc_flags(struct pt_regs *regs) > +{ > + unsigned long siar; > + > + if (!regs_use_siar(regs)) > + return 0; > + > + siar = mfspr(SPRN_SIAR); > + if (!siar) > + return 0; > + > + return is_kernel_addr(siar) ? PERF_RECORD_MISC_KERNEL : > + PERF_RECORD_MISC_USER; > } > > static inline int siar_valid(struct pt_regs *regs) > @@ -163,20 +194,6 @@ unsigned long get_pmcs_ext_regs(int idx) > return cpuhw->pmcs[idx]; > } > > -static bool regs_use_siar(struct pt_regs *regs) > -{ > - /* > - * When we take a performance monitor exception the regs are setup > - * using perf_read_regs() which overloads some fields, in particular > - * regs->result to tell us whether to use SIAR. > - * > - * However if the regs are from another exception, eg. a syscall, then > - * they have not been setup using perf_read_regs() and so regs->result > - * is something random. > - */ > - return ((TRAP(regs) == INTERRUPT_PERFMON) && regs->result); > -} > - > /* > * Things that are specific to 64-bit implementations. > */ >