Skip to contentSkip to conversation

Miscellaneous fixes for PMU driver

PATCH Superseded Atish Patra 4 participants 7 messages May 13, 2022 – Jun 9, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Miscellaneous fixes for PMU driver

This series fixes issues PMU driver code.
PATCH 1 & 3 are fixes for rv32 while PATCH 2 fixes a redundant user page update issue during counter start.

Changes from v1->v2:
1. Add proper compile time rv32 checks.

Atish Patra (3):
RISC-V: Fix counter restart during overflow for RV32
RISC-V: Update user page mapping only once during start
RISC-V: Fix SBI PMU calls for RV32

drivers/perf/riscv_pmu.c | 1 -
drivers/perf/riscv_pmu_sbi.c | 16 ++++++++++++++++

2 files changed, 16 insertions(+), 1 deletion(-)

--
2.25.1

#1 lore raw

PATCH v2 1/3 RISC-V: Fix counter restart during overflow for RV32

Pass the upper half of the initial value of the counter correctly for RV32.

Fixes 4905ec2fb7e6 ("RISC-V: Add sscofpmf extension support")
---
 drivers/perf/riscv_pmu_sbi.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/perf/riscv_pmu_sbi.c +5 -0
index a1317a483512..1e6c150c892a 100644
@@ -525,8 +525,13 @@ static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu,
 			hwc = &event->hw;
 			max_period = riscv_pmu_ctr_get_width_mask(event);
 			init_val = local64_read(&hwc->prev_count) & max_period;
+#if defined(CONFIG_32BIT)
+			sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, idx, 1,
+				  flag, init_val, init_val >> 32, 0);
+#else
 			sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, idx, 1,
 				  flag, init_val, 0, 0);
+#endif
 		}
 		ctr_ovf_mask = ctr_ovf_mask >> 1;
 		idx++;
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/3 RISC-V: Update user page mapping only once during start

In reply to Atish Patra

Currently, riscv_pmu_event_set_period updates the userpage mapping. However, the caller of riscv_pmu_event_set_period should update the userpage mapping because the counter can not be updated/started from set_period function in counter overflow path.

Invoke the perf_event_update_userpage at the caller so that it doesn't get invoked twice during counter start path.

Fixes f5bfa23f576f ("RISC-V: Add a perf core library for pmu drivers")
---
 drivers/perf/riscv_pmu.c     | 1 -
 drivers/perf/riscv_pmu_sbi.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/perf/riscv_pmu.c +0 -1
index b2b8d2074ed0..130b9f1a40e0 100644
@@ -170,7 +170,6 @@ int riscv_pmu_event_set_period(struct perf_event *event)
 		left = (max_period >> 1);
 
 	local64_set(&hwc->prev_count, (u64)-left);
-	perf_event_update_userpage(event);
 
 	return overflow;
 }
drivers/perf/riscv_pmu_sbi.c +1 -0
index 1e6c150c892a..7ad92039a718 100644
@@ -532,6 +532,7 @@ static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu,
 			sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, idx, 1,
 				  flag, init_val, 0, 0);
 #endif
+			perf_event_update_userpage(event);
 		}
 		ctr_ovf_mask = ctr_ovf_mask >> 1;
 		idx++;
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 3/3 RISC-V: Fix SBI PMU calls for RV32

In reply to Atish Patra

Some of the SBI PMU calls does not pass 64bit arguments correctly and not under RV32 compile time flags. Currently, this doesn't create any incorrect results as RV64 ignores any value in the additional register and qemu doesn't support raw events.

Fix those SBI calls in order to set correct values for RV32.

Fixes e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU extension")
---
 drivers/perf/riscv_pmu_sbi.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/perf/riscv_pmu_sbi.c +10 -0
index 7ad92039a718..fab0dd497393 100644
@@ -274,8 +274,13 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event)
 		cflags |= SBI_PMU_CFG_FLAG_SET_UINH;
 
 	/* retrieve the available counter index */
+#if defined(CONFIG_32BIT)
+	ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, cmask,
+			cflags, hwc->event_base, hwc->config, hwc->config >> 32);
+#else
 	ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, cmask,
 			cflags, hwc->event_base, hwc->config, 0);
+#endif
 	if (ret.error) {
 		pr_debug("Not able to find a counter for event %lx config %llx\n",
 			hwc->event_base, hwc->config);
@@ -417,8 +422,13 @@ static void pmu_sbi_ctr_start(struct perf_event *event, u64 ival)
 	struct hw_perf_event *hwc = &event->hw;
 	unsigned long flag = SBI_PMU_START_FLAG_SET_INIT_VALUE;
 
+#if defined(CONFIG_32BIT)
 	ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, hwc->idx,
 			1, flag, ival, ival >> 32, 0);
+#else
+	ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, hwc->idx,
+			1, flag, ival, 0, 0);
+#endif
 	if (ret.error && (ret.error != SBI_ERR_ALREADY_STARTED))
 		pr_err("Starting counter idx %d failed with error %d\n",
 			hwc->idx, sbi_err_map_linux_errno(ret.error));
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
reviewer Reviewed-by on v2 3/3
#4 lore raw

Re: [PATCH v2 3/3] RISC-V: Fix SBI PMU calls for RV32

Quoted 7 lines · Atish Patra

Some of the SBI PMU calls does not pass 64bit arguments correctly and not under RV32 compile time flags. Currently, this doesn't create any incorrect results as RV64 ignores any value in the additional register and qemu doesn't support raw events.

Quoted 5 lines

Fix those SBI calls in order to set correct values for RV32.

Fixes e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU extension")

Looks good to me.

Regards,
Anup

Quoted 39 lines
---
 drivers/perf/riscv_pmu_sbi.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/perf/riscv_pmu_sbi.c +10 -1
index 7ad92039a718..fab0dd497393 100644
@@ -274,8 +274,13 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event)
                cflags |= SBI_PMU_CFG_FLAG_SET_UINH;
 
        /* retrieve the available counter index */
+#if defined(CONFIG_32BIT)
+       ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, cmask,
+                       cflags, hwc->event_base, hwc->config, hwc->config >> 32);
+#else
        ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase, cmask,
                        cflags, hwc->event_base, hwc->config, 0);
+#endif
        if (ret.error) {
                pr_debug("Not able to find a counter for event %lx config %llx\n",
                        hwc->event_base, hwc->config);
@@ -417,8 +422,13 @@ static void pmu_sbi_ctr_start(struct perf_event *event, u64 ival)
        struct hw_perf_event *hwc = &event->hw;
        unsigned long flag = SBI_PMU_START_FLAG_SET_INIT_VALUE;
 
+#if defined(CONFIG_32BIT)
        ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, hwc->idx,
                        1, flag, ival, ival >> 32, 0);
+#else
+       ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, hwc->idx,
+                       1, flag, ival, 0, 0);
+#endif
        if (ret.error && (ret.error != SBI_ERR_ALREADY_STARTED))
                pr_err("Starting counter idx %d failed with error %d\n",
                        hwc->idx, sbi_err_map_linux_errno(ret.error));
--

2.25.1

maintainer
#5 lore raw
In reply to Atish Patra
Quoted 7 lines · Atish Patra

This series fixes issues PMU driver code.
PATCH 1 & 3 are fixes for rv32 while PATCH 2 fixes a redundant user page update issue during counter start.

Changes from v1->v2:
1. Add proper compile time rv32 checks.

Quoted 8 lines

Atish Patra (3):
RISC-V: Fix counter restart during overflow for RV32
RISC-V: Update user page mapping only once during start
RISC-V: Fix SBI PMU calls for RV32

drivers/perf/riscv_pmu.c | 1 -
drivers/perf/riscv_pmu_sbi.c | 16 ++++++++++++++++

2 files changed, 16 insertions(+), 1 deletion(-)

+Will and Mark.

Will recently took some stuff for drivers/perf/riscv_* into his for-next/perf tree (which I didn't even know about until then, oops), but the previous stuff I took through the RISC-V tree. Always happy to get stuff out of my tree, just LMK what you want me to do here.

I did some minor cleanups to the commit text and put them over at palmer/riscv-pmu_fixes, it's all passing my tests. These generally look fine to me and they're all stable backports, so no big rush on the merge window (which I still have stuff for).

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#6 lore raw

Hey Palmer,

Quoted 24 lines · Palmer Dabbelt
Quoted 7 lines · Atish Patra

This series fixes issues PMU driver code.
PATCH 1 & 3 are fixes for rv32 while PATCH 2 fixes a redundant user page update issue during counter start.

Changes from v1->v2:
1. Add proper compile time rv32 checks.

Quoted 8 lines

Atish Patra (3):
RISC-V: Fix counter restart during overflow for RV32
RISC-V: Update user page mapping only once during start
RISC-V: Fix SBI PMU calls for RV32

drivers/perf/riscv_pmu.c | 1 -
drivers/perf/riscv_pmu_sbi.c | 16 ++++++++++++++++

2 files changed, 16 insertions(+), 1 deletion(-)

+Will and Mark.

Will recently took some stuff for drivers/perf/riscv_* into his for-next/perf tree (which I didn't even know about until then, oops), but the previous stuff I took through the RISC-V tree. Always happy to get stuff out of my tree, just LMK what you want me to do here.

Quoted 4 lines

I did some minor cleanups to the commit text and put them over at palmer/riscv-pmu_fixes, it's all passing my tests. These generally look fine to me and they're all stable backports, so no big rush on the merge window (which I still have stuff for).

I don't have any perf driver fixes queued at the moment, so please just include these changes along with any other riscv fixes you have.

Thanks,

Will