Skip to content

Commit 409771d

Browse files
Stefano StabelliniJeremy Fitzhardinge
authored andcommitted
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>
1 parent 99ad198 commit 409771d

5 files changed

Lines changed: 66 additions & 22 deletions

File tree

‎arch/x86/xen/enlighten.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,6 @@ static const struct pv_init_ops xen_init_ops __initdata = {
935935
.patch = xen_patch,
936936
};
937937

938-
static const struct pv_time_ops xen_time_ops __initdata = {
939-
.sched_clock = xen_sched_clock,
940-
};
941-
942938
static const struct pv_cpu_ops xen_cpu_ops __initdata = {
943939
.cpuid = xen_cpuid,
944940

@@ -1076,21 +1072,14 @@ asmlinkage void __init xen_start_kernel(void)
10761072
/* Install Xen paravirt ops */
10771073
pv_info = xen_info;
10781074
pv_init_ops = xen_init_ops;
1079-
pv_time_ops = xen_time_ops;
10801075
pv_cpu_ops = xen_cpu_ops;
10811076
pv_apic_ops = xen_apic_ops;
10821077

10831078
x86_init.resources.memory_setup = xen_memory_setup;
10841079
x86_init.oem.arch_setup = xen_arch_setup;
10851080
x86_init.oem.banner = xen_banner;
10861081

1087-
x86_init.timers.timer_init = xen_time_init;
1088-
x86_init.timers.setup_percpu_clockev = x86_init_noop;
1089-
x86_cpuinit.setup_percpu_clockev = x86_init_noop;
1090-
1091-
x86_platform.calibrate_tsc = xen_tsc_khz;
1092-
x86_platform.get_wallclock = xen_get_wallclock;
1093-
x86_platform.set_wallclock = xen_set_wallclock;
1082+
xen_init_time_ops();
10941083

10951084
/*
10961085
* Set up some pagetable state before starting to set any ptes.
@@ -1327,6 +1316,7 @@ static void __init xen_hvm_guest_init(void)
13271316
register_cpu_notifier(&xen_hvm_cpu_notifier);
13281317
have_vcpu_info_placement = 0;
13291318
x86_init.irqs.intr_init = xen_init_IRQ;
1319+
xen_hvm_init_time_ops();
13301320
}
13311321

13321322
static bool __init xen_hvm_platform(void)

‎arch/x86/xen/suspend.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ void xen_pre_suspend(void)
2828

2929
void xen_hvm_post_suspend(int suspend_cancelled)
3030
{
31+
int cpu;
3132
xen_hvm_init_shared_info();
3233
xen_callback_vector();
34+
if (xen_feature(XENFEAT_hvm_safe_pvclock)) {
35+
for_each_online_cpu(cpu) {
36+
xen_setup_runstate_info(cpu);
37+
}
38+
}
3339
}
3440

3541
void xen_post_suspend(int suspend_cancelled)

‎arch/x86/xen/time.c‎

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <asm/xen/hypercall.h>
2121

2222
#include <xen/events.h>
23+
#include <xen/features.h>
2324
#include <xen/interface/xen.h>
2425
#include <xen/interface/vcpu.h>
2526

@@ -160,7 +161,7 @@ static void do_stolen_accounting(void)
160161
* nanoseconds, which is nanoseconds the VCPU spent in RUNNING+BLOCKED
161162
* states.
162163
*/
163-
unsigned long long xen_sched_clock(void)
164+
static unsigned long long xen_sched_clock(void)
164165
{
165166
struct vcpu_runstate_info state;
166167
cycle_t now;
@@ -195,7 +196,7 @@ unsigned long long xen_sched_clock(void)
195196

196197

197198
/* Get the TSC speed from Xen */
198-
unsigned long xen_tsc_khz(void)
199+
static unsigned long xen_tsc_khz(void)
199200
{
200201
struct pvclock_vcpu_time_info *info =
201202
&HYPERVISOR_shared_info->vcpu_info[0].time;
@@ -230,15 +231,15 @@ static void xen_read_wallclock(struct timespec *ts)
230231
put_cpu_var(xen_vcpu);
231232
}
232233

233-
unsigned long xen_get_wallclock(void)
234+
static unsigned long xen_get_wallclock(void)
234235
{
235236
struct timespec ts;
236237

237238
xen_read_wallclock(&ts);
238239
return ts.tv_sec;
239240
}
240241

241-
int xen_set_wallclock(unsigned long now)
242+
static int xen_set_wallclock(unsigned long now)
242243
{
243244
/* do nothing for domU */
244245
return -1;
@@ -473,7 +474,11 @@ void xen_timer_resume(void)
473474
}
474475
}
475476

476-
__init void xen_time_init(void)
477+
static const struct pv_time_ops xen_time_ops __initdata = {
478+
.sched_clock = xen_sched_clock,
479+
};
480+
481+
static __init void xen_time_init(void)
477482
{
478483
int cpu = smp_processor_id();
479484
struct timespec tp;
@@ -497,3 +502,46 @@ __init void xen_time_init(void)
497502
xen_setup_timer(cpu);
498503
xen_setup_cpu_clockevents();
499504
}
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+
519+
static 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+

‎arch/x86/xen/xen-ops.h‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ void xen_setup_runstate_info(int cpu);
4949
void xen_teardown_timer(int cpu);
5050
cycle_t xen_clocksource_read(void);
5151
void xen_setup_cpu_clockevents(void);
52-
unsigned long xen_tsc_khz(void);
53-
void __init xen_time_init(void);
54-
unsigned long xen_get_wallclock(void);
55-
int xen_set_wallclock(unsigned long time);
56-
unsigned long long xen_sched_clock(void);
52+
void __init xen_init_time_ops(void);
53+
void __init xen_hvm_init_time_ops(void);
5754

5855
irqreturn_t xen_debug_interrupt(int irq, void *dev_id);
5956

‎include/xen/interface/features.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
/* x86: Does this Xen host support the HVM callback vector type? */
4545
#define XENFEAT_hvm_callback_vector 8
4646

47+
/* x86: pvclock algorithm is safe to use on HVM */
48+
#define XENFEAT_hvm_safe_pvclock 9
49+
4750
#define XENFEAT_NR_SUBMAPS 1
4851

4952
#endif /* __XEN_PUBLIC_FEATURES_H__ */

0 commit comments

Comments
 (0)