From: "Dan Magenheimer" <dan.magenheimer@oracle.com>
To: "Xen-Devel (E-mail)" <xen-devel@lists.xensource.com>
Subject: [PATCH] [RFC] Building guests on monotonic Xen system time
Date: Fri, 16 May 2008 11:31:01 -0600 [thread overview]
Message-ID: <20080516113101500.00000002648@djm-pc> (raw)
[-- Attachment #1: Type: text/plain, Size: 1344 bytes --]
Currently, hvm guest platform timers are built on top of the tsc.
Even though the guest believes it is utilizing a monotonic timesource
(such as pit, hpet, or pmtimer), all of these plumb down to an
rdtsc instruction.
Since on many SMP platforms tsc's in different processors are not
synchronized, VMs re-scheduled from a "fast tsc" processor to
a "slow tsc" processor may experience "time going backwards".
This is discussed in the following thread:
http://lists.xensource.com/archives/html/xen-devel/2008-04/msg00277.html
The fix proposed by Keir is that "The logic in vpt.c should
be fixed to use Xen's concept of system time and everything,
guest TSC included, should be derived from that."
The attached patch is a first attempt to derive all
guest timers from Xen's system time... and also to ensure
that system time is non-decreasing. I don't believe the
patch is complete... and possibly not even correct.
For example, I'm concerned that Xen's system time uses
different units than a guest tsc and I don't recall if
all guest tsc accesses are trapped.
Dan
===================================
Thanks... for the memory
I really could use more / My throughput's on the floor
The balloon is flat / My swap disk's fat / I've OOM's in store
Overcommitted so much
(with apologies to the late great Bob Hope)
[-- Attachment #2: hvmstime.patch --]
[-- Type: application/octet-stream, Size: 2977 bytes --]
diff -r e3b13e1ecf6c xen/arch/x86/hvm/hvm.c
--- a/xen/arch/x86/hvm/hvm.c Thu May 15 15:10:05 2008 +0100
+++ b/xen/arch/x86/hvm/hvm.c Thu May 15 17:10:09 2008 -0600
@@ -31,6 +31,7 @@
#include <xen/hypercall.h>
#include <xen/guest_access.h>
#include <xen/event.h>
+#include <xen/time.h>
#include <asm/current.h>
#include <asm/e820.h>
#include <asm/io.h>
@@ -136,9 +137,7 @@ uint8_t hvm_combine_hw_exceptions(uint8_
void hvm_set_guest_tsc(struct vcpu *v, u64 guest_tsc)
{
- u64 host_tsc;
-
- rdtscll(host_tsc);
+ u64 host_tsc = (u64)get_s_time_mono();
v->arch.hvm_vcpu.cache_tsc_offset = guest_tsc - host_tsc;
hvm_funcs.set_tsc_offset(v, v->arch.hvm_vcpu.cache_tsc_offset);
@@ -146,9 +145,8 @@ void hvm_set_guest_tsc(struct vcpu *v, u
u64 hvm_get_guest_tsc(struct vcpu *v)
{
- u64 host_tsc;
+ u64 host_tsc = (u64)get_s_time_mono();
- rdtscll(host_tsc);
return host_tsc + v->arch.hvm_vcpu.cache_tsc_offset;
}
diff -r e3b13e1ecf6c xen/arch/x86/time.c
--- a/xen/arch/x86/time.c Thu May 15 15:10:05 2008 +0100
+++ b/xen/arch/x86/time.c Thu May 15 17:10:09 2008 -0600
@@ -535,6 +535,8 @@ static s_time_t read_platform_stime(void
return stime;
}
+extern void get_s_time_mono_init(void);
+
static void platform_time_calibration(void)
{
u64 count;
@@ -593,6 +595,7 @@ static void init_platform_timer(void)
plt_overflow(NULL);
platform_timer_stamp = plt_stamp64;
+ get_s_time_mono_init();
printk("Platform timer is %s %s\n",
freq_string(pts->frequency), pts->name);
@@ -728,6 +731,29 @@ s_time_t get_s_time(void)
rdtscll(tsc);
delta = tsc - t->local_tsc_stamp;
now = t->stime_local_stamp + scale_delta(delta, &t->tsc_scale);
+
+ return now;
+}
+
+spinlock_t get_s_time_mono_lock;
+
+void get_s_time_mono_init(void)
+{
+ spin_lock_init(&get_s_time_mono_lock);
+}
+
+s_time_t get_s_time_mono(void)
+{
+ s_time_t now;
+ static s_time_t last = (s_time_t)0;
+
+ spin_lock(&get_s_time_mono_lock);
+ now = get_s_time();
+ if (now > last)
+ last = now;
+ else
+ now = last;
+ spin_unlock(&get_s_time_mono_lock);
return now;
}
diff -r e3b13e1ecf6c xen/include/xen/time.h
--- a/xen/include/xen/time.h Thu May 15 15:10:05 2008 +0100
+++ b/xen/include/xen/time.h Thu May 15 17:10:09 2008 -0600
@@ -24,6 +24,8 @@ struct domain;
* System Time
* 64 bit value containing the nanoseconds elapsed since boot time.
* This value is adjusted by frequency drift.
+ * mono version guarantees that consecutive reads are non-decreasing,
+ * (e.g. when first read is on a different processor than second read)
* NOW() returns the current time.
* The other macros are for convenience to approximate short intervals
* of real time into system time
@@ -32,6 +34,7 @@ typedef s64 s_time_t;
typedef s64 s_time_t;
s_time_t get_s_time(void);
+s_time_t get_s_time_mono(void);
unsigned long get_localtime(struct domain *d);
struct tm {
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next reply other threads:[~2008-05-16 17:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-16 17:31 Dan Magenheimer [this message]
2008-05-19 18:27 ` [PATCH] [RFC] Building guests on monotonic Xen system time Dan Magenheimer
2008-05-20 0:56 ` Dan Magenheimer
2008-05-20 7:36 ` Keir Fraser
2008-05-21 19:01 ` Dan Magenheimer
2008-05-22 8:46 ` Keir Fraser
2008-05-22 16:05 ` Dan Magenheimer
2008-05-22 16:11 ` Keir Fraser
2008-05-23 22:44 ` Dan Magenheimer
2008-05-24 7:34 ` Keir Fraser
2008-06-03 19:47 ` Dan Magenheimer
2008-06-03 21:10 ` Keir Fraser
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=20080516113101500.00000002648@djm-pc \
--to=dan.magenheimer@oracle.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.