Skip to content

Commit b7ec15b

Browse files
cfd-36Linus Torvalds
authored andcommitted
uml: virtualized time fix
With the current timekeeping, !CONFIG_UML_REAL_TIME_CLOCK has inconsistent behavior. Previously, gettimeofday could be (and was) isolated from the clock ticking. Now, it's not, so when CONFIG_UML_REAL_TIME_CLOCK is disabled, gettimeofday must progress in lockstep with the clock, making it fully virtual. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 83ff7df commit b7ec15b

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎arch/um/kernel/time.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ unsigned long long sched_clock(void)
3434
return (unsigned long long)jiffies_64 * (1000000000 / HZ);
3535
}
3636

37-
static unsigned long long prev_nsecs[NR_CPUS];
3837
#ifdef CONFIG_UML_REAL_TIME_CLOCK
38+
static unsigned long long prev_nsecs[NR_CPUS];
3939
static long long delta[NR_CPUS]; /* Deviation per interval */
4040
#endif
4141

@@ -94,7 +94,12 @@ irqreturn_t um_timer(int irq, void *dev)
9494

9595
do_timer(1);
9696

97+
#ifdef CONFIG_UML_REAL_TIME_CLOCK
9798
nsecs = get_time();
99+
#else
100+
nsecs = (unsigned long long) xtime.tv_sec * BILLION + xtime.tv_nsec +
101+
BILLION / HZ;
102+
#endif
98103
xtime.tv_sec = nsecs / NSEC_PER_SEC;
99104
xtime.tv_nsec = nsecs - xtime.tv_sec * NSEC_PER_SEC;
100105

@@ -127,13 +132,18 @@ void time_init(void)
127132
nsecs = os_nsecs();
128133
set_normalized_timespec(&wall_to_monotonic, -nsecs / BILLION,
129134
-nsecs % BILLION);
135+
set_normalized_timespec(&xtime, nsecs / BILLION, nsecs % BILLION);
130136
late_time_init = register_timer;
131137
}
132138

133139
void do_gettimeofday(struct timeval *tv)
134140
{
141+
#ifdef CONFIG_UML_REAL_TIME_CLOCK
135142
unsigned long long nsecs = get_time();
136-
143+
#else
144+
unsigned long long nsecs = (unsigned long long) xtime.tv_sec * BILLION +
145+
xtime.tv_nsec;
146+
#endif
137147
tv->tv_sec = nsecs / NSEC_PER_SEC;
138148
/* Careful about calculations here - this was originally done as
139149
* (nsecs - tv->tv_sec * NSEC_PER_SEC) / NSEC_PER_USEC

0 commit comments

Comments
 (0)