Skip to content

Commit

Permalink
x86/xen/time: Output xen sched_clock time from 0
Browse files Browse the repository at this point in the history
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 <pasha.tatashin@oracle.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: steven.sistare@oracle.com
Cc: daniel.m.jordan@oracle.com
Cc: linux@armlinux.org.uk
Cc: schwidefsky@de.ibm.com
Cc: heiko.carstens@de.ibm.com
Cc: john.stultz@linaro.org
Cc: sboyd@codeaurora.org
Cc: hpa@zytor.com
Cc: douly.fnst@cn.fujitsu.com
Cc: peterz@infradead.org
Cc: prarit@redhat.com
Cc: feng.tang@intel.com
Cc: pmladek@suse.com
Cc: gnomes@lxorguk.ukuu.org.uk
Cc: linux-s390@vger.kernel.org
Cc: boris.ostrovsky@oracle.com
Cc: jgross@suse.com
Cc: pbonzini@redhat.com
Link: https://lkml.kernel.org/r/20180719205545.16512-14-pasha.tatashin@oracle.com
  • Loading branch information
Pavel Tatashin authored and Thomas Gleixner committed Jul 19, 2018
1 parent 7b25b9c commit 38669ba
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion arch/x86/xen/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
/* Xen may fire a timer up to this many ns early */
#define TIMER_SLOP 100000

static u64 xen_sched_clock_offset __read_mostly;

/* Get the TSC speed from Xen */
static unsigned long xen_tsc_khz(void)
{
Expand All @@ -57,6 +59,11 @@ static u64 xen_clocksource_get_cycles(struct clocksource *cs)
return xen_clocksource_read();
}

static u64 xen_sched_clock(void)
{
return xen_clocksource_read() - xen_sched_clock_offset;
}

static void xen_read_wallclock(struct timespec64 *ts)
{
struct shared_info *s = HYPERVISOR_shared_info;
Expand Down Expand Up @@ -367,7 +374,7 @@ void xen_timer_resume(void)
}

static const struct pv_time_ops xen_time_ops __initconst = {
.sched_clock = xen_clocksource_read,
.sched_clock = xen_sched_clock,
.steal_clock = xen_steal_clock,
};

Expand Down Expand Up @@ -505,6 +512,7 @@ static void __init xen_time_init(void)

void __init xen_init_time_ops(void)
{
xen_sched_clock_offset = xen_clocksource_read();
pv_time_ops = xen_time_ops;

x86_init.timers.timer_init = xen_time_init;
Expand Down Expand Up @@ -546,6 +554,7 @@ void __init xen_hvm_init_time_ops(void)
return;
}

xen_sched_clock_offset = xen_clocksource_read();
pv_time_ops = xen_time_ops;
x86_init.timers.setup_percpu_clockev = xen_time_init;
x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
Expand Down

0 comments on commit 38669ba

Please sign in to comment.