From 34ff407a2ff5cbc0095fb95b30b1ba4e66f0f0c7 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 15 Sep 2017 11:23:31 -0700 Subject: [PATCH] Fix timesync state to be uncalibrated when adjustment is large (>60ms). VMtools has timesync plugin to adjust guest time to match 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, state machine should reset to uncalibrated state. There is a bug currently that would leave the state in PLL mode even if the guest and host times differ by more than 60ms since absolute value of adjustment is not considered. This causes the time sync to happen slower than expected. --- open-vm-tools/lib/include/vmware/tools/utils.h | 6 +++++- open-vm-tools/services/plugins/timeSync/timeSync.c | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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, -- 2.47.3