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

Philippe Mathieu-Daudé posted 1 patch 3 days, 6 hours ago
target/arm/cpregs-pmu.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] target/arm: Include the overflowing event in PMU timer delays
Posted by Philippe Mathieu-Daudé 3 days, 6 hours ago
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")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
 target/arm/cpregs-pmu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/target/arm/cpregs-pmu.c b/target/arm/cpregs-pmu.c
index 46df6597b1ab..9e27c38f855f 100644
--- a/target/arm/cpregs-pmu.c
+++ b/target/arm/cpregs-pmu.c
@@ -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
 
-- 
2.55.0