public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Yicong Yang <yangyicong@huawei.com>
To: <will@kernel.org>, <mark.rutland@arm.com>,
	<catalin.marinas@arm.com>, <broonie@kernel.org>,
	<james.morse@arm.com>, <anshuman.khandual@arm.com>,
	<linux-arm-kernel@lists.infradead.org>
Cc: <jonathan.cameron@huawei.com>,
	<shameerali.kolothum.thodi@huawei.com>,
	<prime.zeng@hisilicon.com>, <fanghao11@huawei.com>,
	<yangyicong@hisilicon.com>, <linuxarm@huawei.com>
Subject: [PATCH v2 3/3] perf: arm_spe: Enable the profiling of EL0&1 translation regime
Date: Thu, 30 Nov 2023 15:46:09 +0800	[thread overview]
Message-ID: <20231130074609.58668-4-yangyicong@huawei.com> (raw)
In-Reply-To: <20231130074609.58668-1-yangyicong@huawei.com>

From: Yicong Yang <yangyicong@hisilicon.com>

On a VHE enabled host, the PMSCR_EL1 will be redirect to PMSCR_EL2
and we're actually enabling E0SPE and E2SPE in the driver. This means
the data from EL0&1 translation regime of a VM will not be profiled.
So this patch tries to add the support of profiling EL0 and EL1 of
a VM. Users can filter data of different exception level by using
the perf's exclude_* attributes. The exclude_* decision is referred
to Documentation/arch/arm64/perf.rst and the implementation of
arm_pmuv3.

Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 drivers/perf/arm_spe_pmu.c | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index 09570d4d63cd..a647d625f359 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -316,21 +316,44 @@ static u64 arm_spe_event_to_pmscr(struct perf_event *event)
 static void arm_spe_pmu_set_pmscr(struct perf_event *event)
 {
 	struct perf_event_attr *attr = &event->attr;
-	u64 reg = 0;
+	u64 pmscr_el1, pmscr_el12;
 
-	reg = arm_spe_event_to_pmscr(event);
-	if (!attr->exclude_user)
-		reg |= PMSCR_EL1x_E0SPE;
+	pmscr_el1 = pmscr_el12 = arm_spe_event_to_pmscr(event);
+
+	/*
+	 * Map the exclude_* descision to ELx according to
+	 * Documentation/arch/arm64/perf.rst.
+	 */
+	if (is_kernel_in_hyp_mode()) {
+		if (!attr->exclude_kernel && !attr->exclude_host)
+			pmscr_el1 |= PMSCR_EL1x_E1SPE;
 
-	if (!attr->exclude_kernel)
-		reg |= PMSCR_EL1x_E1SPE;
+		if (!attr->exclude_kernel && !attr->exclude_guest)
+			pmscr_el12 |= PMSCR_EL1x_E1SPE;
+
+		if (!attr->exclude_user && !attr->exclude_host) {
+			pmscr_el1 |= PMSCR_EL1x_E0SPE;
+			pmscr_el12 |= PMSCR_EL1x_E0SPE;
+		}
+	} else {
+		if (!attr->exclude_kernel)
+			pmscr_el1 |= PMSCR_EL1x_E1SPE;
+
+		if (!attr->exclude_user)
+			pmscr_el1 |= PMSCR_EL1x_E0SPE;
+	}
 
 	isb();
-	write_sysreg_s(reg, SYS_PMSCR_EL1);
+	write_sysreg_s(pmscr_el1, SYS_PMSCR_EL1);
+	if (is_kernel_in_hyp_mode())
+		write_sysreg_s(pmscr_el12, SYS_PMSCR_EL12);
 }
 
 static void arm_spe_pmu_clr_pmscr(void)
 {
+	if (is_kernel_in_hyp_mode())
+		write_sysreg_s(0, SYS_PMSCR_EL12);
+
 	write_sysreg_s(0, SYS_PMSCR_EL1);
 	isb();
 }
-- 
2.24.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2023-11-30  7:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-30  7:46 [PATCH v2 0/3] Enable the profiling of EL0&1 translation regime of ARM SPE Yicong Yang
2023-11-30  7:46 ` [PATCH v2 1/3] arm64/sysreg: Add PMSCR_EL12 and factor out the common fields Yicong Yang
2023-11-30  7:46 ` [PATCH v2 2/3] perf: arm_spe: Factor out PMSCR set/clear operations Yicong Yang
2023-11-30  7:46 ` Yicong Yang [this message]
2024-04-11 14:28   ` [PATCH v2 3/3] perf: arm_spe: Enable the profiling of EL0&1 translation regime Will Deacon
2024-04-12  9:22     ` Yicong Yang
2024-04-12  9:59       ` Marc Zyngier
2024-04-12 10:12         ` Yicong Yang

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=20231130074609.58668-4-yangyicong@huawei.com \
    --to=yangyicong@huawei.com \
    --cc=anshuman.khandual@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=fanghao11@huawei.com \
    --cc=james.morse@arm.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linuxarm@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=prime.zeng@hisilicon.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=will@kernel.org \
    --cc=yangyicong@hisilicon.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