SBI PMU firmware counters and events improvement
v3 cover SBI PMU firmware counters and events improvement
This patchset implements the improvements described in the following proposal from Anup Patel:
https://lists.riscv.org/g/tech-prs/message/102
Changes in v3:
- Break patch 4 from v2 into multiple smaller patches
- Add reviewed-by tags
Changes in v2:
- Update Risc V platform specific firmware event handling as per the SBI spec update: https://lists.riscv.org/g/tech-prs/message/211
Mayuresh Chitale (8):
lib: sbi_pmu: add callback for counter width
lib: sbi_pmu: Implement sbi_pmu_counter_fw_read_hi
lib: sbi_pmu: Reserve space for implementation specific firmware
events
lib: sbi_pmu: Rename fw_counter_value
lib: sbi_pmu: Update sbi_pmu dev ops
lib: sbi_pmu: Use dedicated event code for platform firmware events
lib: sbi_pmu: Introduce fw_counter_write_value API
lib: sbi_pmu: Add hartid parameter PMU device ops
include/sbi/sbi_ecall_interface.h | 12 +++ include/sbi/sbi_pmu.h | 31 ++++--- lib/sbi/sbi_ecall_pmu.c | 8 ++ lib/sbi/sbi_pmu.c | 141 +++++++++++++++++++++--------- 4 files changed, 141 insertions(+), 51 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/8 lib: sbi_pmu: add callback for counter width
This patch adds a callback to fetch the number of bits implemented for a custom firmware counter. If the callback fails or is not implemented then width defaults to 63.
--- include/sbi/sbi_pmu.h | 5 +++++ lib/sbi/sbi_pmu.c | 6 ++++++ 2 files changed, 11 insertions(+)
include/sbi/sbi_pmu.h +5 -0
@@ -41,6 +41,11 @@ struct sbi_pmu_device {bool (*fw_counter_match_code)(uint32_t counter_index,uint32_t event_idx_code); +/** +* Fetch the max width of this counter in number of bits. +*/ +int (*fw_counter_width)(void ); +/** * Read value of custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
lib/sbi/sbi_pmu.c +6 -0
@@ -761,6 +761,7 @@ unsigned long sbi_pmu_num_ctr(void)int sbi_pmu_ctr_get_info (uint32_t cidx,unsigned long *ctr_info) { +int width;union sbi_pmu_ctr_info cinfo = {0 };struct sbi_scratch *scratch =sbi_scratch_thishart_ptr ();
@@ -782,6 +783,11 @@ int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info) cinfo.type =SBI_PMU_CTR_TYPE_FW ;/* Firmware counters are always 64 bits wide */ cinfo.width =63 ; +if (pmu_dev && pmu_dev->fw_counter_width) { + width = pmu_dev->fw_counter_width (); +if (width) + cinfo.width = width -1 ; + } } *ctr_info = cinfo.value;
Signature · 1 line
2.34.1
PATCH v3 1/8 lib: sbi_pmu: add callback for counter width
Quoted 7 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
This patch adds a callback to fetch the number of bits implemented for a custom firmware counter. If the callback fails or is not implemented then width defaults to 63.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Atish Patra <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 53 lines
--- include/sbi/sbi_pmu.h | 5 +++++ lib/sbi/sbi_pmu.c | 6 ++++++ 2 files changed, 11 insertions(+)include/sbi/sbi_pmu.h +5
-0@@ -41,6 +41,11 @@ struct sbi_pmu_device {bool (*fw_counter_match_code)(uint32_t counter_index,uint32_t event_idx_code); +/** +* Fetch the max width of this counter in number of bits. +*/ +int (*fw_counter_width)(void ); +/** * Read value of custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX lib/sbi/sbi_pmu.c +6
-1@@ -761,6 +761,7 @@ unsigned long sbi_pmu_num_ctr(void)int sbi_pmu_ctr_get_info (uint32_t cidx,unsigned long *ctr_info) { +int width;union sbi_pmu_ctr_info cinfo = {0 };struct sbi_scratch *scratch =sbi_scratch_thishart_ptr ();@@ -782,6 +783,11 @@ int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info) cinfo.type =SBI_PMU_CTR_TYPE_FW ;/* Firmware counters are always 64 bits wide */ cinfo.width =63 ; +if (pmu_dev && pmu_dev->fw_counter_width) { + width = pmu_dev->fw_counter_width (); +if (width) + cinfo.width = width -1 ; + } } *ctr_info = cinfo.value; --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 2/8 lib: sbi_pmu: Implement sbi_pmu_counter_fw_read_hi
In reply to Mayuresh ChitaleTo support 64 bit firmware counters on RV32 systems, we implement sbi_pmu_counter_fw_read_hi() which returns the upper 32 bits of the firmware counter value. On RV64 (or higher) systems, this function will always return zero.
--- include/sbi/sbi_ecall_interface.h | 1 + lib/sbi/sbi_ecall_pmu.c | 8 ++++++++ 2 files changed, 9 insertions(+)
include/sbi/sbi_ecall_interface.h +1 -0
@@ -101,6 +101,7 @@#define SBI_EXT_PMU_COUNTER_START 0x3#define SBI_EXT_PMU_COUNTER_STOP 0x4#define SBI_EXT_PMU_COUNTER_FW_READ 0x5 +#define SBI_EXT_PMU_COUNTER_FW_READ_HI 0x6/** General pmu event codes specified in SBI PMU extension */ enum sbi_pmu_hw_generic_events_t {
lib/sbi/sbi_ecall_pmu.c +8 -0
@@ -54,6 +54,14 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid, ret =sbi_pmu_ctr_fw_read (regs->a0, &temp); *out_val = temp;break ; +case SBI_EXT_PMU_COUNTER_FW_READ_HI : +#if __riscv_xlen ==32 + ret =sbi_pmu_ctr_fw_read (regs->a0, &temp); + *out_val = temp >>32 +#else + *out_val =0 ; +#endif +break ;case SBI_EXT_PMU_COUNTER_START :#if __riscv_xlen ==32
Signature · 1 line
2.34.1
PATCH v3 2/8 lib: sbi_pmu: Implement sbi_pmu_counter_fw_read_hi
Quoted 8 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
To support 64 bit firmware counters on RV32 systems, we implement
sbi_pmu_counter_fw_read_hi()which returns the upper 32 bits of the firmware counter value. On RV64 (or higher) systems, this function will always return zero.Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Atish Patra <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 44 lines
--- include/sbi/sbi_ecall_interface.h | 1 + lib/sbi/sbi_ecall_pmu.c | 8 ++++++++ 2 files changed, 9 insertions(+)include/sbi/sbi_ecall_interface.h +1
-0@@ -101,6 +101,7 @@#define SBI_EXT_PMU_COUNTER_START 0x3#define SBI_EXT_PMU_COUNTER_STOP 0x4#define SBI_EXT_PMU_COUNTER_FW_READ 0x5 +#define SBI_EXT_PMU_COUNTER_FW_READ_HI 0x6/** General pmu event codes specified in SBI PMU extension */ enum sbi_pmu_hw_generic_events_t {lib/sbi/sbi_ecall_pmu.c +8
-1@@ -54,6 +54,14 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid, ret =sbi_pmu_ctr_fw_read (regs->a0, &temp); *out_val = temp;break ; +case SBI_EXT_PMU_COUNTER_FW_READ_HI : +#if __riscv_xlen ==32 + ret =sbi_pmu_ctr_fw_read (regs->a0, &temp); + *out_val = temp >>32 +#else + *out_val =0 ; +#endif +break ;case SBI_EXT_PMU_COUNTER_START :#if __riscv_xlen ==32 --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 3/8 lib: sbi_pmu: Reserve space for implementation specific firmware events
In reply to Mayuresh ChitaleWe reserve space for SBI implementation specific custom firmware events which can be used by M-mode firmwares and HS-mode hypervisors for their own use. This reserved space is intentionally large to ensure that SBI implementation has enough space to accommodate platform specific firmware events as well.
--- include/sbi/sbi_ecall_interface.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/sbi/sbi_ecall_interface.h +11 -0
@@ -185,6 +185,17 @@ enum sbi_pmu_fw_event_code_id {SBI_PMU_FW_HFENCE_VVMA_ASID_SENT =20 ,SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD =21 ,SBI_PMU_FW_MAX , +/* +* Event codes 22 to 255 are reserved for future use. +* Event codes 256 to 65534 are reserved for SBI implementation +* specific custom firmware events. +*/ +SBI_PMU_FW_RESERVED_MAX =0xFFFE , +/* +* Event code 0xFFFF is used for platform specific firmware +* events where the event data contains any event specific information. +*/ + SBI_PMU_FW_PLATFORM = 0xFFFF, };/** SBI PMU event idx type */
Signature · 1 line
2.34.1
PATCH v3 3/8 lib: sbi_pmu: Reserve space for implementation specific firmware events
Quoted 9 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
We reserve space for SBI implementation specific custom firmware events which can be used by M-mode firmwares and HS-mode hypervisors for their own use. This reserved space is intentionally large to ensure that SBI implementation has enough space to accommodate platform specific firmware events as well.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Atish Patra <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 34 lines
--- include/sbi/sbi_ecall_interface.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/sbi/sbi_ecall_interface.h +11
-1@@ -185,6 +185,17 @@ enum sbi_pmu_fw_event_code_id {SBI_PMU_FW_HFENCE_VVMA_ASID_SENT =20 ,SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD =21 ,SBI_PMU_FW_MAX , +/* +* Event codes 22 to 255 are reserved for future use. +* Event codes 256 to 65534 are reserved for SBI implementation +* specific custom firmware events. +*/ +SBI_PMU_FW_RESERVED_MAX =0xFFFE , +/* +* Event code 0xFFFF is used for platform specific firmware +* events where the event data contains any event specific information. +*/ + SBI_PMU_FW_PLATFORM = 0xFFFF, };/** SBI PMU event idx type */ --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 3/8 lib: sbi_pmu: Reserve space for implementation specific firmware events
In reply to Mayuresh ChitaleQuoted 20 lines · Mayuresh Chitale
We reserve space for SBI implementation specific custom firmware events which can be used by M-mode firmwares and HS-mode hypervisors for their own use. This reserved space is intentionally large to ensure that SBI implementation has enough space to accommodate platform specific firmware events as well.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Atish Patra <[email protected]>--- include/sbi/sbi_ecall_interface.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/sbi/sbi_ecall_interface.h +0
-0@@ -185,6 +185,17 @@ enum sbi_pmu_fw_event_code_id {SBI_PMU_FW_HFENCE_VVMA_ASID_SENT =20 ,SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD =21 , SBI_PMU_FW_MAX,
include/sbi/sbi_ecall_interface.h enum sbi_pmu_fw_event_code_id { · line 197
Quoted 10 lines
include/sbi/sbi_ecall_interface.h +10
-0+/* +* Event codes 22 to 255 are reserved for future use. +* Event codes 256 to 65534 are reserved for SBI implementation +* specific custom firmware events. +*/ + SBI_PMU_FW_RESERVED_MAX = 0xFFFE, +/* +* Event code 0xFFFF is used for platform specific firmware +* events where the event data contains any event specific information. +*/
The above three lines need to be spaced over one space. And, then, "the stars will align", which should improve our luck!
Thanks,
drew
Quoted 12 lines
include/sbi/sbi_ecall_interface.h +1
-0+ SBI_PMU_FW_PLATFORM = 0xFFFF, };/** SBI PMU event idx type */ Signature · 7 lines
2.34.1 -- opensbi mailing list opensbi at lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 3/8 lib: sbi_pmu: Reserve space for implementation specific firmware events
Quoted 30 lines · Andrew Jones
Quoted 29 lines · Mayuresh Chitale
We reserve space for SBI implementation specific custom firmware events which can be used by M-mode firmwares and HS-mode hypervisors
for their own use. This reserved space is intentionally large to ensure that SBI implementation has enough space to accommodate platform specific firmware events as well.Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Atish Patra <[email protected]>--- include/sbi/sbi_ecall_interface.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/sbi/sbi_ecall_interface.h +7
-0@@ -185,6 +185,17 @@ enum sbi_pmu_fw_event_code_id {SBI_PMU_FW_HFENCE_VVMA_ASID_SENT =20 ,SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD =21 ,SBI_PMU_FW_MAX , +/* +* Event codes 22 to 255 are reserved for future use. +* Event codes 256 to 65534 are reserved for SBI implementation +* specific custom firmware events. +*/ + SBI_PMU_FW_RESERVED_MAX = 0xFFFE, +/*
Quoted 8 lines
include/sbi/sbi_ecall_interface.h
Quoted 4 lines
include/sbi/sbi_ecall_interface.h +2
-0+* Event code 0xFFFF is used for platform specific firmware +* events where the event data contains any event specific information.
include/sbi/sbi_ecall_interface.h +1
-0+*/ The above three lines need to be spaced over one space. And, then, "the
stars will align", which should improve our luck!
Ok :). Will fix it.
Quoted 16 lines
Thanks,
drewQuoted 12 lines
include/sbi/sbi_ecall_interface.h +1
-0+ SBI_PMU_FW_PLATFORM = 0xFFFF, };/** SBI PMU event idx type */ Signature · 7 lines
2.34.1 -- opensbi mailing list opensbi at lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 4/8 lib: sbi_pmu: Rename fw_counter_value
In reply to Mayuresh ChitaleRename and reuse fw_counter_value arrary to save both the counter values for the SBI firmware events and event data for the SBI platform specific firmware events.
--- lib/sbi/sbi_pmu.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
lib/sbi/sbi_pmu.c +13 -9
@@ -65,8 +65,12 @@ static uint32_t active_events[SBI_HARTMASK_MAX_BITS][SBI_PMU_HW_CTR_MAX + SBI_PM#endif static unsigned long fw_counters_started[SBI_HARTMASK_MAX_BITS ]; -/* Values of firmwares counters on each HART */ -static uint64_t fw_counters_value[SBI_HARTMASK_MAX_BITS ][SBI_PMU_FW_CTR_MAX ] = {0 }; +/* +* Counter values for SBI firmware events and event codes for platform +* firmware events. Both are mutually exclusive and hence can optimally share +* the same memory. +*/ +static uint64_t fw_counters_data[SBI_HARTMASK_MAX_BITS ][SBI_PMU_FW_CTR_MAX ] = {0 };/* Maximum number of hardware events available */ static uint32_t num_hw_events;
@@ -185,10 +189,10 @@ int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval)if (SBI_PMU_FW_MAX <= event_code && pmu_dev && pmu_dev->fw_counter_read_value) - fw_counters_value[hartid][cidx - num_hw_ctrs] = + fw_counters_data[hartid][cidx - num_hw_ctrs] = pmu_dev->fw_counter_read_value (cidx - num_hw_ctrs); - *cval = fw_counters_value[hartid][cidx - num_hw_ctrs]; + *cval = fw_counters_data[hartid][cidx - num_hw_ctrs];return 0 ; }
@@ -372,7 +376,7 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, }if (ival_update) - fw_counters_value[hartid][cidx - num_hw_ctrs] = ival; + fw_counters_data[hartid][cidx - num_hw_ctrs] = ival; fw_counters_started[hartid] |=BIT (cidx - num_hw_ctrs);return 0 ;
@@ -711,13 +715,13 @@ skip_match:pmu_ctr_start_hw (ctr_idx,0 , false); }else if (event_type ==SBI_PMU_EVENT_TYPE_FW ) {if (flags &SBI_PMU_CFG_FLAG_CLEAR_VALUE ) - fw_counters_value[hartid][ctr_idx - num_hw_ctrs] =0 ; + fw_counters_data[hartid][ctr_idx - num_hw_ctrs] =0 ;if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) {if (SBI_PMU_FW_MAX <= event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start ( ctr_idx - num_hw_ctrs, event_code, - fw_counters_value[hartid][ctr_idx - num_hw_ctrs], + fw_counters_data[hartid][ctr_idx - num_hw_ctrs], true);if (ret)return ret;
@@ -743,7 +747,7 @@ int sbi_pmu_ctr_incr_fw(enum sbi_pmu_fw_event_code_id fw_id)for (cidx = num_hw_ctrs; cidx < total_ctrs; cidx++) {if (get_cidx_code (active_events[hartid][cidx]) == fw_id && (fw_counters_started[hartid] &BIT (cidx - num_hw_ctrs))) { - fcounter = &fw_counters_value[hartid][cidx - num_hw_ctrs]; + fcounter = &fw_counters_data[hartid][cidx - num_hw_ctrs];break ; } }
@@ -803,7 +807,7 @@ static void pmu_reset_event_map(u32 hartid)for (j =3 ; j < total_ctrs; j++) active_events[hartid][j] =SBI_PMU_EVENT_IDX_INVALID ;for (j =0 ; j <SBI_PMU_FW_CTR_MAX ; j++) - fw_counters_value[hartid][j] =0 ; + fw_counters_data[hartid][j] =0 ; fw_counters_started[hartid] =0 ; }
Signature · 1 line
2.34.1
PATCH v3 4/8 lib: sbi_pmu: Rename fw_counter_value
Quoted 6 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
Rename and reuse
fw_counter_valuearrary to save both the counter values for the SBI firmware events and event data for the SBI platform specific firmware events.Signed-off-by Mayuresh Chitale <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 87 lines
--- lib/sbi/sbi_pmu.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)lib/sbi/sbi_pmu.c +13
-10@@ -65,8 +65,12 @@ static uint32_t active_events[SBI_HARTMASK_MAX_BITS][SBI_PMU_HW_CTR_MAX + SBI_PM#endif static unsigned long fw_counters_started[SBI_HARTMASK_MAX_BITS ]; -/* Values of firmwares counters on each HART */ -static uint64_t fw_counters_value[SBI_HARTMASK_MAX_BITS ][SBI_PMU_FW_CTR_MAX ] = {0 }; +/* +* Counter values for SBI firmware events and event codes for platform +* firmware events. Both are mutually exclusive and hence can optimally share +* the same memory. +*/ +static uint64_t fw_counters_data[SBI_HARTMASK_MAX_BITS ][SBI_PMU_FW_CTR_MAX ] = {0 };/* Maximum number of hardware events available */ static uint32_t num_hw_events;@@ -185,10 +189,10 @@ int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval)if (SBI_PMU_FW_MAX <= event_code && pmu_dev && pmu_dev->fw_counter_read_value) - fw_counters_value[hartid][cidx - num_hw_ctrs] = + fw_counters_data[hartid][cidx - num_hw_ctrs] = pmu_dev->fw_counter_read_value (cidx - num_hw_ctrs); - *cval = fw_counters_value[hartid][cidx - num_hw_ctrs]; + *cval = fw_counters_data[hartid][cidx - num_hw_ctrs];return 0 ; }@@ -372,7 +376,7 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, }if (ival_update) - fw_counters_value[hartid][cidx - num_hw_ctrs] = ival; + fw_counters_data[hartid][cidx - num_hw_ctrs] = ival; fw_counters_started[hartid] |=BIT (cidx - num_hw_ctrs);return 0 ;@@ -711,13 +715,13 @@ skip_match:pmu_ctr_start_hw (ctr_idx,0 , false); }else if (event_type ==SBI_PMU_EVENT_TYPE_FW ) {if (flags &SBI_PMU_CFG_FLAG_CLEAR_VALUE ) - fw_counters_value[hartid][ctr_idx - num_hw_ctrs] =0 ; + fw_counters_data[hartid][ctr_idx - num_hw_ctrs] =0 ;if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) {if (SBI_PMU_FW_MAX <= event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start ( ctr_idx - num_hw_ctrs, event_code, - fw_counters_value[hartid][ctr_idx - num_hw_ctrs], + fw_counters_data[hartid][ctr_idx - num_hw_ctrs], true);if (ret)return ret;@@ -743,7 +747,7 @@ int sbi_pmu_ctr_incr_fw(enum sbi_pmu_fw_event_code_id fw_id)for (cidx = num_hw_ctrs; cidx < total_ctrs; cidx++) {if (get_cidx_code (active_events[hartid][cidx]) == fw_id && (fw_counters_started[hartid] &BIT (cidx - num_hw_ctrs))) { - fcounter = &fw_counters_value[hartid][cidx - num_hw_ctrs]; + fcounter = &fw_counters_data[hartid][cidx - num_hw_ctrs];break ; } }@@ -803,7 +807,7 @@ static void pmu_reset_event_map(u32 hartid)for (j =3 ; j < total_ctrs; j++) active_events[hartid][j] =SBI_PMU_EVENT_IDX_INVALID ;for (j =0 ; j <SBI_PMU_FW_CTR_MAX ; j++) - fw_counters_value[hartid][j] =0 ; + fw_counters_data[hartid][j] =0 ; fw_counters_started[hartid] =0 ; } --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 4/8 lib: sbi_pmu: Rename fw_counter_value
In reply to Mayuresh ChitaleQuoted 1 line · Mayuresh Chitale
Rename and reuse
fw_counter_valuearrary to save both the counter values
array
Quoted 7 lines
for the SBI firmware events and event data for the SBI platform specific firmware events.
Signed-off-by Mayuresh Chitale <[email protected]>--- lib/sbi/sbi_pmu.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
Otherwise
PATCH v3 5/8 lib: sbi_pmu: Update sbi_pmu dev ops
In reply to Mayuresh ChitaleUpdate fw_event_validate_code, fw_counter_match_code and fw_counter_start ops which used a 32 bit event code to use the 64 bit event data instead.
--- include/sbi/sbi_pmu.h | 9 ++++----- lib/sbi/sbi_pmu.c | 30 +++++++++++++++++------------- 2 files changed, 21 insertions(+), 18 deletions(-)
include/sbi/sbi_pmu.h +4 -5
@@ -30,16 +30,15 @@ struct sbi_pmu_device {/** * Validate event code of custom firmware event -* Note: SBI_PMU_FW_MAX <= event_idx_code */ -int (*fw_event_validate_code)(uint32_t event_idx_code); +int (*fw_event_validate_encoding)(uint64_t event_data);/** * Match custom firmware counter with custom firmware event * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -bool (*fw_counter_match_code)(uint32_t counter_index, -uint32_t event_idx_code); +bool (*fw_counter_match_encoding)(uint32_t counter_index, +uint64_t event_data);/** * Fetch the max width of this counter in number of bits.
@@ -58,7 +57,7 @@ struct sbi_pmu_device {* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ int (*fw_counter_start)(uint32_t counter_index, -uint32_t event_idx_code, +uint64_t event_data,uint64_t init_val,bool init_val_update);/**
lib/sbi/sbi_pmu.c +17 -13
@@ -110,7 +110,7 @@ static bool pmu_event_select_overlap(struct sbi_pmu_hw_event *evt,return false; } -static int pmu_event_validate (unsigned long event_idx) +static int pmu_event_validate (unsigned long event_idx,uint64_t edata) {uint32_t event_idx_type =get_cidx_type (event_idx);uint32_t event_idx_code =get_cidx_code (event_idx);
@@ -123,8 +123,8 @@ static int pmu_event_validate(unsigned long event_idx)break ;case SBI_PMU_EVENT_TYPE_FW :if (SBI_PMU_FW_MAX <= event_idx_code && - pmu_dev && pmu_dev->fw_event_validate_code) -return pmu_dev->fw_event_validate_code (event_idx_code); + pmu_dev && pmu_dev->fw_event_validate_encoding) +return pmu_dev->fw_event_validate_encoding (edata);else event_idx_code_max =SBI_PMU_FW_MAX ;break ;
@@ -361,7 +361,8 @@ int sbi_pmu_irq_bit(void) }static int pmu_ctr_start_fw (uint32_t cidx,uint32_t event_code, -uint64_t ival,bool ival_update) +uint64_t event_data,uint64_t ival, +bool ival_update) {int ret;u32 hartid =current_hartid ();
@@ -369,7 +370,7 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,if (SBI_PMU_FW_MAX <= event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start (cidx - num_hw_ctrs, - event_code, + event_data, ival, ival_update);if (ret)return ret;
@@ -390,6 +391,7 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask,int ret =SBI_EINVAL ;bool bUpdate = false;int i, cidx; +uint64_t edata =0 ;if ((cbase +sbi_fls (cmask)) >= total_ctrs)return ret;
@@ -404,7 +406,8 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask,/* Continue the start operation for other counters */ continue ; else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) - ret =pmu_ctr_start_fw (cidx, event_code, ival, bUpdate); + ret =pmu_ctr_start_fw (cidx, event_code, edata, ival, + bUpdate); else ret =pmu_ctr_start_hw (cidx, ival, bUpdate); }
@@ -644,7 +647,7 @@ static int pmu_ctr_find_hw(unsigned long cbase, unsigned long cmask, unsigned lo* check. */ static int pmu_ctr_find_fw (unsigned long cbase,unsigned long cmask, -uint32_t event_code,u32 hartid) +uint32_t event_code,u32 hartid,uint64_t edata) {int i, cidx;
@@ -655,9 +658,9 @@ static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask,if (active_events[hartid][i] !=SBI_PMU_EVENT_IDX_INVALID )continue ;if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_match_code) { -if (!pmu_dev->fw_counter_match_code (cidx - num_hw_ctrs, - event_code)) + pmu_dev && pmu_dev->fw_counter_match_encoding) { +if (!pmu_dev->fw_counter_match_encoding (cidx - num_hw_ctrs, + edata))continue ; }
@@ -679,7 +682,7 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,if ((cidx_base +sbi_fls (cidx_mask)) >= total_ctrs)return SBI_EINVAL ; - event_type =pmu_event_validate (event_idx); + event_type =pmu_event_validate (event_idx, event_data);if (event_type <0 )return SBI_EINVAL ; event_code =get_cidx_code (event_idx);
@@ -697,7 +700,8 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,if (event_type ==SBI_PMU_EVENT_TYPE_FW ) {/* Any firmware counter can be used track any firmware event */ - ctr_idx =pmu_ctr_find_fw (cidx_base, cidx_mask, event_code, hartid); + ctr_idx =pmu_ctr_find_fw (cidx_base, cidx_mask, event_code, + hartid, event_data); }else { ctr_idx =pmu_ctr_find_hw (cidx_base, cidx_mask, flags, event_idx, event_data);
@@ -720,7 +724,7 @@ skip_match:if (SBI_PMU_FW_MAX <= event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start ( - ctr_idx - num_hw_ctrs, event_code, + ctr_idx - num_hw_ctrs, event_data, fw_counters_data[hartid][ctr_idx - num_hw_ctrs], true);if (ret)
Signature · 1 line
2.34.1
PATCH v3 5/8 lib: sbi_pmu: Update sbi_pmu dev ops
Quoted 5 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
Update
fw_event_validate_code,fw_counter_match_codeandfw_counter_startops which used a 32 bit event code to use the 64 bit event data instead.Signed-off-by Mayuresh Chitale <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 157 lines
--- include/sbi/sbi_pmu.h | 9 ++++----- lib/sbi/sbi_pmu.c | 30 +++++++++++++++++------------- 2 files changed, 21 insertions(+), 18 deletions(-)include/sbi/sbi_pmu.h +4
-5@@ -30,16 +30,15 @@ struct sbi_pmu_device {/** * Validate event code of custom firmware event -* Note: SBI_PMU_FW_MAX <= event_idx_code */ -int (*fw_event_validate_code)(uint32_t event_idx_code); +int (*fw_event_validate_encoding)(uint64_t event_data);/** * Match custom firmware counter with custom firmware event * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -bool (*fw_counter_match_code)(uint32_t counter_index, -uint32_t event_idx_code); +bool (*fw_counter_match_encoding)(uint32_t counter_index, +uint64_t event_data);/** * Fetch the max width of this counter in number of bits. @@ -58,7 +57,7 @@ struct sbi_pmu_device {* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ int (*fw_counter_start)(uint32_t counter_index, -uint32_t event_idx_code, +uint64_t event_data,uint64_t init_val,bool init_val_update);/** lib/sbi/sbi_pmu.c +17
-14@@ -110,7 +110,7 @@ static bool pmu_event_select_overlap(struct sbi_pmu_hw_event *evt,return false; } -static int pmu_event_validate (unsigned long event_idx) +static int pmu_event_validate (unsigned long event_idx,uint64_t edata) {uint32_t event_idx_type =get_cidx_type (event_idx);uint32_t event_idx_code =get_cidx_code (event_idx);@@ -123,8 +123,8 @@ static int pmu_event_validate(unsigned long event_idx)break ;case SBI_PMU_EVENT_TYPE_FW :if (SBI_PMU_FW_MAX <= event_idx_code && - pmu_dev && pmu_dev->fw_event_validate_code) -return pmu_dev->fw_event_validate_code (event_idx_code); + pmu_dev && pmu_dev->fw_event_validate_encoding) +return pmu_dev->fw_event_validate_encoding (edata);else event_idx_code_max =SBI_PMU_FW_MAX ;break ;@@ -361,7 +361,8 @@ int sbi_pmu_irq_bit(void) }static int pmu_ctr_start_fw (uint32_t cidx,uint32_t event_code, -uint64_t ival,bool ival_update) +uint64_t event_data,uint64_t ival, +bool ival_update) {int ret;u32 hartid =current_hartid ();@@ -369,7 +370,7 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,if (SBI_PMU_FW_MAX <= event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start (cidx - num_hw_ctrs, - event_code, + event_data, ival, ival_update);if (ret)return ret;@@ -390,6 +391,7 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask,int ret =SBI_EINVAL ;bool bUpdate = false;int i, cidx; +uint64_t edata =0 ;if ((cbase +sbi_fls (cmask)) >= total_ctrs)return ret;@@ -404,7 +406,8 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask,/* Continue the start operation for other counters */ continue ; else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) - ret =pmu_ctr_start_fw (cidx, event_code, ival, bUpdate); + ret =pmu_ctr_start_fw (cidx, event_code, edata, ival, + bUpdate); else ret =pmu_ctr_start_hw (cidx, ival, bUpdate); }@@ -644,7 +647,7 @@ static int pmu_ctr_find_hw(unsigned long cbase, unsigned long cmask, unsigned lo* check. */ static int pmu_ctr_find_fw (unsigned long cbase,unsigned long cmask, -uint32_t event_code,u32 hartid) +uint32_t event_code,u32 hartid,uint64_t edata) {int i, cidx;@@ -655,9 +658,9 @@ static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask,if (active_events[hartid][i] !=SBI_PMU_EVENT_IDX_INVALID )continue ;if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_match_code) { -if (!pmu_dev->fw_counter_match_code (cidx - num_hw_ctrs, - event_code)) + pmu_dev && pmu_dev->fw_counter_match_encoding) { +if (!pmu_dev->fw_counter_match_encoding (cidx - num_hw_ctrs, + edata))continue ; }@@ -679,7 +682,7 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,if ((cidx_base +sbi_fls (cidx_mask)) >= total_ctrs)return SBI_EINVAL ; - event_type =pmu_event_validate (event_idx); + event_type =pmu_event_validate (event_idx, event_data);if (event_type <0 )return SBI_EINVAL ; event_code =get_cidx_code (event_idx);@@ -697,7 +700,8 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,if (event_type ==SBI_PMU_EVENT_TYPE_FW ) {/* Any firmware counter can be used track any firmware event */ - ctr_idx =pmu_ctr_find_fw (cidx_base, cidx_mask, event_code, hartid); + ctr_idx =pmu_ctr_find_fw (cidx_base, cidx_mask, event_code, + hartid, event_data); }else { ctr_idx =pmu_ctr_find_hw (cidx_base, cidx_mask, flags, event_idx, event_data);@@ -720,7 +724,7 @@ skip_match:if (SBI_PMU_FW_MAX <= event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start ( - ctr_idx - num_hw_ctrs, event_code, + ctr_idx - num_hw_ctrs, event_data, fw_counters_data[hartid][ctr_idx - num_hw_ctrs], true);if (ret) --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 6/8 lib: sbi_pmu: Use dedicated event code for platform firmware events
In reply to Mayuresh ChitaleFor all platform specific firmware event operations use the dedicated event code (0xFFFF) when matching against the input firmware event. Furthermore save the real platform specific firmware event code received as the event data for future use.
--- lib/sbi/sbi_pmu.c | 65 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 13 deletions(-)
lib/sbi/sbi_pmu.c +52 -13
@@ -122,7 +122,12 @@ static int pmu_event_validate(unsigned long event_idx, uint64_t edata) event_idx_code_max =SBI_PMU_HW_GENERAL_MAX ;break ;case SBI_PMU_EVENT_TYPE_FW : -if (SBI_PMU_FW_MAX <= event_idx_code && +if ((event_idx_code >=SBI_PMU_FW_MAX && + event_idx_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_idx_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_idx_code && pmu_dev && pmu_dev->fw_event_validate_encoding)return pmu_dev->fw_event_validate_encoding (edata);else
@@ -187,12 +192,19 @@ int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval)if (event_idx_type !=SBI_PMU_EVENT_TYPE_FW )return SBI_EINVAL ; -if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_read_value) - fw_counters_data[hartid][cidx - num_hw_ctrs] = - pmu_dev->fw_counter_read_value (cidx - num_hw_ctrs); +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; - *cval = fw_counters_data[hartid][cidx - num_hw_ctrs]; +if (SBI_PMU_FW_PLATFORM == event_code) { +if (pmu_dev && pmu_dev->fw_counter_read_value) + *cval = pmu_dev->fw_counter_read_value (cidx - + num_hw_ctrs); +else + *cval =0 ; + }else + *cval = fw_counters_data[hartid][cidx - num_hw_ctrs];return 0 ; }
@@ -367,8 +379,17 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,int ret;u32 hartid =current_hartid (); -if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_start) { +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_code) { +if (!pmu_dev || + !pmu_dev->fw_counter_start) { +return SBI_EINVAL ; + } + ret = pmu_dev->fw_counter_start (cidx - num_hw_ctrs, event_data, ival, ival_update);
@@ -386,12 +407,13 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,int sbi_pmu_ctr_start (unsigned long cbase,unsigned long cmask,unsigned long flags,uint64_t ival) { +u32 hartid =current_hartid ();int event_idx_type;uint32_t event_code;int ret =SBI_EINVAL ;bool bUpdate = false;int i, cidx; -uint64_t edata =0 ; +uint64_t edata;if ((cbase +sbi_fls (cmask)) >= total_ctrs)return ret;
@@ -405,9 +427,13 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask,if (event_idx_type <0 )/* Continue the start operation for other counters */ continue ; -else if (event_idx_type ==SBI_PMU_EVENT_TYPE_FW ) +else if (event_idx_type ==SBI_PMU_EVENT_TYPE_FW ) { + edata = (event_code ==SBI_PMU_FW_PLATFORM ) ? + fw_counters_data[hartid][cidx - num_hw_ctrs] + :0x0 ; ret =pmu_ctr_start_fw (cidx, event_code, edata, ival, bUpdate); + }else ret =pmu_ctr_start_hw (cidx, ival, bUpdate); }
@@ -441,7 +467,12 @@ static int pmu_ctr_stop_fw(uint32_t cidx, uint32_t event_code) {int ret; -if (SBI_PMU_FW_MAX <= event_code && +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_stop) { ret = pmu_dev->fw_counter_stop (cidx - num_hw_ctrs);if (ret)
@@ -651,13 +682,18 @@ static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask, {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)continue ;if (active_events[hartid][i] !=SBI_PMU_EVENT_IDX_INVALID )continue ; -if (SBI_PMU_FW_MAX <= event_code && +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_match_encoding) {if (!pmu_dev->fw_counter_match_encoding (cidx - num_hw_ctrs, edata))
@@ -702,6 +738,9 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,/* Any firmware counter can be used track any firmware event */ ctr_idx =pmu_ctr_find_fw (cidx_base, cidx_mask, event_code, hartid, event_data); +if (event_code ==SBI_PMU_FW_PLATFORM ) + fw_counters_data[hartid][ctr_idx - num_hw_ctrs] = + event_data; }else { ctr_idx =pmu_ctr_find_hw (cidx_base, cidx_mask, flags, event_idx, event_data);
@@ -721,7 +760,7 @@ skip_match:if (flags &SBI_PMU_CFG_FLAG_CLEAR_VALUE ) fw_counters_data[hartid][ctr_idx - num_hw_ctrs] =0 ;if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) { -if (SBI_PMU_FW_MAX <= event_code && +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start( ctr_idx - num_hw_ctrs, event_data,
Signature · 1 line
2.34.1
PATCH v3 6/8 lib: sbi_pmu: Use dedicated event code for platform firmware events
Quoted 75 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
For all platform specific firmware event operations use the dedicated event code (
0xFFFF) when matching against the input firmware event. Furthermore save the real platform specific firmware event code received as the event data for future use.Signed-off-by Mayuresh Chitale <[email protected]>--- lib/sbi/sbi_pmu.c | 65 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 13 deletions(-)lib/sbi/sbi_pmu.c +29
-8@@ -122,7 +122,12 @@ static int pmu_event_validate(unsigned long event_idx, uint64_t edata) event_idx_code_max =SBI_PMU_HW_GENERAL_MAX ;break ;case SBI_PMU_EVENT_TYPE_FW : -if (SBI_PMU_FW_MAX <= event_idx_code && +if ((event_idx_code >=SBI_PMU_FW_MAX && + event_idx_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_idx_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_idx_code && pmu_dev && pmu_dev->fw_event_validate_encoding)return pmu_dev->fw_event_validate_encoding (edata);else @@ -187,12 +192,19 @@ int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval)if (event_idx_type !=SBI_PMU_EVENT_TYPE_FW )return SBI_EINVAL ; -if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_read_value) - fw_counters_data[hartid][cidx - num_hw_ctrs] = - pmu_dev->fw_counter_read_value (cidx - num_hw_ctrs); +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; - *cval = fw_counters_data[hartid][cidx - num_hw_ctrs]; +if (SBI_PMU_FW_PLATFORM == event_code) { +if (pmu_dev && pmu_dev->fw_counter_read_value) + *cval = pmu_dev->fw_counter_read_value (cidx - + num_hw_ctrs); +else + *cval =0 ; + }else + *cval = fw_counters_data[hartid][cidx - num_hw_ctrs];return 0 ; }@@ -367,8 +379,17 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,int ret;u32 hartid =current_hartid (); -if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_start) { +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_code) { +if (!pmu_dev || + !pmu_dev->fw_counter_start) { +return SBI_EINVAL ; + } + ret = pmu_dev->fw_counter_start (cidx - num_hw_ctrs, event_data, ival, ival_update);
lib/sbi/sbi_pmu.c static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, · line 410
Quoted 4 lines
lib/sbi/sbi_pmu.c +1
-0@@ -386,12 +407,13 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,int sbi_pmu_ctr_start (unsigned long cbase,unsigned long cmask,unsigned long flags,uint64_t ival) { +u32 hartid =current_hartid ();
This is an unrelated change. Probably belongs to a different patch.
Quoted 82 lines
lib/sbi/sbi_pmu.c +22
-6int event_idx_type;uint32_t event_code;int ret =SBI_EINVAL ;bool bUpdate = false;int i, cidx; -uint64_t edata =0 ; +uint64_t edata;if ((cbase +sbi_fls (cmask)) >= total_ctrs)return ret;@@ -405,9 +427,13 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask,if (event_idx_type <0 )/* Continue the start operation for other counters */ continue ; -else if (event_idx_type ==SBI_PMU_EVENT_TYPE_FW ) +else if (event_idx_type ==SBI_PMU_EVENT_TYPE_FW ) { + edata = (event_code ==SBI_PMU_FW_PLATFORM ) ? + fw_counters_data[hartid][cidx - num_hw_ctrs] + :0x0 ; ret =pmu_ctr_start_fw (cidx, event_code, edata, ival, bUpdate); + }else ret =pmu_ctr_start_hw (cidx, ival, bUpdate); }@@ -441,7 +467,12 @@ static int pmu_ctr_stop_fw(uint32_t cidx, uint32_t event_code) {int ret; -if (SBI_PMU_FW_MAX <= event_code && +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_stop) { ret = pmu_dev->fw_counter_stop (cidx - num_hw_ctrs);if (ret)@@ -651,13 +682,18 @@ static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask, {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)continue ;if (active_events[hartid][i] !=SBI_PMU_EVENT_IDX_INVALID )continue ; -if (SBI_PMU_FW_MAX <= event_code && +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_match_encoding) {if (!pmu_dev->fw_counter_match_encoding (cidx - num_hw_ctrs, edata))@@ -702,6 +738,9 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,/* Any firmware counter can be used track any firmware event */ ctr_idx =pmu_ctr_find_fw (cidx_base, cidx_mask, event_code, hartid, event_data); +if (event_code ==SBI_PMU_FW_PLATFORM ) + fw_counters_data[hartid][ctr_idx - num_hw_ctrs] = + event_data; }else { ctr_idx =pmu_ctr_find_hw (cidx_base, cidx_mask, flags, event_idx, event_data);@@ -721,7 +760,7 @@ skip_match:if (flags &SBI_PMU_CFG_FLAG_CLEAR_VALUE ) fw_counters_data[hartid][ctr_idx - num_hw_ctrs] =0 ;if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) { -if (SBI_PMU_FW_MAX <= event_code && +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start( ctr_idx - num_hw_ctrs, event_data, --2.34.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Otherwise, it looks good to me.
Regards,
Anup
PATCH v3 6/8 lib: sbi_pmu: Use dedicated event code for platform firmware events
Quoted 86 lines · Anup Patel
Quoted 84 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
For all platform specific firmware event operations use the dedicated
event code (0xFFFF) when matching against the input firmware event. Furthermore save the real platform specific firmware event code received as
the event data for future use.Signed-off-by Mayuresh Chitale <[email protected]>--- lib/sbi/sbi_pmu.c | 65 +++++++++++++++++++++++++++++++++++++---- ------ 1 file changed, 52 insertions(+), 13 deletions(-)lib/sbi/sbi_pmu.c +6
-1@@ -122,7 +122,12 @@ static int pmu_event_validate(unsigned long event_idx, uint64_t edata) event_idx_code_max =SBI_PMU_HW_GENERAL_MAX ;break ;case SBI_PMU_EVENT_TYPE_FW : -if (SBI_PMU_FW_MAX <= event_idx_code && +if ((event_idx_code >=SBI_PMU_FW_MAX && + event_idx_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_idx_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_idx_code && pmu_dev && pmu_dev->fw_event_validate_encoding) return pmu_dev-Quoted 1 line
fw_event_validate_encoding(edata);else
lib/sbi/sbi_pmu.c +8
-6@@ -187,12 +192,19 @@ int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval)if (event_idx_type !=SBI_PMU_EVENT_TYPE_FW )return SBI_EINVAL ; -if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_read_value) - fw_counters_data[hartid][cidx - num_hw_ctrs] = - pmu_dev->fw_counter_read_value (cidx - num_hw_ctrs); +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; - *cval = fw_counters_data[hartid][cidx - num_hw_ctrs]; + if (SBI_PMU_FW_PLATFORM == event_code) { + if (pmu_dev && pmu_dev->fw_counter_read_value) + *cval = pmu_dev->fw_counter_read_value(cidx - + num_
hw_ctrs);lib/sbi/sbi_pmu.c +4
-0+else + *cval =0 ; + }else + *cval = fw_counters_data[hartid][cidx -
num_hw_ctrs];return 0;}
lib/sbi/sbi_pmu.c +11
-2@@ -367,8 +379,17 @@ static int pmu_ctr_start_fw(uint32_t cidx,uint32_t event_code, int ret;u32 hartid =current_hartid (); -if (SBI_PMU_FW_MAX <= event_code && - pmu_dev && pmu_dev->fw_counter_start) { +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_code) { +if (!pmu_dev || + !pmu_dev->fw_counter_start) { +return SBI_EINVAL ; + } + ret = pmu_dev->fw_counter_start(cidx - num_hw_ctrs, event_data,ival, ival_update);
Quoted 8 lines
lib/sbi/sbi_pmu.c static int pmu_ctr_start_fw(uint32_t cidx, · line 411
Quoted 6 lines
lib/sbi/sbi_pmu.c +1
-0@@ -386,12 +407,13 @@ static int pmu_ctr_start_fw(uint32_t cidx,uint32_t event_code, int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask, unsigned long flags, uint64_t ival) { + u32 hartid = current_hartid();This is an unrelated change. Probably belongs to a different patch.
When comparing with the platform fw event code we need the hartid to get the event data that was saved for that hart and counter index.
Quoted 114 lines
Quoted 103 lines
lib/sbi/sbi_pmu.c +1
-1int event_idx_type;uint32_t event_code;int ret =SBI_EINVAL ;bool bUpdate = false;int i, cidx; -uint64_t edata =0 ; +uint64_t edata;if ((cbase +sbi_fls (cmask)) >= total_ctrs)return ret;lib/sbi/sbi_pmu.c +0
-0@@ -405,9 +427,13 @@ int sbi_pmu_ctr_start(unsigned long cbase,unsigned long cmask, if (event_idx_type < 0)/* Continue the start operation for other counters */
continue;lib/sbi/sbi_pmu.c +2
-1-else if (event_idx_type ==SBI_PMU_EVENT_TYPE_FW ) +else if (event_idx_type ==SBI_PMU_EVENT_TYPE_FW ) { + edata = (event_code ==SBI_PMU_FW_PLATFORM )?
+ fw_counters_data[hartid][cidx -num_hw_ctrs]
+ :0x0;
ret = pmu_ctr_start_fw(cidx,event_code,
edata, ival,bUpdate); + } else ret = pmu_ctr_start_hw(cidx, ival, bUpdate); }lib/sbi/sbi_pmu.c +6
-1@@ -441,7 +467,12 @@ static int pmu_ctr_stop_fw(uint32_t cidx, uint32_t event_code) {int ret; -if (SBI_PMU_FW_MAX <= event_code && +if ((event_code >=SBI_PMU_FW_MAX && + event_code <=SBI_PMU_FW_RESERVED_MAX ) || + event_code >SBI_PMU_FW_PLATFORM ) +return SBI_EINVAL ; + +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_stop) { ret = pmu_dev->fw_counter_stop (cidx - num_hw_ctrs);if (ret)
lib/sbi/sbi_pmu.c +6
-1@@ -651,13 +682,18 @@ static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask, { 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)continue ;if (active_events[hartid][i] !=SBI_PMU_EVENT_IDX_INVALID )continue ; -if (SBI_PMU_FW_MAX <= event_code && +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_match_encoding){ if (!pmu_dev-Quoted 1 line
fw_counter_match_encoding(cidx -
num_hw_ctrs,eda
ta))lib/sbi/sbi_pmu.c +0
-0@@ -702,6 +738,9 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,/* Any firmware counter can be used track any firmware event */
ctr_idx= pmu_ctr_find_fw(cidx_base,cidx_mask,event_code,hartid, event_data);lib/sbi/sbi_pmu.c +2
-0+if (event_code ==SBI_PMU_FW_PLATFORM ) + fw_counters_data[hartid][ctr_idx -
num_hw_ctrs] =
+ event_data;
} else {
ctr_idx= pmu_ctr_find_hw(cidx_base,cidx_mask,
flags,event_idx,event_data);lib/sbi/sbi_pmu.c +1
-1@@ -721,7 +760,7 @@ skip_match:if (flags &SBI_PMU_CFG_FLAG_CLEAR_VALUE ) fw_counters_data[hartid][ctr_idx - num_hw_ctrs] =0 ;if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) { -if (SBI_PMU_FW_MAX <= event_code && +if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_start) { ret = pmu_dev->fw_counter_start(
ctr_idx-num_hw_ctrs,event_data,
--
2.34.1Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbiOtherwise, it looks good to me.
Reviewed-by Anup Patel <[email protected]>Regards,
Anup
PATCH v3 7/8 lib: sbi_pmu: Introduce fw_counter_write_value API
In reply to Mayuresh ChitaleAdd fw_counter_write_value API for platform specific firmware events which separates setting the counter's initial value from starting the counter. This is required so that the fw_event_data array can be reused to save the event data received.
--- include/sbi/sbi_pmu.h | 11 ++++++++--- lib/sbi/sbi_pmu.c | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-)
include/sbi/sbi_pmu.h +8 -3
@@ -51,14 +51,19 @@ struct sbi_pmu_device {*/ uint64_t (*fw_counter_read_value)(uint32_t counter_index); +/** +* Write value to custom firmware counter +* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX +*/ +void (*fw_counter_write_value)(uint32_t counter_index, +uint64_t value); +/** * Start custom firmware counter -* Note: SBI_PMU_FW_MAX <= event_idx_code * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ int (*fw_counter_start)(uint32_t counter_index, -uint64_t event_data, -uint64_t init_val,bool init_val_update); +uint64_t event_data);/** * Stop custom firmware counter
lib/sbi/sbi_pmu.c +13 -12
@@ -376,7 +376,6 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, uint64_t event_data, uint64_t ival, bool ival_update) { - int ret; u32 hartid = current_hartid(); if ((event_code >= SBI_PMU_FW_MAX &&
@@ -386,19 +385,22 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,if (SBI_PMU_FW_PLATFORM == event_code) {if (!pmu_dev || + !pmu_dev->fw_counter_write_value || !pmu_dev->fw_counter_start) {return SBI_EINVAL ; } - ret = pmu_dev->fw_counter_start (cidx - num_hw_ctrs, - event_data, - ival, ival_update); -if (ret) -return ret; +if (ival_update) + pmu_dev->fw_counter_write_value (cidx - num_hw_ctrs, + ival); + +return pmu_dev->fw_counter_start (cidx - num_hw_ctrs, + event_data); + }else { +if (ival_update) + fw_counters_data[hartid][cidx - num_hw_ctrs] = ival; } -if (ival_update) - fw_counters_data[hartid][cidx - num_hw_ctrs] = ival; fw_counters_started[hartid] |=BIT (cidx - num_hw_ctrs);return 0 ;
@@ -762,10 +764,9 @@ skip_match:if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) {if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_start) { - ret = pmu_dev->fw_counter_start ( - ctr_idx - num_hw_ctrs, event_data, - fw_counters_data[hartid][ctr_idx - num_hw_ctrs], - true); + ret = pmu_dev->fw_counter_start (ctr_idx - + num_hw_ctrs, + event_data);if (ret)return ret; }
Signature · 1 line
2.34.1
PATCH v3 7/8 lib: sbi_pmu: Introduce fw_counter_write_value API
Quoted 7 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
Add
fw_counter_write_valueAPI for platform specific firmware events which separates setting the counter's initial value from starting the counter. This is required so that thefw_event_dataarray can be reused to save the event data received.Signed-off-by Mayuresh Chitale <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 96 lines
--- include/sbi/sbi_pmu.h | 11 ++++++++--- lib/sbi/sbi_pmu.c | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-)include/sbi/sbi_pmu.h +8
-3@@ -51,14 +51,19 @@ struct sbi_pmu_device {*/ uint64_t (*fw_counter_read_value)(uint32_t counter_index); +/** +* Write value to custom firmware counter +* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX +*/ +void (*fw_counter_write_value)(uint32_t counter_index, +uint64_t value); +/** * Start custom firmware counter -* Note: SBI_PMU_FW_MAX <= event_idx_code * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ int (*fw_counter_start)(uint32_t counter_index, -uint64_t event_data, -uint64_t init_val,bool init_val_update); +uint64_t event_data);/** * Stop custom firmware counter lib/sbi/sbi_pmu.c +13
-13@@ -376,7 +376,6 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, uint64_t event_data, uint64_t ival, bool ival_update) { - int ret; u32 hartid = current_hartid(); if ((event_code >= SBI_PMU_FW_MAX &&@@ -386,19 +385,22 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,if (SBI_PMU_FW_PLATFORM == event_code) {if (!pmu_dev || + !pmu_dev->fw_counter_write_value || !pmu_dev->fw_counter_start) {return SBI_EINVAL ; } - ret = pmu_dev->fw_counter_start (cidx - num_hw_ctrs, - event_data, - ival, ival_update); -if (ret) -return ret; +if (ival_update) + pmu_dev->fw_counter_write_value (cidx - num_hw_ctrs, + ival); + +return pmu_dev->fw_counter_start (cidx - num_hw_ctrs, + event_data); + }else { +if (ival_update) + fw_counters_data[hartid][cidx - num_hw_ctrs] = ival; } -if (ival_update) - fw_counters_data[hartid][cidx - num_hw_ctrs] = ival; fw_counters_started[hartid] |=BIT (cidx - num_hw_ctrs);return 0 ;@@ -762,10 +764,9 @@ skip_match:if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) {if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_start) { - ret = pmu_dev->fw_counter_start ( - ctr_idx - num_hw_ctrs, event_data, - fw_counters_data[hartid][ctr_idx - num_hw_ctrs], - true); + ret = pmu_dev->fw_counter_start (ctr_idx - + num_hw_ctrs, + event_data);if (ret)return ret; } --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v3 8/8 lib: sbi_pmu: Add hartid parameter PMU device ops
In reply to Mayuresh ChitalePlatform specific firmware event handler may leverage the hartid to program per hart specific registers for a given counter.
--- include/sbi/sbi_pmu.h | 14 ++++++++------ lib/sbi/sbi_pmu.c | 25 +++++++++++++++---------- 2 files changed, 23 insertions(+), 16 deletions(-)
include/sbi/sbi_pmu.h +8 -6
@@ -31,13 +31,14 @@ struct sbi_pmu_device {/** * Validate event code of custom firmware event */ -int (*fw_event_validate_encoding)(uint64_t event_data); +int (*fw_event_validate_encoding)(uint32_t hartid,uint64_t event_data);/** * Match custom firmware counter with custom firmware event * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -bool (*fw_counter_match_encoding)(uint32_t counter_index, +bool (*fw_counter_match_encoding)(uint32_t hartid, +uint32_t counter_index,uint64_t event_data);/**
@@ -49,27 +50,28 @@ struct sbi_pmu_device {* Read value of custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -uint64_t (*fw_counter_read_value)(uint32_t counter_index); +uint64_t (*fw_counter_read_value)(uint32_t hartid, +uint32_t counter_index);/** * Write value to custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -void (*fw_counter_write_value)(uint32_t counter_index, +void (*fw_counter_write_value)(uint32_t hartid,uint32_t counter_index,uint64_t value);/** * Start custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -int (*fw_counter_start)(uint32_t counter_index, +int (*fw_counter_start)(uint32_t hartid,uint32_t counter_index,uint64_t event_data);/** * Stop custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -int (*fw_counter_stop)(uint32_t counter_index); +int (*fw_counter_stop)(uint32_t hartid,uint32_t counter_index);/** * Custom enable irq for hardware counter
lib/sbi/sbi_pmu.c +15 -10
@@ -116,6 +116,7 @@ static int pmu_event_validate(unsigned long event_idx, uint64_t edata)uint32_t event_idx_code =get_cidx_code (event_idx);uint32_t event_idx_code_max =-1 ;uint32_t cache_ops_result, cache_ops_id, cache_id; +u32 hartid =current_hartid ();switch (event_idx_type) {case SBI_PMU_EVENT_TYPE_HW :
@@ -129,7 +130,8 @@ static int pmu_event_validate(unsigned long event_idx, uint64_t edata)if (SBI_PMU_FW_PLATFORM == event_idx_code && pmu_dev && pmu_dev->fw_event_validate_encoding) -return pmu_dev->fw_event_validate_encoding (edata); +return pmu_dev->fw_event_validate_encoding (hartid, + edata);else event_idx_code_max =SBI_PMU_FW_MAX ;break ;
@@ -199,7 +201,8 @@ int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval)if (SBI_PMU_FW_PLATFORM == event_code) {if (pmu_dev && pmu_dev->fw_counter_read_value) - *cval = pmu_dev->fw_counter_read_value (cidx - + *cval = pmu_dev->fw_counter_read_value (hartid, + cidx - num_hw_ctrs);else *cval =0 ;
@@ -391,10 +394,11 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, }if (ival_update) - pmu_dev->fw_counter_write_value (cidx - num_hw_ctrs, + pmu_dev->fw_counter_write_value (hartid, + cidx - num_hw_ctrs, ival); -return pmu_dev->fw_counter_start (cidx - num_hw_ctrs, +return pmu_dev->fw_counter_start (hartid, cidx - num_hw_ctrs, event_data); }else {if (ival_update)
@@ -467,6 +471,7 @@ static int pmu_ctr_stop_hw(uint32_t cidx)static int pmu_ctr_stop_fw (uint32_t cidx,uint32_t event_code) { +u32 hartid =current_hartid ();int ret; if ((event_code >= SBI_PMU_FW_MAX &&
@@ -476,7 +481,7 @@ static int pmu_ctr_stop_fw(uint32_t cidx, uint32_t event_code)if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_stop) { - ret = pmu_dev->fw_counter_stop (cidx - num_hw_ctrs); + ret = pmu_dev->fw_counter_stop (hartid, cidx - num_hw_ctrs);if (ret)return ret; }
@@ -697,8 +702,9 @@ static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask,continue ;if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_match_encoding) { -if (!pmu_dev->fw_counter_match_encoding (cidx - num_hw_ctrs, - edata)) +if (!pmu_dev->fw_counter_match_encoding (hartid, + cidx - num_hw_ctrs, + edata))continue ; }
@@ -764,9 +770,8 @@ skip_match:if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) {if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_start) { - ret = pmu_dev->fw_counter_start (ctr_idx - - num_hw_ctrs, - event_data); + ret = pmu_dev->fw_counter_start (hartid, + ctr_idx - num_hw_ctrs, event_data);if (ret)return ret; }
Signature · 1 line
2.34.1
PATCH v3 8/8 lib: sbi_pmu: Add hartid parameter PMU device ops
Quoted 6 lines · On Thu, Mar 9, 2023 at 11:21?AM Mayuresh Chitale <[email protected]>…
Platform specific firmware event handler may leverage the hartid to program per hart specific registers for a given counter.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Atish Patra <[email protected]>
Looks good to me.
Regards,
Anup
Quoted 154 lines
--- include/sbi/sbi_pmu.h | 14 ++++++++------ lib/sbi/sbi_pmu.c | 25 +++++++++++++++---------- 2 files changed, 23 insertions(+), 16 deletions(-)include/sbi/sbi_pmu.h +8
-6@@ -31,13 +31,14 @@ struct sbi_pmu_device {/** * Validate event code of custom firmware event */ -int (*fw_event_validate_encoding)(uint64_t event_data); +int (*fw_event_validate_encoding)(uint32_t hartid,uint64_t event_data);/** * Match custom firmware counter with custom firmware event * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -bool (*fw_counter_match_encoding)(uint32_t counter_index, +bool (*fw_counter_match_encoding)(uint32_t hartid, +uint32_t counter_index,uint64_t event_data);/** @@ -49,27 +50,28 @@ struct sbi_pmu_device {* Read value of custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -uint64_t (*fw_counter_read_value)(uint32_t counter_index); +uint64_t (*fw_counter_read_value)(uint32_t hartid, +uint32_t counter_index);/** * Write value to custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -void (*fw_counter_write_value)(uint32_t counter_index, +void (*fw_counter_write_value)(uint32_t hartid,uint32_t counter_index,uint64_t value);/** * Start custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -int (*fw_counter_start)(uint32_t counter_index, +int (*fw_counter_start)(uint32_t hartid,uint32_t counter_index,uint64_t event_data);/** * Stop custom firmware counter * Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX */ -int (*fw_counter_stop)(uint32_t counter_index); +int (*fw_counter_stop)(uint32_t hartid,uint32_t counter_index);/** * Custom enable irq for hardware counter lib/sbi/sbi_pmu.c +15
-11@@ -116,6 +116,7 @@ static int pmu_event_validate(unsigned long event_idx, uint64_t edata)uint32_t event_idx_code =get_cidx_code (event_idx);uint32_t event_idx_code_max =-1 ;uint32_t cache_ops_result, cache_ops_id, cache_id; +u32 hartid =current_hartid ();switch (event_idx_type) {case SBI_PMU_EVENT_TYPE_HW :@@ -129,7 +130,8 @@ static int pmu_event_validate(unsigned long event_idx, uint64_t edata)if (SBI_PMU_FW_PLATFORM == event_idx_code && pmu_dev && pmu_dev->fw_event_validate_encoding) -return pmu_dev->fw_event_validate_encoding (edata); +return pmu_dev->fw_event_validate_encoding (hartid, + edata);else event_idx_code_max =SBI_PMU_FW_MAX ;break ;@@ -199,7 +201,8 @@ int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval)if (SBI_PMU_FW_PLATFORM == event_code) {if (pmu_dev && pmu_dev->fw_counter_read_value) - *cval = pmu_dev->fw_counter_read_value (cidx - + *cval = pmu_dev->fw_counter_read_value (hartid, + cidx - num_hw_ctrs);else *cval =0 ;@@ -391,10 +394,11 @@ static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code, }if (ival_update) - pmu_dev->fw_counter_write_value (cidx - num_hw_ctrs, + pmu_dev->fw_counter_write_value (hartid, + cidx - num_hw_ctrs, ival); -return pmu_dev->fw_counter_start (cidx - num_hw_ctrs, +return pmu_dev->fw_counter_start (hartid, cidx - num_hw_ctrs, event_data); }else {if (ival_update)@@ -467,6 +471,7 @@ static int pmu_ctr_stop_hw(uint32_t cidx)static int pmu_ctr_stop_fw (uint32_t cidx,uint32_t event_code) { +u32 hartid =current_hartid ();int ret; if ((event_code >= SBI_PMU_FW_MAX &&@@ -476,7 +481,7 @@ static int pmu_ctr_stop_fw(uint32_t cidx, uint32_t event_code)if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_stop) { - ret = pmu_dev->fw_counter_stop (cidx - num_hw_ctrs); + ret = pmu_dev->fw_counter_stop (hartid, cidx - num_hw_ctrs);if (ret)return ret; }@@ -697,8 +702,9 @@ static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask,continue ;if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_match_encoding) { -if (!pmu_dev->fw_counter_match_encoding (cidx - num_hw_ctrs, - edata)) +if (!pmu_dev->fw_counter_match_encoding (hartid, + cidx - num_hw_ctrs, + edata))continue ; }@@ -764,9 +770,8 @@ skip_match:if (flags &SBI_PMU_CFG_FLAG_AUTO_START ) {if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_start) { - ret = pmu_dev->fw_counter_start (ctr_idx - - num_hw_ctrs, - event_data); + ret = pmu_dev->fw_counter_start (hartid, + ctr_idx - num_hw_ctrs, event_data);if (ret)return ret; } --2.34.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi