xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
/*
|
|
|
|
* Xen time implementation.
|
|
|
|
*
|
|
|
|
* This is implemented in terms of a clocksource driver which uses
|
|
|
|
* the hypervisor clock as a nanosecond timebase, and a clockevent
|
|
|
|
* driver which uses the hypervisor's timer mechanism.
|
|
|
|
*
|
|
|
|
* Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/clocksource.h>
|
|
|
|
#include <linux/clockchips.h>
|
2007-07-18 08:37:05 +07:00
|
|
|
#include <linux/kernel_stat.h>
|
2008-06-12 15:47:56 +07:00
|
|
|
#include <linux/math64.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/gfp.h>
|
2013-06-05 04:09:36 +07:00
|
|
|
#include <linux/slab.h>
|
2013-06-27 17:35:47 +07:00
|
|
|
#include <linux/pvclock_gtod.h>
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
|
2008-06-03 21:17:30 +07:00
|
|
|
#include <asm/pvclock.h>
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
#include <asm/xen/hypervisor.h>
|
|
|
|
#include <asm/xen/hypercall.h>
|
|
|
|
|
|
|
|
#include <xen/events.h>
|
2010-05-14 18:48:19 +07:00
|
|
|
#include <xen/features.h>
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
#include <xen/interface/xen.h>
|
|
|
|
#include <xen/interface/vcpu.h>
|
|
|
|
|
|
|
|
#include "xen-ops.h"
|
|
|
|
|
|
|
|
/* Xen may fire a timer up to this many ns early */
|
|
|
|
#define TIMER_SLOP 100000
|
2007-07-18 08:37:05 +07:00
|
|
|
#define NS_PER_TICK (1000000000LL / HZ)
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
|
2007-07-18 08:37:05 +07:00
|
|
|
/* runstate info updated by Xen */
|
2009-10-29 20:34:13 +07:00
|
|
|
static DEFINE_PER_CPU(struct vcpu_runstate_info, xen_runstate);
|
2007-07-18 08:37:05 +07:00
|
|
|
|
|
|
|
/* snapshots of runstate info */
|
2009-10-29 20:34:13 +07:00
|
|
|
static DEFINE_PER_CPU(struct vcpu_runstate_info, xen_runstate_snapshot);
|
2007-07-18 08:37:05 +07:00
|
|
|
|
2011-10-19 03:42:59 +07:00
|
|
|
/* unused ns of stolen time */
|
2009-10-29 20:34:13 +07:00
|
|
|
static DEFINE_PER_CPU(u64, xen_residual_stolen);
|
2007-07-18 08:37:05 +07:00
|
|
|
|
|
|
|
/* return an consistent snapshot of 64-bit time/counter value */
|
|
|
|
static u64 get64(const u64 *p)
|
|
|
|
{
|
|
|
|
u64 ret;
|
|
|
|
|
|
|
|
if (BITS_PER_LONG < 64) {
|
|
|
|
u32 *p32 = (u32 *)p;
|
|
|
|
u32 h, l;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read high then low, and then make sure high is
|
|
|
|
* still the same; this will only loop if low wraps
|
|
|
|
* and carries into high.
|
|
|
|
* XXX some clean way to make this endian-proof?
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
h = p32[1];
|
|
|
|
barrier();
|
|
|
|
l = p32[0];
|
|
|
|
barrier();
|
|
|
|
} while (p32[1] != h);
|
|
|
|
|
|
|
|
ret = (((u64)h) << 32) | l;
|
|
|
|
} else
|
|
|
|
ret = *p;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runstate accounting
|
|
|
|
*/
|
|
|
|
static void get_runstate_snapshot(struct vcpu_runstate_info *res)
|
|
|
|
{
|
|
|
|
u64 state_time;
|
|
|
|
struct vcpu_runstate_info *state;
|
|
|
|
|
2007-07-18 08:37:06 +07:00
|
|
|
BUG_ON(preemptible());
|
2007-07-18 08:37:05 +07:00
|
|
|
|
2009-10-29 20:34:13 +07:00
|
|
|
state = &__get_cpu_var(xen_runstate);
|
2007-07-18 08:37:05 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The runstate info is always updated by the hypervisor on
|
|
|
|
* the current CPU, so there's no need to use anything
|
|
|
|
* stronger than a compiler barrier when fetching it.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
state_time = get64(&state->state_entry_time);
|
|
|
|
barrier();
|
|
|
|
*res = *state;
|
|
|
|
barrier();
|
|
|
|
} while (get64(&state->state_entry_time) != state_time);
|
|
|
|
}
|
|
|
|
|
2007-10-17 01:51:30 +07:00
|
|
|
/* return true when a vcpu could run but has no real cpu to run on */
|
|
|
|
bool xen_vcpu_stolen(int vcpu)
|
|
|
|
{
|
2009-10-29 20:34:13 +07:00
|
|
|
return per_cpu(xen_runstate, vcpu).state == RUNSTATE_runnable;
|
2007-10-17 01:51:30 +07:00
|
|
|
}
|
|
|
|
|
2009-11-21 07:35:55 +07:00
|
|
|
void xen_setup_runstate_info(int cpu)
|
2007-07-18 08:37:05 +07:00
|
|
|
{
|
|
|
|
struct vcpu_register_runstate_memory_area area;
|
|
|
|
|
2009-10-29 20:34:13 +07:00
|
|
|
area.addr.v = &per_cpu(xen_runstate, cpu);
|
2007-07-18 08:37:05 +07:00
|
|
|
|
|
|
|
if (HYPERVISOR_vcpu_op(VCPUOP_register_runstate_memory_area,
|
|
|
|
cpu, &area))
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_stolen_accounting(void)
|
|
|
|
{
|
|
|
|
struct vcpu_runstate_info state;
|
|
|
|
struct vcpu_runstate_info *snap;
|
2011-10-19 03:42:59 +07:00
|
|
|
s64 runnable, offline, stolen;
|
2007-07-18 08:37:05 +07:00
|
|
|
cputime_t ticks;
|
|
|
|
|
|
|
|
get_runstate_snapshot(&state);
|
|
|
|
|
|
|
|
WARN_ON(state.state != RUNSTATE_running);
|
|
|
|
|
2009-10-29 20:34:13 +07:00
|
|
|
snap = &__get_cpu_var(xen_runstate_snapshot);
|
2007-07-18 08:37:05 +07:00
|
|
|
|
|
|
|
/* work out how much time the VCPU has not been runn*ing* */
|
|
|
|
runnable = state.time[RUNSTATE_runnable] - snap->time[RUNSTATE_runnable];
|
|
|
|
offline = state.time[RUNSTATE_offline] - snap->time[RUNSTATE_offline];
|
|
|
|
|
|
|
|
*snap = state;
|
|
|
|
|
|
|
|
/* Add the appropriate number of ticks of stolen time,
|
2008-12-31 21:11:38 +07:00
|
|
|
including any left-overs from last time. */
|
2010-12-07 00:16:29 +07:00
|
|
|
stolen = runnable + offline + __this_cpu_read(xen_residual_stolen);
|
2007-07-18 08:37:05 +07:00
|
|
|
|
|
|
|
if (stolen < 0)
|
|
|
|
stolen = 0;
|
|
|
|
|
2008-06-12 15:47:56 +07:00
|
|
|
ticks = iter_div_u64_rem(stolen, NS_PER_TICK, &stolen);
|
2010-12-07 00:16:29 +07:00
|
|
|
__this_cpu_write(xen_residual_stolen, stolen);
|
2008-12-31 21:11:38 +07:00
|
|
|
account_steal_ticks(ticks);
|
2007-07-18 08:37:05 +07:00
|
|
|
}
|
|
|
|
|
2008-07-02 01:43:36 +07:00
|
|
|
/* Get the TSC speed from Xen */
|
2010-05-14 18:48:19 +07:00
|
|
|
static unsigned long xen_tsc_khz(void)
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
{
|
2008-07-28 21:47:52 +07:00
|
|
|
struct pvclock_vcpu_time_info *info =
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
&HYPERVISOR_shared_info->vcpu_info[0].time;
|
|
|
|
|
2008-07-28 21:47:52 +07:00
|
|
|
return pvclock_tsc_khz(info);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
}
|
|
|
|
|
2008-08-22 03:17:56 +07:00
|
|
|
cycle_t xen_clocksource_read(void)
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
{
|
2008-06-03 21:17:30 +07:00
|
|
|
struct pvclock_vcpu_time_info *src;
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
cycle_t ret;
|
|
|
|
|
2011-08-24 23:54:24 +07:00
|
|
|
preempt_disable_notrace();
|
|
|
|
src = &__get_cpu_var(xen_vcpu)->time;
|
2008-06-03 21:17:30 +07:00
|
|
|
ret = pvclock_clocksource_read(src);
|
2011-08-24 23:54:24 +07:00
|
|
|
preempt_enable_notrace();
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-22 02:24:00 +07:00
|
|
|
static cycle_t xen_clocksource_get_cycles(struct clocksource *cs)
|
|
|
|
{
|
|
|
|
return xen_clocksource_read();
|
|
|
|
}
|
|
|
|
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
static void xen_read_wallclock(struct timespec *ts)
|
|
|
|
{
|
2008-06-03 21:17:30 +07:00
|
|
|
struct shared_info *s = HYPERVISOR_shared_info;
|
|
|
|
struct pvclock_wall_clock *wall_clock = &(s->wc);
|
|
|
|
struct pvclock_vcpu_time_info *vcpu_time;
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
|
2008-06-03 21:17:30 +07:00
|
|
|
vcpu_time = &get_cpu_var(xen_vcpu)->time;
|
|
|
|
pvclock_read_wallclock(wall_clock, vcpu_time, ts);
|
|
|
|
put_cpu_var(xen_vcpu);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
}
|
|
|
|
|
2013-05-14 00:56:06 +07:00
|
|
|
static void xen_get_wallclock(struct timespec *now)
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
{
|
2013-05-14 00:56:06 +07:00
|
|
|
xen_read_wallclock(now);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
}
|
|
|
|
|
2013-05-14 00:56:06 +07:00
|
|
|
static int xen_set_wallclock(const struct timespec *now)
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
{
|
2013-06-27 17:35:48 +07:00
|
|
|
return -1;
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
}
|
|
|
|
|
2013-06-27 17:35:48 +07:00
|
|
|
static int xen_pvclock_gtod_notify(struct notifier_block *nb,
|
|
|
|
unsigned long was_set, void *priv)
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
{
|
2013-06-27 17:35:48 +07:00
|
|
|
/* Protected by the calling core code serialization */
|
|
|
|
static struct timespec next_sync;
|
2013-06-27 17:35:47 +07:00
|
|
|
|
2010-03-27 01:21:22 +07:00
|
|
|
struct xen_platform_op op;
|
2013-06-27 17:35:48 +07:00
|
|
|
struct timespec now;
|
2010-03-27 01:21:22 +07:00
|
|
|
|
2013-06-27 17:35:47 +07:00
|
|
|
now = __current_kernel_time();
|
|
|
|
|
2013-06-27 17:35:48 +07:00
|
|
|
/*
|
|
|
|
* We only take the expensive HV call when the clock was set
|
|
|
|
* or when the 11 minutes RTC synchronization time elapsed.
|
|
|
|
*/
|
|
|
|
if (!was_set && timespec_compare(&now, &next_sync) < 0)
|
|
|
|
return NOTIFY_OK;
|
2010-03-27 01:21:22 +07:00
|
|
|
|
|
|
|
op.cmd = XENPF_settime;
|
2013-06-27 17:35:47 +07:00
|
|
|
op.u.settime.secs = now.tv_sec;
|
|
|
|
op.u.settime.nsecs = now.tv_nsec;
|
2010-03-27 01:21:22 +07:00
|
|
|
op.u.settime.system_time = xen_clocksource_read();
|
|
|
|
|
2013-06-27 17:35:47 +07:00
|
|
|
(void)HYPERVISOR_dom0_op(&op);
|
2010-03-27 01:21:22 +07:00
|
|
|
|
2013-06-27 17:35:48 +07:00
|
|
|
/*
|
|
|
|
* Move the next drift compensation time 11 minutes
|
|
|
|
* ahead. That's emulating the sync_cmos_clock() update for
|
|
|
|
* the hardware RTC.
|
|
|
|
*/
|
|
|
|
next_sync = now;
|
|
|
|
next_sync.tv_sec += 11 * 60;
|
|
|
|
|
2013-06-27 17:35:47 +07:00
|
|
|
return NOTIFY_OK;
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
}
|
|
|
|
|
2013-06-27 17:35:47 +07:00
|
|
|
static struct notifier_block xen_pvclock_gtod_notifier = {
|
|
|
|
.notifier_call = xen_pvclock_gtod_notify,
|
|
|
|
};
|
|
|
|
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
static struct clocksource xen_clocksource __read_mostly = {
|
|
|
|
.name = "xen",
|
|
|
|
.rating = 400,
|
2009-04-22 02:24:00 +07:00
|
|
|
.read = xen_clocksource_get_cycles,
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
.mask = ~0,
|
|
|
|
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Xen clockevent implementation
|
|
|
|
|
|
|
|
Xen has two clockevent implementations:
|
|
|
|
|
|
|
|
The old timer_op one works with all released versions of Xen prior
|
|
|
|
to version 3.0.4. This version of the hypervisor provides a
|
|
|
|
single-shot timer with nanosecond resolution. However, sharing the
|
|
|
|
same event channel is a 100Hz tick which is delivered while the
|
|
|
|
vcpu is running. We don't care about or use this tick, but it will
|
|
|
|
cause the core time code to think the timer fired too soon, and
|
|
|
|
will end up resetting it each time. It could be filtered, but
|
|
|
|
doing so has complications when the ktime clocksource is not yet
|
|
|
|
the xen clocksource (ie, at boot time).
|
|
|
|
|
|
|
|
The new vcpu_op-based timer interface allows the tick timer period
|
|
|
|
to be changed or turned off. The tick timer is not useful as a
|
|
|
|
periodic timer because events are only delivered to running vcpus.
|
|
|
|
The one-shot timer can report when a timeout is in the past, so
|
|
|
|
set_next_event is capable of returning -ETIME when appropriate.
|
|
|
|
This interface is used when available.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get a hypervisor absolute time. In theory we could maintain an
|
|
|
|
offset between the kernel's time and the hypervisor's time, and
|
|
|
|
apply that to a kernel's absolute timeout. Unfortunately the
|
|
|
|
hypervisor and kernel times can drift even if the kernel is using
|
|
|
|
the Xen clocksource, because ntp can warp the kernel's clocksource.
|
|
|
|
*/
|
|
|
|
static s64 get_abs_timeout(unsigned long delta)
|
|
|
|
{
|
|
|
|
return xen_clocksource_read() + delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xen_timerop_set_mode(enum clock_event_mode mode,
|
|
|
|
struct clock_event_device *evt)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case CLOCK_EVT_MODE_PERIODIC:
|
|
|
|
/* unsupported */
|
|
|
|
WARN_ON(1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLOCK_EVT_MODE_ONESHOT:
|
2007-07-21 18:37:34 +07:00
|
|
|
case CLOCK_EVT_MODE_RESUME:
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLOCK_EVT_MODE_UNUSED:
|
|
|
|
case CLOCK_EVT_MODE_SHUTDOWN:
|
|
|
|
HYPERVISOR_set_timer_op(0); /* cancel timeout */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xen_timerop_set_next_event(unsigned long delta,
|
|
|
|
struct clock_event_device *evt)
|
|
|
|
{
|
|
|
|
WARN_ON(evt->mode != CLOCK_EVT_MODE_ONESHOT);
|
|
|
|
|
|
|
|
if (HYPERVISOR_set_timer_op(get_abs_timeout(delta)) < 0)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
/* We may have missed the deadline, but there's no real way of
|
|
|
|
knowing for sure. If the event was in the past, then we'll
|
|
|
|
get an immediate interrupt. */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clock_event_device xen_timerop_clockevent = {
|
|
|
|
.name = "xen",
|
|
|
|
.features = CLOCK_EVT_FEAT_ONESHOT,
|
|
|
|
|
|
|
|
.max_delta_ns = 0xffffffff,
|
|
|
|
.min_delta_ns = TIMER_SLOP,
|
|
|
|
|
|
|
|
.mult = 1,
|
|
|
|
.shift = 0,
|
|
|
|
.rating = 500,
|
|
|
|
|
|
|
|
.set_mode = xen_timerop_set_mode,
|
|
|
|
.set_next_event = xen_timerop_set_next_event,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void xen_vcpuop_set_mode(enum clock_event_mode mode,
|
|
|
|
struct clock_event_device *evt)
|
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case CLOCK_EVT_MODE_PERIODIC:
|
|
|
|
WARN_ON(1); /* unsupported */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLOCK_EVT_MODE_ONESHOT:
|
|
|
|
if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL))
|
|
|
|
BUG();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLOCK_EVT_MODE_UNUSED:
|
|
|
|
case CLOCK_EVT_MODE_SHUTDOWN:
|
|
|
|
if (HYPERVISOR_vcpu_op(VCPUOP_stop_singleshot_timer, cpu, NULL) ||
|
|
|
|
HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL))
|
|
|
|
BUG();
|
|
|
|
break;
|
2007-07-21 18:37:34 +07:00
|
|
|
case CLOCK_EVT_MODE_RESUME:
|
|
|
|
break;
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xen_vcpuop_set_next_event(unsigned long delta,
|
|
|
|
struct clock_event_device *evt)
|
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
struct vcpu_set_singleshot_timer single;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
WARN_ON(evt->mode != CLOCK_EVT_MODE_ONESHOT);
|
|
|
|
|
|
|
|
single.timeout_abs_ns = get_abs_timeout(delta);
|
|
|
|
single.flags = VCPU_SSHOTTMR_future;
|
|
|
|
|
|
|
|
ret = HYPERVISOR_vcpu_op(VCPUOP_set_singleshot_timer, cpu, &single);
|
|
|
|
|
|
|
|
BUG_ON(ret != 0 && ret != -ETIME);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clock_event_device xen_vcpuop_clockevent = {
|
|
|
|
.name = "xen",
|
|
|
|
.features = CLOCK_EVT_FEAT_ONESHOT,
|
|
|
|
|
|
|
|
.max_delta_ns = 0xffffffff,
|
|
|
|
.min_delta_ns = TIMER_SLOP,
|
|
|
|
|
|
|
|
.mult = 1,
|
|
|
|
.shift = 0,
|
|
|
|
.rating = 500,
|
|
|
|
|
|
|
|
.set_mode = xen_vcpuop_set_mode,
|
|
|
|
.set_next_event = xen_vcpuop_set_next_event,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct clock_event_device *xen_clockevent =
|
|
|
|
&xen_timerop_clockevent;
|
2013-06-05 04:06:36 +07:00
|
|
|
|
|
|
|
struct xen_clock_event_device {
|
|
|
|
struct clock_event_device evt;
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
static DEFINE_PER_CPU(struct xen_clock_event_device, xen_clock_events) = { .evt.irq = -1 };
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
|
|
|
|
static irqreturn_t xen_timer_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
2013-06-05 04:06:36 +07:00
|
|
|
struct clock_event_device *evt = &__get_cpu_var(xen_clock_events).evt;
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
irqreturn_t ret;
|
|
|
|
|
|
|
|
ret = IRQ_NONE;
|
|
|
|
if (evt->event_handler) {
|
|
|
|
evt->event_handler(evt);
|
|
|
|
ret = IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2007-07-18 08:37:05 +07:00
|
|
|
do_stolen_accounting();
|
|
|
|
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-05 04:13:29 +07:00
|
|
|
void xen_teardown_timer(int cpu)
|
|
|
|
{
|
|
|
|
struct clock_event_device *evt;
|
|
|
|
BUG_ON(cpu == 0);
|
|
|
|
evt = &per_cpu(xen_clock_events, cpu).evt;
|
|
|
|
|
|
|
|
if (evt->irq >= 0) {
|
|
|
|
unbind_from_irqhandler(evt->irq, NULL);
|
|
|
|
evt->irq = -1;
|
|
|
|
kfree(per_cpu(xen_clock_events, cpu).name);
|
|
|
|
per_cpu(xen_clock_events, cpu).name = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-18 08:37:06 +07:00
|
|
|
void xen_setup_timer(int cpu)
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
{
|
2013-06-05 04:09:36 +07:00
|
|
|
char *name;
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
struct clock_event_device *evt;
|
|
|
|
int irq;
|
|
|
|
|
2013-06-05 04:06:36 +07:00
|
|
|
evt = &per_cpu(xen_clock_events, cpu).evt;
|
2013-04-09 08:05:15 +07:00
|
|
|
WARN(evt->irq >= 0, "IRQ%d for CPU%d is already allocated\n", evt->irq, cpu);
|
2013-06-05 04:13:29 +07:00
|
|
|
if (evt->irq >= 0)
|
|
|
|
xen_teardown_timer(cpu);
|
2013-04-09 08:05:15 +07:00
|
|
|
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
printk(KERN_INFO "installing Xen timer for CPU %d\n", cpu);
|
|
|
|
|
|
|
|
name = kasprintf(GFP_KERNEL, "timer%d", cpu);
|
|
|
|
if (!name)
|
|
|
|
name = "<timer kasprintf failed>";
|
|
|
|
|
|
|
|
irq = bind_virq_to_irqhandler(VIRQ_TIMER, cpu, xen_timer_interrupt,
|
2013-09-07 13:46:49 +07:00
|
|
|
IRQF_PERCPU|IRQF_NOBALANCING|IRQF_TIMER|
|
2011-02-08 21:03:31 +07:00
|
|
|
IRQF_FORCE_RESUME,
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
name, NULL);
|
|
|
|
|
|
|
|
memcpy(evt, xen_clockevent, sizeof(*evt));
|
|
|
|
|
2008-12-13 17:50:26 +07:00
|
|
|
evt->cpumask = cpumask_of(cpu);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
evt->irq = irq;
|
2013-06-05 04:09:36 +07:00
|
|
|
per_cpu(xen_clock_events, cpu).name = name;
|
2007-07-18 08:37:06 +07:00
|
|
|
}
|
|
|
|
|
2008-08-22 17:52:15 +07:00
|
|
|
|
2007-07-18 08:37:06 +07:00
|
|
|
void xen_setup_cpu_clockevents(void)
|
|
|
|
{
|
|
|
|
BUG_ON(preemptible());
|
2007-07-18 08:37:05 +07:00
|
|
|
|
2013-06-05 04:06:36 +07:00
|
|
|
clockevents_register_device(&__get_cpu_var(xen_clock_events).evt);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
}
|
|
|
|
|
2008-05-31 07:33:03 +07:00
|
|
|
void xen_timer_resume(void)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
2010-10-26 06:53:46 +07:00
|
|
|
pvclock_resume();
|
|
|
|
|
2008-05-31 07:33:03 +07:00
|
|
|
if (xen_clockevent != &xen_vcpuop_clockevent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL))
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-05 01:18:45 +07:00
|
|
|
static const struct pv_time_ops xen_time_ops __initconst = {
|
2010-08-05 04:49:16 +07:00
|
|
|
.sched_clock = xen_clocksource_read,
|
2010-05-14 18:48:19 +07:00
|
|
|
};
|
|
|
|
|
2011-05-05 01:18:45 +07:00
|
|
|
static void __init xen_time_init(void)
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
2010-03-12 05:04:47 +07:00
|
|
|
struct timespec tp;
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
|
2010-04-27 09:03:05 +07:00
|
|
|
clocksource_register_hz(&xen_clocksource, NSEC_PER_SEC);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
|
|
|
|
if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL) == 0) {
|
2007-07-18 08:37:05 +07:00
|
|
|
/* Successfully turned off 100Hz tick, so we have the
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
vcpuop-based timer interface */
|
|
|
|
printk(KERN_DEBUG "Xen: using vcpuop timer interface\n");
|
|
|
|
xen_clockevent = &xen_vcpuop_clockevent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set initial system time with full resolution */
|
2010-03-12 05:04:47 +07:00
|
|
|
xen_read_wallclock(&tp);
|
|
|
|
do_settimeofday(&tp);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
|
2008-01-30 19:33:20 +07:00
|
|
|
setup_force_cpu_cap(X86_FEATURE_TSC);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
|
2009-11-21 07:35:55 +07:00
|
|
|
xen_setup_runstate_info(cpu);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
xen_setup_timer(cpu);
|
2007-07-18 08:37:06 +07:00
|
|
|
xen_setup_cpu_clockevents();
|
2013-06-27 17:35:47 +07:00
|
|
|
|
|
|
|
if (xen_initial_domain())
|
|
|
|
pvclock_gtod_register_notifier(&xen_pvclock_gtod_notifier);
|
xen: time implementation
Xen maintains a base clock which measures nanoseconds since system
boot. This is provided to guests via a shared page which contains a
base time in ns, a tsc timestamp at that point and tsc frequency
parameters. Guests can compute the current time by reading the tsc
and using it to extrapolate the current time from the basetime. The
hypervisor makes sure that the frequency parameters are updated
regularly, paricularly if the tsc changes rate or stops.
This is implemented as a clocksource, so the interface to the rest of
the kernel is a simple clocksource which simply returns the current
time directly in nanoseconds.
Xen also provides a simple timer mechanism, which allows a timeout to
be set in the future. When that time arrives, a timer event is sent
to the guest. There are two timer interfaces:
- An old one which also delivers a stream of (unused) ticks at 100Hz,
and on the same event, the actual timer events. The 100Hz ticks
cause a lot of spurious wakeups, but are basically harmless.
- The new timer interface doesn't have the 100Hz ticks, and can also
fail if the specified time is in the past.
This code presents the Xen timer as a clockevent driver, and uses the
new interface by preference.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
2007-07-18 08:37:05 +07:00
|
|
|
}
|
2010-05-14 18:48:19 +07:00
|
|
|
|
2011-05-05 01:18:45 +07:00
|
|
|
void __init xen_init_time_ops(void)
|
2010-05-14 18:48:19 +07:00
|
|
|
{
|
|
|
|
pv_time_ops = xen_time_ops;
|
|
|
|
|
|
|
|
x86_init.timers.timer_init = xen_time_init;
|
|
|
|
x86_init.timers.setup_percpu_clockev = x86_init_noop;
|
|
|
|
x86_cpuinit.setup_percpu_clockev = x86_init_noop;
|
|
|
|
|
|
|
|
x86_platform.calibrate_tsc = xen_tsc_khz;
|
|
|
|
x86_platform.get_wallclock = xen_get_wallclock;
|
2013-06-27 17:35:48 +07:00
|
|
|
/* Dom0 uses the native method to set the hardware RTC. */
|
|
|
|
if (!xen_initial_domain())
|
|
|
|
x86_platform.set_wallclock = xen_set_wallclock;
|
2010-05-14 18:48:19 +07:00
|
|
|
}
|
|
|
|
|
2010-07-29 20:37:48 +07:00
|
|
|
#ifdef CONFIG_XEN_PVHVM
|
2010-05-14 18:48:19 +07:00
|
|
|
static void xen_hvm_setup_cpu_clockevents(void)
|
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
xen_setup_runstate_info(cpu);
|
2013-04-17 02:18:00 +07:00
|
|
|
/*
|
|
|
|
* xen_setup_timer(cpu) - snprintf is bad in atomic context. Hence
|
|
|
|
* doing it xen_hvm_cpu_notify (which gets called by smp_init during
|
|
|
|
* early bootup and also during CPU hotplug events).
|
|
|
|
*/
|
2010-05-14 18:48:19 +07:00
|
|
|
xen_setup_cpu_clockevents();
|
|
|
|
}
|
|
|
|
|
2011-05-05 01:18:45 +07:00
|
|
|
void __init xen_hvm_init_time_ops(void)
|
2010-05-14 18:48:19 +07:00
|
|
|
{
|
|
|
|
/* vector callback is needed otherwise we cannot receive interrupts
|
2010-10-01 23:35:46 +07:00
|
|
|
* on cpu > 0 and at this point we don't know how many cpus are
|
|
|
|
* available */
|
|
|
|
if (!xen_have_vector_callback)
|
2010-05-14 18:48:19 +07:00
|
|
|
return;
|
|
|
|
if (!xen_feature(XENFEAT_hvm_safe_pvclock)) {
|
|
|
|
printk(KERN_INFO "Xen doesn't support pvclock on HVM,"
|
|
|
|
"disable pv timer\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
x86_platform.calibrate_tsc = xen_tsc_khz;
|
|
|
|
x86_platform.get_wallclock = xen_get_wallclock;
|
|
|
|
x86_platform.set_wallclock = xen_set_wallclock;
|
|
|
|
}
|
2010-07-29 20:37:48 +07:00
|
|
|
#endif
|