Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 72134
b: refs/heads/master
c: 9da8f4e
h: refs/heads/master
v: v3
  • Loading branch information
Kevin Pedretti authored and Avi Kivity committed Oct 22, 2007
1 parent 9036e2f commit 4803e6e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b33ac88b4c23330043acad930517282eb486db1d
refs/heads/master: 9da8f4e83a824dabf3fb7ad0890549257ae614a0
36 changes: 26 additions & 10 deletions trunk/drivers/kvm/lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,19 @@ static void apic_send_ipi(struct kvm_lapic *apic)

static u32 apic_get_tmcct(struct kvm_lapic *apic)
{
u32 counter_passed;
ktime_t passed, now = apic->timer.dev.base->get_time();
u32 tmcct = apic_get_reg(apic, APIC_TMICT);
u64 counter_passed;
ktime_t passed, now;
u32 tmcct;

ASSERT(apic != NULL);

now = apic->timer.dev.base->get_time();
tmcct = apic_get_reg(apic, APIC_TMICT);

/* if initial count is 0, current count should also be 0 */
if (tmcct == 0)
return 0;

if (unlikely(ktime_to_ns(now) <=
ktime_to_ns(apic->timer.last_update))) {
/* Wrap around */
Expand All @@ -514,15 +521,24 @@ static u32 apic_get_tmcct(struct kvm_lapic *apic)

counter_passed = div64_64(ktime_to_ns(passed),
(APIC_BUS_CYCLE_NS * apic->timer.divide_count));
tmcct -= counter_passed;

if (tmcct <= 0) {
if (unlikely(!apic_lvtt_period(apic)))
if (counter_passed > tmcct) {
if (unlikely(!apic_lvtt_period(apic))) {
/* one-shot timers stick at 0 until reset */
tmcct = 0;
else
do {
tmcct += apic_get_reg(apic, APIC_TMICT);
} while (tmcct <= 0);
} else {
/*
* periodic timers reset to APIC_TMICT when they
* hit 0. The while loop simulates this happening N
* times. (counter_passed %= tmcct) would also work,
* but might be slower or not work on 32-bit??
*/
while (counter_passed > tmcct)
counter_passed -= tmcct;
tmcct -= counter_passed;
}
} else {
tmcct -= counter_passed;
}

return tmcct;
Expand Down

0 comments on commit 4803e6e

Please sign in to comment.