lib: pmu: allow to use the highest available counter
authorSergey Matyukevich <geomatsi@gmail.com>
Fri, 24 Jun 2022 11:03:30 +0000 (14:03 +0300)
committerAnup Patel <anup@brainfault.org>
Sat, 25 Jun 2022 03:14:20 +0000 (08:44 +0530)
commit3f66465fb6bf0aea99f7dbe5801996dec9605d3c
treeaa3137ecc8adabcf1c051003a99dfe47f40ebe8c
parentc6fdbcf83fc350d8b1f12ada228e677df931291c
lib: pmu: allow to use the highest available counter

OpenSBI explicitly assumes that there is no pmu hardware counter with
index 1: hardware uses that bit for TM control. So OpenSBI filters
out that index in sanity checks. However OpenSBI also excludes that
counter when reports total amount of hardware counters to Linux. As
a result, Linux uses incomplete counters mask excluding the highest
available counter.

Return accurate number of counters, update the firmware counter
starting index, fix range checks that include num_hw_ctrs.

The simple test is to make sure that there is no counter multiplexing
in the following command:

$ perf stat -e \
r8000000000000000,r8000000000000001,r8000000000000002,r8000000000000003, \
r8000000000000004,r8000000000000005,r8000000000000006,r8000000000000007, \
r8000000000000008,r8000000000000009,r800000000000000a,r800000000000000b, \
r800000000000000c,r800000000000000d,r800000000000000e,r800000000000000f  \
ls

Note that 16 firmware events with 16 counters won't require multiplexing.

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
lib/sbi/sbi_pmu.c