Skip to contentSkip to conversation

lib: sbi_pmu: Track SBI_PMU_FW_PLATFORM started counter

PATCH In review Charlie Jenkins 3 participants 4 messages Jan 27 – Feb 26

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi_pmu: Track SBI_PMU_FW_PLATFORM started counter

When a SBI_PMU_FW_PLATFORM starts, add the counter to the counter array instead of returning early. This will cause fw_counter_stop() to be called when a SBI_PMU_FW_PLATFORM counter should be stopped.

---
 lib/sbi/sbi_pmu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
lib/sbi/sbi_pmu.c +6 -4
index e084005d..3c61079b 100644
@@ -448,6 +448,8 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
 			    uint64_t event_data, uint64_t ival,
 			    bool ival_update)
 {
+	int rc = 0;
+
 	if ((event_code >= SBI_PMU_FW_MAX &&
 	    event_code <= SBI_PMU_FW_RESERVED_MAX) ||
 	    event_code > SBI_PMU_FW_PLATFORM)
@@ -468,9 +470,9 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
 							cidx - num_hw_ctrs,
 							ival);
 
-		return pmu_dev->fw_counter_start(phs->hartid,
-						 cidx - num_hw_ctrs,
-						 event_data);
+		rc = pmu_dev->fw_counter_start(phs->hartid,
+					       cidx - num_hw_ctrs,
+					       event_data);
 	} else {
 		if (ival_update)
 			phs->fw_counters_data[cidx - num_hw_ctrs] = ival;
@@ -478,7 +480,7 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
 
 	phs->fw_counters_started |= BIT(cidx - num_hw_ctrs);
 
-	return 0;
+	return rc;
 }
 
 static void pmu_update_inhibit_flags(unsigned long flags, uint64_t *mhpmevent_val)

---
base-commit: 74434f255873d74e56cc50aa762d1caf24c099f8
change-id: 20260127-pmu_platform_stop-febef65abf54

- Charlie

Reviewed-by on v1 1/1
#1 lore raw
Quoted 39 lines · On 1/27/26 3:58 PM, Charlie Jenkins via B4 Relay wrote:

From: Charlie Jenkins <[email protected]>

When a SBI_PMU_FW_PLATFORM starts, add the counter to the counter array instead of returning early. This will cause fw_counter_stop() to be called when a SBI_PMU_FW_PLATFORM counter should be stopped.

---
  lib/sbi/sbi_pmu.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
lib/sbi/sbi_pmu.c +5 -3
index e084005d..3c61079b 100644
@@ -448,6 +448,8 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
  			    uint64_t event_data, uint64_t ival,
  			    bool ival_update)
  {
+	int rc = 0;
+
  	if ((event_code >= SBI_PMU_FW_MAX &&
  	    event_code <= SBI_PMU_FW_RESERVED_MAX) ||
  	    event_code > SBI_PMU_FW_PLATFORM)
@@ -468,9 +470,9 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
  							cidx - num_hw_ctrs,
  							ival);
 
-		return pmu_dev->fw_counter_start(phs->hartid,
-						 cidx - num_hw_ctrs,
-						 event_data);
+		rc = pmu_dev->fw_counter_start(phs->hartid,
+					       cidx - num_hw_ctrs,
+					       event_data);
  	} else {
  		if (ival_update)
  			phs->fw_counters_data[cidx - num_hw_ctrs] = ival;

lib/sbi/sbi_pmu.c static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs, · line 486

Quoted 8 lines
lib/sbi/sbi_pmu.c +1 -1
@@ -478,7 +480,7 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
 
  	phs->fw_counters_started |= BIT(cidx - num_hw_ctrs);
 
-	return 0;
+	return rc;
  }
 
  static void pmu_update_inhibit_flags(unsigned long flags, uint64_t *mhpmevent_val)
Quoted 8 lines

---
base-commit: 74434f255873d74e56cc50aa762d1caf24c099f8
change-id: 20260127-pmu_platform_stop-febef65abf54

- Charlie

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#2 lore raw
In reply to Charlie Jenkins
Quoted 8 lines · On Wed, Jan 28, 2026 at 5:28 AM Charlie Jenkins via B4 Relay…

From: Charlie Jenkins <[email protected]>

When a SBI_PMU_FW_PLATFORM starts, add the counter to the counter array instead of returning early. This will cause fw_counter_stop() to be called when a SBI_PMU_FW_PLATFORM counter should be stopped.

This is already covered by the following patch:
"lib: sbi_pmu: Fix multiple FW counter start operations with custom PMU device"

Regards,
Anup

Quoted 52 lines
---
 lib/sbi/sbi_pmu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
lib/sbi/sbi_pmu.c +6 -5
index e084005d..3c61079b 100644
@@ -448,6 +448,8 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
                            uint64_t event_data, uint64_t ival,
                            bool ival_update)
 {
+       int rc = 0;
+
        if ((event_code >= SBI_PMU_FW_MAX &&
            event_code <= SBI_PMU_FW_RESERVED_MAX) ||
            event_code > SBI_PMU_FW_PLATFORM)
@@ -468,9 +470,9 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
                                                        cidx - num_hw_ctrs,
                                                        ival);
 
-               return pmu_dev->fw_counter_start(phs->hartid,
-                                                cidx - num_hw_ctrs,
-                                                event_data);
+               rc = pmu_dev->fw_counter_start(phs->hartid,
+                                              cidx - num_hw_ctrs,
+                                              event_data);
        } else {
                if (ival_update)
                        phs->fw_counters_data[cidx - num_hw_ctrs] = ival;
@@ -478,7 +480,7 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
 
        phs->fw_counters_started |= BIT(cidx - num_hw_ctrs);
 
-       return 0;
+       return rc;
 }
 
 static void pmu_update_inhibit_flags(unsigned long flags, uint64_t *mhpmevent_val)
 
---

base-commit: 74434f255873d74e56cc50aa762d1caf24c099f8
change-id: 20260127-pmu_platform_stop-febef65abf54

- Charlie

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

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#3 lore raw
Quoted 9 lines · Anup Patel
Quoted 7 lines · On Wed, Jan 28, 2026 at 5:28 AM Charlie Jenkins via B4 Relay…

From: Charlie Jenkins <[email protected]>

When a SBI_PMU_FW_PLATFORM starts, add the counter to the counter array instead of returning early. This will cause fw_counter_stop() to be called when a SBI_PMU_FW_PLATFORM counter should be stopped.

Quoted 7 lines
Quoted 1 line

This is already covered by the following patch:
"lib: sbi_pmu: Fix multiple FW counter start operations with custom PMU device"

Regards,
Anup

Great, thanks for applying that one!

- Charlie

Quoted 58 lines
Quoted 53 lines
---
 lib/sbi/sbi_pmu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
lib/sbi/sbi_pmu.c +6 -5
index e084005d..3c61079b 100644
@@ -448,6 +448,8 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
                            uint64_t event_data, uint64_t ival,
                            bool ival_update)
 {
+       int rc = 0;
+
        if ((event_code >= SBI_PMU_FW_MAX &&
            event_code <= SBI_PMU_FW_RESERVED_MAX) ||
            event_code > SBI_PMU_FW_PLATFORM)
@@ -468,9 +470,9 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
                                                        cidx - num_hw_ctrs,
                                                        ival);
 
-               return pmu_dev->fw_counter_start(phs->hartid,
-                                                cidx - num_hw_ctrs,
-                                                event_data);
+               rc = pmu_dev->fw_counter_start(phs->hartid,
+                                              cidx - num_hw_ctrs,
+                                              event_data);
        } else {
                if (ival_update)
                        phs->fw_counters_data[cidx - num_hw_ctrs] = ival;
@@ -478,7 +480,7 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs,
 
        phs->fw_counters_started |= BIT(cidx - num_hw_ctrs);
 
-       return 0;
+       return rc;
 }
 
 static void pmu_update_inhibit_flags(unsigned long flags, uint64_t *mhpmevent_val)
 
---

base-commit: 74434f255873d74e56cc50aa762d1caf24c099f8
change-id: 20260127-pmu_platform_stop-febef65abf54

- Charlie

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

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi