All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad@kernel.org>
To: David Vrabel <david.vrabel@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>, xen-devel@lists.xen.org
Subject: Re: [PATCH 3/3] xen/privcmd: add IOCTL_PRIVCMD_SYNC_WALLCLOCK to sync Xen's wallclock
Date: Fri, 12 Oct 2012 09:41:47 -0400	[thread overview]
Message-ID: <20121012134147.GA11778@phenom.dumpdata.com> (raw)
In-Reply-To: <1350046634-2462-4-git-send-email-david.vrabel@citrix.com>

On Fri, Oct 12, 2012 at 01:57:14PM +0100, David Vrabel wrote:
> From: David Vrabel <david.vrabel@citrix.com>
> 
> Add a new ioctl to synchronize Xen's wallclock with the current system
> time.
> 
> This may be used by the tools to ensure that newly created domains see
> the correct wallclock time if NTP is not used in dom0 or if domains
> are started before NTP has synchronized.

So... how does this work with NTPD? As in does ntpd _not_ update the
hwclock enough?


> 
> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
> ---
>  arch/x86/xen/time.c   |   25 ++++++++++++++++++-------
>  drivers/xen/privcmd.c |   12 ++++++++++++
>  include/xen/privcmd.h |    8 ++++++++
>  include/xen/xen-ops.h |    2 ++
>  4 files changed, 40 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
> index 11770d0..d481ac9 100644
> --- a/arch/x86/xen/time.c
> +++ b/arch/x86/xen/time.c
> @@ -8,6 +8,7 @@
>   * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
>   */
>  #include <linux/kernel.h>
> +#include <linux/export.h>
>  #include <linux/interrupt.h>
>  #include <linux/clocksource.h>
>  #include <linux/clockchips.h>
> @@ -192,6 +193,19 @@ static void xen_read_wallclock(struct timespec *ts)
>  	put_cpu_var(xen_vcpu);
>  }
>  
> +int xen_write_wallclock(const struct timespec *ts)
> +{
> +	struct xen_platform_op op;
> +
> +	op.cmd = XENPF_settime;
> +	op.u.settime.secs = ts->tv_sec;
> +	op.u.settime.nsecs = ts->tv_nsec;
> +	op.u.settime.system_time = xen_clocksource_read();
> +
> +	return HYPERVISOR_dom0_op(&op);
> +}
> +EXPORT_SYMBOL_GPL(xen_write_wallclock);
> +
>  static unsigned long xen_get_wallclock(void)
>  {
>  	struct timespec ts;
> @@ -202,7 +216,7 @@ static unsigned long xen_get_wallclock(void)
>  
>  static int xen_set_wallclock(unsigned long now)
>  {
> -	struct xen_platform_op op;
> +	struct timespec ts;
>  	int rc;
>  
>  	/* do nothing for domU */
> @@ -218,12 +232,9 @@ static int xen_set_wallclock(unsigned long now)
>  	 * update_persistent_wallclock() is called ~500 ms after 'now'
>  	 * so add an extra 500 ms.
>  	 */
> -	op.cmd = XENPF_settime;
> -	op.u.settime.secs = now;
> -	op.u.settime.nsecs = NSEC_PER_SEC / 2;
> -	op.u.settime.system_time = xen_clocksource_read();
> -
> -	rc = HYPERVISOR_dom0_op(&op);
> +	ts.tv_sec = now;
> +	ts.tv_nsec = NSEC_PER_SEC / 2;
> +	rc = xen_write_wallclock(&ts);
>  	WARN(rc != 0, "XENPF_settime failed: now=%ld\n", now);
>  
>  	return rc;
> diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
> index ccee0f1..ed2caf3 100644
> --- a/drivers/xen/privcmd.c
> +++ b/drivers/xen/privcmd.c
> @@ -338,6 +338,14 @@ out:
>  	return ret;
>  }
>  
> +static long privcmd_ioctl_sync_wallclock(void)
> +{
> +	struct timespec ts;
> +
> +	getnstimeofday(&ts);
> +	return xen_write_wallclock(&ts);
> +}
> +
>  static long privcmd_ioctl(struct file *file,
>  			  unsigned int cmd, unsigned long data)
>  {
> @@ -357,6 +365,10 @@ static long privcmd_ioctl(struct file *file,
>  		ret = privcmd_ioctl_mmap_batch(udata);
>  		break;
>  
> +	case IOCTL_PRIVCMD_SYNC_WALLCLOCK:
> +		ret = privcmd_ioctl_sync_wallclock();
> +		break;
> +
>  	default:
>  		ret = -EINVAL;
>  		break;
> diff --git a/include/xen/privcmd.h b/include/xen/privcmd.h
> index 17857fb..d17d087 100644
> --- a/include/xen/privcmd.h
> +++ b/include/xen/privcmd.h
> @@ -66,6 +66,12 @@ struct privcmd_mmapbatch {
>   * @cmd: IOCTL_PRIVCMD_HYPERCALL
>   * @arg: &privcmd_hypercall_t
>   * Return: Value returned from execution of the specified hypercall.
> + *
> + * @cmd: IOCTL_PRIVCMD_SYNC_WALLCLOCK
> + * @arg: Unused.
> + * Synchronizes the Xen wallclock with the current system time.
> + * Return: 0 on success, or -1 on error with errno set to EPERM or
> + * EACCES.
>   */
>  #define IOCTL_PRIVCMD_HYPERCALL					\
>  	_IOC(_IOC_NONE, 'P', 0, sizeof(struct privcmd_hypercall))
> @@ -73,5 +79,7 @@ struct privcmd_mmapbatch {
>  	_IOC(_IOC_NONE, 'P', 2, sizeof(struct privcmd_mmap))
>  #define IOCTL_PRIVCMD_MMAPBATCH					\
>  	_IOC(_IOC_NONE, 'P', 3, sizeof(struct privcmd_mmapbatch))
> +#define IOCTL_PRIVCMD_SYNC_WALLCLOCK				\
> +	_IOC(_IOC_NONE, 'P', 5, 0)
>  
>  #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
> diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
> index 6a198e4..eefed22 100644
> --- a/include/xen/xen-ops.h
> +++ b/include/xen/xen-ops.h
> @@ -29,4 +29,6 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
>  			       unsigned long mfn, int nr,
>  			       pgprot_t prot, unsigned domid);
>  
> +int xen_write_wallclock(const struct timespec *ts);
> +
>  #endif /* INCLUDE_XEN_OPS_H */
> -- 
> 1.7.2.5
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
> 

  reply	other threads:[~2012-10-12 13:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-12 12:57 [PATCH 0/3] xen: fix various wallclock problems David Vrabel
2012-10-12 12:57 ` [PATCH 1/3] xen: sync the CMOS RTC as well as the Xen wallclock David Vrabel
2012-10-12 14:57   ` Konrad Rzeszutek Wilk
2012-10-12 16:13     ` David Vrabel
2012-10-12 12:57 ` [PATCH 2/3] xen: add correct 500 ms offset when setting " David Vrabel
2012-10-15  9:25   ` Ian Campbell
2012-10-15 12:21     ` David Vrabel
2012-10-15 12:27       ` Ian Campbell
2012-10-12 12:57 ` [PATCH 3/3] xen/privcmd: add IOCTL_PRIVCMD_SYNC_WALLCLOCK to sync Xen's wallclock David Vrabel
2012-10-12 13:41   ` Konrad Rzeszutek Wilk [this message]
2012-10-12 14:02     ` David Vrabel
2012-10-12 14:29       ` Konrad Rzeszutek Wilk
2012-10-12 14:59         ` David Vrabel
2012-10-12 15:02           ` Konrad Rzeszutek Wilk
2012-10-12 16:14             ` David Vrabel
2012-10-12 16:16               ` Konrad Rzeszutek Wilk
2012-10-12 16:30                 ` David Vrabel
2012-10-12 16:25 ` [PATCH 0/3] xen: fix various wallclock problems David Vrabel
2012-10-15  9:26   ` Ian Campbell
2012-10-15 12:23     ` David Vrabel

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=20121012134147.GA11778@phenom.dumpdata.com \
    --to=konrad@kernel.org \
    --cc=david.vrabel@citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=xen-devel@lists.xen.org \
    /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.