All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: Qin Li <qin.l.li@oracle.com>
Cc: Roger Pau Monne <roger.pau@citrix.com>,
	xen-devel@lists.xensource.com,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: Re: Could you please answer some questions regarding Solaris PVHVM pvclock support.
Date: Thu, 27 Feb 2014 13:03:48 +0000	[thread overview]
Message-ID: <alpine.DEB.2.02.1402271253000.31489@kaball.uk.xensource.com> (raw)
In-Reply-To: <530DD57A.8010709@oracle.com>

[-- Attachment #1: Type: text/plain, Size: 2947 bytes --]

On Wed, 26 Feb 2014, Qin Li wrote:
> 
> 于 2014/1/16 20:17, Stefano Stabellini 写道:
> 
> . For a PV-on-HVM guest OS, the "shared_info->vcpu_info->vcpu_time_info"
> > is already visiable. Does guest OS still need any action to ask
> > hypervisor to update this piece of memory periodically?
> 
> I don't think you need to ask the hypervisor to update vcpu_time_info
> periodically, what gave you that idea?
> 
> Hi Stefano,
> 
> Now, I see it's the hypervisor that will update vcpu_time_info, but another thing confuse me:
> HVM guest has time drift issue because TSC on different vCPU could be out-of-sync, especially after domain suspend/resume.
> But how pvclock actually fix this issue? Let's see how FreeBSD port calculate the system time:
> 
> ==================
> static uint64_t
> get_nsec_offset(struct vcpu_time_info *tinfo)
> {
> 
>     return (scale_delta(rdtsc() - tinfo->tsc_timestamp,
>         tinfo->tsc_to_system_mul, tinfo->tsc_shift));
> }
> 
> /**
>  * \brief Get the current time, in nanoseconds, since the hypervisor booted.
>  *
>  * \note This function returns the current CPU's idea of this value, unless
>  *       it happens to be less than another CPU's previously determined value.
>  */
> static uint64_t
> xen_fetch_vcpu_time(void)
> {
>     struct vcpu_time_info dst;
>     struct vcpu_time_info *src;
>     uint32_t pre_version;
>     uint64_t now;
>     volatile uint64_t last;
>     struct vcpu_info *vcpu = DPCPU_GET(vcpu_info);
> 
>     src = &vcpu->time;
> 
>     critical_enter();
>     do {
>         pre_version = xen_fetch_vcpu_tinfo(&dst, src);
>         barrier();
>         now = dst.system_time + get_nsec_offset(&dst);
>         barrier();
>     } while (pre_version != src->version);
> 
>     /*
>      * Enforce a monotonically increasing clock time across all
>      * VCPUs.  If our time is too old, use the last time and return.
>      * Otherwise, try to update the last time.
>      */
>     do {
>         last = last_time;
>         if (last > now) {
>             now = last;
>             break;
>         }
>     } while (!atomic_cmpset_64(&last_time, last, now));
> 
>     critical_exit();
> 
>     return (now);
> }
> ==================================
> 
> I guest linux guest will do the same thing, rdtsc() fetch current timestamp from current running vCPU, TSC out-of-sync issue is still there.
> It seems to me pvclock finally fix the time drift issue just because the workaround enforced as above, right?

First you should know that TSC is not always guaranteed to be
synchronized across multiple processors, especially on older systems.
On "TSC-safe" systems, Xen would export a consistent TSC to guests, by
setting the vtsc offset and scale appropriately.

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2014-02-27 13:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <52D6566C.5050302@oracle.com>
2014-01-16 12:17 ` Could you please answer some questions regarding Solaris PVHVM pvclock support Stefano Stabellini
2014-01-24  0:21   ` Mukesh Rathor
2014-02-26 11:52   ` Qin Li
2014-02-27 13:03     ` Stefano Stabellini [this message]
2014-02-28  3:27       ` Qin Li
2014-02-28 15:04         ` Stefano Stabellini

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=alpine.DEB.2.02.1402271253000.31489@kaball.uk.xensource.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=qin.l.li@oracle.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xensource.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 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.