From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 A302F606A336 for ; Wed, 18 Nov 2026 09:51:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=zVmGPzHQ; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=i0Q0+vah DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=bd8Cnycxgyr/ojYs5MysmoTkBj0fIEXfTZ9x/S6rg5o=; b=zVmGPzHQsV82UuGZXkEUX6r2x4 WOD6i1p4HUwZJRhFuIn+nzG3rSfzvbx8Eemgjnc+DIa9oDTtj2U9vtgV7mn7abMRrsRnQnE8TXHvv 0oVA5t1FW/r64/WYhjl8b07OR3bV3CDSF5SZEUNgbGWzdycylZFoXJICN5Y3UBh42OeUPd9puxRwE bZAq5L0Az/OqaQHkeMpYa9hpYQlP8q7fNDWT3xopBFRA9sC0LNinsewe3mupdiFWh77HY75Dr6A/5 pbHrXhDIXPCDNK+O9OH5nOUqDJkpCwJoe7i6sVaJylZVJIc3W/exPYYpbtq7lyirPp4KX8RaMAEOp vvZKhPkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTcKK-00000008R3g-1rcn; Wed, 18 Nov 2026 09:51:40 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTcKI-00000008R32-12BY; Wed, 18 Nov 2026 09:51:39 +0000 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AI9k3xL3353922; Wed, 18 Nov 2026 09:51:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=bd8Cnycxgyr/ojYs5MysmoTkBj0fIEXfTZ9 x/S6rg5o=; b=i0Q0+vahXLEPMFPkBFgljkZ1aLVVlGcHx3l99MNj8vAgO55EDu1 0b9SqvmwyJ9ic0+M/MASq3DArIve3mYuQYs34CO9+z7/uRQPZWixMzarRMCiwAVS PpYC3pdRA7hG0TnQm7lC4MTJQhFpBiPIfz5GAU/o4zMNovOVGEB8qyDxSura64FC l9/ajri4XlVatmVsxDxAvAUzuKTxlnmmIT+xK1u+YZEWasXk/cwKR0Hw9ELca++j j1BwpTxTgeZt9NO6cCJ1BKTNqJdUmgJu4AazTdYudqUyNPo+HfV/txvjgiaS3SkK Ou6TTElXcBbHsC3GN+6ztvZ2KouWEH8gvcQ== Received: from apblrppmta02.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j0yvateaq-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 18 Nov 2026 09:51:06 +0000 (GMT) Received: from pps.filterd (apblrppmta02.qualcomm.com [127.0.0.1]) by APBLRPPMTA02.qualcomm.com (8.18.1.11/8.18.1.11) with ESMTP id 6AI9p3Gn375487; Wed, 18 Nov 2026 09:51:03 GMT Received: from hu-devc-blr-u24-a.qualcomm.com (hu-vikrsi-blr.qualcomm.com [10.190.111.249]) by APBLRPPMTA02.qualcomm.com (PPS) with ESMTPS id 6AI9p35w375477 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 18 Nov 2026 09:51:03 +0000 (GMT) Received: by hu-devc-blr-u24-a.qualcomm.com (Postfix, from userid 4853235) id B62A624881; Wed, 18 Nov 2026 15:21:02 +0530 (+0530) From: Vikram Singh To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, atishp@rivosinc.com, anup.patel@oss.qualcomm.com, will@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, beeman@rivosinc.com Cc: Vikram Singh , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Conor Dooley , devicetree@vger.kernel.org Subject: [PATCH v5 0/7] riscv: pmu: Add support for Control Transfer Records Ext. Date: Wed, 18 Nov 2026 15:20:46 +0530 Message-ID: <20261118095053.3871267-1-vikram.singh3@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Reinject: loops=2 maxloops=12 X-QCInternal: smtphost X-QCInternal: smtphost X-Authority-Analysis: v=2.4 cv=SMzXx+vH c=1 sm=1 tr=0 ts=6afd750a cx=c_pps a=Ou0eQOY4+eZoSc0qltEV5Q==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=xvfqbYfxAAAA:20 a=O76HWA22AAAA:20 a=VwQbUJbxAAAA:8 a=h0uksLzaAAAA:8 a=NEAV23lmAAAA:8 a=JfrnYn6hAAAA:8 a=20KFwNOVAAAA:8 a=7CQSdrXTAAAA:8 a=QyXUC8HyAAAA:8 a=1XWaLZrsAAAA:8 a=pFyQfRViAAAA:8 a=_O3DOGVWAAAA:8 a=EUspDBNiAAAA:8 a=Epjr2bh0dWxRFF0fu90A:9 a=MSi_79tMYmZZG2gvAgS0:22 a=1CNFftbPRP8L7MoqJWF3:22 a=a-qgeE7W1pNrGK8U0ZQC:22 a=oJz5jJLG1JtSoe7EL652:22 a=2TKV-7w1aU1AVAwN0oqT:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-GUID: vH15hF1coqHfeu1IT8UqIny5nynf735H X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTE4MDAzOSBTYWx0ZWRfX/X3bV1lru355 9tC/vs2FhX7+bXPuXptsLYDQi7K83t0UIRq2wnwKoWdysqht99gzyK0lez+0N/hQVpoNjvvQ55g KkvDMvw1MGB8YObUUAz9DzBOzQAtZxYFiVzB10lOlIO/iuYJXtUarkzuUfoqzeNTcZfOHfI+PJu grPEKPdjjyhcAkBYr0A41WJYmFEkMz4X4qQD2JL3X5GpHvxKg2mcni//U1K84HBtCYp2cRYGSct cvSu5WuYS8ZKs2R3TvUzU0oJBGdEGJngpIAmUN40p71di+di472wx+8OFu3UeGZfCH6WAyqIwzH QaENYrW1FmaCCS9llUfohpmK+jMbPi7EAJezsxukiEfBfpytP2nJp47c6NitEfLyGWmy5qzV+ss Itakfe6Hcv5VLMGtjdj72UCJSy9yePjokFy4TX4nsquoCzQw/Cb8NcFrjFRE3stLJUgehdwYv5D d+QZj3aHDNwUaDBqnAw== X-Proofpoint-ORIG-GUID: vH15hF1coqHfeu1IT8UqIny5nynf735H X-Proofpoint-Spam-Info: AW1haW4tMjYxMTE4MDAzOSBTYWx0ZWRfX+gIjO3f4yV1h vK8U8oBbsvrbhICNQFB0ekStS5cC7ijLKmc1uwVKx2bcNnIiVm/Cka5EnoDizPk8jhqCTPY+x7T dwA4euVs/13JbxM9t/G7hyPNfBfbk1Y= 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-18_02,2026-11-16_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 priorityscore=1501 suspectscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611180039 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261118_015138_290104_0DB39663 X-CRM114-Status: GOOD ( 23.64 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 his series enables Control Transfer Records extension support on riscv architecture. This extension is similar to Arch LBR in x86 and BRBE in ARM. The Extension has been ratified and latest release can be found here [0] CTR extension depends on both the implementation of S-mode and Sscsrind extension v1.0.0 [1]. CTR access ctrsource, ctrtartget and ctrdata CSRs using sscsrind extension. The series is based on Smcdeleg/Ssccfg counter delegation extension [2] patches [3]. CTR itself doesn't depend on counter delegation support. This rebase is basically to include the Smcsrind patches. The last patch is in the perf tool to allow processing 256 entries. Without this perf seems to consider that sample as corrupted and discards it. Here is the link to a quick guide [4] to setup and run a basic perf demo on Linux to use CTR Ext. Qemu patches are merged upstream and is available with latest version. Opensbi patch is merged upstream and is available with latest version. [0]: https://github.com/riscv/riscv-control-transfer-records/releases/tag/v1.0 [1]: https://github.com/riscvarchive/riscv-indirect-csr-access/releases/tag/v1.0.0 [2]: https://github.com/riscvarchive/riscv-smcdeleg-ssccfg/releases/tag/v1.0.0 [3]: https://lore.kernel.org/lkml/20250114-counter_delegation-v2-0-8ba74cdb851b@rivosinc.com/ [4]: https://github.com/vikramsgh/riscv_linux_ctr_demo/wiki/Steps-to-run-basic-CTR-demo-on-RISCV-Virt To: Peter Zijlstra To: Ingo Molnar To: Arnaldo Carvalho de Melo To: Namhyung Kim To: Mark Rutland To: Alexander Shishkin To: Jiri Olsa To: Ian Rogers To: Adrian Hunter To: Paul Walmsley To: Palmer Dabbelt To: Albert Ou To: Alexandre Ghiti To: Atish Kumar Patra To: Anup Patel To: Will Deacon To: Rob Herring To: Krzysztof Kozlowski To: Conor Dooley To: Beeman Strong Cc: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-riscv@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Cc: Conor Dooley Cc: devicetree@vger.kernel.org --- Changelog: v5: - Rebased CTR driver and support files to Linux kernel version 7.4 RC3 v4: - Ported CTR driver and support files from kernel version 6.14 to kernel version 7.2 - Added CSR indirect access header file to be used by CTR driver - Changes in sched_task call back signature to accomodate new kernel headers - Minor clean up v3: - Added missing To/Cc, especially devicetree@vger.kernel.org - Changed the commit description to better describe the need of perf tool change that increases max sample size processing capacity of remove_loops function. - Minor fixes found while doing a virtualization PoC. - Added the missing commit and repository information to dt-bindings, indicating where the extension was ratified. v2 - Added context save/restore support for tasks using CTR feature. - https://lore.kernel.org/lkml/20250116230955.867152-1-rkanwal@rivosinc.com/ v1: - https://lore.kernel.org/lkml/20240529185337.182722-1-rkanwal@rivosinc.com/ --- Vikram Singh (7): perf: Increase the maximum number of branches remove_loops() can process. riscv: pmu: Add Control transfer records CSR definations. riscv: Add Control Transfer Records extension parsing riscv: pmu: Add infrastructure for Control Transfer Record riscv: pmu: Add driver for Control Transfer Records Ext riscv: pmu: Integrate CTR Ext support in riscv_pmu_dev driver dt-bindings: riscv: add Sxctr ISA extension description .../devicetree/bindings/riscv/extensions.yaml | 29 + MAINTAINERS | 3 + arch/riscv/include/asm/csr.h | 95 +++ arch/riscv/include/asm/hwcap.h | 6 + arch/riscv/kernel/cpufeature.c | 2 + drivers/perf/Kconfig | 16 + drivers/perf/Makefile | 1 + drivers/perf/riscv_ctr.c | 609 ++++++++++++++++++ drivers/perf/riscv_pmu.c | 21 +- drivers/perf/riscv_pmu_legacy.c | 2 + drivers/perf/riscv_pmu_sbi.c | 87 ++- include/linux/perf/riscv_pmu.h | 59 +- tools/perf/util/machine.c | 21 +- 13 files changed, 939 insertions(+), 12 deletions(-) create mode 100644 drivers/perf/riscv_ctr.c -- 2.43.0