Skip to content

Commit

Permalink
hv: timer: restruct add_timer/del_timer API
Browse files Browse the repository at this point in the history
add initialize_timer to initialize or reset a timer;
add_timer add timer to corresponding physical cpu timer list.
del_timer delete timer from corresponding physical cpu timer list.

Signed-off-by: Li, Fei1 <fei1.li@intel.com>
  • Loading branch information
lifeix authored and jren1 committed May 15, 2018
1 parent be9f4ee commit 9bfa574
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 258 deletions.
25 changes: 9 additions & 16 deletions hypervisor/arch/x86/guest/vlapic.c
Expand Up @@ -1576,10 +1576,7 @@ vlapic_reset(struct vlapic *vlapic)

vlapic->svr_last = lapic->svr;

if (vlapic->last_timer > 0) {
cancel_timer(vlapic->last_timer, vlapic->vcpu->pcpu_id);
vlapic->last_timer = -1;
}
initialize_timer(&vlapic->timer, NULL, NULL, 0);
}

void
Expand Down Expand Up @@ -1969,22 +1966,19 @@ vlapic_wrmsr(struct vcpu *vcpu, uint32_t msr, uint64_t val)
if (!VLAPIC_TSCDEADLINE(lapic->lvt_timer))
return error;

if (val == 0UL) {
cancel_timer(vlapic->last_timer, vcpu->pcpu_id);
vlapic->last_timer = -1;
} else {
del_timer(&vlapic->timer);
if (val != 0UL) {
/* transfer guest tsc to host tsc */
val -= vcpu->arch_vcpu.contexts[vcpu->
arch_vcpu.cur_context].tsc_offset;

vlapic->last_timer = update_timer(vlapic->last_timer,
tsc_periodic_time,
(void *)vcpu,
initialize_timer(&vlapic->timer,
tsc_periodic_time, (void *)vcpu,
val);

if (vlapic->last_timer < 0) {
pr_err("vLAPIC failed to add timer on VM %d VCPU%d",
vcpu->vm->attr.id, vcpu->vcpu_id);
if (add_timer(&vlapic->timer) != 0) {
pr_err("failed to add timer on VM %d",
vcpu->vm->attr.id);
error = -1;
}
}
Expand Down Expand Up @@ -2139,8 +2133,7 @@ void vlapic_free(struct vcpu *vcpu)
if (vlapic == NULL)
return;

if (vlapic->last_timer > 0)
cancel_timer(vlapic->last_timer, vcpu->pcpu_id);
del_timer(&vlapic->timer);

if (!is_vapic_supported()) {
unregister_mmio_emulation_handler(vcpu->vm,
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/arch/x86/guest/vlapic_priv.h
Expand Up @@ -122,7 +122,7 @@ struct vlapic {
struct bintime timer_fire_bt; /* callout expiry time */
struct bintime timer_freq_bt; /* timer frequency */
struct bintime timer_period_bt; /* timer period */
long last_timer; /* the last timer id */
struct timer timer;

spinlock_t timer_mtx;

Expand Down

0 comments on commit 9bfa574

Please sign in to comment.