Implement PMU enhancements in SBI v3.0
cover Implement PMU enhancements in SBI v3.0
SBI v3.0 specification[1] added two new improvements to the PMU chaper.
1. Added an additional get_event_info function to query event availability in bulk instead of individual SBI calls for each event. This improves the supervisor OS boot time if implemented.
2. Raw event width allowed by the platform is widened to have 56 bits with RAW event v2 as per new clarification in the priv ISA[2].
[1] https://github.com/riscv-non-isa/riscv-sbi-doc/releases/download/vv3.0-rc2/riscv-sbi.pdf
[2] https://github.com/riscv/riscv-isa-manual/issues/1578
To: [email protected]
Cc: apatel at ventanamicro.com
---
Atish Patra (5):
lib: sbi_pmu: PMU raw event v2 support
lib: sbi_pmu: Remove redundant check for fw events
lib: sbi_pmu: Add SBI PMU event info function details.
lib: sbi_pmu: Implement SBI PMU event info function
include: sbi: Change spec version to 3.0
include/sbi/sbi_ecall.h | 2 +- include/sbi/sbi_ecall_interface.h | 11 +++++ include/sbi/sbi_pmu.h | 2 + lib/sbi/sbi_ecall_pmu.c | 3 ++ lib/sbi/sbi_pmu.c | 95 ++++++++++++++++++++++++++++++++++----- platform/generic/platform.c | 3 +- 6 files changed, 104 insertions(+), 12 deletions(-)
---
base-commit: 86d2c1797a44975e628bcf77e30e687fd6738e81
change-id: 20241111-pmu_event_info-ee78dfa947cc --
Regards,
Atish patra
PATCH 1/5 lib: sbi_pmu: PMU raw event v2 support
As per the updated ISA specification and SBI PMU v3.0, lower 56 bits are available for the platform to implement mhpmeventX encoding. Implement the PMU raw event V2 support defined in SBI v3.0 which allows more bits for platforms to encode the raw events.
--- include/sbi/sbi_ecall_interface.h | 2 ++ lib/sbi/sbi_pmu.c | 14 +++++++++----- platform/generic/platform.c | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-)
include/sbi/sbi_ecall_interface.h +2 -0
@@ -245,6 +245,7 @@ enum sbi_pmu_event_type_id {SBI_PMU_EVENT_TYPE_HW =0x0 ,SBI_PMU_EVENT_TYPE_HW_CACHE =0x1 ,SBI_PMU_EVENT_TYPE_HW_RAW =0x2 , +SBI_PMU_EVENT_TYPE_HW_RAW_V2 =0x3 ,SBI_PMU_EVENT_TYPE_FW =0xf , SBI_PMU_EVENT_TYPE_MAX, };
@@ -261,6 +262,7 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_EVENT_IDX_TYPE_MASK (0xF << SBI_PMU_EVENT_IDX_TYPE_OFFSET)#define SBI_PMU_EVENT_IDX_CODE_MASK 0xFFFF#define SBI_PMU_EVENT_RAW_IDX 0x20000 +#define SBI_PMU_EVENT_RAW_V2_IDX 0x30000#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFF
lib/sbi/sbi_pmu.c +9 -5
@@ -172,6 +172,7 @@ static int pmu_event_validate(struct sbi_pmu_hart_state *phs,return SBI_EINVAL ;break ;case SBI_PMU_EVENT_TYPE_HW_RAW : +case SBI_PMU_EVENT_TYPE_HW_RAW_V2 : event_idx_code_max =1 ;// event_idx.code should be zero break ;default :
@@ -259,7 +260,8 @@ static int pmu_add_hw_event_map(u32 eidx_start, u32 eidx_end, u32 cmap,/* Sanity check */ for (i =0 ; i < num_hw_events; i++) { -if (eidx_start ==SBI_PMU_EVENT_RAW_IDX ) +if (eidx_start ==SBI_PMU_EVENT_RAW_IDX || + eidx_start ==SBI_PMU_EVENT_RAW_V2_IDX )/* All raw events have same event idx. Just do sanity check on select */ is_overlap =pmu_event_select_overlap (&hw_event_map[i], select, select_mask);
@@ -290,8 +292,8 @@ reset_event:*/ int sbi_pmu_add_hw_event_counter_map (u32 eidx_start,u32 eidx_end,u32 cmap) { -if ((eidx_start > eidx_end) || eidx_start ==SBI_PMU_EVENT_RAW_IDX || - eidx_end ==SBI_PMU_EVENT_RAW_IDX ) +if ((eidx_start > eidx_end) || eidx_start >=SBI_PMU_EVENT_RAW_V2_IDX || + eidx_end >=SBI_PMU_EVENT_RAW_V2_IDX )return SBI_EINVAL ;return pmu_add_hw_event_map (eidx_start, eidx_end, cmap,0 ,0 );
@@ -299,8 +301,9 @@ int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap)int sbi_pmu_add_raw_event_counter_map (uint64_t select,uint64_t select_mask,u32 cmap) { +sbi_printf ("%s: select %lx select_mask %lx cmap %x\n" , __func__, select, select_mask, cmap);return pmu_add_hw_event_map (SBI_PMU_EVENT_RAW_IDX , -SBI_PMU_EVENT_RAW_IDX , cmap, select, select_mask); +SBI_PMU_EVENT_RAW_V2_IDX , cmap, select, select_mask); }void sbi_pmu_ovf_irq ()
@@ -736,7 +739,8 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,continue ;/* For raw events, event data is used as the select value */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) { +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) {uint64_t select_mask = temp->select_mask;/* The non-event map bits of data should match the selector */
platform/generic/platform.c +2 -1
@@ -393,7 +393,8 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx,uint64_t evt_val =0 ;/* data is valid only for raw events and is equal to event selector */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) evt_val = data;else {/**
Signature · 1 line
2.34.1
PATCH 1/5 lib: sbi_pmu: PMU raw event v2 support
Quoted 7 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
As per the updated ISA specification and SBI PMU v3.0, lower 56 bits are available for the platform to implement mhpmeventX encoding. Implement the PMU raw event V2 support defined in SBI v3.0 which allows more bits for platforms to encode the raw events.
Signed-off-by Atish Patra <[email protected]>
LGTM.
Regards,
Anup
Quoted 103 lines
--- include/sbi/sbi_ecall_interface.h | 2 ++ lib/sbi/sbi_pmu.c | 14 +++++++++----- platform/generic/platform.c | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-)include/sbi/sbi_ecall_interface.h +2
-0@@ -245,6 +245,7 @@ enum sbi_pmu_event_type_id {SBI_PMU_EVENT_TYPE_HW =0x0 ,SBI_PMU_EVENT_TYPE_HW_CACHE =0x1 ,SBI_PMU_EVENT_TYPE_HW_RAW =0x2 , +SBI_PMU_EVENT_TYPE_HW_RAW_V2 =0x3 ,SBI_PMU_EVENT_TYPE_FW =0xf , SBI_PMU_EVENT_TYPE_MAX, };@@ -261,6 +262,7 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_EVENT_IDX_TYPE_MASK (0xF << SBI_PMU_EVENT_IDX_TYPE_OFFSET)#define SBI_PMU_EVENT_IDX_CODE_MASK 0xFFFF#define SBI_PMU_EVENT_RAW_IDX 0x20000 +#define SBI_PMU_EVENT_RAW_V2_IDX 0x30000#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFFlib/sbi/sbi_pmu.c +9
-5@@ -172,6 +172,7 @@ static int pmu_event_validate(struct sbi_pmu_hart_state *phs,return SBI_EINVAL ;break ;case SBI_PMU_EVENT_TYPE_HW_RAW : +case SBI_PMU_EVENT_TYPE_HW_RAW_V2 : event_idx_code_max =1 ;// event_idx.code should be zero break ;default :@@ -259,7 +260,8 @@ static int pmu_add_hw_event_map(u32 eidx_start, u32 eidx_end, u32 cmap,/* Sanity check */ for (i =0 ; i < num_hw_events; i++) { -if (eidx_start ==SBI_PMU_EVENT_RAW_IDX ) +if (eidx_start ==SBI_PMU_EVENT_RAW_IDX || + eidx_start ==SBI_PMU_EVENT_RAW_V2_IDX )/* All raw events have same event idx. Just do sanity check on select */ is_overlap =pmu_event_select_overlap (&hw_event_map[i], select, select_mask);@@ -290,8 +292,8 @@ reset_event:*/ int sbi_pmu_add_hw_event_counter_map (u32 eidx_start,u32 eidx_end,u32 cmap) { -if ((eidx_start > eidx_end) || eidx_start ==SBI_PMU_EVENT_RAW_IDX || - eidx_end ==SBI_PMU_EVENT_RAW_IDX ) +if ((eidx_start > eidx_end) || eidx_start >=SBI_PMU_EVENT_RAW_V2_IDX || + eidx_end >=SBI_PMU_EVENT_RAW_V2_IDX )return SBI_EINVAL ;return pmu_add_hw_event_map (eidx_start, eidx_end, cmap,0 ,0 );@@ -299,8 +301,9 @@ int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap)int sbi_pmu_add_raw_event_counter_map (uint64_t select,uint64_t select_mask,u32 cmap) { +sbi_printf ("%s: select %lx select_mask %lx cmap %x\n" , __func__, select, select_mask, cmap);return pmu_add_hw_event_map (SBI_PMU_EVENT_RAW_IDX , -SBI_PMU_EVENT_RAW_IDX , cmap, select, select_mask); +SBI_PMU_EVENT_RAW_V2_IDX , cmap, select, select_mask); }void sbi_pmu_ovf_irq ()@@ -736,7 +739,8 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,continue ;/* For raw events, event data is used as the select value */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) { +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) {uint64_t select_mask = temp->select_mask;/* The non-event map bits of data should match the selector */ platform/generic/platform.c +2
-2@@ -393,7 +393,8 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx,uint64_t evt_val =0 ;/* data is valid only for raw events and is equal to event selector */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) evt_val = data;else {/** -- 2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Anup Patel
AppliedPATCH 1/5 lib: sbi_pmu: PMU raw event v2 support
In reply to Atish PatraQuoted 67 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
As per the updated ISA specification and SBI PMU v3.0, lower 56 bits are available for the platform to implement mhpmeventX encoding. Implement the PMU raw event V2 support defined in SBI v3.0 which allows more bits for platforms to encode the raw events.
Signed-off-by Atish Patra <[email protected]>--- include/sbi/sbi_ecall_interface.h | 2 ++ lib/sbi/sbi_pmu.c | 14 +++++++++----- platform/generic/platform.c | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-)include/sbi/sbi_ecall_interface.h +2
-0@@ -245,6 +245,7 @@ enum sbi_pmu_event_type_id {SBI_PMU_EVENT_TYPE_HW =0x0 ,SBI_PMU_EVENT_TYPE_HW_CACHE =0x1 ,SBI_PMU_EVENT_TYPE_HW_RAW =0x2 , +SBI_PMU_EVENT_TYPE_HW_RAW_V2 =0x3 ,SBI_PMU_EVENT_TYPE_FW =0xf , SBI_PMU_EVENT_TYPE_MAX, };@@ -261,6 +262,7 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_EVENT_IDX_TYPE_MASK (0xF << SBI_PMU_EVENT_IDX_TYPE_OFFSET)#define SBI_PMU_EVENT_IDX_CODE_MASK 0xFFFF#define SBI_PMU_EVENT_RAW_IDX 0x20000 +#define SBI_PMU_EVENT_RAW_V2_IDX 0x30000#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFFlib/sbi/sbi_pmu.c +5
-3@@ -172,6 +172,7 @@ static int pmu_event_validate(struct sbi_pmu_hart_state *phs,return SBI_EINVAL ;break ;case SBI_PMU_EVENT_TYPE_HW_RAW : +case SBI_PMU_EVENT_TYPE_HW_RAW_V2 : event_idx_code_max =1 ;// event_idx.code should be zero break ;default :@@ -259,7 +260,8 @@ static int pmu_add_hw_event_map(u32 eidx_start, u32 eidx_end, u32 cmap,/* Sanity check */ for (i =0 ; i < num_hw_events; i++) { -if (eidx_start ==SBI_PMU_EVENT_RAW_IDX ) +if (eidx_start ==SBI_PMU_EVENT_RAW_IDX || + eidx_start ==SBI_PMU_EVENT_RAW_V2_IDX )/* All raw events have same event idx. Just do sanity check on select */ is_overlap =pmu_event_select_overlap (&hw_event_map[i], select, select_mask);@@ -290,8 +292,8 @@ reset_event:*/ int sbi_pmu_add_hw_event_counter_map (u32 eidx_start,u32 eidx_end,u32 cmap) { -if ((eidx_start > eidx_end) || eidx_start ==SBI_PMU_EVENT_RAW_IDX || - eidx_end ==SBI_PMU_EVENT_RAW_IDX ) +if ((eidx_start > eidx_end) || eidx_start >=SBI_PMU_EVENT_RAW_V2_IDX || + eidx_end >=SBI_PMU_EVENT_RAW_V2_IDX )return SBI_EINVAL ;return pmu_add_hw_event_map (eidx_start, eidx_end, cmap,0 ,0 );
lib/sbi/sbi_pmu.c int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap) · line 304
Quoted 4 lines
lib/sbi/sbi_pmu.c +1
-0@@ -299,8 +301,9 @@ int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap)int sbi_pmu_add_raw_event_counter_map (uint64_t select,uint64_t select_mask,u32 cmap) { +sbi_printf ("%s: select %lx select_mask %lx cmap %x\n" , __func__, select, select_mask, cmap);
Looks like this printf() sneaked in the patch. I have dropped it at the time of merging this patch.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 39 lines
lib/sbi/sbi_pmu.c +3
-2return pmu_add_hw_event_map (SBI_PMU_EVENT_RAW_IDX , -SBI_PMU_EVENT_RAW_IDX , cmap, select, select_mask); +SBI_PMU_EVENT_RAW_V2_IDX , cmap, select, select_mask); }void sbi_pmu_ovf_irq ()@@ -736,7 +739,8 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,continue ;/* For raw events, event data is used as the select value */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) { +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) {uint64_t select_mask = temp->select_mask;/* The non-event map bits of data should match the selector */ platform/generic/platform.c +2
-2@@ -393,7 +393,8 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx,uint64_t evt_val =0 ;/* data is valid only for raw events and is equal to event selector */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) evt_val = data;else {/** -- 2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/5 lib: sbi_pmu: PMU raw event v2 support
Quoted 70 lines · On Sun, Dec 1, 2024 at 8:28?PM Anup Patel <[email protected]> wrote:
Quoted 68 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
As per the updated ISA specification and SBI PMU v3.0, lower 56 bits are available for the platform to implement mhpmeventX encoding. Implement the PMU raw event V2 support defined in SBI v3.0 which allows more bits for platforms to encode the raw events.
Signed-off-by Atish Patra <[email protected]>--- include/sbi/sbi_ecall_interface.h | 2 ++ lib/sbi/sbi_pmu.c | 14 +++++++++----- platform/generic/platform.c | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-)include/sbi/sbi_ecall_interface.h +2
-0@@ -245,6 +245,7 @@ enum sbi_pmu_event_type_id {SBI_PMU_EVENT_TYPE_HW =0x0 ,SBI_PMU_EVENT_TYPE_HW_CACHE =0x1 ,SBI_PMU_EVENT_TYPE_HW_RAW =0x2 , +SBI_PMU_EVENT_TYPE_HW_RAW_V2 =0x3 ,SBI_PMU_EVENT_TYPE_FW =0xf , SBI_PMU_EVENT_TYPE_MAX, };@@ -261,6 +262,7 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_EVENT_IDX_TYPE_MASK (0xF << SBI_PMU_EVENT_IDX_TYPE_OFFSET)#define SBI_PMU_EVENT_IDX_CODE_MASK 0xFFFF#define SBI_PMU_EVENT_RAW_IDX 0x20000 +#define SBI_PMU_EVENT_RAW_V2_IDX 0x30000#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFFlib/sbi/sbi_pmu.c +5
-3@@ -172,6 +172,7 @@ static int pmu_event_validate(struct sbi_pmu_hart_state *phs,return SBI_EINVAL ;break ;case SBI_PMU_EVENT_TYPE_HW_RAW : +case SBI_PMU_EVENT_TYPE_HW_RAW_V2 : event_idx_code_max =1 ;// event_idx.code should be zero break ;default :@@ -259,7 +260,8 @@ static int pmu_add_hw_event_map(u32 eidx_start, u32 eidx_end, u32 cmap,/* Sanity check */ for (i =0 ; i < num_hw_events; i++) { -if (eidx_start ==SBI_PMU_EVENT_RAW_IDX ) +if (eidx_start ==SBI_PMU_EVENT_RAW_IDX || + eidx_start ==SBI_PMU_EVENT_RAW_V2_IDX )/* All raw events have same event idx. Just do sanity check on select */ is_overlap =pmu_event_select_overlap (&hw_event_map[i], select, select_mask);@@ -290,8 +292,8 @@ reset_event:*/ int sbi_pmu_add_hw_event_counter_map (u32 eidx_start,u32 eidx_end,u32 cmap) { -if ((eidx_start > eidx_end) || eidx_start ==SBI_PMU_EVENT_RAW_IDX || - eidx_end ==SBI_PMU_EVENT_RAW_IDX ) +if ((eidx_start > eidx_end) || eidx_start >=SBI_PMU_EVENT_RAW_V2_IDX || + eidx_end >=SBI_PMU_EVENT_RAW_V2_IDX )return SBI_EINVAL ;return pmu_add_hw_event_map (eidx_start, eidx_end, cmap,0 ,0 );@@ -299,8 +301,9 @@ int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap)
Quoted 7 lines
lib/sbi/sbi_pmu.c int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap) · line 304
Quoted 3 lines
lib/sbi/sbi_pmu.c +1
-0int sbi_pmu_add_raw_event_counter_map (uint64_t select,uint64_t select_mask,u32 cmap) { +sbi_printf ("%s: select %lx select_mask %lx cmap %x\n" , __func__, select, select_mask, cmap);Looks like this
printf()sneaked in the patch. I have dropped it at the time of merging this patch.
Oops. Sorry.
Quoted 2 lines
Applied this patch to the riscv/opensbi repo.
Thanks!
Quoted 42 lines
Thanks,
AnupQuoted 39 lines
lib/sbi/sbi_pmu.c +3
-2return pmu_add_hw_event_map (SBI_PMU_EVENT_RAW_IDX , -SBI_PMU_EVENT_RAW_IDX , cmap, select, select_mask); +SBI_PMU_EVENT_RAW_V2_IDX , cmap, select, select_mask); }void sbi_pmu_ovf_irq ()@@ -736,7 +739,8 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,continue ;/* For raw events, event data is used as the select value */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) { +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) {uint64_t select_mask = temp->select_mask;/* The non-event map bits of data should match the selector */ platform/generic/platform.c +2
-2@@ -393,7 +393,8 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx,uint64_t evt_val =0 ;/* data is valid only for raw events and is equal to event selector */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) evt_val = data;else {/** -- 2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/5 lib: sbi_pmu: PMU raw event v2 support
In reply to Atish PatraHi Atish,
Quoted 55 lines · Atish Patra
As per the updated ISA specification and SBI PMU v3.0, lower 56 bits are available for the platform to implement mhpmeventX encoding. Implement the PMU raw event V2 support defined in SBI v3.0 which allows more bits for platforms to encode the raw events.
Signed-off-by Atish Patra <[email protected]>--- include/sbi/sbi_ecall_interface.h | 2 ++ lib/sbi/sbi_pmu.c | 14 +++++++++----- platform/generic/platform.c | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-)include/sbi/sbi_ecall_interface.h +2
-0@@ -245,6 +245,7 @@ enum sbi_pmu_event_type_id {SBI_PMU_EVENT_TYPE_HW =0x0 ,SBI_PMU_EVENT_TYPE_HW_CACHE =0x1 ,SBI_PMU_EVENT_TYPE_HW_RAW =0x2 , +SBI_PMU_EVENT_TYPE_HW_RAW_V2 =0x3 ,SBI_PMU_EVENT_TYPE_FW =0xf , SBI_PMU_EVENT_TYPE_MAX, };@@ -261,6 +262,7 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_EVENT_IDX_TYPE_MASK (0xF << SBI_PMU_EVENT_IDX_TYPE_OFFSET)#define SBI_PMU_EVENT_IDX_CODE_MASK 0xFFFF#define SBI_PMU_EVENT_RAW_IDX 0x20000 +#define SBI_PMU_EVENT_RAW_V2_IDX 0x30000#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFFlib/sbi/sbi_pmu.c +3
-1@@ -172,6 +172,7 @@ static int pmu_event_validate(struct sbi_pmu_hart_state *phs,return SBI_EINVAL ;break ;case SBI_PMU_EVENT_TYPE_HW_RAW : +case SBI_PMU_EVENT_TYPE_HW_RAW_V2 : event_idx_code_max =1 ;// event_idx.code should be zero break ;default :@@ -259,7 +260,8 @@ static int pmu_add_hw_event_map(u32 eidx_start, u32 eidx_end, u32 cmap,/* Sanity check */ for (i =0 ; i < num_hw_events; i++) { -if (eidx_start ==SBI_PMU_EVENT_RAW_IDX ) +if (eidx_start ==SBI_PMU_EVENT_RAW_IDX || + eidx_start ==SBI_PMU_EVENT_RAW_V2_IDX )/* All raw events have same event idx. Just do sanity check on select */ is_overlap =pmu_event_select_overlap (&hw_event_map[i], select, select_mask);
lib/sbi/sbi_pmu.c reset_event: · line 297
Quoted 8 lines
lib/sbi/sbi_pmu.c +2
-2@@ -290,8 +292,8 @@ reset_event:*/ int sbi_pmu_add_hw_event_counter_map (u32 eidx_start,u32 eidx_end,u32 cmap) { -if ((eidx_start > eidx_end) || eidx_start ==SBI_PMU_EVENT_RAW_IDX || - eidx_end ==SBI_PMU_EVENT_RAW_IDX ) +if ((eidx_start > eidx_end) || eidx_start >=SBI_PMU_EVENT_RAW_V2_IDX || + eidx_end >=SBI_PMU_EVENT_RAW_V2_IDX )return SBI_EINVAL ;
I may be misunderstanding this code, but this condition seems to be trying to exclude raw events. So I believe it should check >= SBI_PMU_EVENT_RAW_IDX -- this function should fail for both raw and raw v2 events.
Regards,
Samuel
Quoted 38 lines
lib/sbi/sbi_pmu.c +4
-2return pmu_add_hw_event_map (eidx_start, eidx_end, cmap,0 ,0 );@@ -299,8 +301,9 @@ int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap)int sbi_pmu_add_raw_event_counter_map (uint64_t select,uint64_t select_mask,u32 cmap) { +sbi_printf ("%s: select %lx select_mask %lx cmap %x\n" , __func__, select, select_mask, cmap);return pmu_add_hw_event_map (SBI_PMU_EVENT_RAW_IDX , -SBI_PMU_EVENT_RAW_IDX , cmap, select, select_mask); +SBI_PMU_EVENT_RAW_V2_IDX , cmap, select, select_mask); }void sbi_pmu_ovf_irq ()@@ -736,7 +739,8 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,continue ;/* For raw events, event data is used as the select value */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) { +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) {uint64_t select_mask = temp->select_mask;/* The non-event map bits of data should match the selector */ platform/generic/platform.c +2
-1@@ -393,7 +393,8 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx,uint64_t evt_val =0 ;/* data is valid only for raw events and is equal to event selector */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) evt_val = data;else {/**
PATCH 1/5 lib: sbi_pmu: PMU raw event v2 support
Quoted 63 lines · On Mon, Dec 2, 2024 at 2:17?PM Samuel Holland <[email protected]> wrote:
Hi Atish,
Quoted 59 lines · Atish Patra
As per the updated ISA specification and SBI PMU v3.0, lower 56 bits are available for the platform to implement mhpmeventX encoding. Implement the PMU raw event V2 support defined in SBI v3.0 which allows more bits for platforms to encode the raw events.
Signed-off-by Atish Patra <[email protected]>--- include/sbi/sbi_ecall_interface.h | 2 ++ lib/sbi/sbi_pmu.c | 14 +++++++++----- platform/generic/platform.c | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-)include/sbi/sbi_ecall_interface.h +2
-0@@ -245,6 +245,7 @@ enum sbi_pmu_event_type_id {SBI_PMU_EVENT_TYPE_HW =0x0 ,SBI_PMU_EVENT_TYPE_HW_CACHE =0x1 ,SBI_PMU_EVENT_TYPE_HW_RAW =0x2 , +SBI_PMU_EVENT_TYPE_HW_RAW_V2 =0x3 ,SBI_PMU_EVENT_TYPE_FW =0xf , SBI_PMU_EVENT_TYPE_MAX, };@@ -261,6 +262,7 @@ enum sbi_pmu_ctr_type {#define SBI_PMU_EVENT_IDX_TYPE_MASK (0xF << SBI_PMU_EVENT_IDX_TYPE_OFFSET)#define SBI_PMU_EVENT_IDX_CODE_MASK 0xFFFF#define SBI_PMU_EVENT_RAW_IDX 0x20000 +#define SBI_PMU_EVENT_RAW_V2_IDX 0x30000#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFFlib/sbi/sbi_pmu.c +3
-2@@ -172,6 +172,7 @@ static int pmu_event_validate(struct sbi_pmu_hart_state *phs,return SBI_EINVAL ;break ;case SBI_PMU_EVENT_TYPE_HW_RAW : +case SBI_PMU_EVENT_TYPE_HW_RAW_V2 : event_idx_code_max =1 ;// event_idx.code should be zero break ;default :@@ -259,7 +260,8 @@ static int pmu_add_hw_event_map(u32 eidx_start, u32 eidx_end, u32 cmap,/* Sanity check */ for (i =0 ; i < num_hw_events; i++) { -if (eidx_start ==SBI_PMU_EVENT_RAW_IDX ) +if (eidx_start ==SBI_PMU_EVENT_RAW_IDX || + eidx_start ==SBI_PMU_EVENT_RAW_V2_IDX )/* All raw events have same event idx. Just do sanity check on select */ is_overlap =pmu_event_select_overlap (&hw_event_map[i], select, select_mask);@@ -290,8 +292,8 @@ reset_event:*/ int sbi_pmu_add_hw_event_counter_map (u32 eidx_start,u32 eidx_end,u32 cmap) { - if ((eidx_start > eidx_end) || eidx_start == SBI_PMU_EVENT_RAW_IDX ||
Quoted 9 lines
lib/sbi/sbi_pmu.c reset_event: · line 297
Quoted 4 lines
lib/sbi/sbi_pmu.c +2
-1- eidx_end == SBI_PMU_EVENT_RAW_IDX) +if ((eidx_start > eidx_end) || eidx_start >=SBI_PMU_EVENT_RAW_V2_IDX || + eidx_end >=SBI_PMU_EVENT_RAW_V2_IDX )return SBI_EINVAL ;I may be misunderstanding this code, but this condition seems to be trying to exclude raw events. So I believe it should check
>= SBI_PMU_EVENT_RAW_IDX-- this function should fail for both raw and raw v2 events.
You are correct. This was a typo. I will send a fixup patch as this patch is already merged.
Thanks for catching this.
Quoted 42 lines
Regards,
SamuelQuoted 38 lines
lib/sbi/sbi_pmu.c +4
-2return pmu_add_hw_event_map (eidx_start, eidx_end, cmap,0 ,0 );@@ -299,8 +301,9 @@ int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap)int sbi_pmu_add_raw_event_counter_map (uint64_t select,uint64_t select_mask,u32 cmap) { +sbi_printf ("%s: select %lx select_mask %lx cmap %x\n" , __func__, select, select_mask, cmap);return pmu_add_hw_event_map (SBI_PMU_EVENT_RAW_IDX , -SBI_PMU_EVENT_RAW_IDX , cmap, select, select_mask); +SBI_PMU_EVENT_RAW_V2_IDX , cmap, select, select_mask); }void sbi_pmu_ovf_irq ()@@ -736,7 +739,8 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,continue ;/* For raw events, event data is used as the select value */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) { +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) {uint64_t select_mask = temp->select_mask;/* The non-event map bits of data should match the selector */ platform/generic/platform.c +2
-1@@ -393,7 +393,8 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx,uint64_t evt_val =0 ;/* data is valid only for raw events and is equal to event selector */ -if (event_idx ==SBI_PMU_EVENT_RAW_IDX ) +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) evt_val = data;else {/**
PATCH 2/5 lib: sbi_pmu: Remove redundant check for fw events
In reply to Atish PatraThe pmu_validate_event already has the same check for fw events. The validate function is called prior to the current function to find a counter for firmware. That's why, the redudant check can be removed from the find counter function.
--- lib/sbi/sbi_pmu.c | 5 ----- 1 file changed, 5 deletions(-)
lib/sbi/sbi_pmu.c +0 -5
@@ -796,11 +796,6 @@ static int pmu_ctr_find_fw(struct sbi_pmu_hart_state *phs, {int i, cidx; -if ((event_code >=SBI_PMU_FW_MAX && - event_code <=SBI_PMU_FW_RESERVED_MAX ) || - event_code >SBI_PMU_FW_PLATFORM ) -return SBI_EINVAL ; -for_each_set_bit (i, &cmask,BITS_PER_LONG ) { cidx = i + cbase;if (cidx < num_hw_ctrs || total_ctrs <= cidx)
Signature · 1 line
2.34.1
PATCH 2/5 lib: sbi_pmu: Remove redundant check for fw events
Quoted 7 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
The
pmu_validate_eventalready has the same check for fw events. The validate function is called prior to the current function to find a counter for firmware. That's why, the redudant check can be removed from the find counter function.Signed-off-by Atish Patra <[email protected]>
LGTM.
Regards,
Anup
Quoted 29 lines
--- lib/sbi/sbi_pmu.c | 5 ----- 1 file changed, 5 deletions(-)lib/sbi/sbi_pmu.c +0
-6@@ -796,11 +796,6 @@ static int pmu_ctr_find_fw(struct sbi_pmu_hart_state *phs, {int i, cidx; -if ((event_code >=SBI_PMU_FW_MAX && - event_code <=SBI_PMU_FW_RESERVED_MAX ) || - event_code >SBI_PMU_FW_PLATFORM ) -return SBI_EINVAL ; -for_each_set_bit (i, &cmask,BITS_PER_LONG ) { cidx = i + cbase;if (cidx < num_hw_ctrs || total_ctrs <= cidx) --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Anup Patel
AppliedPATCH 2/5 lib: sbi_pmu: Remove redundant check for fw events
In reply to Atish PatraQuoted 7 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
The
pmu_validate_eventalready has the same check for fw events. The validate function is called prior to the current function to find a counter for firmware. That's why, the redudant check can be removed from the find counter function.Signed-off-by Atish Patra <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 29 lines
--- lib/sbi/sbi_pmu.c | 5 ----- 1 file changed, 5 deletions(-)lib/sbi/sbi_pmu.c +0
-6@@ -796,11 +796,6 @@ static int pmu_ctr_find_fw(struct sbi_pmu_hart_state *phs, {int i, cidx; -if ((event_code >=SBI_PMU_FW_MAX && - event_code <=SBI_PMU_FW_RESERVED_MAX ) || - event_code >SBI_PMU_FW_PLATFORM ) -return SBI_EINVAL ; -for_each_set_bit (i, &cmask,BITS_PER_LONG ) { cidx = i + cbase;if (cidx < num_hw_ctrs || total_ctrs <= cidx) --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 3/5 lib: sbi_pmu: Add SBI PMU event info function details.
In reply to Atish PatraThe SBI v3.0 introduced a new function to query about the events without invoking CFG_MATCH. This allows supervisor software to identify which events are supported on the platform with single SBI call instead of a CFG_MATCH for each event.
--- include/sbi/sbi_ecall_interface.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/sbi/sbi_ecall_interface.h +9 -0
@@ -12,6 +12,8 @@/* clang-format off */ +#include <sbi/sbi_types.h> +/* SBI Extension IDs */ #define SBI_EXT_0_1_SET_TIMER 0x0#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
@@ -107,6 +109,7 @@#define SBI_EXT_PMU_COUNTER_FW_READ 0x5#define SBI_EXT_PMU_COUNTER_FW_READ_HI 0x6#define SBI_EXT_PMU_SNAPSHOT_SET_SHMEM 0x7 +#define SBI_EXT_PMU_EVENT_GET_INFO 0x8/* SBI function IDs for DBTR extension */ #define SBI_EXT_DBTR_NUM_TRIGGERS 0x0
@@ -256,6 +259,12 @@ enum sbi_pmu_ctr_type { SBI_PMU_CTR_TYPE_FW, }; +struct sbi_pmu_event_info { +uint32_t event_idx; +uint32_t output; +uint64_t event_data; +}; +/* Helper macros to decode event idx */ #define SBI_PMU_EVENT_IDX_MASK 0xFFFFF#define SBI_PMU_EVENT_IDX_TYPE_OFFSET 16
Signature · 1 line
2.34.1
PATCH 3/5 lib: sbi_pmu: Add SBI PMU event info function details.
Quoted 7 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
The SBI v3.0 introduced a new function to query about the events without invoking
CFG_MATCH. This allows supervisor software to identify which events are supported on the platform with single SBI call instead of aCFG_MATCHfor each event.Signed-off-by Atish Patra <[email protected]>
LGTM.
Regards,
Anup
Quoted 47 lines
--- include/sbi/sbi_ecall_interface.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/sbi/sbi_ecall_interface.h +9
-1@@ -12,6 +12,8 @@/* clang-format off */ +#include <sbi/sbi_types.h> +/* SBI Extension IDs */ #define SBI_EXT_0_1_SET_TIMER 0x0#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1@@ -107,6 +109,7 @@#define SBI_EXT_PMU_COUNTER_FW_READ 0x5#define SBI_EXT_PMU_COUNTER_FW_READ_HI 0x6#define SBI_EXT_PMU_SNAPSHOT_SET_SHMEM 0x7 +#define SBI_EXT_PMU_EVENT_GET_INFO 0x8/* SBI function IDs for DBTR extension */ #define SBI_EXT_DBTR_NUM_TRIGGERS 0x0@@ -256,6 +259,12 @@ enum sbi_pmu_ctr_type { SBI_PMU_CTR_TYPE_FW, }; +struct sbi_pmu_event_info { +uint32_t event_idx; +uint32_t output; +uint64_t event_data; +}; +/* Helper macros to decode event idx */ #define SBI_PMU_EVENT_IDX_MASK 0xFFFFF#define SBI_PMU_EVENT_IDX_TYPE_OFFSET 16 --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Anup Patel
AppliedPATCH 3/5 lib: sbi_pmu: Add SBI PMU event info function details.
In reply to Atish PatraQuoted 7 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
The SBI v3.0 introduced a new function to query about the events without invoking
CFG_MATCH. This allows supervisor software to identify which events are supported on the platform with single SBI call instead of aCFG_MATCHfor each event.Signed-off-by Atish Patra <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 47 lines
--- include/sbi/sbi_ecall_interface.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/sbi/sbi_ecall_interface.h +9
-1@@ -12,6 +12,8 @@/* clang-format off */ +#include <sbi/sbi_types.h> +/* SBI Extension IDs */ #define SBI_EXT_0_1_SET_TIMER 0x0#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1@@ -107,6 +109,7 @@#define SBI_EXT_PMU_COUNTER_FW_READ 0x5#define SBI_EXT_PMU_COUNTER_FW_READ_HI 0x6#define SBI_EXT_PMU_SNAPSHOT_SET_SHMEM 0x7 +#define SBI_EXT_PMU_EVENT_GET_INFO 0x8/* SBI function IDs for DBTR extension */ #define SBI_EXT_DBTR_NUM_TRIGGERS 0x0@@ -256,6 +259,12 @@ enum sbi_pmu_ctr_type { SBI_PMU_CTR_TYPE_FW, }; +struct sbi_pmu_event_info { +uint32_t event_idx; +uint32_t output; +uint64_t event_data; +}; +/* Helper macros to decode event idx */ #define SBI_PMU_EVENT_IDX_MASK 0xFFFFF#define SBI_PMU_EVENT_IDX_TYPE_OFFSET 16 --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 4/5 lib: sbi_pmu: Implement SBI PMU event info function
In reply to Atish PatraAllow the supervisor software to query about the event using the new function. This supports both firmware and hardware events. The hardware event presence is verified hw_event_map which is populated via PMU device tree node. The firmware event presence is checked through event validation function which should take care of both standard and platform firmware events.
--- include/sbi/sbi_pmu.h | 2 ++ lib/sbi/sbi_ecall_pmu.c | 3 ++ lib/sbi/sbi_pmu.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)
include/sbi/sbi_pmu.h +2 -0
@@ -142,6 +142,8 @@ int sbi_pmu_ctr_start(unsigned long cidx_base, unsigned long cidx_mask, unsigned long flags, uint64_t ival);int sbi_pmu_ctr_get_info (uint32_t cidx,unsigned long *ctr_info); +int sbi_pmu_event_get_info (unsigned long shmem_lo,unsigned long shmem_high, +unsigned long num_events,unsigned long flags);unsigned long sbi_pmu_num_ctr (void );
lib/sbi/sbi_ecall_pmu.c +3 -0
@@ -73,6 +73,9 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,case SBI_EXT_PMU_COUNTER_STOP : ret =sbi_pmu_ctr_stop (regs->a0, regs->a1, regs->a2);break ; +case SBI_EXT_PMU_EVENT_GET_INFO : + ret =sbi_pmu_event_get_info (regs->a0, regs->a1, regs->a2, regs->a3); +break ;case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM :/* fallthrough as OpenSBI doesn't support snapshot yet */ default :
lib/sbi/sbi_pmu.c +76 -0
88 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 4/5 lib: sbi_pmu: Implement SBI PMU event info function
Quoted 9 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
Allow the supervisor software to query about the event using the new function. This supports both firmware and hardware events. The hardware event presence is verified
hw_event_mapwhich is populated via PMU device tree node. The firmware event presence is checked through event validation function which should take care of both standard and platform firmware events.Signed-off-by Atish Patra <[email protected]>
LGTM.
Regards,
Anup
Quoted 136 lines
--- include/sbi/sbi_pmu.h | 2 ++ lib/sbi/sbi_ecall_pmu.c | 3 ++ lib/sbi/sbi_pmu.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)include/sbi/sbi_pmu.h +2
-0@@ -142,6 +142,8 @@ int sbi_pmu_ctr_start(unsigned long cidx_base, unsigned long cidx_mask, unsigned long flags, uint64_t ival);int sbi_pmu_ctr_get_info (uint32_t cidx,unsigned long *ctr_info); +int sbi_pmu_event_get_info (unsigned long shmem_lo,unsigned long shmem_high, +unsigned long num_events,unsigned long flags);unsigned long sbi_pmu_num_ctr (void );lib/sbi/sbi_ecall_pmu.c +3
-0@@ -73,6 +73,9 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,case SBI_EXT_PMU_COUNTER_STOP : ret =sbi_pmu_ctr_stop (regs->a0, regs->a1, regs->a2);break ; +case SBI_EXT_PMU_EVENT_GET_INFO : + ret =sbi_pmu_event_get_info (regs->a0, regs->a1, regs->a2, regs->a3); +break ;case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM :/* fallthrough as OpenSBI doesn't support snapshot yet */ default :lib/sbi/sbi_pmu.c +76
-1@@ -10,6 +10,7 @@#include <sbi/riscv_asm.h> #include <sbi/sbi_bitops.h> #include <sbi/sbi_console.h> +#include <sbi/sbi_domain.h> #include <sbi/sbi_ecall_interface.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_heap.h> @@ -968,6 +969,81 @@ int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info)return 0 ; } +int sbi_pmu_event_get_info (unsigned long shmem_phys_lo,unsigned long shmem_phys_hi, +unsigned long num_events,unsigned long flags) +{ +unsigned long shmem_size = num_events *sizeof (struct sbi_pmu_event_info ); +int i, j, event_type; +struct sbi_pmu_event_info *einfo; +struct sbi_pmu_hart_state *phs =pmu_thishart_state_ptr (); +uint32_t event_idx; +struct sbi_pmu_hw_event *temp; +bool found = false; + +if (flags !=0 ) +return SBI_ERR_INVALID_PARAM ; + +/** Check shared memory size and address aligned to 16 byte */ +if (!num_events || (shmem_phys_lo &0xF )) +return SBI_ERR_INVALID_PARAM ; + +/* +* On RV32, the M-mode can only access the first 4GB of +* the physical address space because M-mode does not have +* MMU to access full 34-bit physical address space. +* +* Based on above, we simply fail if the upper 32bits of +* the physical address (i.e. a2 register) is non-zero on +* RV32. +*/ +if (shmem_phys_hi) +return SBI_EINVALID_ADDR ; + +if (!sbi_domain_check_addr_range (sbi_domain_thishart_ptr (), + shmem_phys_lo, shmem_size,PRV_S , +SBI_DOMAIN_READ |SBI_DOMAIN_WRITE )) +return SBI_ERR_INVALID_ADDRESS ; + +sbi_hart_map_saddr (shmem_phys_lo, shmem_size); + + einfo = (struct sbi_pmu_event_info *)(shmem_phys_lo); +for (i =0 ; i < num_events; i++) { + event_idx = einfo[i].event_idx; + event_type =pmu_event_validate (phs, event_idx, einfo[i].event_data); +if (event_type <0 ) { + einfo[i].output =0 ; + }else { +for (j =0 ; j < num_hw_events; j++) { + temp = &hw_event_map[j]; +if (temp->start_idx <= event_idx && event_idx <= temp->end_idx) { + found = true; +break ; + } +/* For raw events, event data is used as the select value */ +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) { +uint64_t select_mask = temp->select_mask; + +/* just match the selector */ +if (temp->select == (einfo[i].event_data & select_mask)) { + found = true; +break ; + } + } + } +if (found) + einfo[i].output =1 ; +else + einfo[i].output =0 ; + found = false; + } + } + +sbi_hart_unmap_saddr (); + +return 0 ; +} +static void pmu_reset_event_map (struct sbi_pmu_hart_state *phs) {int j; --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Anup Patel
AppliedPATCH 4/5 lib: sbi_pmu: Implement SBI PMU event info function
In reply to Atish PatraQuoted 9 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
Allow the supervisor software to query about the event using the new function. This supports both firmware and hardware events. The hardware event presence is verified
hw_event_mapwhich is populated via PMU device tree node. The firmware event presence is checked through event validation function which should take care of both standard and platform firmware events.Signed-off-by Atish Patra <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 136 lines
--- include/sbi/sbi_pmu.h | 2 ++ lib/sbi/sbi_ecall_pmu.c | 3 ++ lib/sbi/sbi_pmu.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)include/sbi/sbi_pmu.h +2
-0@@ -142,6 +142,8 @@ int sbi_pmu_ctr_start(unsigned long cidx_base, unsigned long cidx_mask, unsigned long flags, uint64_t ival);int sbi_pmu_ctr_get_info (uint32_t cidx,unsigned long *ctr_info); +int sbi_pmu_event_get_info (unsigned long shmem_lo,unsigned long shmem_high, +unsigned long num_events,unsigned long flags);unsigned long sbi_pmu_num_ctr (void );lib/sbi/sbi_ecall_pmu.c +3
-0@@ -73,6 +73,9 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,case SBI_EXT_PMU_COUNTER_STOP : ret =sbi_pmu_ctr_stop (regs->a0, regs->a1, regs->a2);break ; +case SBI_EXT_PMU_EVENT_GET_INFO : + ret =sbi_pmu_event_get_info (regs->a0, regs->a1, regs->a2, regs->a3); +break ;case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM :/* fallthrough as OpenSBI doesn't support snapshot yet */ default :lib/sbi/sbi_pmu.c +76
-1@@ -10,6 +10,7 @@#include <sbi/riscv_asm.h> #include <sbi/sbi_bitops.h> #include <sbi/sbi_console.h> +#include <sbi/sbi_domain.h> #include <sbi/sbi_ecall_interface.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_heap.h> @@ -968,6 +969,81 @@ int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info)return 0 ; } +int sbi_pmu_event_get_info (unsigned long shmem_phys_lo,unsigned long shmem_phys_hi, +unsigned long num_events,unsigned long flags) +{ +unsigned long shmem_size = num_events *sizeof (struct sbi_pmu_event_info ); +int i, j, event_type; +struct sbi_pmu_event_info *einfo; +struct sbi_pmu_hart_state *phs =pmu_thishart_state_ptr (); +uint32_t event_idx; +struct sbi_pmu_hw_event *temp; +bool found = false; + +if (flags !=0 ) +return SBI_ERR_INVALID_PARAM ; + +/** Check shared memory size and address aligned to 16 byte */ +if (!num_events || (shmem_phys_lo &0xF )) +return SBI_ERR_INVALID_PARAM ; + +/* +* On RV32, the M-mode can only access the first 4GB of +* the physical address space because M-mode does not have +* MMU to access full 34-bit physical address space. +* +* Based on above, we simply fail if the upper 32bits of +* the physical address (i.e. a2 register) is non-zero on +* RV32. +*/ +if (shmem_phys_hi) +return SBI_EINVALID_ADDR ; + +if (!sbi_domain_check_addr_range (sbi_domain_thishart_ptr (), + shmem_phys_lo, shmem_size,PRV_S , +SBI_DOMAIN_READ |SBI_DOMAIN_WRITE )) +return SBI_ERR_INVALID_ADDRESS ; + +sbi_hart_map_saddr (shmem_phys_lo, shmem_size); + + einfo = (struct sbi_pmu_event_info *)(shmem_phys_lo); +for (i =0 ; i < num_events; i++) { + event_idx = einfo[i].event_idx; + event_type =pmu_event_validate (phs, event_idx, einfo[i].event_data); +if (event_type <0 ) { + einfo[i].output =0 ; + }else { +for (j =0 ; j < num_hw_events; j++) { + temp = &hw_event_map[j]; +if (temp->start_idx <= event_idx && event_idx <= temp->end_idx) { + found = true; +break ; + } +/* For raw events, event data is used as the select value */ +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) { +uint64_t select_mask = temp->select_mask; + +/* just match the selector */ +if (temp->select == (einfo[i].event_data & select_mask)) { + found = true; +break ; + } + } + } +if (found) + einfo[i].output =1 ; +else + einfo[i].output =0 ; + found = false; + } + } + +sbi_hart_unmap_saddr (); + +return 0 ; +} +static void pmu_reset_event_map (struct sbi_pmu_hart_state *phs) {int j; --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 4/5 lib: sbi_pmu: Implement SBI PMU event info function
In reply to Atish PatraHi Atish,
Quoted 96 lines · Atish Patra
Allow the supervisor software to query about the event using the new function. This supports both firmware and hardware events. The hardware event presence is verified
hw_event_mapwhich is populated via PMU device tree node. The firmware event presence is checked through event validation function which should take care of both standard and platform firmware events.Signed-off-by Atish Patra <[email protected]>--- include/sbi/sbi_pmu.h | 2 ++ lib/sbi/sbi_ecall_pmu.c | 3 ++ lib/sbi/sbi_pmu.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)include/sbi/sbi_pmu.h +2
-0@@ -142,6 +142,8 @@ int sbi_pmu_ctr_start(unsigned long cidx_base, unsigned long cidx_mask, unsigned long flags, uint64_t ival);int sbi_pmu_ctr_get_info (uint32_t cidx,unsigned long *ctr_info); +int sbi_pmu_event_get_info (unsigned long shmem_lo,unsigned long shmem_high, +unsigned long num_events,unsigned long flags);unsigned long sbi_pmu_num_ctr (void );lib/sbi/sbi_ecall_pmu.c +3
-0@@ -73,6 +73,9 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,case SBI_EXT_PMU_COUNTER_STOP : ret =sbi_pmu_ctr_stop (regs->a0, regs->a1, regs->a2);break ; +case SBI_EXT_PMU_EVENT_GET_INFO : + ret =sbi_pmu_event_get_info (regs->a0, regs->a1, regs->a2, regs->a3); +break ;case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM :/* fallthrough as OpenSBI doesn't support snapshot yet */ default :lib/sbi/sbi_pmu.c +40
-0@@ -10,6 +10,7 @@#include <sbi/riscv_asm.h> #include <sbi/sbi_bitops.h> #include <sbi/sbi_console.h> +#include <sbi/sbi_domain.h> #include <sbi/sbi_ecall_interface.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_heap.h> @@ -968,6 +969,81 @@ int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info)return 0 ; } +int sbi_pmu_event_get_info (unsigned long shmem_phys_lo,unsigned long shmem_phys_hi, +unsigned long num_events,unsigned long flags) +{ +unsigned long shmem_size = num_events *sizeof (struct sbi_pmu_event_info ); +int i, j, event_type; +struct sbi_pmu_event_info *einfo; +struct sbi_pmu_hart_state *phs =pmu_thishart_state_ptr (); +uint32_t event_idx; +struct sbi_pmu_hw_event *temp; +bool found = false; + +if (flags !=0 ) +return SBI_ERR_INVALID_PARAM ; + +/** Check shared memory size and address aligned to 16 byte */ +if (!num_events || (shmem_phys_lo &0xF )) +return SBI_ERR_INVALID_PARAM ; + +/* +* On RV32, the M-mode can only access the first 4GB of +* the physical address space because M-mode does not have +* MMU to access full 34-bit physical address space. +* +* Based on above, we simply fail if the upper 32bits of +* the physical address (i.e. a2 register) is non-zero on +* RV32. +*/ +if (shmem_phys_hi) +return SBI_EINVALID_ADDR ; + +if (!sbi_domain_check_addr_range (sbi_domain_thishart_ptr (), + shmem_phys_lo, shmem_size,PRV_S , +SBI_DOMAIN_READ |SBI_DOMAIN_WRITE )) +return SBI_ERR_INVALID_ADDRESS ; + +sbi_hart_map_saddr (shmem_phys_lo, shmem_size); + + einfo = (struct sbi_pmu_event_info *)(shmem_phys_lo); +for (i =0 ; i < num_events; i++) {
lib/sbi/sbi_pmu.c int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info) · line 1020
Quoted 10 lines
lib/sbi/sbi_pmu.c +10
-0+ event_idx = einfo[i].event_idx; + event_type =pmu_event_validate (phs, event_idx, einfo[i].event_data); +if (event_type <0 ) { + einfo[i].output =0 ; + }else { +for (j =0 ; j < num_hw_events; j++) { + temp = &hw_event_map[j]; +if (temp->start_idx <= event_idx && event_idx <= temp->end_idx) { + found = true; +break ;
Won't this check succeed for every raw event (since they all have the same event_idx), so the break will prevent the block below from ever executing?
Regards,
Samuel
Quoted 30 lines
lib/sbi/sbi_pmu.c +26
-0+ } +/* For raw events, event data is used as the select value */ +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) { +uint64_t select_mask = temp->select_mask; + +/* just match the selector */ +if (temp->select == (einfo[i].event_data & select_mask)) { + found = true; +break ; + } + } + } +if (found) + einfo[i].output =1 ; +else + einfo[i].output =0 ; + found = false; + } + } + +sbi_hart_unmap_saddr (); + +return 0 ; +} +static void pmu_reset_event_map (struct sbi_pmu_hart_state *phs) {int j;
PATCH 4/5 lib: sbi_pmu: Implement SBI PMU event info function
Quoted 105 lines · On Mon, Dec 2, 2024 at 2:28?PM Samuel Holland <[email protected]> wrote:
Hi Atish,
Quoted 101 lines · Atish Patra
Allow the supervisor software to query about the event using the new function. This supports both firmware and hardware events. The hardware event presence is verified
hw_event_mapwhich is populated via PMU device tree node. The firmware event presence is checked through event validation function which should take care of both standard and platform firmware events.Signed-off-by Atish Patra <[email protected]>--- include/sbi/sbi_pmu.h | 2 ++ lib/sbi/sbi_ecall_pmu.c | 3 ++ lib/sbi/sbi_pmu.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+)include/sbi/sbi_pmu.h +2
-0@@ -142,6 +142,8 @@ int sbi_pmu_ctr_start(unsigned long cidx_base, unsigned long cidx_mask, unsigned long flags, uint64_t ival);int sbi_pmu_ctr_get_info (uint32_t cidx,unsigned long *ctr_info); +int sbi_pmu_event_get_info (unsigned long shmem_lo,unsigned long shmem_high, +unsigned long num_events,unsigned long flags);unsigned long sbi_pmu_num_ctr (void );lib/sbi/sbi_ecall_pmu.c +3
-0@@ -73,6 +73,9 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,case SBI_EXT_PMU_COUNTER_STOP : ret =sbi_pmu_ctr_stop (regs->a0, regs->a1, regs->a2);break ; +case SBI_EXT_PMU_EVENT_GET_INFO : + ret =sbi_pmu_event_get_info (regs->a0, regs->a1, regs->a2, regs->a3); +break ;case SBI_EXT_PMU_SNAPSHOT_SET_SHMEM :/* fallthrough as OpenSBI doesn't support snapshot yet */ default :lib/sbi/sbi_pmu.c +45
-0@@ -10,6 +10,7 @@#include <sbi/riscv_asm.h> #include <sbi/sbi_bitops.h> #include <sbi/sbi_console.h> +#include <sbi/sbi_domain.h> #include <sbi/sbi_ecall_interface.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_heap.h> @@ -968,6 +969,81 @@ int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info)return 0 ; } +int sbi_pmu_event_get_info (unsigned long shmem_phys_lo,unsigned long shmem_phys_hi, +unsigned long num_events,unsigned long flags) +{ +unsigned long shmem_size = num_events *sizeof (struct sbi_pmu_event_info ); +int i, j, event_type; +struct sbi_pmu_event_info *einfo; +struct sbi_pmu_hart_state *phs =pmu_thishart_state_ptr (); +uint32_t event_idx; +struct sbi_pmu_hw_event *temp; +bool found = false; + +if (flags !=0 ) +return SBI_ERR_INVALID_PARAM ; + +/** Check shared memory size and address aligned to 16 byte */ +if (!num_events || (shmem_phys_lo &0xF )) +return SBI_ERR_INVALID_PARAM ; + +/* +* On RV32, the M-mode can only access the first 4GB of +* the physical address space because M-mode does not have +* MMU to access full 34-bit physical address space. +* +* Based on above, we simply fail if the upper 32bits of +* the physical address (i.e. a2 register) is non-zero on +* RV32. +*/ +if (shmem_phys_hi) +return SBI_EINVALID_ADDR ; + +if (!sbi_domain_check_addr_range (sbi_domain_thishart_ptr (), + shmem_phys_lo, shmem_size,PRV_S , +SBI_DOMAIN_READ |SBI_DOMAIN_WRITE )) +return SBI_ERR_INVALID_ADDRESS ; + +sbi_hart_map_saddr (shmem_phys_lo, shmem_size); + + einfo = (struct sbi_pmu_event_info *)(shmem_phys_lo); +for (i =0 ; i < num_events; i++) { + event_idx = einfo[i].event_idx; + event_type =pmu_event_validate (phs, event_idx, einfo[i].event_data); +if (event_type <0 ) { + einfo[i].output =0 ; + }else {
Quoted 9 lines
lib/sbi/sbi_pmu.c int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info) · line 1020
Quoted 5 lines
lib/sbi/sbi_pmu.c +5
-0+for (j =0 ; j < num_hw_events; j++) { + temp = &hw_event_map[j]; +if (temp->start_idx <= event_idx && event_idx <= temp->end_idx) { + found = true; +break ;Won't this check succeed for every raw event (since they all have the same
event_idx), so thebreakwill prevent the block below from ever executing?
Yeah. The check order should be reversed. It is supposed to check the raw events first and other
hardware events after that. I will send a fix.
Quoted 34 lines
Regards,
SamuelQuoted 30 lines
lib/sbi/sbi_pmu.c +26
-0+ } +/* For raw events, event data is used as the select value */ +if (event_idx ==SBI_PMU_EVENT_RAW_IDX || + event_idx ==SBI_PMU_EVENT_RAW_V2_IDX ) { +uint64_t select_mask = temp->select_mask; + +/* just match the selector */ +if (temp->select == (einfo[i].event_data & select_mask)) { + found = true; +break ; + } + } + } +if (found) + einfo[i].output =1 ; +else + einfo[i].output =0 ; + found = false; + } + } + +sbi_hart_unmap_saddr (); + +return 0 ; +} +static void pmu_reset_event_map (struct sbi_pmu_hart_state *phs) {int j;
PATCH 5/5 include: sbi: Change spec version to 3.0
In reply to Atish PatraSBI version 3.0 is on its way for ratification. Change the spec version for easier testing of SBI v3.0 features.
---
This patch can be merged after SBI v3.0 is frozen.
---
--- include/sbi/sbi_ecall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/sbi/sbi_ecall.h +1 -1
@@ -13,7 +13,7 @@#include <sbi/sbi_types.h> #include <sbi/sbi_list.h> -#define SBI_ECALL_VERSION_MAJOR 2 +#define SBI_ECALL_VERSION_MAJOR 3#define SBI_ECALL_VERSION_MINOR 0#define SBI_OPENSBI_IMPID 1
Signature · 1 line
2.34.1
PATCH 5/5 include: sbi: Change spec version to 3.0
Quoted 8 lines · On Wed, Nov 20, 2024 at 1:04?AM Atish Patra <[email protected]> wrote:
SBI version 3.0 is on its way for ratification. Change the spec version for easier testing of SBI v3.0 features.
Signed-off-by Atish Patra <[email protected]>---
This patch can be merged after SBI v3.0 is frozen.
Yes, it's too early to make this change.
Regards,
Anup
Quoted 27 lines
---
--- include/sbi/sbi_ecall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/sbi/sbi_ecall.h +1
-2@@ -13,7 +13,7 @@#include <sbi/sbi_types.h> #include <sbi/sbi_list.h> -#define SBI_ECALL_VERSION_MAJOR 2 +#define SBI_ECALL_VERSION_MAJOR 3#define SBI_ECALL_VERSION_MINOR 0#define SBI_OPENSBI_IMPID 1 --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi