Migrate tsc values during migration
PATCH 1/2 Migrate tsc values during migration
Migrate the last TSC values for more accurate timekeeping during live migration
tools/libxc/xc_domain_restore.c +18 -0
@@ -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, intERROR ("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 )
tools/libxc/xc_domain_save.c +16 -0
@@ -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 ioPERROR ("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 ;
xen/arch/x86/hvm/hvm.c +6 -0
@@ -2385,6 +2385,12 @@ long do_hvm_op(unsigned long op, XEN_GUEif ( 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) )
xen/include/public/hvm/params.h +5 -1
@@ -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__ */
xen/include/xen/sched.h +3 -0
@@ -233,6 +233,9 @@ struct domainstruct 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
[email protected]
http://lists.xensource.com/xen-devel
tools/libxc/xc_domain_restore.c line 42
Quoted 11 lines
diff -r
f1508348ffabtools/libxc/xc_domain_restore.c
...tools/libxc/xc_domain_restore.c +6
-0+#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;
The "rdtscll" definition is buggy for __i386__ since sizeof "int" and "long" usually are 4 there.
-- Dexuan
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ben Guthro
Sent: 2008年6月5日 23:00
To: xen-devel; Dave Winchell
Subject: [Xen-devel] [PATCH 1/2] Migrate tsc values during migration
Migrate the last TSC values for more accurate timekeeping during live migration
Dexuan,
Thanks for catching this. How about this (taken from msr.h)?
#if defined(__i386__)
#define rdtscll(val) \__asm__ __volatile__("rdtsc" : "=A" (val)) #elif defined(__x86_64__)
#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)
#endif
thanks,
Dave
Quoted 32 lines · Dexuan
Quoted 8 lines
diff -r
f1508348ffabtools/libxc/xc_domain_restore.c
...tools/libxc/xc_domain_restore.c +6
-0+#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) +Quoted 5 lines
/* max mfn of the current host machine */
static unsigned longmax_mfn;
...The "rdtscll" definition is buggy for
__i386__since sizeof "int" and "long" usually are 4 there.-- Dexuan
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ben Guthro
Sent: 2008年6月5日 23:00
To: xen-devel; Dave Winchell
Subject: [Xen-devel] [PATCH 1/2] Migrate tsc values during migrationMigrate the last TSC values for more accurate timekeeping during live migration
Signed-off-by Dave Winchell <[email protected]>Signed-off-by Ben Guthro <[email protected]>