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

[Xen-devel] [PATCH 1/2] Migrate tsc values during migration



Migrate the last TSC values for more accurate timekeeping during live migration

Signed-off-by: Dave Winchell <dwinchell@xxxxxxxxxxxxxxx>
Signed-off-by: Ben Guthro <bguthro@xxxxxxxxxxxxxxx>
diff -r f1508348ffab tools/libxc/xc_domain_restore.c
--- a/tools/libxc/xc_domain_restore.c   Mon Jun 02 11:35:39 2008 +0900
+++ b/tools/libxc/xc_domain_restore.c   Mon Jun 02 17:04:46 2008 -0400
@@ -32,6 +32,12 @@
 #include <xen/hvm/ioreq.h>
 #include <xen/hvm/params.h>
 
+#define rdtscll(val) do { \
+     unsigned int a,d; \
+     asm volatile("rdtsc" : "=a" (a), "=d" (d)); \
+     (val) = ((unsigned long)a) | (((unsigned long)d)<<32); \
+} while(0)
+
 /* max mfn of the current host machine */
 static unsigned long max_mfn;
 
@@ -327,6 +333,8 @@ int xc_domain_restore(int xc_handle, int
     /* Buffer for holding HVM context */
     uint8_t *hvm_buf = NULL;
 
+    uint64_t last_tsc, cur_tsc;
+
     /* For info only */
     nr_pfns = 0;
 
@@ -738,6 +746,16 @@ int xc_domain_restore(int xc_handle, int
             ERROR("error loading the HVM context");
             goto out;
         }
+
+        if ( read_exact(io_fd, &last_tsc, sizeof(last_tsc)) )
+        {
+            ERROR("error loading the last_tsc");
+            goto out;
+        }
+
+       rdtscll(cur_tsc);
+        xc_set_hvm_param(xc_handle, dom, HVM_PARAM_MIG_LAST_TSC, last_tsc);
+        xc_set_hvm_param(xc_handle, dom, HVM_PARAM_MIG_CUR_TSC, cur_tsc);
         
         frc = xc_domain_hvm_setcontext(xc_handle, dom, hvm_buf, rec_len);
         if ( frc )
diff -r f1508348ffab tools/libxc/xc_domain_save.c
--- a/tools/libxc/xc_domain_save.c      Mon Jun 02 11:35:39 2008 +0900
+++ b/tools/libxc/xc_domain_save.c      Mon Jun 02 17:04:14 2008 -0400
@@ -29,6 +29,12 @@
 */
 #define DEF_MAX_ITERS   29   /* limit us to 30 times round loop   */
 #define DEF_MAX_FACTOR   3   /* never send more than 3x p2m_size  */
+
+#define rdtscll(val) do { \
+     unsigned int a,d; \
+     asm volatile("rdtsc" : "=a" (a), "=d" (d)); \
+     (val) = ((unsigned long)a) | (((unsigned long)d)<<32); \
+} while(0)
 
 /* max mfn of the whole machine */
 static unsigned long max_mfn;
@@ -845,6 +851,8 @@ int xc_domain_save(int xc_handle, int io
     /* HVM: a buffer for holding HVM context */
     uint32_t hvm_buf_size = 0;
     uint8_t *hvm_buf = NULL;
+
+    uint64_t last_tsc;
 
     /* HVM: magic frames for ioreqs and xenstore comms. */
     uint64_t magic_pfns[3]; /* ioreq_pfn, bufioreq_pfn, store_pfn */
@@ -1474,6 +1482,14 @@ int xc_domain_save(int xc_handle, int io
             PERROR("write HVM info failed!\n");
             goto out;
         }
+
+        rdtscll(last_tsc);
+        if ( write_exact(io_fd, &last_tsc, sizeof(last_tsc)) )
+        {
+            PERROR("error write last_tsc");
+            goto out;
+        }
+
         
         /* HVM guests are done now */
         rc = 0;
diff -r f1508348ffab xen/arch/x86/hvm/hvm.c
--- a/xen/arch/x86/hvm/hvm.c    Mon Jun 02 11:35:39 2008 +0900
+++ b/xen/arch/x86/hvm/hvm.c    Mon Jun 02 17:08:16 2008 -0400
@@ -2385,6 +2385,12 @@ long do_hvm_op(unsigned long op, XEN_GUE
                 if ( a.value > HVMPTM_one_missed_tick_pending )
                     rc = -EINVAL;
                 break;
+            case HVM_PARAM_MIG_LAST_TSC:
+                d->last_tsc_sender = a.value;
+                break;
+            case HVM_PARAM_MIG_CUR_TSC:
+                d->first_tsc_receiver = a.value;
+                break;
             case HVM_PARAM_IDENT_PT:
                 rc = -EPERM;
                 if ( !IS_PRIV(current->domain) )
diff -r f1508348ffab xen/include/public/hvm/params.h
--- a/xen/include/public/hvm/params.h   Mon Jun 02 11:35:39 2008 +0900
+++ b/xen/include/public/hvm/params.h   Mon Jun 02 17:18:14 2008 -0400
@@ -93,6 +93,10 @@
 /* ACPI S state: currently support S0 and S3 on x86. */
 #define HVM_PARAM_ACPI_S_STATE 14
 
-#define HVM_NR_PARAMS          15
+/* Migrate uses these to allow hpet load time compensation. */
+#define HVM_PARAM_MIG_LAST_TSC 15
+#define HVM_PARAM_MIG_CUR_TSC  16
+
+#define HVM_NR_PARAMS          17
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
diff -r f1508348ffab xen/include/xen/sched.h
--- a/xen/include/xen/sched.h   Mon Jun 02 11:35:39 2008 +0900
+++ b/xen/include/xen/sched.h   Mon Jun 02 17:09:46 2008 -0400
@@ -233,6 +233,9 @@ struct domain
 
     struct rcu_head rcu;
 
+    unsigned long last_tsc_sender;
+    unsigned long first_tsc_receiver;
+
     /*
      * Hypercall deadlock avoidance lock. Used if a hypercall might
      * cause a deadlock. Acquirers don't spin waiting; they preempt.
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

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