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

-- 
2.51.0


Reply via email to