]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix timesync state to be uncalibrated when adjustment is large (>60ms).
authorOliver Kurth <okurth@vmware.com>
Fri, 21 Apr 2017 01:04:18 +0000 (18:04 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 21 Apr 2017 01:04:18 +0000 (18:04 -0700)
Open-vm-tools has a timesync plugin to adjust the guest time to match the
host time. Timesync relies on a state machine (uncalibrated, calibrating
and PLL states) to adjust the amount of guest time to match host time.
If the guest and host time differ by more than 60ms, the state machine
should reset to the uncalibrated state. This change fixes a bug that could
leave the state in PLL mode even when the guest and host times differed by
more than 60ms, since the absolute value of adjustment was not considered,
which in turn caused the time sync to happen more slowly than expected.

open-vm-tools/lib/include/vmware/tools/utils.h
open-vm-tools/services/plugins/timeSync/timeSync.c

index efe2e5ce79f4243f1f5ddc2e8c449d1f7dd4619f..b5968a432098499186c98c613882445ea3a8ae91 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2017 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
 #  define G_INLINE_FUNC static __inline
 #endif
 
+#ifndef ABS
+#  define ABS(x) (((x) >= 0) ? (x) : -(x))
+#endif
+
 
 /**
  * Converts an UTF-8 path to the local (i.e., glib) file name encoding.
index 8f3138ef20fcd0e2258263ac973adb00ca5a1aad..fbe509cf425fdd3f8712bb43a5a113083a7d51b1 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2017 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -430,7 +430,7 @@ TimeSyncSlewTime(TimeSyncData *data, int64 adjustment)
       return FALSE;
    }
 
-   if (adjustment > TIMESYNC_PLL_UNSYNC && 
+   if (ABS(adjustment) > TIMESYNC_PLL_UNSYNC && 
        data->slewState != TimeSyncUncalibrated) {
       g_debug("Adjustment too large (%"FMT64"d), resetting PLL state.\n", 
               adjustment);
@@ -443,7 +443,7 @@ TimeSyncSlewTime(TimeSyncData *data, int64 adjustment)
          data->slewState = TimeSyncUncalibrated;
          return FALSE;
       }
-      if (adjustment < TIMESYNC_PLL_ACTIVATE && TimeSync_PLLSupported()) {
+      if (ABS(adjustment) < TIMESYNC_PLL_ACTIVATE && TimeSync_PLLSupported()) {
          g_debug("Starting PLL calibration.\n");
          calibrationStart = now;
          /* Starting out the calibration period we are adjustment behind,