aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorJeff Dike <jdike@addtoit.com>2008-06-06 01:46:10 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-06-06 14:29:10 -0400
commit06e1e4ffbd1932e288839b3140cda6b8141eb684 (patch)
treec76ad0854f28a0600885301e25e8e7197e4e924c /arch
parent34397892a3d677d857fdaf8dec66a66b07dde0b5 (diff)
uml: deal with host time going backwards
Protection against the host's time going backwards (eg, ntp activity on the host) by keeping track of the time at the last tick and if it's greater than the current time, keep time stopped until the host catches up. Cc: Nix <nix@esperi.org.uk> Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/um/os-Linux/time.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/arch/um/os-Linux/time.c b/arch/um/os-Linux/time.c
index bee98f466d66..dec5678fc17f 100644
--- a/arch/um/os-Linux/time.c
+++ b/arch/um/os-Linux/time.c
@@ -106,6 +106,10 @@ static void deliver_alarm(void)
106 unsigned long long this_tick = os_nsecs(); 106 unsigned long long this_tick = os_nsecs();
107 int one_tick = UM_NSEC_PER_SEC / UM_HZ; 107 int one_tick = UM_NSEC_PER_SEC / UM_HZ;
108 108
109 /* Protection against the host's time going backwards */
110 if ((last_tick != 0) && (this_tick < last_tick))
111 this_tick = last_tick;
112
109 if (last_tick == 0) 113 if (last_tick == 0)
110 last_tick = this_tick - one_tick; 114 last_tick = this_tick - one_tick;
111 115
@@ -148,6 +152,9 @@ static int after_sleep_interval(struct timespec *ts)
148 start_usecs = usec; 152 start_usecs = usec;
149 153
150 start_usecs -= skew / UM_NSEC_PER_USEC; 154 start_usecs -= skew / UM_NSEC_PER_USEC;
155 if (start_usecs < 0)
156 start_usecs = 0;
157
151 tv = ((struct timeval) { .tv_sec = start_usecs / UM_USEC_PER_SEC, 158 tv = ((struct timeval) { .tv_sec = start_usecs / UM_USEC_PER_SEC,
152 .tv_usec = start_usecs % UM_USEC_PER_SEC }); 159 .tv_usec = start_usecs % UM_USEC_PER_SEC });
153 interval = ((struct itimerval) { { 0, usec }, tv }); 160 interval = ((struct itimerval) { { 0, usec }, tv });