public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@imgtec.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	David Daney <ddaney.cavm@gmail.com>,
	David Daney <david.daney@cavium.com>,
	Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
Cc: <linux-mips@linux-mips.org>, Gleb Natapov <gleb@kernel.org>,
	<kvm@vger.kernel.org>, Ralf Baechle <ralf@linux-mips.org>,
	Sanjay Lal <sanjayl@kymasys.com>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [PATCH 14/21] MIPS: KVM: Add nanosecond count bias KVM register
Date: Wed, 28 May 2014 15:21:24 +0100	[thread overview]
Message-ID: <5385F0E4.1080207@imgtec.com> (raw)
In-Reply-To: <535B7E58.4070304@redhat.com>

Hi Paolo, David, Andreas,

On 26/04/14 10:37, Paolo Bonzini wrote:
> Il 26/04/2014 00:34, James Hogan ha scritto:
>> So yes, you could technically manage without (4) by using (2) ((4) was
>> implemented first), but I think it probably still has some value since
>> you can
>> do it with a single ioctl rather than 4 ioctls (freeze timer, read
>> resume_time, read or write count, unfreeze timer).
>>
>> Enough value to be worthwhile? I haven't really made up my mind yet
>> but I'm
>> leaning towards yes.
> 
> It would be interesting to see how the userspace patches use this
> independent of COUNT_RESUME.

The implementation in QEMU that I've settled upon makes do with just
COUNT_CTL and COUNT_RESUME, but with a slight kernel modification so
that COUNT_RESUME is writeable (to any positive monotonic nanosecond
value <= now). It works fairly cleanly and correctly even with stopping
and starting VM clock (gdb, stop/cont, savevm/loadvm, live migration),
to match the behaviour of the existing mips cpu timer emulation, so I
plan to drop this bias patch, and will post a v2 patchset soon with just
a few modifications.

QEMU saves the state of the KVM timer from kvm_arch_get_registers() or
when the VM clock is stopped (via a vmstate notifier) - whichever comes
first. It then restores the KVM timer from kvm_arch_put_registers() or
when the VM clock is started - whichever comes last.
Example sequence:
stop VM - SAVE
get regs - vm clock already stopped, not saved again
start VM - regs dirty, not restored
put regs - vm clock running, RESTORE

Saving involves:
COUNT_CTL.DC = 1 (freeze KVM timer)
get CP0_Cause, CP0_Count and COUNT_RESUME
store a copy of the calculated VM clock @COUNT_RESUME nanoseconds
(i.e. the VM clock corresponding to the saved CP0_Count)

Restoring involves:
put COUNT_RESUME = now - (vm clock @now - saved vm clock)
(resume occurs at the same interval into the past that the VM clock has
increased since saving)
put CP0_Cause, CP0_Count
(the stored CP0_Count applies at that resume time)
COUNT_CTL.DC = 0 (resume KVM timer from CP0_Count at COUNT_RESUME)

I'll post an updated QEMU patchset ASAP after the KVM patchset, but
wanted to explain how this API can actually be used. Does it sound
reasonable?

Thanks
James

  reply	other threads:[~2014-05-28 14:21 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-25 15:19 [PATCH 00/21] MIPS: KVM: Fixes and guest timer rewrite James Hogan
2014-04-25 15:19 ` [PATCH 01/21] MIPS: KVM: Allocate at least 16KB for exception handlers James Hogan
2014-04-25 15:19 ` [PATCH 02/21] MIPS: KVM: Use local_flush_icache_range to fix RI on XBurst James Hogan
2014-04-25 15:19 ` [PATCH 03/21] MIPS: KVM: Use tlb_write_random James Hogan
2014-04-25 15:19 ` [PATCH 04/21] MIPS: KVM: Fix CP0_EBASE KVM register id James Hogan
2014-04-25 16:36   ` David Daney
2014-04-25 19:22     ` James Hogan
2014-04-25 15:19 ` [PATCH 05/21] MIPS: KVM: Add CP0_EPC KVM register access James Hogan
2014-04-25 16:44   ` David Daney
2014-04-25 20:29     ` James Hogan
2014-04-25 21:45       ` David Daney
2014-04-25 15:19 ` [PATCH 06/21] MIPS: KVM: Move KVM_{GET,SET}_ONE_REG definitions into kvm_host.h James Hogan
2014-04-25 15:19 ` [PATCH 07/21] MIPS: KVM: Add CP0_Count/Compare KVM register access James Hogan
2014-04-25 15:19 ` [PATCH 08/21] MIPS: KVM: Deliver guest interrupts after local_irq_disable() James Hogan
2014-04-25 15:19 ` [PATCH 09/21] MIPS: KVM: Fix timer race modifying guest CP0_Cause James Hogan
2014-04-25 16:55   ` David Daney
2014-04-25 20:42     ` James Hogan
2014-04-25 15:19 ` [PATCH 10/21] MIPS: KVM: Migrate hrtimer to follow VCPU James Hogan
2014-04-25 15:19 ` [PATCH 11/21] MIPS: KVM: Rewrite count/compare timer emulation James Hogan
2014-04-25 17:00   ` David Daney
2014-04-25 21:05     ` James Hogan
2014-04-25 15:19 ` [PATCH 12/21] MIPS: KVM: Override guest kernel timer frequency directly James Hogan
2014-04-25 15:19 ` [PATCH 13/21] MIPS: KVM: Add master disable count interface James Hogan
2014-04-25 15:19 ` [PATCH 14/21] MIPS: KVM: Add nanosecond count bias KVM register James Hogan
2014-04-25 17:27   ` David Daney
2014-04-25 22:34     ` James Hogan
2014-04-26  9:37       ` Paolo Bonzini
2014-05-28 14:21         ` James Hogan [this message]
2014-05-28 16:24           ` Paolo Bonzini
2014-04-28 12:01   ` Paolo Bonzini
2014-04-28 15:17     ` James Hogan
2014-04-28 15:42       ` Paolo Bonzini
2014-04-25 15:19 ` [PATCH 15/21] MIPS: KVM: Add count frequency " James Hogan
2014-04-25 15:19 ` [PATCH 16/21] MIPS: KVM: Make kvm_mips_comparecount_{func,wakeup} static James Hogan
2014-04-25 15:20 ` [PATCH 17/21] MIPS: KVM: Whitespace fixes in kvm_mips_callbacks James Hogan
2014-04-25 15:20 ` [PATCH 18/21] MIPS: KVM: Fix kvm_debug bit-rottage James Hogan
2014-04-25 15:20 ` [PATCH 19/21] MIPS: KVM: Remove ifdef DEBUG around kvm_debug James Hogan
2014-04-25 15:20 ` [PATCH 20/21] MIPS: KVM: Quieten kvm_info() logging James Hogan
2014-04-25 15:20 ` [PATCH 21/21] MIPS: KVM: Remove redundant NULL checks before kfree() James Hogan
2014-04-28 12:02 ` [PATCH 00/21] MIPS: KVM: Fixes and guest timer rewrite Paolo Bonzini

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=5385F0E4.1080207@imgtec.com \
    --to=james.hogan@imgtec.com \
    --cc=andreas.herrmann@caviumnetworks.com \
    --cc=david.daney@cavium.com \
    --cc=ddaney.cavm@gmail.com \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ralf@linux-mips.org \
    --cc=sanjayl@kymasys.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