Skip to content

Commit a091fe6

Browse files
committed
KVM: x86: Grab lapic_timer in a local variable to cleanup periodic code
Stash apic->lapic_timer in a local "ktimer" variable in advance_periodic_target_expiration() to eliminate a few unaligned wraps, and to make the code easier to read overall. No functional change intended. Link: https://patch.msgid.link/20251113205114.1647493-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 18ab3fc commit a091fe6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

arch/x86/kvm/lapic.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,7 @@ static bool set_target_expiration(struct kvm_lapic *apic, u32 count_reg)
21262126

21272127
static void advance_periodic_target_expiration(struct kvm_lapic *apic)
21282128
{
2129+
struct kvm_timer *ktimer = &apic->lapic_timer;
21292130
ktime_t now = ktime_get();
21302131
u64 tscl = rdtsc();
21312132
ktime_t delta;
@@ -2137,9 +2138,8 @@ static void advance_periodic_target_expiration(struct kvm_lapic *apic)
21372138
* over time as differences in the periods accumulate, e.g. due to
21382139
* differences in the underlying clocks or numerical approximation errors.
21392140
*/
2140-
apic->lapic_timer.target_expiration =
2141-
ktime_add_ns(apic->lapic_timer.target_expiration,
2142-
apic->lapic_timer.period);
2141+
ktimer->target_expiration = ktime_add_ns(ktimer->target_expiration,
2142+
ktimer->period);
21432143

21442144
/*
21452145
* If the new expiration is in the past, e.g. because userspace stopped
@@ -2150,17 +2150,17 @@ static void advance_periodic_target_expiration(struct kvm_lapic *apic)
21502150
* past will do nothing more than waste host cycles, and can even lead
21512151
* to a hard lockup in extreme cases.
21522152
*/
2153-
if (ktime_before(apic->lapic_timer.target_expiration, now))
2154-
apic->lapic_timer.target_expiration = now;
2153+
if (ktime_before(ktimer->target_expiration, now))
2154+
ktimer->target_expiration = now;
21552155

21562156
/*
21572157
* Note, ensuring the expiration isn't in the past also prevents delta
21582158
* from going negative, which could cause the TSC deadline to become
21592159
* excessively large due to it an unsigned value.
21602160
*/
2161-
delta = ktime_sub(apic->lapic_timer.target_expiration, now);
2162-
apic->lapic_timer.tscdeadline = kvm_read_l1_tsc(apic->vcpu, tscl) +
2163-
nsec_to_cycles(apic->vcpu, delta);
2161+
delta = ktime_sub(ktimer->target_expiration, now);
2162+
ktimer->tscdeadline = kvm_read_l1_tsc(apic->vcpu, tscl) +
2163+
nsec_to_cycles(apic->vcpu, delta);
21642164
}
21652165

21662166
static void start_sw_period(struct kvm_lapic *apic)

0 commit comments

Comments
 (0)