From: Oliver Kurth Date: Fri, 21 Apr 2017 01:04:18 +0000 (-0700) Subject: Fix timesync state to be uncalibrated when adjustment is large (>60ms). X-Git-Tag: stable-10.1.10~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0efa46ca41c3b58d5bf65d2dfb154b3d986d946f;p=thirdparty%2Fopen-vm-tools.git Fix timesync state to be uncalibrated when adjustment is large (>60ms). 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. --- diff --git a/open-vm-tools/lib/include/vmware/tools/utils.h b/open-vm-tools/lib/include/vmware/tools/utils.h index efe2e5ce7..b5968a432 100644 --- a/open-vm-tools/lib/include/vmware/tools/utils.h +++ b/open-vm-tools/lib/include/vmware/tools/utils.h @@ -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 @@ -60,6 +60,10 @@ # 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. diff --git a/open-vm-tools/services/plugins/timeSync/timeSync.c b/open-vm-tools/services/plugins/timeSync/timeSync.c index 8f3138ef2..fbe509cf4 100644 --- a/open-vm-tools/services/plugins/timeSync/timeSync.c +++ b/open-vm-tools/services/plugins/timeSync/timeSync.c @@ -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,