lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters
PATCH 1/1 lib: sbi: sbi_pmu: Fix multiple start and stop operations of FW counters
Currently, OpenSBI returns SBI_ERR_ALREADY_STARTED when attempting to start a HW counter that is already started and SBI_ERR_ALREADY_STOPPED when attempting to stop a HW counter that is already stopped. However, this is not yet implemented for FW counters.
Add the necessary checks to return the same error codes when attempting the same actions on FW counters.
--- lib/sbi/sbi_pmu.c | 6 ++++++ 1 file changed, 6 insertions(+)
lib/sbi/sbi_pmu.c +6 -0
@@ -468,6 +468,9 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs, cidx - num_hw_ctrs, event_data); }else { +if (phs->fw_counters_started &BIT (cidx - num_hw_ctrs)) +return SBI_EALREADY_STARTED ; +if (ival_update) phs->fw_counters_data[cidx - num_hw_ctrs] = ival; }
@@ -629,6 +632,9 @@ static int pmu_ctr_stop_fw(struct sbi_pmu_hart_state *phs,return ret; } +if (!(phs->fw_counters_started &BIT (cidx - num_hw_ctrs))) +return SBI_EALREADY_STOPPED ; + phs->fw_counters_started &= ~BIT (cidx - num_hw_ctrs);return 0 ;
Signature · 7 lines
2.43.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Quoted 19 lines · James Raphael Tiovalen
Currently, OpenSBI returns
SBI_ERR_ALREADY_STARTEDwhen attempting to start a HW counter that is already started andSBI_ERR_ALREADY_STOPPEDwhen attempting to stop a HW counter that is already stopped. However, this is not yet implemented for FW counters.Add the necessary checks to return the same error codes when attempting the same actions on FW counters.
Signed-off-by James Raphael Tiovalen <[email protected]>--- lib/sbi/sbi_pmu.c | 6 ++++++ 1 file changed, 6 insertions(+)lib/sbi/sbi_pmu.c +0
-0
lib/sbi/sbi_pmu.c static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs, · line 473
Quoted 6 lines
lib/sbi/sbi_pmu.c +3
-0@@ -468,6 +468,9 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs, cidx - num_hw_ctrs, event_data); }else { +if (phs->fw_counters_started &BIT (cidx - num_hw_ctrs)) +return SBI_EALREADY_STARTED ; +
This check should also be done for platform firmware counters hence it should be just before this if-else block.
lib/sbi/sbi_pmu.c static int pmu_ctr_stop_fw(struct sbi_pmu_hart_state *phs, · line 637
Quoted 10 lines
lib/sbi/sbi_pmu.c +3
-0if (ival_update) phs->fw_counters_data[cidx - num_hw_ctrs] = ival; }@@ -629,6 +632,9 @@ static int pmu_ctr_stop_fw(struct sbi_pmu_hart_state *phs,return ret; } +if (!(phs->fw_counters_started &BIT (cidx - num_hw_ctrs))) +return SBI_EALREADY_STOPPED ; +
As comment as above, this check should be before the previous if block.
Quoted 11 lines
lib/sbi/sbi_pmu.c +0
-1phs->fw_counters_started &= ~BIT (cidx - num_hw_ctrs);return 0 ; --2.43.0
--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
I have taken care of the above comments at the time of merging this patch.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi