All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Guthro <bguthro@virtualiron.com>
To: xen-devel <xen-devel@lists.xensource.com>,
	Dave Winchell <dwinchell@virtualiron.com>
Subject: [PATCH 1/2] Migrate tsc values during migration
Date: Thu, 05 Jun 2008 10:59:59 -0400	[thread overview]
Message-ID: <4847FF6F.4090506@virtualiron.com> (raw)

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

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

Signed-off-by: Dave Winchell <dwinchell@virtualiron.com>
Signed-off-by: Ben Guthro <bguthro@virtualiron.com>

[-- Attachment #2: lm-migrate-tsc.patch --]
[-- Type: text/plain, Size: 4366 bytes --]

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.

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

             reply	other threads:[~2008-06-05 14:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-05 14:59 Ben Guthro [this message]
2008-06-06  2:42 ` [PATCH 1/2] Migrate tsc values during migration Cui, Dexuan
2008-06-06 14:49   ` Dave Winchell

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=4847FF6F.4090506@virtualiron.com \
    --to=bguthro@virtualiron.com \
    --cc=dwinchell@virtualiron.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.