Subject: Implement xen_sched_clock Implement xen_sched_clock, which returns the number of ns the current vcpu has been actually in the running state (vs blocked, runnable-but-not-running, or offline) since boot. Signed-off-by: Jeremy Fitzhardinge Cc: john stultz --- arch/i386/xen/enlighten.c | 2 +- arch/i386/xen/time.c | 14 ++++++++++++++ arch/i386/xen/xen-ops.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) =================================================================== --- a/arch/i386/xen/enlighten.c +++ b/arch/i386/xen/enlighten.c @@ -664,7 +664,7 @@ static const struct paravirt_ops xen_par .set_wallclock = xen_set_wallclock, .get_wallclock = xen_get_wallclock, .get_cpu_khz = xen_cpu_khz, - .get_scheduled_cycles = native_read_tsc, + .sched_clock = xen_sched_clock, #ifdef CONFIG_X86_LOCAL_APIC .apic_write = paravirt_nop, =================================================================== --- a/arch/i386/xen/time.c +++ b/arch/i386/xen/time.c @@ -16,6 +16,8 @@ #define XEN_SHIFT 22 #define TIMER_SLOP 100000 /* Xen may fire a timer up to this many ns early */ #define NS_PER_TICK (1000000000ll / HZ) + +static cycle_t xen_clocksource_read(void); static DEFINE_PER_CPU(struct clock_event_device, xen_clock_events); @@ -120,6 +122,18 @@ static void do_stolen_accounting(void) account_steal_time(idle_task(smp_processor_id()), ticks); } +/* Xen sched_clock implementation. Returns the number of RUNNING ns */ +unsigned long long xen_sched_clock(void) +{ + struct vcpu_runstate_info state; + cycle_t now = xen_clocksource_read(); + + get_runstate_snapshot(&state); + + WARN_ON(state.state != RUNSTATE_running); + + return state.time[RUNSTATE_running] + (now - state.state_entry_time); +} /* Get the CPU speed from Xen */ =================================================================== --- a/arch/i386/xen/xen-ops.h +++ b/arch/i386/xen/xen-ops.h @@ -14,6 +14,7 @@ void __init xen_time_init(void); void __init xen_time_init(void); unsigned long xen_get_wallclock(void); int xen_set_wallclock(unsigned long time); +unsigned long long xen_sched_clock(void); void xen_mark_init_mm_pinned(void);