Skip to contentSkip to conversation

target/arm: Include the overflowing event in PMU timer delays

PATCH New Philippe Mathieu-Daudé 1 participant 1 message Nov 19

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Include the overflowing event in PMU timer delays

pmevcntr_op_finish() passes the number of events remaining minus one. When it reaches zero, the instruction event converts that to a zero delay and no timer is armed. Add the overflowing event to avoid the last event leaving the PMU interrupt pending forever.

Fixes 4e7beb0cc0f3 ("target/arm: Add a timer to predict PMU counter overflow")
---
 target/arm/cpregs-pmu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/arm/cpregs-pmu.c +6 -1
index 46df6597b1ab..9e27c38f855f 100644
@@ -106,7 +106,12 @@ static uint64_t instructions_get_count(CPUARMState *env)
 static int64_t instructions_ns_per(uint64_t icount)
 {
     assert(icount_enabled() == ICOUNT_PRECISE);
-    return icount_to_ns((int64_t)icount);
+    /*
+     * The caller passes the events left minus one, and a zero result is
+     * not armed: with a timer due exactly when the count is reached, the
+     * last event would raise no interrupt.  Wait for the overflowing one.
+     */
+    return icount_to_ns((int64_t)(icount + (icount != UINT64_MAX)));
 }
 #endif
 
Signature · 1 line
2.55.0