Hi,
(old patch merged as b2d7a7c7e4e30fb5341d38deac968de675f9419c)
On 18/7/24 04:10, Alistair Francis wrote:
From: Atish Patra <ati...@rivosinc.com>
Privilege mode filtering can also be emulated for cycle/instret by
tracking host_ticks/icount during each privilege mode switch. This
patch implements that for both cycle/instret and mhpmcounters. The
first one requires Smcntrpmf while the other one requires Sscofpmf
to be enabled.
The cycle/instret are still computed using host ticks when icount
is not enabled. Otherwise, they are computed using raw icount which
is more accurate in icount mode.
Co-Developed-by: Rajnesh Kanwal <rkan...@rivosinc.com>
Signed-off-by: Rajnesh Kanwal <rkan...@rivosinc.com>
Reviewed-by: Daniel Henrique Barboza <dbarb...@ventanamicro.com>
Acked-by: Alistair Francis <alistair.fran...@wdc.com>
Signed-off-by: Atish Patra <ati...@rivosinc.com>
Message-ID: <20240711-smcntrpmf_v7-v8-7-b7c38ae7b...@rivosinc.com>
Signed-off-by: Alistair Francis <alistair.fran...@wdc.com>
---
target/riscv/cpu.h | 11 ++++
target/riscv/pmu.h | 2 +
target/riscv/cpu_helper.c | 9 ++-
target/riscv/csr.c | 117 ++++++++++++++++++++++++++------------
target/riscv/pmu.c | 92 ++++++++++++++++++++++++++++++
5 files changed, 194 insertions(+), 37 deletions(-)
+#if defined(CONFIG_USER_ONLY)
/* User Timers and Counters */
-static target_ulong get_ticks(bool shift, bool instructions)
+static target_ulong get_ticks(bool shift)
{
- int64_t val;
- target_ulong result;
-
-#if !defined(CONFIG_USER_ONLY)
- if (icount_enabled()) {
- if (instructions) {
- val = icount_get_raw();
- } else {
- val = icount_get();
- }
- } else {
- val = cpu_get_host_ticks();
- }
I see this comes from old commit c7b95171881 ("RISC-V: Implement
modular CSR helper interface"), ...
-#else
- val = cpu_get_host_ticks();
-#endif
-
- if (shift) {
- result = val >> 32;
- } else {
- result = val;
- }
+ int64_t val = cpu_get_host_ticks();
+ target_ulong result = shift ? val >> 32 : val;
return result;
}
+{
+ uint64_t *snapshot_prev, *snapshot_new;
+ uint64_t current_ticks;
+ uint64_t *counter_arr;
+ uint64_t delta;
+
+ if (icount_enabled()) {
+ current_ticks = icount_get();
+ } else {
+ current_ticks = cpu_get_host_ticks();
+ }
... but still I wonder, why not use cpus_get_elapsed_ticks()?
Regards,
Phil.