target/riscv: Make hpmcounterh return the upper 32-bits
PATCH v2 1/1 target/riscv: Make hpmcounterh return the upper 32-bits
From: Portia Stephens <[email protected]>
The counter value was not being bitshifted for a hpmcounterh read resulting in hpmcounterh returning the bottom 32-bits.
Fixes cfc96df65e01 ("target/riscv: Remove upper_half from riscv_pmu_ctr_get_fixed_counters_val")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3498
Signed-off-by Portia Stephens <[email protected]>
Reviewed-by Alistair Francis <[email protected]>
--- target/riscv/csr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/riscv/csr.c +3 -2
@@ -1389,8 +1389,9 @@ RISCVException riscv_pmu_read_ctr(CPURISCVState *env, target_ulong *val,*/ if (riscv_pmu_ctr_monitor_cycles (env, ctr_idx) ||riscv_pmu_ctr_monitor_instructions (env, ctr_idx)) { - *val =riscv_pmu_ctr_get_fixed_counters_val (env, ctr_idx) - - ctr_prev + ctr_val; +uint64_t cntr =riscv_pmu_ctr_get_fixed_counters_val (env, ctr_idx) - + ctr_prev + ctr_val; + *val =extract64 (cntr, start, length); }else { *val = ctr_val; }
Signature · 1 line
2.43.0
Alistair Francis
AppliedQuoted 11 lines · On Tue, May 19, 2026 at 2:35 PM <[email protected]> wrote:
From: Portia Stephens <[email protected]>
The counter value was not being bitshifted for a hpmcounterh read resulting in hpmcounterh returning the bottom 32-bits.
Fixes cfc96df65e01 ("target/riscv: Remove upper_half from riscv_pmu_ctr_get_fixed_counters_val")Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3498
Signed-off-by Portia Stephens <[email protected]>Reviewed-by Alistair Francis <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 24 lines
--- target/riscv/csr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)target/riscv/csr.c +3
-3@@ -1389,8 +1389,9 @@ RISCVException riscv_pmu_read_ctr(CPURISCVState *env, target_ulong *val,*/ if (riscv_pmu_ctr_monitor_cycles (env, ctr_idx) ||riscv_pmu_ctr_monitor_instructions (env, ctr_idx)) { - *val =riscv_pmu_ctr_get_fixed_counters_val (env, ctr_idx) - - ctr_prev + ctr_val; +uint64_t cntr =riscv_pmu_ctr_get_fixed_counters_val (env, ctr_idx) - + ctr_prev + ctr_val; + *val =extract64 (cntr, start, length); }else { *val = ctr_val; } --2.43.0