Skip to content

RFC More extendable PMU subsystem.

Aleksandr Sergeev qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest6 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6target/riscv: Refactor counter index calculation.target/riscv/cpu_bits.h target/riscv/csr.c target/riscv/pmu.c +1 more+73 -490 replies
2/6target/riscv: Reimplement Smcdeleg/Ssccfg via read_*, write_* methodstarget/riscv/csr.c+22 -580 replies
3/6target/riscv: Get rid of hardcoded SBI events.target/riscv/cpu.h target/riscv/cpu_helper.c target/riscv/csr.c +2 more+16 -2870 replies
4/6target/riscv: Rearrange custom hpm counter apitarget/riscv/cpu.h target/riscv/cpu_helper.c target/riscv/csr.c +3 more+431 -4050 replies
5/6target/riscv: Add PMU events implementation for `virt`hw/misc/Kconfig hw/misc/meson.build hw/misc/virt_pmu.c +6 more+248 -561 reply
6/6target/riscv/machine: Add smcntrpmf registers to VMStateDescriptiontarget/riscv/machine.c+4 -00 replies

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by.

PatchAlexei Filippov
1/6R-b
2/6R-b
3/6R-b
4/6R-b
5/6R-b
6/6R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 0/6] More extendable PMU subsystem.

Currently, the pmu implementation consists of two parts:
the first part is mcycle & minstret registers (let's call them "builtin events") and the second part is mhpmcounters.

The builtin events are supported well, including implementation of inhibiting, filtering, etc.

But the implementation of mhpmcounters has few problems:
1. Non-builtin events are vendor-specific.
The vendor, who wants to implement them (including filtering, interrupts, etc), has to write exactly the same code
as which is already written for mcycle & minstret events.
2. To implement custom events vendor must
hardcode it right inside the general methods.
So if there are two different vendors with
their own events, they would write their code
right beside each other, making the code
harder to support.
Also some collisions may occur in event indexes,
as it is a global enum.
3. SBI events hardcoded right inside the general code.
As they are not a part of RISCV specification,
it should be up to vendor to implement them or not.

To solve these problems, let's:
1. Generalize code, handling builtin events & mhpmcounters the same way. So if some vendors want to get logic of builtin events, it would take minimum affort.
2. Add special callbacks for custom events. So when vendors want custom events for their machine, they would not have to change the common code.
3. SBI events are now implemented for virt machine only as a demo of how a new pmu subsystem works.

Aleksandr Sergeev (6):
target/riscv: Refactor counter index calculation. target/riscv: Reimplement Smcdeleg/Ssccfg via read_*, write_* methods target/riscv: Get rid of hardcoded SBI events. target/riscv: Rearrange custom hpm counter api target/riscv: Add PMU events implementation for virt target/riscv/machine: Add smcntrpmf registers to VMStateDescription

 hw/misc/Kconfig            |   3 +
 hw/misc/meson.build        |   1 +
 hw/misc/virt_pmu.c         | 142 ++++++++
 hw/riscv/Kconfig           |   1 +
 hw/riscv/virt.c            |   4 +-
 include/hw/misc/virt_pmu.h |  91 +++++
 target/riscv/cpu.c         |   8 +
 target/riscv/cpu.h         |  96 +++--
 target/riscv/cpu_bits.h    |   4 +
 target/riscv/cpu_helper.c  |  34 +-
 target/riscv/csr.c         | 470 ++++++++----------------
 target/riscv/machine.c     |  11 +-
 target/riscv/pmu.c         | 708 ++++++++++++++-----------------------
 target/riscv/pmu.h         |  26 +-
 14 files changed, 769 insertions(+), 830 deletions(-)
 create mode 100644 hw/misc/virt_pmu.c
 create mode 100644 include/hw/misc/virt_pmu.h
Signature · 1 line
2.51.0