From nobody Wed Apr 8 19:14:14 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 469972F6922; Wed, 25 Feb 2026 06:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772000744; cv=none; b=PRwhIEVvXjVVFOAyL4sh2OgeL1Xe2ZqkGjYHhgI4imjOWaYNRd7UpqZP/R4NVzu8yuhm1LFFSGXON5+CPvCsYeXh3tbYC6oGF0xnO/wTMRZNnBBTAHa8q0obuOwtVVzmuLNvJfadbdYpTbIK+Fbjtl1J8c7WT+BUucjSYpBMRG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772000744; c=relaxed/simple; bh=+DL1DclBlXFeMArXfCaUevQHEMgSDsY+8x6YxAFkm14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VbT30mBBCgJOM04arTPKJPCm+PxleKttshyUvs4GNo1nv57kEBqoHny8RbRCsZ3QI53L6vOCbYifyOHZLfxES+1b2UzWyovOC52bw0VYoDVyCCMaZ+hjVNuTr6LQCxazdWcBMlkhWegvYXNrK91N7IrlvU+RP2gNPmITNCZWNbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=a3UZ1eyO; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="a3UZ1eyO" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61OLaCwH2432418; Wed, 25 Feb 2026 06:25:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=paPXV6QvgMm syxf0ALUvgRJENAz5jaR9fVu6RhkIUR8=; b=a3UZ1eyOgxRH3XwrEFbIZxKSzYw OxXwrqqHAURnE12qXqG1C1qR8uOckjumyz17L0oF9YH8isDC6LTAIW2BUGcyFXoG UvZkOCp7TSz7QhdfAU8OgAu16S/Xdzommcfw8kdpTHsXBo62In5g5VjYR3sRJ3Au HQlHTpBOLgnmYsir2ZJi8TkN5vv7cALdZE0YognhxEChk/cxrR+QijqgArKKsFJV 1zWCMV0RwSgyFvPLEjqiYnHNSzgbt+zFKt4t00TI4NGOauANlxpUFsILpOv52DjU LvGWwpHFUHHDQhaj85cuxIYaEibHJutJN1/hHLAW7MSgEjx31fJjssPqnzw== Received: from apblrppmta01.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4chekjajv2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Feb 2026 06:25:00 +0000 (GMT) Received: from pps.filterd (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTP id 61P6OtoB001344; Wed, 25 Feb 2026 06:24:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 4cf5sm83eu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Feb 2026 06:24:56 +0000 Received: from APBLRPPMTA01.qualcomm.com (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 61P6OtgG001314; Wed, 25 Feb 2026 06:24:55 GMT Received: from hu-devc-blr-u24-a.qualcomm.com (hu-anuppate-blr.qualcomm.com [10.131.36.165]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 61P6OtGF001304 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Feb 2026 06:24:55 +0000 Received: by hu-devc-blr-u24-a.qualcomm.com (Postfix, from userid 486687) id DBE7A24B76; Wed, 25 Feb 2026 11:54:53 +0530 (+0530) From: Anup Patel To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Palmer Dabbelt , Paul Walmsley , Greg KH , Alexander Shishkin , Ian Rogers Cc: Alexandre Ghiti , Peter Zijlstra , Ingo Molnar , Namhyung Kim , Mark Rutland , Jiri Olsa , Adrian Hunter , Liang Kan , Mayuresh Chitale , Anup Patel , Atish Patra , Andrew Jones , Sunil V L , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Mayuresh Chitale , Anup Patel , Nutty Liu Subject: [PATCH v3 10/12] perf tools: Add RISC-V trace PMU record capabilities Date: Wed, 25 Feb 2026 11:54:46 +0530 Message-ID: <20260225062448.4027948-11-anup.patel@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260225062448.4027948-1-anup.patel@oss.qualcomm.com> References: <20260225062448.4027948-1-anup.patel@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Authority-Analysis: v=2.4 cv=RNe+3oi+ c=1 sm=1 tr=0 ts=699e95bc cx=c_pps a=Ou0eQOY4+eZoSc0qltEV5Q==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=69EAbJreAAAA:8 a=kkaCVUy_t53esOPYLmQA:9 X-Proofpoint-ORIG-GUID: AaNR_0HlXantu2wAn2mDH_lOpq3AXZUI X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjI1MDA2MSBTYWx0ZWRfX3jRX0iKg+9XI ruWV8steDOVgIpVzAxlzrWk2tEA8Ct3tbeq6wlMzopMolPe8NO8I2ltmJqa7yL3SKVvPf2pn0EC 1EK6B/B5qs9TpMvUrTdqSDfrDgDkOunvMKmDvceId2tFPvX/agZ4A6KUJB8H0DkWPSaPGBgdOzb zBWk9GYtcJMGn6PrCIzT+k+hn1q/UiCodbCmP8CmXgaIqW9n5GOySesGsZXnuzR46+DjXhZfr2d 7HakI7WrqHt7AejYBdACMUcK15ETBrMwo5bNh/3W+4gVFDXKBp7XhJ2yFAz8K9EMyuyZZ0aiSOb /eEPKnbjmuN8wqs0GI4L3WaFKaFEZtdGpEQEoilnR8xAzj7TFme47wUqZQLKXBWp2tGgnoCYLBP IaO/yuWOwP13+wM9aPnpgQPfT/aPvbADOmki5e5/2/Y7gPyc511OwQKBPpvoPBuSu91nkSlALou n+tGmR6qdUVA0EYWSJQ== X-Proofpoint-GUID: AaNR_0HlXantu2wAn2mDH_lOpq3AXZUI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-24_03,2026-02-23_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 phishscore=0 clxscore=1015 spamscore=0 impostorscore=0 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2602250061 Content-Type: text/plain; charset="utf-8" From: Mayuresh Chitale Introduce the required auxiliary API functions allowing the perf core to interact with RISC-V trace perf driver. Co-developed-by: Anup Patel Signed-off-by: Anup Patel Signed-off-by: Mayuresh Chitale Reviewed-by: Nutty Liu --- tools/perf/arch/riscv/util/Build | 1 + tools/perf/arch/riscv/util/auxtrace.c | 219 ++++++++++++++++++++++++++ tools/perf/util/auxtrace.c | 1 + tools/perf/util/auxtrace.h | 1 + tools/perf/util/rvtrace.h | 18 +++ 5 files changed, 240 insertions(+) create mode 100644 tools/perf/arch/riscv/util/auxtrace.c create mode 100644 tools/perf/util/rvtrace.h diff --git a/tools/perf/arch/riscv/util/Build b/tools/perf/arch/riscv/util/= Build index 2328fb9a30a3..e07d5525ece6 100644 --- a/tools/perf/arch/riscv/util/Build +++ b/tools/perf/arch/riscv/util/Build @@ -1 +1,2 @@ perf-util-y +=3D header.o +perf-util-y +=3D auxtrace.o diff --git a/tools/perf/arch/riscv/util/auxtrace.c b/tools/perf/arch/riscv/= util/auxtrace.c new file mode 100644 index 000000000000..5293ece2147d --- /dev/null +++ b/tools/perf/arch/riscv/util/auxtrace.c @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Risc-V E-Trace support + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include "../../../util/auxtrace.h" +#include "../../../util/cpumap.h" +#include "../../../util/debug.h" +#include "../../../util/event.h" +#include "../../../util/evlist.h" +#include "../../../util/evsel.h" +#include "../../../util/rvtrace.h" +#include "../../../util/pmu.h" +#include "../../../util/record.h" +#include "../../../util/session.h" +#include "../../../util/tsc.h" + +#define RVTRACE_PMU_NAME "rvtrace" +#define KiB(x) ((x) * 1024) +#define MiB(x) ((x) * 1024 * 1024) + +struct rvtrace_recording { + struct auxtrace_record itr; + struct perf_pmu *rvtrace_pmu; + struct evlist *evlist; +}; + +static size_t rvtrace_info_priv_size(struct auxtrace_record *itr __maybe_u= nused, + struct evlist *evlist __maybe_unused) +{ + return RVTRACE_AUXTRACE_PRIV_SIZE; +} + +static int rvtrace_info_fill(struct auxtrace_record *itr, struct perf_sess= ion *session, + struct perf_record_auxtrace_info *auxtrace_info, size_t priv_size) +{ + struct rvtrace_recording *ptr =3D container_of(itr, struct rvtrace_record= ing, itr); + struct perf_pmu *rvtrace_pmu =3D ptr->rvtrace_pmu; + + if (priv_size !=3D RVTRACE_AUXTRACE_PRIV_SIZE) + return -EINVAL; + + if (!session->evlist->core.nr_mmaps) + return -EINVAL; + + auxtrace_info->type =3D PERF_AUXTRACE_RISCV_TRACE; + auxtrace_info->priv[0] =3D rvtrace_pmu->type; + + return 0; +} + +static int rvtrace_set_auxtrace_mmap_page(struct record_opts *opts) +{ + bool privileged =3D perf_event_paranoid_check(-1); + + if (!opts->full_auxtrace) + return 0; + + if (opts->full_auxtrace && !opts->auxtrace_mmap_pages) { + if (privileged) { + opts->auxtrace_mmap_pages =3D MiB(16) / page_size; + } else { + opts->auxtrace_mmap_pages =3D KiB(128) / page_size; + if (opts->mmap_pages =3D=3D UINT_MAX) + opts->mmap_pages =3D KiB(256) / page_size; + } + } + + /* Validate auxtrace_mmap_pages */ + if (opts->auxtrace_mmap_pages) { + size_t sz =3D opts->auxtrace_mmap_pages * (size_t)page_size; + size_t min_sz =3D KiB(8); + + if (sz < min_sz || !is_power_of_2(sz)) { + pr_err("Invalid mmap size : must be at least %zuKiB and a power of 2\n", + min_sz / 1024); + return -EINVAL; + } + } + + return 0; +} + +static int rvtrace_recording_options(struct auxtrace_record *itr, struct e= vlist *evlist, + struct record_opts *opts) +{ + struct rvtrace_recording *ptr =3D container_of(itr, struct rvtrace_record= ing, itr); + struct perf_pmu *rvtrace_pmu =3D ptr->rvtrace_pmu; + struct evsel *evsel, *rvtrace_evsel =3D NULL; + struct evsel *tracking_evsel; + int err; + + ptr->evlist =3D evlist; + evlist__for_each_entry(evlist, evsel) { + if (evsel->core.attr.type =3D=3D rvtrace_pmu->type) { + if (rvtrace_evsel) { + pr_err("There may be only one " RVTRACE_PMU_NAME "x event\n"); + return -EINVAL; + } + evsel->core.attr.freq =3D 0; + evsel->core.attr.sample_period =3D 1; + evsel->needs_auxtrace_mmap =3D true; + rvtrace_evsel =3D evsel; + opts->full_auxtrace =3D true; + } + } + + err =3D rvtrace_set_auxtrace_mmap_page(opts); + if (err) + return err; + /* + * To obtain the auxtrace buffer file descriptor, the auxtrace event + * must come first. + */ + evlist__to_front(evlist, rvtrace_evsel); + evsel__set_sample_bit(rvtrace_evsel, TIME); + + /* Add dummy event to keep tracking */ + err =3D parse_event(evlist, "dummy:u"); + if (err) + return err; + + tracking_evsel =3D evlist__last(evlist); + evlist__set_tracking_event(evlist, tracking_evsel); + + tracking_evsel->core.attr.freq =3D 0; + tracking_evsel->core.attr.sample_period =3D 1; + evsel__set_sample_bit(tracking_evsel, TIME); + + return 0; +} + +static u64 rvtrace_reference(struct auxtrace_record *itr __maybe_unused) +{ + return rdtsc(); +} + +static void rvtrace_recording_free(struct auxtrace_record *itr) +{ + struct rvtrace_recording *ptr =3D + container_of(itr, struct rvtrace_recording, itr); + + free(ptr); +} + +static struct auxtrace_record *rvtrace_recording_init(int *err, struct per= f_pmu *rvtrace_pmu) +{ + struct rvtrace_recording *ptr; + + if (!rvtrace_pmu) { + *err =3D -ENODEV; + return NULL; + } + + ptr =3D zalloc(sizeof(*ptr)); + if (!ptr) { + *err =3D -ENOMEM; + return NULL; + } + + ptr->rvtrace_pmu =3D rvtrace_pmu; + ptr->itr.recording_options =3D rvtrace_recording_options; + ptr->itr.info_priv_size =3D rvtrace_info_priv_size; + ptr->itr.info_fill =3D rvtrace_info_fill; + ptr->itr.free =3D rvtrace_recording_free; + ptr->itr.reference =3D rvtrace_reference; + ptr->itr.read_finish =3D auxtrace_record__read_finish; + ptr->itr.alignment =3D 0; + + *err =3D 0; + return &ptr->itr; +} + +static struct perf_pmu *find_pmu_for_event(struct perf_pmu **pmus, + int pmu_nr, struct evsel *evsel) +{ + int i; + + if (!pmus) + return NULL; + + for (i =3D 0; i < pmu_nr; i++) { + if (evsel->core.attr.type =3D=3D pmus[i]->type) + return pmus[i]; + } + + return NULL; +} + +struct auxtrace_record *auxtrace_record__init(struct evlist *evlist, int *= err) +{ + struct perf_pmu *rvtrace_pmu =3D NULL; + struct perf_pmu *found_pmu =3D NULL; + struct evsel *evsel; + + if (!evlist) + return NULL; + + rvtrace_pmu =3D perf_pmus__find(RVTRACE_PMU_NAME); + evlist__for_each_entry(evlist, evsel) { + if (rvtrace_pmu && !found_pmu) + found_pmu =3D find_pmu_for_event(&rvtrace_pmu, 1, evsel); + } + + if (found_pmu) + return rvtrace_recording_init(err, rvtrace_pmu); + + *err =3D 0; + return NULL; +} diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index a224687ffbc1..944a43d48739 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -1411,6 +1411,7 @@ int perf_event__process_auxtrace_info(const struct pe= rf_tool *tool __maybe_unuse case PERF_AUXTRACE_VPA_DTL: err =3D powerpc_vpadtl_process_auxtrace_info(event, session); break; + case PERF_AUXTRACE_RISCV_TRACE: case PERF_AUXTRACE_UNKNOWN: default: return -EINVAL; diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index 6947f3f284c0..4f4714c1b53f 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -46,6 +46,7 @@ enum auxtrace_type { PERF_AUXTRACE_S390_CPUMSF, PERF_AUXTRACE_HISI_PTT, PERF_AUXTRACE_VPA_DTL, + PERF_AUXTRACE_RISCV_TRACE, }; =20 enum itrace_period_type { diff --git a/tools/perf/util/rvtrace.h b/tools/perf/util/rvtrace.h new file mode 100644 index 000000000000..24b32947fb4c --- /dev/null +++ b/tools/perf/util/rvtrace.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: Mayuresh Chitale + */ + +#ifndef INCLUDE__UTIL_PERF_RVTRACE_H__ +#define INCLUDE__UTIL_PERF_RVTRACE_H__ + +#include "debug.h" +#include "auxtrace.h" +#include "util/event.h" +#include "util/session.h" +#include + +#define RVTRACE_AUXTRACE_PRIV_SIZE sizeof(u64) + +#endif --=20 2.43.0