From: Dan Magenheimer Subject: RE: [PATCH 05/12] xen/pvclock: add monotonicity check Date: Wed, 14 Oct 2009 20:26:48 -0700 (PDT) Message-ID: <0be3e26b-76b6-47c9-b7ab-51ed72b72b69@default> References: <1255548516-15260-6-git-send-email-jeremy.fitzhardinge@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=Windows-1252 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <1255548516-15260-6-git-send-email-jeremy.fitzhardinge@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jeremy Fitzhardinge , Linux Kernel Mailing List Cc: Xen-devel , kurt.hackel@oracle.com, arch/x86 maintainers , Glauber de Oliveira Costa , Avi Kivity , the, chris.mason@oracle.com List-Id: xen-devel@lists.xenproject.org > Other tsc-based clocksources add a monotonicity test to make=20 > sure there's > no regression in the returned cycles. >=20 > Signed-off-by: Jeremy Fitzhardinge > --- > arch/x86/xen/time.c | 7 ++++++- > 1 files changed, 6 insertions(+), 1 deletions(-) >=20 > 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) > =09return ret; > } > =20 > +static struct clocksource xen_clocksource; > + > static cycle_t xen_clocksource_get_cycles(struct clocksource *cs) > { > -=09return xen_clocksource_read(); > +=09cycle_t ret =3D xen_clocksource_read(); > + > +=09return ret >=3D xen_clocksource.cycle_last ? > +=09=09ret : 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. +=09return ret > xen_clocksource.cycle_last ? +=09=09ret : ++xen_clocksource.cycle_last;