Skip to contentSkip to conversation

lib: sbi: Allow programmable counters to monitor cycle/instret events for Andes PMU

PATCH Applied Leo Yu-Chi Liang 3 participants 3 messages Mar 28, 2025 – Apr 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib: sbi: Allow programmable counters to monitor cycle/instret events for Andes PMU

Referencing commit 0c304b661965
("lib: sbi: Allow programmable counters to monitor cycle/instret events") to support this functionality for Andes PMU.

---
Change since v1:
- Modify the comment

---
 lib/sbi/sbi_pmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/sbi/sbi_pmu.c +4 -3
index b9e84543..575799eb 100644
@@ -719,12 +719,13 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,
 		return SBI_EINVAL;
 
 	/**
-	 * If Sscof is present try to find the programmable counter for
-	 * cycle/instret as well.
+	 * If Sscofpmf or Andes PMU is present, try to find
+	 * the programmable counter for cycle/instret as well.
 	 */
 	fixed_ctr = pmu_ctr_find_fixed_hw(event_idx);
 	if (fixed_ctr >= 0 &&
-	    !sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF))
+	    !sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF) &&
+	    !sbi_hart_has_extension(scratch, SBI_HART_EXT_XANDESPMU))
 		return pmu_fixed_ctr_update_inhibit_bits(fixed_ctr, flags);
 
 	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11)
Signature · 7 lines
2.34.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Reviewed-by on v2 1/1
#1 lore raw
Quoted 24 lines · Leo Yu-Chi Liang

Referencing commit 0c304b661965
("lib: sbi: Allow programmable counters to monitor cycle/instret events") to support this functionality for Andes PMU.

---
Change since v1:
- Modify the comment

---
  lib/sbi/sbi_pmu.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
lib/sbi/sbi_pmu.c +1 -2
index b9e84543..575799eb 100644
@@ -719,12 +719,13 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,
  		return SBI_EINVAL;
 
  	/**
-	 * If Sscof is present try to find the programmable counter for
-	 * cycle/instret as well.
+	 * If Sscofpmf or Andes PMU is present, try to find

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

Quoted 10 lines
lib/sbi/sbi_pmu.c +3 -1
+	 * the programmable counter for cycle/instret as well.
  	 */
  	fixed_ctr = pmu_ctr_find_fixed_hw(event_idx);
  	if (fixed_ctr >= 0 &&
-	    !sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF))
+	    !sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF) &&
+	    !sbi_hart_has_extension(scratch, SBI_HART_EXT_XANDESPMU))
  		return pmu_fixed_ctr_update_inhibit_bits(fixed_ctr, flags);
 
  	if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11)
Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Applied
#2 lore raw
In reply to Leo Yu-Chi Liang
Quoted 7 lines · Leo Yu-Chi Liang

Referencing commit 0c304b661965
("lib: sbi: Allow programmable counters to monitor cycle/instret events") to support this functionality for Andes PMU.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 36 lines

---
Change since v1:
- Modify the comment

---
 lib/sbi/sbi_pmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/sbi/sbi_pmu.c +4 -4
index b9e84543..575799eb 100644
@@ -719,12 +719,13 @@ static int pmu_ctr_find_hw(struct sbi_pmu_hart_state *phs,
                return SBI_EINVAL;
 
        /**
-        * If Sscof is present try to find the programmable counter for
-        * cycle/instret as well.
+        * If Sscofpmf or Andes PMU is present, try to find
+        * the programmable counter for cycle/instret as well.
         */
        fixed_ctr = pmu_ctr_find_fixed_hw(event_idx);
        if (fixed_ctr >= 0 &&
-           !sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF))
+           !sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF) &&
+           !sbi_hart_has_extension(scratch, SBI_HART_EXT_XANDESPMU))
                return pmu_fixed_ctr_update_inhibit_bits(fixed_ctr, flags);
 
        if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11)
--

2.34.1

--
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