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>
Cc: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>,
	Gleb Natapov <gleb@kernel.org>, <kvm@vger.kernel.org>,
	Ralf Baechle <ralf@linux-mips.org>, <linux-mips@linux-mips.org>,
	David Daney <david.daney@cavium.com>,
	Sanjay Lal <sanjayl@kymasys.com>
Subject: Re: [PATCH v2 00/23] MIPS: KVM: Fixes and guest timer rewrite
Date: Thu, 29 May 2014 21:44:46 +0100	[thread overview]
Message-ID: <53879C3E.3040102@imgtec.com> (raw)
In-Reply-To: <53876850.20600@redhat.com>

Hi Paolo,

On 29/05/14 18:03, Paolo Bonzini wrote:
>>> Also, perhaps this bit in kvm_mips_restore_count is unnecessary, and so
>>> is env->count_save_time in general:
>>>
>>>> +        /* find time to resume the saved timer at */
>>>> +        now = get_clock();
>>>> +        count_resume = now - (cpu_get_clock_at(now) -
>>>> env->count_save_time);
>>>
>>> Is the COUNT_RESUME write necessary if the VM is running?
>>
>> Running at that instant or running continuously since the save?
>>
>> At this instant the VM is always running. Either it's just been started
>> and other state isn't dirty, or the registers have been put while the VM
>> is running.
> 
> The possible transitions are:
> 
> running, not dirty -> stopped
>     need to freeze and load the registers
> 
> stopped -> running, not dirty
>     will reload the registers, need to modify COUNT_RESUME
> 
> running, dirty -> stopped
>     no need to do anything
> 
> stopped -> running, dirty
>     will not reload the registers until put, will need to modify
>     COUNT_RESUME on the next transition to "running, not dirty"
> 
> running, not dirty -> running, dirty
>     need to freeze and load the registers
> 
> running, dirty -> running, not dirty
>     need to modify COUNT_RESUME if the machine had been stopped
>     in the meanwhile
> 
> The questions then is, can we skip tracking count_save_time and
> modifying COUNT_RESUME in kvm_mips_restore_count?  Then you can just
> write get_clock() to COUNT_RESUME in kvm_mips_update_state, like this:
> 
>     if (!running) {
>         if (!cs->kvm_vcpu_dirty) {
>             save;
>         }
>     else {
>         write get_clock() to COUNT_RESUME;
>         if (!cs->kvm_vcpu_dirty) {
>             restore;
>         }
>     }
> 
> and even drop patch 1.  COUNT_RESUME is not even ever read by QEMU nor
> stored in CPUState, so.
> 
> The difference is that the guest "loses" the time between the "running,
> not dirty -> running, dirty" and "running, dirty -> stopped"
> transitions, while "gaining" the time between "stopped -> running,
> dirty" and "running, dirty -> running, not dirty".  If this is right, I
> think the difference does not matter in practice and the new/simpler
> code even explains the definition of COUNT_RESUME better in my eyes.

Yes, I agree with your analysis and had considered something like this,
although it doesn't particularly appeal to my sense of perfectionism :).
It would be race free though, and if you're stopping the VM at all you
expect to lose some time anyway.

> 
>>> Does the
>>> master disable bit just latch the values, or does it really stop the
>>> timer?  (My reading of the code is the former, since writing
>>> COUNT_RESUME only modifies the bias: no write => no bias change => timer
>>> runs).
>>
>> It appears latched in the sense that starting it again will jump Count
>> forward to the time it would have been had it not been disabled (with no
>> loss of Compare interrupt in that time).
> 
> Yes, this is the important part because it means that the guest clock
> does not get progressively more skewed.  It also means that it is right
> to never write COUNT_RESUME except if you go through stop/continue.

Yes, if the VM hasn't been stopped the value written is unchanged from
that originally read (see below), so it could skip it in that case.

save:
  count_save_time = cpu_clock_offset + COUNT_RESUME
restore:
  COUNT_RESUME = get_clock() - (cpu_clock_offset + get_clock() -
count_save_time)
		= count_save_time - cpu_clock_offset
		= COUNT_RESUME

Cheers
James

  reply	other threads:[~2014-05-29 20:44 UTC|newest]

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

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=53879C3E.3040102@imgtec.com \
    --to=james.hogan@imgtec.com \
    --cc=andreas.herrmann@caviumnetworks.com \
    --cc=david.daney@cavium.com \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=pbonzini@redhat.com \
    --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