From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Xiao Guangrong <guangrong.xiao@gmail.com>,
Vadim Rozenfeld <vrozenfe@redhat.com>
Subject: Re: [PATCH v2] mc146818rtc: fix timer interrupt reinjection
Date: Thu, 24 Oct 2019 14:08:22 +0200 [thread overview]
Message-ID: <12f2aebb-6919-2ee0-f356-4000652ee3c3@redhat.com> (raw)
In-Reply-To: <cc492782-8e5a-5c39-226d-a4e97cabf914@redhat.com>
On 10/24/19 1:22 PM, Philippe Mathieu-Daudé wrote:
> On 10/10/19 2:30 PM, Marcelo Tosatti wrote:
>>
>> commit 369b41359af46bded5799c9ef8be2b641d92e043 broke timer interrupt
>> reinjection when there is no period change by the guest.
>>
>> In that case, old_period is 0, which ends up zeroing irq_coalesced
>> (counter of reinjected interrupts).
>>
>> The consequence is Windows 7 is unable to synchronize time via NTP.
>> Easily reproducible by playing a fullscreen video with cirrus and VNC.
>>
>> Fix by not updating s->irq_coalesced when old_period is 0.
>>
>> V2: reorganize code (Paolo Bonzini)
>
> ^ This line shouldn't be part of git history,
> Paolo if possible can you drop it?
>
>>
>> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>>
>> diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
>> index 6cb378751b..0e7cf97042 100644
>> --- a/hw/timer/mc146818rtc.c
>> +++ b/hw/timer/mc146818rtc.c
>> @@ -203,24 +203,28 @@ periodic_timer_update(RTCState *s, int64_t
>> current_time, uint32_t old_period)
>> period = rtc_periodic_clock_ticks(s);
>> - if (period) {
>> - /* compute 32 khz clock */
>> - cur_clock =
>> - muldiv64(current_time, RTC_CLOCK_RATE,
>> NANOSECONDS_PER_SECOND);
>> + if (!period) {
>> + s->irq_coalesced = 0;
>> + timer_del(s->periodic_timer);
>> + return;
>> + }
>
> This is the first change, simplify the if statement with a return.
>
>> - /*
>> - * if the periodic timer's update is due to period
>> re-configuration,
>> - * we should count the clock since last interrupt.
>> - */
>> - if (old_period) {
>> - int64_t last_periodic_clock, next_periodic_clock;
>> -
>> - next_periodic_clock = muldiv64(s->next_periodic_time,
>> - RTC_CLOCK_RATE,
>> NANOSECONDS_PER_SECOND);
>> - last_periodic_clock = next_periodic_clock - old_period;
>> - lost_clock = cur_clock - last_periodic_clock;
>> - assert(lost_clock >= 0);
>> - }
>> + /* compute 32 khz clock */
>> + cur_clock =
>> + muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
>> +
>> + /*
>> + * if the periodic timer's update is due to period re-configuration,
>> + * we should count the clock since last interrupt.
>> + */
>> + if (old_period) {
>> + int64_t last_periodic_clock, next_periodic_clock;
>> +
>> + next_periodic_clock = muldiv64(s->next_periodic_time,
>> + RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
>> + last_periodic_clock = next_periodic_clock - old_period;
>> + lost_clock = cur_clock - last_periodic_clock;
>> + assert(lost_clock >= 0);
>> /*
>> * s->irq_coalesced can change for two reasons:
>> @@ -251,22 +255,19 @@ periodic_timer_update(RTCState *s, int64_t
>> current_time, uint32_t old_period)
>> rtc_coalesced_timer_update(s);
>> }
>> } else {
>> - /*
>> + /*
>> * no way to compensate the interrupt if
>> LOST_TICK_POLICY_SLEW
>> * is not used, we should make the time progress anyway.
>> */
>> lost_clock = MIN(lost_clock, period);
>> }
>> + }
>
> This is the second change, changing the logic and fixing the bug.
>
>> - assert(lost_clock >= 0 && lost_clock <= period);
>> + assert(lost_clock >= 0 && lost_clock <= period);
>> - next_irq_clock = cur_clock + period - lost_clock;
>> - s->next_periodic_time = periodic_clock_to_ns(next_irq_clock)
>> + 1;
>> - timer_mod(s->periodic_timer, s->next_periodic_time);
>> - } else {
>> - s->irq_coalesced = 0;
>> - timer_del(s->periodic_timer);
>> - }
>> + next_irq_clock = cur_clock + period - lost_clock;
>> + s->next_periodic_time = periodic_clock_to_ns(next_irq_clock) + 1;
>> + timer_mod(s->periodic_timer, s->next_periodic_time);
>
> This is part of the 1st change.
>
> I'd rather see this patch split in 2 logical changes...
Since this split makes sense to me (easier to understand the patch diff
when reviewing), I can quickly do it if you don't mind.
>> }
>> static void rtc_periodic_timer(void *opaque)
>>
>>
next prev parent reply other threads:[~2019-10-24 12:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-10 12:30 [PATCH v2] mc146818rtc: fix timer interrupt reinjection Marcelo Tosatti
2019-10-10 12:35 ` Paolo Bonzini
2019-10-24 11:22 ` Philippe Mathieu-Daudé
2019-10-24 12:08 ` Philippe Mathieu-Daudé [this message]
2019-11-16 20:58 ` Alex Williamson
2019-11-17 3:20 ` Marcelo Tosatti
2019-11-17 4:31 ` Alex Williamson
2019-11-17 10:12 ` Paolo Bonzini
2019-11-17 18:32 ` Alex Williamson
2019-11-18 21:44 ` Marcelo Tosatti
2019-11-18 22:08 ` Paolo Bonzini
2019-11-18 23:28 ` Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12f2aebb-6919-2ee0-f356-4000652ee3c3@redhat.com \
--to=philmd@redhat.com \
--cc=guangrong.xiao@gmail.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vrozenfe@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).