All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: Glauber Costa <gcosta@redhat.com>
Cc: kvm-devel@lists.sourceforge.net, chrisw@sous-sol.org
Subject: Re: [PATCH 1/2] kvmclock - the host part.
Date: Thu, 14 Feb 2008 11:21:13 +0200	[thread overview]
Message-ID: <47B40809.2060601@qumranet.com> (raw)
In-Reply-To: <47B364DE.8020202@redhat.com>

Glauber Costa wrote:
>>
>>> +static void kvm_write_wall_clock(struct kvm_vcpu *v, gpa_t wall_clock)
>>> +{
>>> +    int version = 1;
>>> +    struct kvm_wall_clock wc;
>>> +    unsigned long flags;
>>> +    struct timespec wc_ts;
>>> +
>>> +    local_irq_save(flags);
>>> +    kvm_get_msr(v, MSR_IA32_TIME_STAMP_COUNTER,
>>> +              &v->arch.hv_clock.tsc_timestamp);
>>>   
>>
>> Why is this needed? IIRC the wall clock is not tied to any vcpu.
>>
>> If we can remove this, the argument to the function should be kvm, 
>> not kvm_vcpu. We can remove the irq games as well.
>
> After some new thoughts, I don't agree. The time calculation in the 
> guest will be in the format wallclock + delta tsc. Everything that has 
> a tsc _is_ tied to a cpu. Although we can store the area globally, I 
> think the best semantics is to have a vcpu to always issue an msr 
> write to the area before reading it, in order to have the tsc updated.
>

No.  Guest time is (wall_clock + system_time) == (wall_clock + 
system_time_base + tsc_adjust).  The wall clock part is vcpu indepenent 
(or it would be unusable by more than one vcpus).

wall_clock is the system boot time; it only changes when the host time 
is adjusted (by ntp or user command).

>
>> For mutual exclusion, I suggest taking kvm->lock instead (for the 
>> entire function).
>
> This function is called too often. since we only need to guarantee 
> mutual exclusion in a tiny part, it seems preferable to me. Do you 
> have any extra reason for kvm->lock'ing the entire function?

Wall clock adjustment should only be called as a result of 
settimeofday() or similar.  Only vcpu time needs frequent adjustment 
(due to vcpu migration or tsc frequency change).

>
>
>>>  
>>> +/* xen binary-compatible interface. See xen headers for details */
>>> +struct kvm_vcpu_time_info {
>>> +    uint32_t version;
>>> +    uint32_t pad0;
>>> +    uint64_t tsc_timestamp;
>>> +    uint64_t system_time;
>>> +    uint32_t tsc_to_system_mul;
>>> +    int8_t   tsc_shift;
>>> +}; /* 32 bytes */
>>> +
>>> +struct kvm_wall_clock {
>>> +    uint32_t wc_version;
>>> +    uint32_t wc_sec;
>>> +    uint32_t wc_nsec;
>>> +};
>>> +
>>>   
>>
>> These structures are dangerously sized. __Suggest__ 
>> __attribute__((__packed__)). (or some padding at the end of 
>> kvm_vcpu_time_info.
>
> They are sized so to have same size as xen's. If it concerns you,
> packed should be better.

Okay, so let's pack kvm_wall_clock to avoid surprises.  The Xen sources 
I have (v2.6.25-rc1:include/xen/interface/xen.h) do have three bytes 
padding in vcpu_time_info to make it 32 bytes.

-- 
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  reply	other threads:[~2008-02-14  9:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-11 18:07 [PATCH 0/2] kvm clock - merge last comments Glauber de Oliveira Costa
2008-02-11 18:07 ` [PATCH 1/2] kvmclock - the host part Glauber de Oliveira Costa
2008-02-11 18:07   ` [PATCH 2/2] kvmclock implementation, the guest part Glauber de Oliveira Costa
2008-02-13 10:49   ` [PATCH 1/2] kvmclock - the host part Avi Kivity
2008-02-13 21:45     ` Glauber Costa
2008-02-14  9:21       ` Avi Kivity [this message]
2008-02-18 14:06     ` Marcelo Tosatti
  -- strict thread matches above, loose matches on Subject: below --
2008-01-16 16:31 [PATCH 0/2] kvm clock - xen compatible by accident Glauber de Oliveira Costa
     [not found] ` <1200501067774-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-01-16 16:31   ` [PATCH 1/2] kvmclock - the host part Glauber de Oliveira Costa
     [not found]     ` <12005010761561-git-send-email-gcosta-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-01-16 19:00       ` Anthony Liguori
     [not found]         ` <478E544C.4020603-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2008-01-17  0:18           ` Glauber de Oliveira Costa
2008-01-17  7:59       ` Gerd Hoffmann
2008-01-20 15:37       ` Avi Kivity
2008-01-20 15:38       ` Avi Kivity

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=47B40809.2060601@qumranet.com \
    --to=avi@qumranet.com \
    --cc=chrisw@sous-sol.org \
    --cc=gcosta@redhat.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.