aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/xen/time.c
diff options
context:
space:
mode:
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>2010-05-14 07:48:19 -0400
committerJeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>2010-07-27 02:13:25 -0400
commit409771d258e9dd71c30f3c9520fd2b796ffc40f0 (patch)
tree68678275563114e9d381ae587fc80bd4d34a7e90 /arch/x86/xen/time.c
parent99ad198c4978036bb9f7ebd11618b225b77046da (diff)
x86: Use xen_vcpuop_clockevent, xen_clocksource and xen wallclock.
Use xen_vcpuop_clockevent instead of hpet and APIC timers as main clockevent device on all vcpus, use the xen wallclock time as wallclock instead of rtc and use xen_clocksource as clocksource. The pv clock algorithm needs to work correctly for the xen_clocksource and xen wallclock to be usable, only modern Xen versions offer a reliable pv clock in HVM guests (XENFEAT_hvm_safe_pvclock). Using the hpet as clocksource means a VMEXIT every time we read/write to the hpet mmio addresses, pvclock give us a better rating without VMEXITs. Same goes for the xen wallclock and xen_vcpuop_clockevent Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Don Dutile <ddutile@redhat.com> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Diffstat (limited to 'arch/x86/xen/time.c')
-rw-r--r--arch/x86/xen/time.c58
1 files changed, 53 insertions, 5 deletions
diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
index b3c6c59ed30..4780e55886a 100644
--- a/arch/x86/xen/time.c
+++ b/arch/x86/xen/time.c
@@ -20,6 +20,7 @@
20#include <asm/xen/hypercall.h> 20#include <asm/xen/hypercall.h>
21 21
22#include <xen/events.h> 22#include <xen/events.h>
23#include <xen/features.h>
23#include <xen/interface/xen.h> 24#include <xen/interface/xen.h>
24#include <xen/interface/vcpu.h> 25#include <xen/interface/vcpu.h>
25 26
@@ -160,7 +161,7 @@ static void do_stolen_accounting(void)
160 * nanoseconds, which is nanoseconds the VCPU spent in RUNNING+BLOCKED 161 * nanoseconds, which is nanoseconds the VCPU spent in RUNNING+BLOCKED
161 * states. 162 * states.
162 */ 163 */
163unsigned long long xen_sched_clock(void) 164static unsigned long long xen_sched_clock(void)
164{ 165{
165 struct vcpu_runstate_info state; 166 struct vcpu_runstate_info state;
166 cycle_t now; 167 cycle_t now;
@@ -195,7 +196,7 @@ unsigned long long xen_sched_clock(void)
195 196
196 197
197/* Get the TSC speed from Xen */ 198/* Get the TSC speed from Xen */
198unsigned long xen_tsc_khz(void) 199static unsigned long xen_tsc_khz(void)
199{ 200{
200 struct pvclock_vcpu_time_info *info = 201 struct pvclock_vcpu_time_info *info =
201 &HYPERVISOR_shared_info->vcpu_info[0].time; 202 &HYPERVISOR_shared_info->vcpu_info[0].time;
@@ -230,7 +231,7 @@ static void xen_read_wallclock(struct timespec *ts)
230 put_cpu_var(xen_vcpu); 231 put_cpu_var(xen_vcpu);
231} 232}
232 233
233unsigned long xen_get_wallclock(void) 234static unsigned long xen_get_wallclock(void)
234{ 235{
235 struct timespec ts; 236 struct timespec ts;
236 237
@@ -238,7 +239,7 @@ unsigned long xen_get_wallclock(void)
238 return ts.tv_sec; 239 return ts.tv_sec;
239} 240}
240 241
241int xen_set_wallclock(unsigned long now) 242static int xen_set_wallclock(unsigned long now)
242{ 243{
243 /* do nothing for domU */ 244 /* do nothing for domU */
244 return -1; 245 return -1;
@@ -473,7 +474,11 @@ void xen_timer_resume(void)
473 } 474 }
474} 475}
475 476
476__init void xen_time_init(void) 477static const struct pv_time_ops xen_time_ops __initdata = {
478 .sched_clock = xen_sched_clock,
479};
480
481static __init void xen_time_init(void)
477{ 482{
478 int cpu = smp_processor_id(); 483 int cpu = smp_processor_id();
479 struct timespec tp; 484 struct timespec tp;
@@ -497,3 +502,46 @@ __init void xen_time_init(void)
497 xen_setup_timer(cpu); 502 xen_setup_timer(cpu);
498 xen_setup_cpu_clockevents(); 503 xen_setup_cpu_clockevents();
499} 504}
505
506__init void xen_init_time_ops(void)
507{
508 pv_time_ops = xen_time_ops;
509
510 x86_init.timers.timer_init = xen_time_init;
511 x86_init.timers.setup_percpu_clockev = x86_init_noop;
512 x86_cpuinit.setup_percpu_clockev = x86_init_noop;
513
514 x86_platform.calibrate_tsc = xen_tsc_khz;
515 x86_platform.get_wallclock = xen_get_wallclock;
516 x86_platform.set_wallclock = xen_set_wallclock;
517}
518
519static void xen_hvm_setup_cpu_clockevents(void)
520{
521 int cpu = smp_processor_id();
522 xen_setup_runstate_info(cpu);
523 xen_setup_timer(cpu);
524 xen_setup_cpu_clockevents();
525}
526
527__init void xen_hvm_init_time_ops(void)
528{
529 /* vector callback is needed otherwise we cannot receive interrupts
530 * on cpu > 0 */
531 if (!xen_have_vector_callback && num_present_cpus() > 1)
532 return;
533 if (!xen_feature(XENFEAT_hvm_safe_pvclock)) {
534 printk(KERN_INFO "Xen doesn't support pvclock on HVM,"
535 "disable pv timer\n");
536 return;
537 }
538
539 pv_time_ops = xen_time_ops;
540 x86_init.timers.setup_percpu_clockev = xen_time_init;
541 x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
542
543 x86_platform.calibrate_tsc = xen_tsc_khz;
544 x86_platform.get_wallclock = xen_get_wallclock;
545 x86_platform.set_wallclock = xen_set_wallclock;
546}
547