Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Christoffer Dall <christoffer.dall@arm.com>
To: Steven Price <steven.price@arm.com>
Cc: marc.zyngier@arm.com, lersek@redhat.com,
	Miriam Zimmerman <mutexlox@google.com>,
	kvmarm@lists.cs.columbia.edu
Subject: Re: Timekeeping on ARM guests/hosts
Date: Thu, 8 Nov 2018 21:06:16 +0100	[thread overview]
Message-ID: <20181108200616.GF3835@e113682-lin.lund.arm.com> (raw)
In-Reply-To: <71ac50f7-2004-c5f4-1220-69b5a25ee18b@arm.com>

On Thu, Nov 08, 2018 at 04:34:08PM +0000, Steven Price wrote:
> On 08/11/2018 10:26, Christoffer Dall wrote:
> > On Wed, Nov 07, 2018 at 10:22:06AM -0800, Miriam Zimmerman wrote:
> >> On Wed, Nov 7, 2018 at 1:42 AM Christoffer Dall
> >> <christoffer.dall@arm.com> wrote:
> >>>
> >>> On Tue, Nov 06, 2018 at 10:37:21AM -0800, Miriam Zimmerman wrote:
> >>>> On Mon, Nov 5, 2018 at 11:45 PM Christoffer Dall
> >>>> <christoffer.dall@arm.com> wrote:
> >>>>>
> >>>>> On Fri, Nov 02, 2018 at 02:23:45PM -0700, Miriam Zimmerman wrote:
> >>>>>> In researching KVM_REG_ARM_TIMER_CNT, I discovered your commit 4b7a6bf
> >>>>>> ("target-arm: kvm: Differentiate registers based on write-back
> >>>>>> levels"), which seems to limit when the KVM_REG_ARM_TIMER_CNT is used
> >>>>>> to save time. Under what circumstances should this be saved in order
> >>>>>> to provide a consistent view of wall clock time (as given by `date` in
> >>>>>> the VM)?
> >>>>>
> >>>>> In general, and not specific to QEMU, I think that the virtual
> >>>>> counter value should stop counting when the entirety of the VM is not
> >>>>> running, for example when the host machine is suspended, or when the
> >>>>> entire VM is stopped/suspended, either as part of a suspend/resume
> >>>>> operation, debug operation, or as part of migration of some sort.
> >>>>>
> >>>>> Supporting these timekeeping semantics is not something anyone has tried
> >>>>> up until now with KVM/Arm, as far as I'm aware, and as such is 'new'
> >>>>> work.
> >>>>
> >>>> Hrm, that's perplexing to me. I thought you said that in your tests,
> >>>> going into S3 suspend on a host did *not* result in time drift on the
> >>>> guest? That would suggest to me that there is code that correctly
> >>>> handles it.
> >>>
> >>> I don't believe I've said that.  I haven't actually tried that myself,
> >>> but I know anecdotally from others that time jumps on the guest when you
> >>> suspend the host, leading to warnings in a guest.
> >>>
> >>> There must be some misunderstanding here.
> >>
> >> Ah, indeed - Steven said that he tried this and saw time track
> >> properly in-guest on ARM. I misremembered and thought that was you.
> > 
> > What Steven said was:
> > 
> >   "On Arm, as far as I know, the guest's view of time is purely from the
> >   virtual counter. Since nothing saves/restores this during the pause,
> >   the counter continues to increment and the jump in time is visible to
> >   the guest."
> > 
> > So here he means that time in the guest jumps, which is not what the
> > guest expects, and thus you see warnings and problems from the guest,
> > even though date/time may be reported correctly in the guest for the
> > same reason.
> > 
> > Adjusting virtual time should prevent the guest from getting confused
> > wrt. watchdogs and starved processes etc.
> 
> Good summary - that's at least what I meant to say :)
> 
> > However, I'm still not entirely clear on how the guest will correctly
> > observe wall-clock if we adjust virtual time.  Should it use the
> > physical counter?  Does PV take care of this?  Does it receive a
> > notification that it must update its clock via NTP?
> > 
> > Steve, any insight?
> 
> PV time doesn't fix the guest observing wall-clock time. All it provides
> the guest is "live physical time" - i.e. a good view of time when it is
> executing, not general time.
> 
> There are two/three approaches I can see we could take:
> 
> 1. Don't "fix" the fact that the virtual time runs when the guest is
> paused, but instead implement the KVM_KVMCLOCK_CTRL ioctl for arm to
> notify the kernel that time has jumped. This will silence the kernel's
> watchdogs but user space will still see a big jump. It also does nothing
> to fix drift caused by other events (e.g. the virtual machine being
> saved to a file or the host machine being suspended/hybernated).
> 
> 2. Stop virtual time when the guest isn't running and provide another
> mechanism for the guest to get hold of wall clock time. E.g. x86 has
> MSR_KVM_WALL_CLOCK_NEW which returns a structure with the actual wall
> clock time of the host.
> 
> 3. Assume the guest can synchronise with something external: i.e. NTP.
> Sadly this doesn't work well in practice because NTP is built around a
> reliable local clock that just needs a minor correction to the
> frequency. NTP will take a while to notice a large jump in time and
> (depending on configuration) can be reluctant to step time to correct it.
> 
> I haven't investigated how this actually works on x86 - it appears to be
> some variant of 2 - but exactly how the MSR_KVM_WALL_CLOCK_NEW
> functionality works I haven't understood yet.
> 

Is the fact that we can have an emulated RTC device in QEMU another
mechanism that we need to consider?

How about the physical counter, does that help (assuming we mandate
trap-and-emulate of the physical counter on migration).  Could we have

  wall_clock_time_requested_hook(void) {
        static old_diff;
  	pcnt = read_sysreg(CNTPCT_EL0);
  	vcnt = read_sysreg(CNTVCT_EL0);

	if (pcnt - vcnt !- old_diff)
		rtc_pl031_update_now();
	old_diff = pcnt - vcnt;
  }

See also the thread from Bijan looking at this from the QEMU side.


Thanks,

    Christoffer

  reply	other threads:[~2018-11-08 20:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 23:39 Timekeeping on ARM guests/hosts Miriam Zimmerman
2018-10-10 10:01 ` Marc Zyngier
2018-10-10 18:38   ` Miriam Zimmerman
2018-10-11  7:54     ` Marc Zyngier
2018-10-11 15:21       ` Laszlo Ersek
2018-10-11 18:40         ` Miriam Zimmerman
2018-10-31 16:41           ` Steven Price
2018-10-31 18:49             ` Miriam Zimmerman
2018-11-02 14:34               ` Christoffer Dall
2018-11-02 18:28                 ` Miriam Zimmerman
2018-11-02 21:23                   ` Miriam Zimmerman
2018-11-06  7:45                     ` Christoffer Dall
2018-11-06 13:39                       ` Alex Bennée
2018-11-06 18:37                       ` Miriam Zimmerman
2018-11-07  9:42                         ` Christoffer Dall
2018-11-07 18:22                           ` Miriam Zimmerman
2018-11-08 10:26                             ` Christoffer Dall
2018-11-08 16:34                               ` Steven Price
2018-11-08 20:06                                 ` Christoffer Dall [this message]
2018-11-03  0:19                 ` Bijan Mottahedeh
2018-11-06  7:49                   ` Christoffer Dall

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=20181108200616.GF3835@e113682-lin.lund.arm.com \
    --to=christoffer.dall@arm.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=lersek@redhat.com \
    --cc=marc.zyngier@arm.com \
    --cc=mutexlox@google.com \
    --cc=steven.price@arm.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