From 59fe8cea208cfa9c253ad7bc00817e2bda14a64a Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 5 Oct 2015 11:12:28 +0200 Subject: Fix time going back in Xen case when backward time correction happens to get bigger than the tick duration. * kern/mach_clock.c (clock_interrupt): When `tickdelta' is bigger than `usec', truncate it to `usec-1'. --- kern/mach_clock.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kern/mach_clock.c b/kern/mach_clock.c index dba2320..c6e2d9d 100644 --- a/kern/mach_clock.c +++ b/kern/mach_clock.c @@ -232,8 +232,16 @@ void clock_interrupt( int delta; if (timedelta < 0) { - delta = usec - tickdelta; - timedelta += tickdelta; + if (usec > tickdelta) { + delta = usec - tickdelta; + timedelta += tickdelta; + } else { + /* Not enough time has passed, defer overflowing + * correction for later, keep only one microsecond + * delta */ + delta = 1; + timedelta += usec - 1; + } } else { delta = usec + tickdelta; -- cgit v1.2.3