[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 3/3] xen/privcmd: add IOCTL_PRIVCMD_SYNC_WALLCLOCK to sync Xen's wallclock



From: David Vrabel <david.vrabel@xxxxxxxxxx>

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.

Signed-off-by: David Vrabel <david.vrabel@xxxxxxxxxx>
---
 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@xxxxxxxxxxxxx>, 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@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.