RE: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check

From: Dan Magenheimer
Date: Wed Oct 14 2009 - 23:30:49 EST


> Other tsc-based clocksources add a monotonicity test to make
> sure there's
> no regression in the returned cycles.
>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>
> ---
> arch/x86/xen/time.c | 7 ++++++-
> 1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
> index 0a5aa44..00f06cc 100644
> --- a/arch/x86/xen/time.c
> +++ b/arch/x86/xen/time.c
> @@ -213,9 +213,14 @@ cycle_t xen_clocksource_read(void)
> return ret;
> }
>
> +static struct clocksource xen_clocksource;
> +
> static cycle_t xen_clocksource_get_cycles(struct clocksource *cs)
> {
> - return xen_clocksource_read();
> + cycle_t ret = xen_clocksource_read();
> +
> + return ret >= xen_clocksource.cycle_last ?
> + ret : xen_clocksource.cycle_last;

As long as we are going through the trouble of making
this monotonic, shouldn't it be monotonically increasing
(rather than just monotonically non-decreasing)? The
rdtsc instruction and any suitably high-precision
hardware timer will never return the same value
on subsequent uses so this might be a reasonable
precedent to obey. E.g.

+ return ret > xen_clocksource.cycle_last ?
+ ret : ++xen_clocksource.cycle_last;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/