From: Samuel Holland <samuel.holland@sifive.com>
To: Atish Patra <atishp@rivosinc.com>,
Anup Patel <anup@brainfault.org>, Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Mayuresh Chitale <mchitale@ventanamicro.com>
Cc: linux-riscv@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Palmer Dabbelt <palmer@rivosinc.com>,
kvm@vger.kernel.org, kvm-riscv@lists.infradead.org
Subject: Re: [PATCH 3/8] drivers/perf: riscv: Add raw event v2 support
Date: Mon, 2 Dec 2024 16:37:36 -0600 [thread overview]
Message-ID: <e124c532-7a08-4788-843d-345827e35f5f@sifive.com> (raw)
In-Reply-To: <20241119-pmu_event_info-v1-3-a4f9691421f8@rivosinc.com>
Hi Atish,
On 2024-11-19 2:29 PM, Atish Patra wrote:
> SBI v3.0 introduced a new raw event type that allows wider
> mhpmeventX width to be programmed via CFG_MATCH.
>
> Use the raw event v2 if SBI v3.0 is available.
>
> Signed-off-by: Atish Patra <atishp@rivosinc.com>
> ---
> arch/riscv/include/asm/sbi.h | 4 ++++
> drivers/perf/riscv_pmu_sbi.c | 18 ++++++++++++------
> 2 files changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
> index 9be38b05f4ad..3ee9bfa5e77c 100644
> --- a/arch/riscv/include/asm/sbi.h
> +++ b/arch/riscv/include/asm/sbi.h
> @@ -159,7 +159,10 @@ struct riscv_pmu_snapshot_data {
>
> #define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0)
> #define RISCV_PMU_PLAT_FW_EVENT_MASK GENMASK_ULL(61, 0)
> +/* SBI v3.0 allows extended hpmeventX width value */
> +#define RISCV_PMU_RAW_EVENT_V2_MASK GENMASK_ULL(55, 0)
> #define RISCV_PMU_RAW_EVENT_IDX 0x20000
> +#define RISCV_PMU_RAW_EVENT_V2_IDX 0x30000
> #define RISCV_PLAT_FW_EVENT 0xFFFF
>
> /** General pmu event codes specified in SBI PMU extension */
> @@ -217,6 +220,7 @@ enum sbi_pmu_event_type {
> SBI_PMU_EVENT_TYPE_HW = 0x0,
> SBI_PMU_EVENT_TYPE_CACHE = 0x1,
> SBI_PMU_EVENT_TYPE_RAW = 0x2,
> + SBI_PMU_EVENT_TYPE_RAW_V2 = 0x3,
> SBI_PMU_EVENT_TYPE_FW = 0xf,
> };
>
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index 50cbdbf66bb7..f0e845ff6b79 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -59,7 +59,7 @@ asm volatile(ALTERNATIVE( \
> #define PERF_EVENT_FLAG_USER_ACCESS BIT(SYSCTL_USER_ACCESS)
> #define PERF_EVENT_FLAG_LEGACY BIT(SYSCTL_LEGACY)
>
> -PMU_FORMAT_ATTR(event, "config:0-47");
> +PMU_FORMAT_ATTR(event, "config:0-55");
> PMU_FORMAT_ATTR(firmware, "config:62-63");
>
> static bool sbi_v2_available;
> @@ -527,18 +527,24 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
> break;
> case PERF_TYPE_RAW:
> /*
> - * As per SBI specification, the upper 16 bits must be unused
> - * for a hardware raw event.
> + * As per SBI v0.3 specification,
> + * -- the upper 16 bits must be unused for a hardware raw event.
> + * As per SBI v3.0 specification,
> + * -- the upper 8 bits must be unused for a hardware raw event.
> * Bits 63:62 are used to distinguish between raw events
> * 00 - Hardware raw event
> * 10 - SBI firmware events
> * 11 - Risc-V platform specific firmware event
> */
> -
> switch (config >> 62) {
> case 0:
> - ret = RISCV_PMU_RAW_EVENT_IDX;
> - *econfig = config & RISCV_PMU_RAW_EVENT_MASK;
> + if (sbi_v3_available) {
> + *econfig = config & RISCV_PMU_RAW_EVENT_V2_MASK;
> + ret = RISCV_PMU_RAW_EVENT_V2_IDX;
> + } else {
> + *econfig = config & RISCV_PMU_RAW_EVENT_MASK;
> + ret = RISCV_PMU_RAW_EVENT_IDX;
Shouldn't we check to see if any of bits 48-55 are set and return an error,
instead of silently requesting the wrong event?
Regards,
Samuel
> + }
> break;
> case 2:
> ret = (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16);
>
next prev parent reply other threads:[~2024-12-02 22:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 20:29 [PATCH 0/8] Add SBI v3.0 PMU enhancements Atish Patra
2024-11-19 20:29 ` [PATCH 1/8] drivers/perf: riscv: Add SBI v3.0 flag Atish Patra
2024-11-19 20:29 ` [PATCH 2/8] drivers/perf: riscv: Fix Platform firmware event data Atish Patra
2024-11-28 13:10 ` Alexandre Ghiti
2024-12-02 18:26 ` Atish Kumar Patra
2024-11-19 20:29 ` [PATCH 3/8] drivers/perf: riscv: Add raw event v2 support Atish Patra
2024-12-02 22:37 ` Samuel Holland [this message]
2024-12-03 0:15 ` Atish Kumar Patra
2024-12-03 2:39 ` Samuel Holland
2024-12-09 18:52 ` Atish Kumar Patra
2024-11-19 20:29 ` [PATCH 4/8] RISC-V: KVM: Add support for Raw event v2 Atish Patra
2024-11-19 20:29 ` [PATCH 5/8] drivers/perf: riscv: Implement PMU event info function Atish Patra
2024-12-02 22:49 ` Samuel Holland
2024-12-10 1:16 ` Atish Kumar Patra
2024-11-19 20:29 ` [PATCH 6/8] drivers/perf: riscv: Export " Atish Patra
2024-11-19 20:29 ` [PATCH 7/8] RISC-V: KVM: Implement get " Atish Patra
2024-12-02 23:02 ` Samuel Holland
2024-12-10 1:16 ` Atish Kumar Patra
2024-11-19 20:29 ` [PATCH 8/8] RISC-V: KVM: Upgrade the supported SBI version to 3.0 Atish Patra
2025-01-09 19:40 ` [PATCH 0/8] Add SBI v3.0 PMU enhancements patchwork-bot+linux-riscv
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=e124c532-7a08-4788-843d-345827e35f5f@sifive.com \
--to=samuel.holland@sifive.com \
--cc=anup@brainfault.org \
--cc=atishp@rivosinc.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mchitale@ventanamicro.com \
--cc=palmer@dabbelt.com \
--cc=palmer@rivosinc.com \
--cc=paul.walmsley@sifive.com \
--cc=will@kernel.org \
/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
all inboxes | Powered by JetHome®