KVM: arm64: timers: Use a per-vcpu, per-timer accumulator for fractional ns
authorMarc Zyngier <maz@kernel.org>
Thu, 30 Mar 2023 17:47:41 +0000 (18:47 +0100)
committerMarc Zyngier <maz@kernel.org>
Thu, 30 Mar 2023 18:01:09 +0000 (19:01 +0100)
Instead of accumulating the fractional ns value generated every time
we compute a ns delta in a global variable, use a per-vcpu, per-timer
variable. This keeps the fractional ns local to the timer instead of
contributing to any odd, unrelated timer.

Reviewed-by: Colton Lewis <coltonlewis@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230330174800.2677007-2-maz@kernel.org
arch/arm64/kvm/arch_timer.c
include/kvm/arm_arch_timer.h

index e1af430..9515c64 100644 (file)
@@ -212,7 +212,7 @@ static u64 kvm_counter_compute_delta(struct arch_timer_context *timer_ctx,
                ns = cyclecounter_cyc2ns(timecounter->cc,
                                         val - now,
                                         timecounter->mask,
-                                        &timecounter->frac);
+                                        &timer_ctx->ns_frac);
                return ns;
        }
 
index c52a6e6..70d47c4 100644 (file)
@@ -44,6 +44,7 @@ struct arch_timer_context {
 
        /* Emulated Timer (may be unused) */
        struct hrtimer                  hrtimer;
+       u64                             ns_frac;
 
        /* Offset for this counter/timer */
        struct arch_timer_offset        offset;