Add Andes PMU extension support
cover Add Andes PMU extension support
This patch series enables perf tool to utilize Andes PMU extension via PMU SBI calls, provides PMU device callbacks for event sampling and mode filtering.
We also provide a PMU node example of AX45MP in the last patch.
The OpenSBI and Linux patches can be found on Andes Technology GitHub
- https://github.com/andestech/opensbi/commits/andes-pmu-support
- https://github.com/andestech/linux/commits/andes-pmu-support
Yu Chien Peter Lin (6):
sbi: sbi_pmu: Add hw_counter_filter_mode() to pmu device
platform: include: andes45: Add PMU related CSR defines
platform: andes: Add Andes custom PMU support
platform: andes: Enable Andes PMU for AE350
platform: rzfive: Enable Andes PMU for RZ/Five
docs: pmu: Add Andes PMU node example
docs/pmu_support.md | 87 ++++++++++++++++++++++ include/sbi/sbi_pmu.h | 6 ++ lib/sbi/sbi_pmu.c | 5 +- platform/generic/Kconfig | 2 + platform/generic/andes/Kconfig | 4 + platform/generic/andes/ae350.c | 2 + platform/generic/andes/andes_pmu.c | 85 +++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes45.h | 26 +++++++ platform/generic/include/andes/andes_pmu.h | 12 +++ platform/generic/renesas/rzfive/rzfive.c | 2 + 11 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 platform/generic/andes/andes_pmu.c create mode 100644 platform/generic/include/andes/andes_pmu.h
Signature · 1 line
2.34.1
PATCH 1/6 sbi: sbi_pmu: Add hw_counter_filter_mode() to pmu device
Add support for custom PMU extensions to set inhibit bits on custom CSRs by introducing the PMU device callback hw_counter_filter_mode(). This allows the perf tool to restrict event counting under a specified privileged mode by appending a modifier, e.g. perf record -e event:k to count events only happening in kernel mode.
--- include/sbi/sbi_pmu.h | 6 ++++++ lib/sbi/sbi_pmu.c | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-)
include/sbi/sbi_pmu.h +6 -0
@@ -89,6 +89,12 @@ struct sbi_pmu_device {* Custom function returning the machine-specific irq-bit. */ int (*hw_counter_irq_bit)(void ); + +/** +* Custom function to inhibit counting of events while in +* specified mode. +*/ +void (*hw_counter_filter_mode)(unsigned long flags,int counter_index); };/** Get the PMU platform device */
lib/sbi/sbi_pmu.c +4 -1
@@ -594,7 +594,10 @@ static int pmu_update_hw_mhpmevent(struct sbi_pmu_hw_event *hw_evt, int ctr_idx, pmu_dev->hw_counter_disable_irq (ctr_idx);/* Update the inhibit flags based on inhibit flags received from supervisor */ -pmu_update_inhibit_flags (flags, &mhpmevent_val); +if (sbi_hart_has_extension (scratch,SBI_HART_EXT_SSCOFPMF )) +pmu_update_inhibit_flags (flags, &mhpmevent_val); +if (pmu_dev && pmu_dev->hw_counter_filter_mode) + pmu_dev->hw_counter_filter_mode (flags, ctr_idx);#if __riscv_xlen ==32 csr_write_num (CSR_MHPMEVENT3 + ctr_idx -3 , mhpmevent_val &0xFFFFFFFF );
Signature · 1 line
2.34.1
PATCH 2/6 platform: include: andes45: Add PMU related CSR defines
In reply to Yu Chien Peter LinThis patch adds CSR for Andes PMU extension.
--- platform/generic/include/andes/andes45.h | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
platform/generic/include/andes/andes45.h +26 -0
@@ -12,6 +12,17 @@#define CSR_MDCM_CFG 0xfc1#define CSR_MMSC_CFG 0xfc2 +/* Machine Trap Related Registers */ +#define CSR_MSLIDELEG 0x7d5 + +/* Counter Related Registers */ +#define CSR_MCOUNTERWEN 0x7ce +#define CSR_MCOUNTERINTEN 0x7cf +#define CSR_MCOUNTERMASK_M 0x7d1 +#define CSR_MCOUNTERMASK_S 0x7d2 +#define CSR_MCOUNTERMASK_U 0x7d3 +#define CSR_MCOUNTEROVF 0x7d4 +#define MICM_CFG_ISZ_OFFSET 6#define MICM_CFG_ISZ_MASK (0x7 << MICM_CFG_ISZ_OFFSET)
@@ -26,4 +37,19 @@#define MCACHE_CTL_CCTL_SUEN_OFFSET 8#define MCACHE_CTL_CCTL_SUEN_MASK (0x1 << MCACHE_CTL_CCTL_SUEN_OFFSET) +/* Performance monitor */ +#define MMSC_CFG_PMNDS_MASK (1 << 15) +#define MIP_PMOVI (1 << 18) + +#ifndef __ASSEMBLER__ + +#define andes_pmu () \ +({ \ + (((csr_read(CSR_MMSC_CFG) & \ + MMSC_CFG_PMNDS_MASK) \ + && misa_extension('S')) ? true : false); \ +}) + +#endif /* __ASSEMBLER__ */ +#endif /* _RISCV_ANDES45_H */
Signature · 1 line
2.34.1
PATCH 3/6 platform: andes: Add Andes custom PMU support
In reply to Yu Chien Peter LinBefore the ratification of Sscofpmf, the Andes PMU extension was designed to support the sampling and filtering of hardware performance counters, compatible with the current SBI PMU extension and Linux perf driver.
This patch implements the PMU extension platform callback and PMU device callbacks to update the corresponding custom CSRs.
--- platform/generic/andes/Kconfig | 4 + platform/generic/andes/andes_pmu.c | 85 ++++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes_pmu.h | 12 +++ 4 files changed, 102 insertions(+) create mode 100644 platform/generic/andes/andes_pmu.c create mode 100644 platform/generic/include/andes/andes_pmu.h
platform/generic/andes/Kconfig +4 -0
@@ -7,3 +7,7 @@ config ANDES45_PMA config ANDES_SBI bool "Andes SBI support" default n + +config ANDES_PMU + bool "Andes PMU support" + default n
platform/generic/andes/andes_pmu.c new file +85 -0
85 lines not on this page · raw message
platform/generic/andes/objects.mk +1 -0
@@ -7,3 +7,4 @@ platform-objs-$(CONFIG_PLATFORM_ANDES_AE350) += andes/ae350.o andes/sleep.o platform-objs-$(CONFIG_ANDES45_PMA) += andes/andes45-pma.o platform-objs-$(CONFIG_ANDES_SBI) += andes/andes_sbi.o +platform-objs-$(CONFIG_ANDES_PMU) += andes/andes_pmu.o
platform/generic/include/andes/andes_pmu.h new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: BSD-2-Clause + +#ifndef _RISCV_ANDES_PMU_H +#define _RISCV_ANDES_PMU_H + +#include <sbi/sbi_hart.h> +#include <sbi_utils/fdt/fdt_helper.h> + +int andes_pmu_extensions_init (const struct fdt_match *match, +struct sbi_hart_features *hfeatures); + +#endif /* _RISCV_ANDES_PMU_H */
Signature · 1 line
2.34.1
Lad
PATCH 3/6 platform: andes: Add Andes custom PMU support
Hi Lin-san,
Thank you for the patch.
Quoted 38 lines · On Wed, Sep 6, 2023 at 10:43?AM Yu Chien Peter Lin <[email protected]>…
Before the ratification of Sscofpmf, the Andes PMU extension was designed to support the sampling and filtering of hardware performance counters, compatible with the current SBI PMU extension and Linux perf driver.
This patch implements the PMU extension platform callback and PMU device callbacks to update the corresponding custom CSRs.
Signed-off-by Yu Chien Peter Lin <[email protected]>Reviewed-by Leo Yu-Chi Liang <[email protected]>--- platform/generic/andes/Kconfig | 4 + platform/generic/andes/andes_pmu.c | 85 ++++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes_pmu.h | 12 +++ 4 files changed, 102 insertions(+) create mode 100644 platform/generic/andes/andes_pmu.c create mode 100644 platform/generic/include/andes/andes_pmu.hplatform/generic/andes/Kconfig +4
-0@@ -7,3 +7,7 @@ config ANDES45_PMA config ANDES_SBI bool "Andes SBI support" default n + +config ANDES_PMU + bool "Andes PMU support" + default nplatform/generic/andes/andes_pmu.c new file +0
-0
platform/generic/andes/andes_pmu.c line 3
Quoted 3 lines
platform/generic/andes/andes_pmu.c new file +3
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* +* Copyright (C) 2022 Andes Technology Corporation
2023?
Quoted 15 lines
platform/generic/andes/andes_pmu.c new file +15
-0+* +*/ +#include <andes/andes45.h> +#include <andes/andes_pmu.h> +#include <sbi/riscv_asm.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_pmu.h> +#include <sbi/sbi_scratch.h> + +static void andes_hw_counter_enable_irq (uint32_t ctr_idx) +{ +unsigned long mip_val; + +if (ctr_idx >=SBI_PMU_HW_CTR_MAX ) +return ;
platform/generic/andes/andes_pmu.c line 28
Quoted 10 lines
platform/generic/andes/andes_pmu.c new file +10
-0+ + mip_val =csr_read (CSR_MIP ); +if (!(mip_val &MIP_PMOVI )) +csr_clear (CSR_MCOUNTEROVF ,BIT (ctr_idx)); + +csr_set (CSR_MCOUNTERINTEN ,BIT (ctr_idx)); +} + +static void andes_hw_counter_disable_irq (uint32_t ctr_idx) +{
Any reason why we dont check for ctr_idx >= SBI_PMU_HW_CTR_MAX?
Quoted 26 lines
platform/generic/andes/andes_pmu.c new file +26
-0+csr_clear (CSR_MCOUNTERINTEN ,BIT (ctr_idx)); +} + +static void andes_hw_counter_filter_mode (unsigned long flags,int ctr_idx) +{ +if (!flags) { +csr_write (CSR_MCOUNTERMASK_S ,0 ); +csr_write (CSR_MCOUNTERMASK_U ,0 ); + } +if (flags &SBI_PMU_CFG_FLAG_SET_UINH ) { +csr_clear (CSR_MCOUNTERMASK_S ,BIT (ctr_idx)); +csr_set (CSR_MCOUNTERMASK_U ,BIT (ctr_idx)); + } +if (flags &SBI_PMU_CFG_FLAG_SET_SINH ) { +csr_set (CSR_MCOUNTERMASK_S ,BIT (ctr_idx)); +csr_clear (CSR_MCOUNTERMASK_U ,BIT (ctr_idx)); + } +} + +static struct sbi_pmu_device andes_pmu = { + .name ="andes_pmu" , + .hw_counter_enable_irq = andes_hw_counter_enable_irq, + .hw_counter_disable_irq = andes_hw_counter_disable_irq, +/* +* In andes_pmu_extensions_init(), we set mslideleg[18] for each +* hart instead of mideleg, so leave hw_counter_irq_bit() hook
platform/generic/andes/andes_pmu.c line 64
Quoted 10 lines
platform/generic/andes/andes_pmu.c new file +10
-0+* unimplemented. +*/ + .hw_counter_irq_bit = NULL, + .hw_counter_filter_mode = andes_hw_counter_filter_mode +}; + +int andes_pmu_extensions_init (const struct fdt_match *match, +struct sbi_hart_features *hfeatures) +{ +if (andes_pmu ()) {
You can reverse the check here and return early?
Quoted 7 lines
platform/generic/andes/andes_pmu.c new file +7
-0+/* +* It is not rational for a hardware to support +* both Andes PMU and standard Sscofpmf, as they +* serve the same purpose. +*/ +if (sbi_hart_has_extension (sbi_scratch_thishart_ptr (), +SBI_HART_EXT_SSCOFPMF ))
platform/generic/andes/andes_pmu.c line 81
Quoted 10 lines
platform/generic/andes/andes_pmu.c new file +10
-0+ebreak (); + +/* Machine counter write enable */ +csr_write (CSR_MCOUNTERWEN ,0xfffffffd ); +/* disable HPM counter in M-mode */ +csr_write (CSR_MCOUNTERMASK_M ,0xfffffffd ); +/* delegate S-mode local interrupt to S-mode */ +csr_write (CSR_MSLIDELEG ,MIP_PMOVI ); + +sbi_pmu_set_device (&andes_pmu);
In my opinion we might want to append the PMU node to DT here and pass that DT fragment to the higher stack instead of adding it in Linux.
Cheers,
Prabhakar
PATCH 3/6 platform: andes: Add Andes custom PMU support
Quoted 124 lines · Prabhakar
Hi Lin-san,
Thank you for the patch.
Quoted 38 lines · On Wed, Sep 6, 2023 at 10:43?AM Yu Chien Peter Lin <[email protected]>…
Before the ratification of Sscofpmf, the Andes PMU extension was designed to support the sampling and filtering of hardware performance counters, compatible with the current SBI PMU extension and Linux perf driver.
This patch implements the PMU extension platform callback and PMU device callbacks to update the corresponding custom CSRs.
Signed-off-by Yu Chien Peter Lin <[email protected]>Reviewed-by Leo Yu-Chi Liang <[email protected]>--- platform/generic/andes/Kconfig | 4 + platform/generic/andes/andes_pmu.c | 85 ++++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes_pmu.h | 12 +++ 4 files changed, 102 insertions(+) create mode 100644 platform/generic/andes/andes_pmu.c create mode 100644 platform/generic/include/andes/andes_pmu.hplatform/generic/andes/Kconfig +4
-0@@ -7,3 +7,7 @@ config ANDES45_PMA config ANDES_SBI bool "Andes SBI support" default n + +config ANDES_PMU + bool "Andes PMU support" + default nplatform/generic/andes/andes_pmu.c new file +0
-0platform/generic/andes/andes_pmu.c line 3
Quoted 3 lines
platform/generic/andes/andes_pmu.c new file +3
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* +* Copyright (C) 2022 Andes Technology Corporation 2023?
Quoted 15 lines
platform/generic/andes/andes_pmu.c new file +15
-0+* +*/ +#include <andes/andes45.h> +#include <andes/andes_pmu.h> +#include <sbi/riscv_asm.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_pmu.h> +#include <sbi/sbi_scratch.h> + +static void andes_hw_counter_enable_irq (uint32_t ctr_idx) +{ +unsigned long mip_val; + +if (ctr_idx >=SBI_PMU_HW_CTR_MAX ) +return ;platform/generic/andes/andes_pmu.c line 28
Quoted 10 lines
platform/generic/andes/andes_pmu.c new file +10
-0+ + mip_val =csr_read (CSR_MIP ); +if (!(mip_val &MIP_PMOVI )) +csr_clear (CSR_MCOUNTEROVF ,BIT (ctr_idx)); + +csr_set (CSR_MCOUNTERINTEN ,BIT (ctr_idx)); +} + +static void andes_hw_counter_disable_irq (uint32_t ctr_idx) +{Any reason why we dont check for
ctr_idx>=SBI_PMU_HW_CTR_MAX?Quoted 26 lines
platform/generic/andes/andes_pmu.c new file +26
-0+csr_clear (CSR_MCOUNTERINTEN ,BIT (ctr_idx)); +} + +static void andes_hw_counter_filter_mode (unsigned long flags,int ctr_idx) +{ +if (!flags) { +csr_write (CSR_MCOUNTERMASK_S ,0 ); +csr_write (CSR_MCOUNTERMASK_U ,0 ); + } +if (flags &SBI_PMU_CFG_FLAG_SET_UINH ) { +csr_clear (CSR_MCOUNTERMASK_S ,BIT (ctr_idx)); +csr_set (CSR_MCOUNTERMASK_U ,BIT (ctr_idx)); + } +if (flags &SBI_PMU_CFG_FLAG_SET_SINH ) { +csr_set (CSR_MCOUNTERMASK_S ,BIT (ctr_idx)); +csr_clear (CSR_MCOUNTERMASK_U ,BIT (ctr_idx)); + } +} + +static struct sbi_pmu_device andes_pmu = { + .name ="andes_pmu" , + .hw_counter_enable_irq = andes_hw_counter_enable_irq, + .hw_counter_disable_irq = andes_hw_counter_disable_irq, +/* +* In andes_pmu_extensions_init(), we set mslideleg[18] for each +* hart instead of mideleg, so leave hw_counter_irq_bit() hook platform/generic/andes/andes_pmu.c line 64
Quoted 10 lines
platform/generic/andes/andes_pmu.c new file +10
-0+* unimplemented. +*/ + .hw_counter_irq_bit = NULL, + .hw_counter_filter_mode = andes_hw_counter_filter_mode +}; + +int andes_pmu_extensions_init (const struct fdt_match *match, +struct sbi_hart_features *hfeatures) +{ +if (andes_pmu ()) {You can reverse the check here and return early?
Quoted 11 lines
platform/generic/andes/andes_pmu.c new file +11
-0+/* +* It is not rational for a hardware to support +* both Andes PMU and standard Sscofpmf, as they +* serve the same purpose. +*/ +if (sbi_hart_has_extension (sbi_scratch_thishart_ptr (), +SBI_HART_EXT_SSCOFPMF )) +ebreak (); + +/* Machine counter write enable */ +csr_write (CSR_MCOUNTERWEN ,0xfffffffd );
Quoted 8 lines
platform/generic/andes/andes_pmu.c line 81
Quoted 6 lines
platform/generic/andes/andes_pmu.c new file +6
-0+/* disable HPM counter in M-mode */ +csr_write (CSR_MCOUNTERMASK_M ,0xfffffffd ); +/* delegate S-mode local interrupt to S-mode */ +csr_write (CSR_MSLIDELEG ,MIP_PMOVI ); + +sbi_pmu_set_device (&andes_pmu);In my opinion we might want to append the PMU node to DT here and pass that DT fragment to the higher stack instead of adding it in Linux.
Hmm, with you saying that it reminded me of something - this wouldn't be
just a "riscv,pmu" compatible either would it, it'd need to have some
sort of custom Andes entry AFAICT.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/opensbi/attachments/20230918/7b72093e/attachment.sig>
PATCH 3/6 platform: andes: Add Andes custom PMU support
In reply to LadHi Prabhakar,
Quoted 40 lines · Prabhakar
Hi Lin-san,
Thank you for the patch.
Quoted 34 lines · On Wed, Sep 6, 2023 at 10:43?AM Yu Chien Peter Lin <[email protected]>…
Before the ratification of Sscofpmf, the Andes PMU extension was designed to support the sampling and filtering of hardware performance counters, compatible with the current SBI PMU extension and Linux perf driver.
This patch implements the PMU extension platform callback and PMU device callbacks to update the corresponding custom CSRs.
Signed-off-by Yu Chien Peter Lin <[email protected]>Reviewed-by Leo Yu-Chi Liang <[email protected]>--- platform/generic/andes/Kconfig | 4 + platform/generic/andes/andes_pmu.c | 85 ++++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes_pmu.h | 12 +++ 4 files changed, 102 insertions(+) create mode 100644 platform/generic/andes/andes_pmu.c create mode 100644 platform/generic/include/andes/andes_pmu.hplatform/generic/andes/Kconfig +4
-0@@ -7,3 +7,7 @@ config ANDES45_PMA config ANDES_SBI bool "Andes SBI support" default n + +config ANDES_PMU + bool "Andes PMU support" + default nplatform/generic/andes/andes_pmu.c new file +0
-0
Quoted 8 lines
platform/generic/andes/andes_pmu.c line 3
Quoted 7 lines
index 0000000..d2574c7
platform/generic/andes/andes_pmu.c new file +3
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* +* Copyright (C) 2022 Andes Technology Corporation 2023?
OK, will update.
Quoted 18 lines
Quoted 18 lines
platform/generic/andes/andes_pmu.c new file +18
-0+* +*/ +#include <andes/andes45.h> +#include <andes/andes_pmu.h> +#include <sbi/riscv_asm.h> +#include <sbi/sbi_error.h> +#include <sbi/sbi_pmu.h> +#include <sbi/sbi_scratch.h> + +static void andes_hw_counter_enable_irq (uint32_t ctr_idx) +{ +unsigned long mip_val; + +if (ctr_idx >=SBI_PMU_HW_CTR_MAX ) +return ; + + mip_val =csr_read (CSR_MIP ); +if (!(mip_val &MIP_PMOVI ))
Quoted 8 lines
platform/generic/andes/andes_pmu.c line 28
Quoted 7 lines
platform/generic/andes/andes_pmu.c new file +7
-0+csr_clear (CSR_MCOUNTEROVF ,BIT (ctr_idx)); + +csr_set (CSR_MCOUNTERINTEN ,BIT (ctr_idx)); +} + +static void andes_hw_counter_disable_irq (uint32_t ctr_idx) +{Any reason why we dont check for
ctr_idx>=SBI_PMU_HW_CTR_MAX?
Its function caller [1] has done the check.
Quoted 29 lines
Quoted 29 lines
platform/generic/andes/andes_pmu.c new file +29
-0+csr_clear (CSR_MCOUNTERINTEN ,BIT (ctr_idx)); +} + +static void andes_hw_counter_filter_mode (unsigned long flags,int ctr_idx) +{ +if (!flags) { +csr_write (CSR_MCOUNTERMASK_S ,0 ); +csr_write (CSR_MCOUNTERMASK_U ,0 ); + } +if (flags &SBI_PMU_CFG_FLAG_SET_UINH ) { +csr_clear (CSR_MCOUNTERMASK_S ,BIT (ctr_idx)); +csr_set (CSR_MCOUNTERMASK_U ,BIT (ctr_idx)); + } +if (flags &SBI_PMU_CFG_FLAG_SET_SINH ) { +csr_set (CSR_MCOUNTERMASK_S ,BIT (ctr_idx)); +csr_clear (CSR_MCOUNTERMASK_U ,BIT (ctr_idx)); + } +} + +static struct sbi_pmu_device andes_pmu = { + .name ="andes_pmu" , + .hw_counter_enable_irq = andes_hw_counter_enable_irq, + .hw_counter_disable_irq = andes_hw_counter_disable_irq, +/* +* In andes_pmu_extensions_init(), we set mslideleg[18] for each +* hart instead of mideleg, so leave hw_counter_irq_bit() hook +* unimplemented. +*/ + .hw_counter_irq_bit =NULL ,
Quoted 8 lines
platform/generic/andes/andes_pmu.c line 64
Quoted 7 lines
platform/generic/andes/andes_pmu.c new file +7
-0+ .hw_counter_filter_mode = andes_hw_counter_filter_mode +}; + +int andes_pmu_extensions_init (const struct fdt_match *match, +struct sbi_hart_features *hfeatures) +{ +if (andes_pmu ()) {You can reverse the check here and return early?
Sure, will do.
Quoted 10 lines
Quoted 10 lines
platform/generic/andes/andes_pmu.c new file +10
-0+/* +* It is not rational for a hardware to support +* both Andes PMU and standard Sscofpmf, as they +* serve the same purpose. +*/ +if (sbi_hart_has_extension (sbi_scratch_thishart_ptr (), +SBI_HART_EXT_SSCOFPMF )) +ebreak (); + +/* Machine counter write enable */
Quoted 8 lines
platform/generic/andes/andes_pmu.c line 81
Quoted 7 lines
platform/generic/andes/andes_pmu.c new file +7
-0+csr_write (CSR_MCOUNTERWEN ,0xfffffffd ); +/* disable HPM counter in M-mode */ +csr_write (CSR_MCOUNTERMASK_M ,0xfffffffd ); +/* delegate S-mode local interrupt to S-mode */ +csr_write (CSR_MSLIDELEG ,MIP_PMOVI ); + +sbi_pmu_set_device (&andes_pmu);In my opinion we might want to append the PMU node to DT here
Sure, I will add fdt fixup so RZ/Five users won't need to manually append the PMU node.
Quoted 1 line
and pass that DT fragment to the higher stack instead of adding it in Linux.
The PMU node is not visible to S-mode SW (U-Boot proper or Linux) since it is only used to initialize the event counter mappings and erased in the generic_final_init() [2].
Thanks,
Peter Lin
[1] https://github.com/riscv-software-src/opensbi/blob/v1.3.1/lib/sbi/sbi_pmu.c#L583
[2] https://github.com/riscv-software-src/opensbi/blob/master/platform/generic/platform.c#L172
Quoted 2 lines
Cheers,
Prabhakar
PATCH 3/6 platform: andes: Add Andes custom PMU support
Quoted 11 lines
Quoted 2 lines
Quoted 1 line
+
sbi_pmu_set_device(&andes_pmu);In my opinion we might want to append the PMU node to DT here
Sure, I will add fdt fixup so RZ/Five users won't need to manually append the PMU node.
Quoted 1 line
and pass that DT fragment to the higher stack instead of adding it in Linux.
The PMU node is not visible to S-mode SW (U-Boot proper or Linux) since it is only used to initialize the event counter mappings and erased in the
generic_final_init()[2].
Sorry. It should be said that part of it (riscv,*event-to-mhpm* properties) will be erased, not the entire node.
the higher stack can still find the pmu node:
pmu {
compatible = "riscv,pmu";
}PATCH 4/6 platform: andes: Enable Andes PMU for AE350
In reply to Yu Chien Peter LinEnable Andes PMU extension support for AE350 platforms.
--- platform/generic/Kconfig | 1 + platform/generic/andes/ae350.c | 2 ++ 2 files changed, 3 insertions(+)
platform/generic/Kconfig +1 -0
@@ -31,6 +31,7 @@ config PLATFORM_ALLWINNER_D1 config PLATFORM_ANDES_AE350 bool "Andes AE350 support" select SYS_ATCSMU + select ANDES_PMU default n config PLATFORM_RENESAS_RZFIVE
platform/generic/andes/ae350.c +2 -0
@@ -8,6 +8,7 @@*/ #include <platform_override.h> +#include <andes/andes_pmu.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/fdt/fdt_fixup.h> #include <sbi_utils/sys/atcsmu.h>
@@ -118,4 +119,5 @@ static const struct fdt_match andes_ae350_match[] = {const struct platform_override andes_ae350 = { .match_table = andes_ae350_match, .final_init = ae350_final_init, + .extensions_init = andes_pmu_extensions_init, };
Signature · 1 line
2.34.1
PATCH 5/6 platform: rzfive: Enable Andes PMU for RZ/Five
In reply to Yu Chien Peter LinEnable Andes PMU extension support for RZ/Five.
--- platform/generic/Kconfig | 1 + platform/generic/renesas/rzfive/rzfive.c | 2 ++ 2 files changed, 3 insertions(+)
platform/generic/Kconfig +1 -0
@@ -38,6 +38,7 @@ config PLATFORM_RENESAS_RZFIVE bool "Renesas RZ/Five support" select ANDES45_PMA select ANDES_SBI + select ANDES_PMU default n config PLATFORM_SIFIVE_FU540
platform/generic/renesas/rzfive/rzfive.c +2 -0
@@ -5,6 +5,7 @@*/ #include <andes/andes45_pma.h> +#include <andes/andes_pmu.h> #include <andes/andes_sbi.h> #include <platform_override.h> #include <sbi/sbi_domain.h>
@@ -57,4 +58,5 @@ const struct platform_override renesas_rzfive = { .early_init = renesas_rzfive_early_init, .final_init = renesas_rzfive_final_init, .vendor_ext_provider = andes_sbi_vendor_ext_provider, + .extensions_init = andes_pmu_extensions_init, };
Signature · 1 line
2.34.1
PATCH 6/6 docs: pmu: Add Andes PMU node example
In reply to Yu Chien Peter LinAdd PMU node example for event index to counter index mapping and selector value translation of Andes' CPUs.
Currently, there are 4 HPM counters that can be used to monitor all of the events for each hart.
--- docs/pmu_support.md | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
docs/pmu_support.md +87 -0
@@ -125,3 +125,90 @@ pmu { <0x0 0x2 0xffffffff 0xffffe0ff 0x18>; }; ``` + +### Example 3 + +``` +/* + * For Andes 45-series platforms. The encodings can be found in the + * "Machine Performance Monitoring Event Selector" section + * http://www.andestech.com/wp-content/uploads/AX45MP-1C-Rev.-5.0.0-Datasheet.pdf + */ +pmu { + compatible = "riscv,pmu"; + riscv,event-to-mhpmevent = + <0x1 0x0000 0x10>, /* CPU_CYCLES -> Cycle count */ + <0x2 0x0000 0x20>, /* INSTRUCTIONS -> Retired instruction count */ + <0x3 0x0000 0x41>, /* CACHE_REFERENCES -> D-Cache access */ + <0x4 0x0000 0x51>, /* CACHE_MISSES -> D-Cache miss */ + <0x5 0x0000 0x80>, /* BRANCH_INSTRUCTIONS -> Conditional branch instruction count */ + <0x6 0x0000 0x02>, /* BRANCH_MISSES -> Misprediction of conditional branches */ + <0x10000 0x0000 0x61>, /* L1D_READ_ACCESS -> D-Cache load access */ + <0x10001 0x0000 0x71>, /* L1D_READ_MISS -> D-Cache load miss */ + <0x10002 0x0000 0x81>, /* L1D_WRITE_ACCESS -> D-Cache store access */ + <0x10003 0x0000 0x91>, /* L1D_WRITE_MISS -> D-Cache store miss */ + <0x10008 0x0000 0x21>, /* L1I_READ_ACCESS -> I-Cache access */ + <0x10009 0x0000 0x31>, /* L1I_READ_MISS -> I-Cache miss */ + <0x10018 0x0000 0x131>, /* DTLB_READ_ACCESS -> Main DTLB access */ + <0x10020 0x0000 0x111>; /* ITLB_READ_ACCESS -> Main ITLB access */ + riscv,event-to-mhpmcounters = <0x1 0x6 0x78>, + <0x10000 0x10003 0x78>, + <0x10008 0x10009 0x78>, + <0x10018 0x10018 0x78>, + <0x10020 0x10020 0x78>; + riscv,raw-event-to-mhpmcounters = + <0x0 0x10 0xffffffff 0xffffffff 0x78>, /* Cycle count */ + <0x0 0x20 0xffffffff 0xffffffff 0x78>, /* Retired instruction count */ + <0x0 0x30 0xffffffff 0xffffffff 0x78>, /* Integer load instruction count */ + <0x0 0x40 0xffffffff 0xffffffff 0x78>, /* Integer store instruction count */ + <0x0 0x50 0xffffffff 0xffffffff 0x78>, /* Atomic instruction count */ + <0x0 0x60 0xffffffff 0xffffffff 0x78>, /* System instruction count */ + <0x0 0x70 0xffffffff 0xffffffff 0x78>, /* Integer computational instruction count */ + <0x0 0x80 0xffffffff 0xffffffff 0x78>, /* Conditional branch instruction count */ + <0x0 0x90 0xffffffff 0xffffffff 0x78>, /* Taken conditional branch instruction count */ + <0x0 0xA0 0xffffffff 0xffffffff 0x78>, /* JAL instruction count */ + <0x0 0xB0 0xffffffff 0xffffffff 0x78>, /* JALR instruction count */ + <0x0 0xC0 0xffffffff 0xffffffff 0x78>, /* Return instruction count */ + <0x0 0xD0 0xffffffff 0xffffffff 0x78>, /* Control transfer instruction count */ + <0x0 0xE0 0xffffffff 0xffffffff 0x78>, /* EXEC.IT instruction count */ + <0x0 0xF0 0xffffffff 0xffffffff 0x78>, /* Integer multiplication instruction count */ + <0x0 0x100 0xffffffff 0xffffffff 0x78>, /* Integer division instruction count */ + <0x0 0x110 0xffffffff 0xffffffff 0x78>, /* Floating-point load instruction count */ + <0x0 0x120 0xffffffff 0xffffffff 0x78>, /* Floating-point store instruction count */ + <0x0 0x130 0xffffffff 0xffffffff 0x78>, /* Floating-point addition/subtraction instruction count */ + <0x0 0x140 0xffffffff 0xffffffff 0x78>, /* Floating-point multiplication instruction count */ + <0x0 0x150 0xffffffff 0xffffffff 0x78>, /* Floating-point fused multiply-add instruction count */ + <0x0 0x160 0xffffffff 0xffffffff 0x78>, /* Floating-point division or square-root instruction count */ + <0x0 0x170 0xffffffff 0xffffffff 0x78>, /* Other floating-point instruction count */ + <0x0 0x180 0xffffffff 0xffffffff 0x78>, /* Integer multiplication and add/sub instruction count */ + <0x0 0x190 0xffffffff 0xffffffff 0x78>, /* Retired operation count */ + <0x0 0x01 0xffffffff 0xffffffff 0x78>, /* ILM access */ + <0x0 0x11 0xffffffff 0xffffffff 0x78>, /* DLM access */ + <0x0 0x21 0xffffffff 0xffffffff 0x78>, /* I-Cache access */ + <0x0 0x31 0xffffffff 0xffffffff 0x78>, /* I-Cache miss */ + <0x0 0x41 0xffffffff 0xffffffff 0x78>, /* D-Cache access */ + <0x0 0x51 0xffffffff 0xffffffff 0x78>, /* D-Cache miss */ + <0x0 0x61 0xffffffff 0xffffffff 0x78>, /* D-Cache load access */ + <0x0 0x71 0xffffffff 0xffffffff 0x78>, /* D-Cache load miss */ + <0x0 0x81 0xffffffff 0xffffffff 0x78>, /* D-Cache store access */ + <0x0 0x91 0xffffffff 0xffffffff 0x78>, /* D-Cache store miss */ + <0x0 0xA1 0xffffffff 0xffffffff 0x78>, /* D-Cache writeback */ + <0x0 0xB1 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for I-Cache fill data */ + <0x0 0xC1 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for D-Cache fill data */ + <0x0 0xD1 0xffffffff 0xffffffff 0x78>, /* Uncached fetch data access from bus */ + <0x0 0xE1 0xffffffff 0xffffffff 0x78>, /* Uncached load data access from bus */ + <0x0 0xF1 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for uncached fetch data from bus */ + <0x0 0x101 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for uncached load data from bus */ + <0x0 0x111 0xffffffff 0xffffffff 0x78>, /* Main ITLB access */ + <0x0 0x121 0xffffffff 0xffffffff 0x78>, /* Main ITLB miss */ + <0x0 0x131 0xffffffff 0xffffffff 0x78>, /* Main DTLB access */ + <0x0 0x141 0xffffffff 0xffffffff 0x78>, /* Main DTLB miss */ + <0x0 0x151 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for Main ITLB fill data */ + <0x0 0x161 0xffffffff 0xffffffff 0x78>, /* Pipeline stall cycles caused by Main DTLB miss */ + <0x0 0x171 0xffffffff 0xffffffff 0x78>, /* Hardware prefetch bus access */ + <0x0 0x181 0xffffffff 0xffffffff 0x78>, /* Cycles waiting for source operand ready in the integer register file scoreboard */ + <0x0 0x02 0xffffffff 0xffffffff 0x78>, /* Misprediction of conditional branches */ + <0x0 0x12 0xffffffff 0xffffffff 0x78>, /* Misprediction of taken conditional branches */ + <0x0 0x22 0xffffffff 0xffffffff 0x78>; /* Misprediction of targets of Return instructions */ +}; +```
Signature · 1 line
2.34.1
cover Add Andes PMU extension support
In reply to Yu Chien Peter LinHi Yu Chien Peter Lin,
Quoted 12 lines · On Wed, Sep 6, 2023 at 3:12?PM Yu Chien Peter Lin <[email protected]>…
This patch series enables perf tool to utilize Andes PMU extension via PMU SBI calls, provides PMU device callbacks for event sampling and mode filtering.
We also provide a PMU node example of AX45MP in the last patch.
The OpenSBI and Linux patches can be found on Andes Technology GitHub
- https://github.com/andestech/opensbi/commits/andes-pmu-support
- https://github.com/andestech/linux/commits/andes-pmu-support
Quoted 7 lines
Yu Chien Peter Lin (6):
sbi:sbi_pmu: Addhw_counter_filter_mode()to pmu device
platform: include: andes45: Add PMU related CSR defines
platform: andes: Add Andes custom PMU support
platform: andes: Enable Andes PMU for AE350
platform: rzfive: Enable Andes PMU for RZ/Five
docs: pmu: Add Andes PMU node example
I assume there is going to be a v2 due to comments on PATCH3 ?
Regards,
Anup
Quoted 19 lines
docs/pmu_support.md | 87 ++++++++++++++++++++++ include/sbi/sbi_pmu.h | 6 ++ lib/sbi/sbi_pmu.c | 5 +- platform/generic/Kconfig | 2 + platform/generic/andes/Kconfig | 4 + platform/generic/andes/ae350.c | 2 + platform/generic/andes/andes_pmu.c | 85 +++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes45.h | 26 +++++++ platform/generic/include/andes/andes_pmu.h | 12 +++ platform/generic/renesas/rzfive/rzfive.c | 2 + 11 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 platform/generic/andes/andes_pmu.c create mode 100644 platform/generic/include/andes/andes_pmu.h--
2.34.1
cover Add Andes PMU extension support
Hi Anup,
Quoted 24 lines · Anup Patel
Hi Yu Chien Peter Lin,
Quoted 12 lines · On Wed, Sep 6, 2023 at 3:12?PM Yu Chien Peter Lin <[email protected]>…
This patch series enables perf tool to utilize Andes PMU extension via PMU SBI calls, provides PMU device callbacks for event sampling and mode filtering.
We also provide a PMU node example of AX45MP in the last patch.
The OpenSBI and Linux patches can be found on Andes Technology GitHub
- https://github.com/andestech/opensbi/commits/andes-pmu-support
- https://github.com/andestech/linux/commits/andes-pmu-supportQuoted 7 lines
Yu Chien Peter Lin (6):
sbi:sbi_pmu: Addhw_counter_filter_mode()to pmu device
platform: include: andes45: Add PMU related CSR defines
platform: andes: Add Andes custom PMU support
platform: andes: Enable Andes PMU for AE350
platform: rzfive: Enable Andes PMU for RZ/Five
docs: pmu: Add Andes PMU node example
Quoted 1 line
I assume there is going to be a v2 due to comments on PATCH3 ?
Yes we are working on this.
Thanks.
Peter Lin
Quoted 22 lines
Regards,
AnupQuoted 19 lines
docs/pmu_support.md | 87 ++++++++++++++++++++++ include/sbi/sbi_pmu.h | 6 ++ lib/sbi/sbi_pmu.c | 5 +- platform/generic/Kconfig | 2 + platform/generic/andes/Kconfig | 4 + platform/generic/andes/ae350.c | 2 + platform/generic/andes/andes_pmu.c | 85 +++++++++++++++++++++ platform/generic/andes/objects.mk | 1 + platform/generic/include/andes/andes45.h | 26 +++++++ platform/generic/include/andes/andes_pmu.h | 12 +++ platform/generic/renesas/rzfive/rzfive.c | 2 + 11 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 platform/generic/andes/andes_pmu.c create mode 100644 platform/generic/include/andes/andes_pmu.h--
2.34.1