From: "Dan Magenheimer" <dan.magenheimer@oracle.com>
To: "Xen-Devel (E-mail)" <xen-devel@lists.xensource.com>,
Keir Fraser <Keir.Fraser@eu.citrix.com>,
"dan.magenheimer@oracle.com" <dan.magenheimer@oracle.com>
Cc: Dave Winchell <dwinchell@virtualiron.com>
Subject: [PATCH] clocksource=tsc
Date: Sat, 12 Jul 2008 15:38:24 -0600 [thread overview]
Message-ID: <20080712153824937.00000080236@djm-pc> (raw)
[-- Attachment #1: Type: text/plain, Size: 817 bytes --]
Attached patch adds clocksource=tsc boot option that
uses TSC as clocksource. This option should only be
used on machines where TSC is known to be synchronized
across all processors. A future TODO is to dynamically
determine if this is the case.
TSC may "beat" with another clocksource, resulting in
cross-processor Xen system time skew. This skew can
be visible in PV guests and can appear as "time is stopped"
in hvm guests. On some systems, this patch can reduce skew
by 30x or more.
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
===================================
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: tscstable.patch --]
[-- Type: application/octet-stream, Size: 4654 bytes --]
diff -r bd97e45e073a xen/arch/x86/time.c
--- a/xen/arch/x86/time.c Tue Jul 08 09:28:50 2008 +0100
+++ b/xen/arch/x86/time.c Sat Jul 12 14:58:44 2008 -0600
@@ -452,6 +452,24 @@ static int init_pmtimer(struct platform_
}
/************************************************************
+ * PLATFORM TIMER 4: TSC
+ */
+
+static bool_t clocksource_is_tsc = 0;
+static u64 tsc_freq;
+
+static int init_tsctimer(struct platform_timesource *pts)
+{
+ /* TODO: evaluate stability of TSC here, return 0 if not stable */
+ pts->name = "TSC";
+ pts->frequency = tsc_freq;
+ pts->read_counter = 0; /* unused as of now */
+ pts->counter_bits = 64;
+ clocksource_is_tsc = 1;
+ return 1;
+}
+
+/************************************************************
* GENERIC PLATFORM TIMER INFRASTRUCTURE
*/
@@ -483,16 +501,28 @@ static void plt_overflow(void *unused)
static s_time_t __read_platform_stime(u64 platform_time)
{
- u64 diff = platform_time - platform_timer_stamp;
+ u64 diff, tsc;
+
+ if ( clocksource_is_tsc )
+ {
+ rdtscll(tsc);
+ return scale_delta(tsc, &plt_scale);
+ }
+ diff = platform_time - platform_timer_stamp;
ASSERT(spin_is_locked(&platform_timer_lock));
return (stime_platform_stamp + scale_delta(diff, &plt_scale));
}
static s_time_t read_platform_stime(void)
{
- u64 count;
+ u64 count, tsc;
s_time_t stime;
+ if ( clocksource_is_tsc )
+ {
+ rdtscll(tsc);
+ return scale_delta(tsc, &plt_scale);
+ }
spin_lock(&platform_timer_lock);
count = plt_stamp64 + ((plt_src.read_counter() - plt_stamp) & plt_mask);
stime = __read_platform_stime(count);
@@ -506,6 +536,8 @@ static void platform_time_calibration(vo
u64 count;
s_time_t stamp;
+ if ( clocksource_is_tsc )
+ return;
spin_lock(&platform_timer_lock);
count = plt_stamp64 + ((plt_src.read_counter() - plt_stamp) & plt_mask);
stamp = __read_platform_stime(count);
@@ -516,6 +548,8 @@ static void platform_time_calibration(vo
static void resume_platform_timer(void)
{
+ if ( clocksource_is_tsc )
+ return;
/* No change in platform_stime across suspend/resume. */
platform_timer_stamp = plt_stamp64;
plt_stamp = plt_src.read_counter();
@@ -536,6 +570,8 @@ static void init_platform_timer(void)
rc = init_cyclone(pts);
else if ( !strcmp(opt_clocksource, "acpi") )
rc = init_pmtimer(pts);
+ else if ( !strcmp(opt_clocksource, "tsc") )
+ rc = init_tsctimer(pts);
if ( rc <= 0 )
printk("WARNING: %s clocksource '%s'.\n",
@@ -549,16 +585,20 @@ static void init_platform_timer(void)
!init_pmtimer(pts) )
init_pit(pts);
- plt_mask = (u32)~0u >> (32 - pts->counter_bits);
-
set_time_scale(&plt_scale, pts->frequency);
- plt_overflow_period = scale_delta(
- 1ull << (pts->counter_bits-1), &plt_scale);
- init_timer(&plt_overflow_timer, plt_overflow, NULL, 0);
- plt_overflow(NULL);
+ if (pts->counter_bits != 64 )
+ {
+ plt_mask = (u32)~0u >> (32 - pts->counter_bits);
- platform_timer_stamp = plt_stamp64;
+ plt_overflow_period = scale_delta(
+ 1ull << (pts->counter_bits-1), &plt_scale);
+ init_timer(&plt_overflow_timer, plt_overflow, NULL, 0);
+ plt_overflow(NULL);
+
+ platform_timer_stamp = plt_stamp64;
+ }
+
printk("Platform timer is %s %s\n",
freq_string(pts->frequency), pts->name);
@@ -580,7 +620,8 @@ void cstate_restore_tsc(void)
u32 plt_count_delta;
u64 tsc_delta;
- if (!tsc_invariant){
+ if ( !tsc_invariant && !clocksource_is_tsc )
+ {
t = &this_cpu(cpu_time);
/* if platform counter overflow happens, interrupt will bring CPU from
@@ -687,14 +728,18 @@ static unsigned long get_cmos_time(void)
s_time_t get_s_time(void)
{
- struct cpu_time *t = &this_cpu(cpu_time);
+ struct cpu_time *t;
u64 tsc, delta;
s_time_t now;
rdtscll(tsc);
- delta = tsc - t->local_tsc_stamp;
- now = t->stime_local_stamp + scale_delta(delta, &t->tsc_scale);
-
+ if ( clocksource_is_tsc )
+ now = scale_delta(tsc, &plt_scale);
+ else {
+ t = &this_cpu(cpu_time);
+ delta = tsc - t->local_tsc_stamp;
+ now = t->stime_local_stamp + scale_delta(delta, &t->tsc_scale);
+ }
return now;
}
@@ -996,6 +1041,7 @@ void __init early_time_init(void)
{
u64 tmp = init_pit_and_calibrate_tsc();
+ tsc_freq = tmp;
set_time_scale(&this_cpu(cpu_time).tsc_scale, tmp);
do_div(tmp, 1000);
[-- 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-07-12 21:38 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-12 21:38 Dan Magenheimer [this message]
2008-07-13 3:59 ` [PATCH] clocksource=tsc Dan Magenheimer
2008-07-14 9:24 ` Keir Fraser
2008-07-14 17:59 ` Dan Magenheimer
2008-07-15 0:35 ` Tian, Kevin
2008-07-17 23:47 ` Dan Magenheimer
2008-07-15 13:05 ` Keir Fraser
2008-07-15 14:44 ` Dan Magenheimer
2008-07-15 15:08 ` Keir Fraser
2008-07-15 15:46 ` Dan Magenheimer
2008-07-15 16:04 ` Dan Magenheimer
2008-07-16 1:15 ` Dan Magenheimer
2008-07-16 4:11 ` Dan Magenheimer
2008-07-16 12:43 ` Dan Magenheimer
2008-07-16 12:49 ` Keir Fraser
2008-07-16 13:43 ` Dan Magenheimer
2008-07-16 15:42 ` Dan Magenheimer
2008-07-16 19:32 ` Keir Fraser
2008-07-17 23:05 ` Dan Magenheimer
2008-07-18 7:24 ` Keir Fraser
2008-07-18 11:01 ` Keir Fraser
2008-07-18 11:10 ` Keir Fraser
2008-07-18 14:19 ` Dan Magenheimer
2008-07-18 14:29 ` Keir Fraser
2008-07-18 14:56 ` Dan Magenheimer
2008-07-18 15:00 ` Keir Fraser
2008-07-18 16:51 ` Dan Magenheimer
2008-07-18 19:28 ` 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=20080712153824937.00000080236@djm-pc \
--to=dan.magenheimer@oracle.com \
--cc=Keir.Fraser@eu.citrix.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.