qemu-kvm: pc: Factor out apic_next_timer
PATCH 1/2 qemu-kvm: pc: Factor out apic_next_timer
Factor out apic_next_timer from apic_timer_update. The former can then be used to update next_timer without actually starting the qemu timer. KVM's in-kernel APIC model will make use of it.
Signed-off-by Jan Kiszka <[email protected]>
--- hw/apic.c | 45 ++++++++++++++++++++++++++++----------------- 1 files changed, 28 insertions(+), 17 deletions(-)
hw/apic.c +29 -18
@@ -661,27 +661,38 @@ static uint32_t apic_get_current_count(APICState *s)return val; } -static void apic_timer_update (APICState *s,int64_t current_time) +static bool apic_next_timer (APICState *s,int64_t current_time) { -int64_t next_time, d; - -if (!(s->lvt[APIC_LVT_TIMER ] &APIC_LVT_MASKED )) { - d = (current_time - s->initial_count_load_time) >> - s->count_shift; -if (s->lvt[APIC_LVT_TIMER ] &APIC_LVT_TIMER_PERIODIC ) { -if (!s->initial_count) - goto no_timer; - d = ((d / ((uint64_t )s->initial_count +1 )) +1 ) * ((uint64_t )s->initial_count +1 ); - }else { -if (d >= s->initial_count) - goto no_timer; - d = (uint64_t )s->initial_count +1 ; +int64_t d; + +if (s->lvt[APIC_LVT_TIMER ] &APIC_LVT_MASKED ) { +return false; + } + + d = (current_time - s->initial_count_load_time) >> s->count_shift; + +if (s->lvt[APIC_LVT_TIMER ] &APIC_LVT_TIMER_PERIODIC ) { +if (!s->initial_count) { +return false; } - next_time = s->initial_count_load_time + (d << s->count_shift); -qemu_mod_timer (s->timer, next_time); - s->next_time = next_time; + d = ((d / ((uint64_t )s->initial_count +1 )) +1 ) * + ((uint64_t )s->initial_count +1 ); + }else { +if (d >= s->initial_count) { +return false; + } + d = (uint64_t )s->initial_count +1 ; + } + s->next_time = s->initial_count_load_time + (d << s->count_shift); + +return true; +} + +static void apic_timer_update (APICState *s,int64_t current_time) +{ +if (apic_next_timer (s, current_time)) { +qemu_mod_timer (s->timer, s->next_time); }else { - no_timer:qemu_del_timer (s->timer); } }
Signature · 1 line
1.7.3.4
Marcelo Tosatti
AppliedQuoted 5 lines · Jan Kiszka
Factor out
apic_next_timerfromapic_timer_update. The former can then be used to updatenext_timerwithout actually starting the qemu timer. KVM's in-kernel APIC model will make use of it.Signed-off-by Jan Kiszka <[email protected]>
Applied both, thanks.