]> xenbits.xensource.com Git - people/pauldu/mini-os.git/commitdiff
Fix time update
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 9 Apr 2016 22:46:32 +0000 (00:46 +0200)
committerWei Liu <wei.liu2@citrix.com>
Fri, 15 Apr 2016 10:07:43 +0000 (11:07 +0100)
The timer handler should actually not update the shadowed copy, since that
makes reading them non-atomic. Users of the shadowed copy should just update
it themselves, which is already the case in monotonic_clock(), we just need
to make to make gettimeofday() update the wallclock.

This also fixes an issue reported by David Vercauteren: when the timer
interrupt was not called yet, gettimeofday was returning bogus values.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
arch/x86/time.c

index cf5fab0be31529b08e38ecdc0b80c351d34e8744..af45e560db7f6d7a70bd0af460935c1ac4a87fdb 100644 (file)
@@ -79,6 +79,12 @@ static inline int time_values_up_to_date(void)
        return (shadow.version == src->version);
 }
 
+static inline int wc_values_up_to_date(void)
+{
+       shared_info_t *s= HYPERVISOR_shared_info;
+
+       return (shadow_ts_version == s->wc_version);
+}
 
 /*
  * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,
@@ -186,9 +192,12 @@ static void update_wallclock(void)
 int gettimeofday(struct timeval *tv, void *tz)
 {
     uint64_t nsec = monotonic_clock();
+
+    if (!wc_values_up_to_date())
+       update_wallclock();
+
     nsec += shadow_ts.tv_nsec;
-    
-    
+
     tv->tv_sec = shadow_ts.tv_sec;
     tv->tv_sec += NSEC_TO_SEC(nsec);
     tv->tv_usec = NSEC_TO_USEC(nsec % 1000000000UL);
@@ -214,8 +223,6 @@ void block_domain(s_time_t until)
  */
 static void timer_handler(evtchn_port_t ev, struct pt_regs *regs, void *ign)
 {
-    get_time_values_from_xen();
-    update_wallclock();
 }