Skip to content

Commit 38669ba

Browse files
Pavel TatashinKAGA-KOKO
authored andcommitted
x86/xen/time: Output xen sched_clock time from 0
It is expected for sched_clock() to output data from 0, when system boots. Add an offset xen_sched_clock_offset (similarly how it is done in other hypervisors i.e. kvm_sched_clock_offset) to count sched_clock() from 0, when time is first initialized. Signed-off-by: Pavel Tatashin <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 7b25b9c commit 38669ba

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arch/x86/xen/time.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
/* Xen may fire a timer up to this many ns early */
3232
#define TIMER_SLOP 100000
3333

34+
static u64 xen_sched_clock_offset __read_mostly;
35+
3436
/* Get the TSC speed from Xen */
3537
static unsigned long xen_tsc_khz(void)
3638
{
@@ -57,6 +59,11 @@ static u64 xen_clocksource_get_cycles(struct clocksource *cs)
5759
return xen_clocksource_read();
5860
}
5961

62+
static u64 xen_sched_clock(void)
63+
{
64+
return xen_clocksource_read() - xen_sched_clock_offset;
65+
}
66+
6067
static void xen_read_wallclock(struct timespec64 *ts)
6168
{
6269
struct shared_info *s = HYPERVISOR_shared_info;
@@ -367,7 +374,7 @@ void xen_timer_resume(void)
367374
}
368375

369376
static const struct pv_time_ops xen_time_ops __initconst = {
370-
.sched_clock = xen_clocksource_read,
377+
.sched_clock = xen_sched_clock,
371378
.steal_clock = xen_steal_clock,
372379
};
373380

@@ -505,6 +512,7 @@ static void __init xen_time_init(void)
505512

506513
void __init xen_init_time_ops(void)
507514
{
515+
xen_sched_clock_offset = xen_clocksource_read();
508516
pv_time_ops = xen_time_ops;
509517

510518
x86_init.timers.timer_init = xen_time_init;
@@ -546,6 +554,7 @@ void __init xen_hvm_init_time_ops(void)
546554
return;
547555
}
548556

557+
xen_sched_clock_offset = xen_clocksource_read();
549558
pv_time_ops = xen_time_ops;
550559
x86_init.timers.setup_percpu_clockev = xen_time_init;
551560
x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;

0 commit comments

Comments
 (0)