/*********************************************************
- * Copyright (c) 2002-2024 Broadcom. All Rights Reserved.
+ * Copyright (c) 2002-2025 Broadcom. All Rights Reserved.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program is free software; you can redistribute it and/or modify it
*/
#define CONFNAME_TIMESYNC_TIMEINFO_ENABLED "timeInfo.enabled"
+/**
+ * Defines the configuration to perform all time synchronization or not.
+ *
+ * @note Illegal values result in a @c g_warning and fallback to the default
+ * value.
+ *
+ * @param boolean If TRUE, all time synchronization is disabled.
+ * If FALSE, one-time synchronization is enabled and periodic
+ * synchronization is controlled by disable-periodic.
+ */
+#define CONFNAME_TIMESYNC_DISABLE_ALL "disable-all"
+
+/**
+ * Defines the configuration to perform periodic time synchronization or not.
+ *
+ * @note Illegal values result in a @c g_warning and fallback to the default
+ * value.
+ *
+ * @param boolean If TRUE, periodic time synchronization is disabled.
+ * If FALSE, periodic time synchronization is enabled if
+ * disable-all is also FALSE.
+ */
+#define CONFNAME_TIMESYNC_DISABLE_PERIODIC "disable-periodic"
+
/*
* END timeSync goodies.
******************************************************************************
/*********************************************************
- * Copyright (C) 2008-2022 VMware, Inc. All rights reserved.
+ * Copyright (c) 2008-2025 Broadcom. All Rights Reserved.
+ * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* 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
/* Period during which the frequency error of guest time is measured. */
#define TIMESYNC_CALIBRATION_DURATION (15 * 60 * US_PER_SEC) /* 15min. */
+/* Default values for timeSync settings in tools config file. */
+#define CONFNAME_TIMESYNC_DISABLE_ALL_DEFAULT FALSE
+#define CONFNAME_TIMESYNC_DISABLE_PERIODIC_DEFAULT FALSE
+
typedef enum TimeSyncState {
TIMESYNC_INITIALIZING,
TIMESYNC_STOPPED,
*/
static gboolean
-TimeSyncDoSync(Bool slewCorrection,
- TimeSyncType syncType,
- Bool allowBackwardSync,
- void *_data)
+TimeSyncDoSyncWork(Bool slewCorrection,
+ TimeSyncType syncType,
+ Bool allowBackwardSync,
+ void *_data)
{
int64 guest, host;
int64 gosError, apparentError, maxTimeError;
syncType, slewCorrection, allowBackwardSync,
data->guestResync, data->guestResyncTimeout);
- if (!TimeSyncReadHostAndGuest(&host, &guest, &apparentError,
+ if (!TimeSyncReadHostAndGuest(&host, &guest, &apparentError,
&apparentErrorValid, &maxTimeError)) {
return FALSE;
}
* step correction.
*/
- if (gosError < -maxTimeError ||
+ if (gosError < -maxTimeError ||
(gosError + apparentError > 0 && allowBackwardSync)) {
if (syncType == TIMESYNC_STEP && data->guestResync &&
TimeSync_IsGuestSyncServiceRunning()) {
ASSERT(data->ctx != NULL);
if (!TimeSync_DoGuestResync(data->ctx)) {
g_warning("Guest resync operation failed.\n");
- return TimeSyncDoSync(data->slewCorrection,
- TIMESYNC_STEP_NORESYNC,
- allowBackwardSync, data);
+ return TimeSyncDoSyncWork(data->slewCorrection,
+ TIMESYNC_STEP_NORESYNC,
+ allowBackwardSync, data);
}
if (data->guestResyncTimeout > 0) {
data->guestResyncTimer =
}
+/**
+ * Check the Tools config of timeSync, skip time sync if it is disabled,
+ * call TimeSyncDoSyncWork to sync time otherwise.
+ *
+ * @param[in] slewCorrection Is clock slewing enabled?
+ * @param[in] syncType Type of synchronization requested.
+ * @param[in] allowBackwardSync Can we sync time backwards when doing
+ * step/resync correction?
+ * @param[in] _data Time sync data.
+ *
+ * @return TRUE on success or when timeSync is disabled.
+ */
+
+static gboolean
+TimeSyncDoSync(Bool slewCorrection,
+ TimeSyncType syncType,
+ Bool allowBackwardSync,
+ void *_data)
+{
+ TimeSyncData *data = _data;
+ Bool disableAll =
+ VMTools_ConfigGetBoolean(data->ctx->config,
+ CONFGROUPNAME_TIMESYNC,
+ CONFNAME_TIMESYNC_DISABLE_ALL,
+ CONFNAME_TIMESYNC_DISABLE_ALL_DEFAULT);
+ Bool disablePeriodic =
+ VMTools_ConfigGetBoolean(data->ctx->config,
+ CONFGROUPNAME_TIMESYNC,
+ CONFNAME_TIMESYNC_DISABLE_PERIODIC,
+ CONFNAME_TIMESYNC_DISABLE_PERIODIC_DEFAULT);
+ /*
+ * Skip all time sync or the periodic type of time sync if they are
+ * configured to be disabled in the Tools config. Return TRUE so that
+ * nothing in timeSync plugin is broken and the sync can be re-enabled
+ * seamlessly, this also avoids warning logs on the FALSE returns.
+ */
+ if (disableAll || (disablePeriodic && syncType == TIMESYNC_PERIODIC)) {
+ g_debug("Time synchronization is disabled.\n");
+ return TRUE;
+ }
+ return TimeSyncDoSyncWork(slewCorrection, syncType, allowBackwardSync,
+ _data);
+}
+
+
/**
* Run the "time synchronization" loop.
*