On 05/03/2017 11:15 PM, Paolo Bonzini wrote:
On 12/04/2017 11:51, guangrong.xiao@xxxxxxxxx wrote:
+ int current_irq_coalesced = s->irq_coalesced;
+
+ s->irq_coalesced = (current_irq_coalesced * s->period) / period;
+
+ /*
+ * calculate the lost clock after it is scaled which should be
+ * compensated in the next interrupt.
+ */
+ lost_clock += current_irq_coalesced * s->period -
+ s->irq_coalesced * period;
This is:
lost_clock = current_irq_coalesced * s->period -
(current_irq_coalesced * s->period) / period * period;
i.e.
/* When switching from a shorter to a longer period, scale down the
* missing ticks since we expect the OS handler to treat the delayed
* ticks as longer. Any leftovers are put back into next_irq_clock.
*
* When switching to a shorter period, scale up the missing ticks
* since we expect the OS handler to treat the delayed ticks as
* shorter.
*/
lost_clock = (s->irq_coalesced * s->period) % period;
s->irq_coalesced = (s->irq_coalesced * s->period) / period;
Is this correct?
Yes, it is correct, it looks smarter, will apply it in the next version.
Thanks!