qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
Cc: qemu-devel@nongnu.org, quintela@redhat.com, mst@redhat.com,
	maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru,
	pbonzini@redhat.com
Subject: Re: [Qemu-devel] [ PATCH  ] hpet: recover timer offset correctly
Date: Wed, 20 Dec 2017 09:17:07 +0000	[thread overview]
Message-ID: <20171220091706.GA2348@work-vm> (raw)
In-Reply-To: <20171220075804.15036.93598.stgit@pasha-VirtualBox>

* Pavel Dovgalyuk (Pavel.Dovgaluk@ispras.ru) wrote:
> HPET saves its state by calculating the current time and recovers timer
> offset using this calculated value. But these calculations include
> divisions and multiplications. Therefore the timer state cannot be recovered
> precise enough.
> This patch introduces saving of the original value of the offset to
> preserve the determinism of the timer.

Please put the extra data in a subsection and tie the subsection to a
property enabled by the machine type.  That avoids breaking backwards
migration compatibility.

Dave

> Signed-off-by: Maria Klimushenkova <maria.klimushenkova@ispras.ru>
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> 
> ---
>  hw/timer/hpet.c |   12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
> index 577371b..4cf6a5b 100644
> --- a/hw/timer/hpet.c
> +++ b/hw/timer/hpet.c
> @@ -221,7 +221,9 @@ static int hpet_pre_save(void *opaque)
>      HPETState *s = opaque;
>  
>      /* save current counter value */
> -    s->hpet_counter = hpet_get_ticks(s);
> +    if (hpet_enabled(s)) {
> +        s->hpet_counter = hpet_get_ticks(s);
> +    }
>  
>      return 0;
>  }
> @@ -252,7 +254,10 @@ static int hpet_post_load(void *opaque, int version_id)
>      HPETState *s = opaque;
>  
>      /* Recalculate the offset between the main counter and guest time */
> -    s->hpet_offset = ticks_to_ns(s->hpet_counter) - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> +    if (version_id <= 2) {
> +        s->hpet_offset = ticks_to_ns(s->hpet_counter)
> +                        - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> +    }
>  
>      /* Push number of timers into capability returned via HPET_ID */
>      s->capability &= ~HPET_ID_NUM_TIM_MASK;
> @@ -303,7 +308,7 @@ static const VMStateDescription vmstate_hpet_timer = {
>  
>  static const VMStateDescription vmstate_hpet = {
>      .name = "hpet",
> -    .version_id = 2,
> +    .version_id = 3,
>      .minimum_version_id = 1,
>      .pre_save = hpet_pre_save,
>      .pre_load = hpet_pre_load,
> @@ -312,6 +317,7 @@ static const VMStateDescription vmstate_hpet = {
>          VMSTATE_UINT64(config, HPETState),
>          VMSTATE_UINT64(isr, HPETState),
>          VMSTATE_UINT64(hpet_counter, HPETState),
> +        VMSTATE_UINT64_V(hpet_offset, HPETState, 3),
>          VMSTATE_UINT8_V(num_timers, HPETState, 2),
>          VMSTATE_VALIDATE("num_timers in range", hpet_validate_num_timers),
>          VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0,
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  parent reply	other threads:[~2017-12-20  9:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-20  7:58 [Qemu-devel] [ PATCH ] hpet: recover timer offset correctly Pavel Dovgalyuk
2017-12-20  9:03 ` Paolo Bonzini
2017-12-20  9:17 ` Dr. David Alan Gilbert [this message]
2017-12-20  9:21   ` Pavel Dovgalyuk
2017-12-20  9:40     ` Dr. David Alan Gilbert
2017-12-20 10:02       ` Pavel Dovgalyuk

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=20171220091706.GA2348@work-vm \
    --to=dgilbert@redhat.com \
    --cc=Pavel.Dovgaluk@ispras.ru \
    --cc=dovgaluk@ispras.ru \
    --cc=maria.klimushenkova@ispras.ru \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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).