summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-04-21 15:21:38 +0200
committerThomas Haller <thaller@redhat.com>2018-04-27 12:33:19 +0200
commit2b8802d8ec37a1e5fc0347954fe64600bd43876c (patch)
tree069d4aac39f1b8308c750b52bd9a1016774c2fc8
parent25ccd3d95d8d48074902bff66d76c3077b681c0c (diff)
downloadNetworkManager-2b8802d8ec37a1e5fc0347954fe64600bd43876c.tar.gz
device/connectivity: refactor concheck_periodic_schedule_do()
Instead of passing the interval for the timeout, let concheck_periodic_schedule_do() figure it out on its own. It only depends on cur-interval and cur-basetime. Additionally, pass now_ns timestamp, because we already made decisions based on this particular timestamp. We don't want to re-evalutate the current time but ensure to use the same timestamp. There is no change in behavior, it just seems nicer this way.
-rw-r--r--src/devices/nm-device.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index ed09d36a03..f48ea0c52e 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -2278,10 +2278,11 @@ concheck_is_possible (NMDevice *self)
}
static gboolean
-concheck_periodic_schedule_do (NMDevice *self, gint64 interval_ns)
+concheck_periodic_schedule_do (NMDevice *self, gint64 now_ns)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
gboolean periodic_check_disabled = FALSE;
+ gint64 expiry, tdiff;
/* we always cancel whatever was pending. */
if (nm_clear_g_source (&priv->concheck_p_cur_id))
@@ -2292,18 +2293,25 @@ concheck_periodic_schedule_do (NMDevice *self, gint64 interval_ns)
goto out;
}
- nm_assert (interval_ns >= 0);
-
if (!concheck_is_possible (self))
goto out;
- _LOGT (LOGD_CONCHECK, "connectivity: periodic-check: %sscheduled in %u milliseconds (%u seconds interval)",
+ nm_assert (now_ns > 0);
+ nm_assert (priv->concheck_p_cur_interval > 0);
+
+ /* we schedule the timeout based on our current settings cur-interval and cur-basetime.
+ * Before calling concheck_periodic_schedule_do(), make sure that these properties are
+ * correct. */
+
+ expiry = priv->concheck_p_cur_basetime_ns + (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND);
+ tdiff = expiry - now_ns;
+
+ _LOGT (LOGD_CONCHECK, "connectivity: periodic-check: %sscheduled in %lld milliseconds (%u seconds interval)",
periodic_check_disabled ? "re-" : "",
- (guint) (interval_ns / NM_UTILS_NS_PER_MSEC),
+ (long long) (tdiff / NM_UTILS_NS_PER_MSEC),
priv->concheck_p_cur_interval);
- nm_assert (priv->concheck_p_cur_interval > 0);
- priv->concheck_p_cur_id = g_timeout_add (interval_ns / NM_UTILS_NS_PER_MSEC,
+ priv->concheck_p_cur_id = g_timeout_add (NM_MAX ((gint64) 0, tdiff) / NM_UTILS_NS_PER_MSEC,
concheck_periodic_timeout_cb,
self);
return TRUE;
@@ -2344,7 +2352,7 @@ concheck_periodic_schedule_set (NMDevice *self,
case CONCHECK_SCHEDULE_UPDATE_INTERVAL_RESTART:
priv->concheck_p_cur_interval = NM_MIN (priv->concheck_p_max_interval, CONCHECK_P_PROBE_INTERVAL);
priv->concheck_p_cur_basetime_ns = nm_utils_get_monotonic_timestamp_ns_cached (&now_ns);
- if (concheck_periodic_schedule_do (self, priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND))
+ if (concheck_periodic_schedule_do (self, now_ns))
concheck_start (self, NULL, NULL, TRUE);
return;
@@ -2372,7 +2380,7 @@ concheck_periodic_schedule_set (NMDevice *self,
* new max_interval passed. We need to start a check right away (and
* schedule a timeout in cur-interval in the future). */
priv->concheck_p_cur_basetime_ns = now_ns;
- if (concheck_periodic_schedule_do (self, priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND))
+ if (concheck_periodic_schedule_do (self, now_ns))
concheck_start (self, NULL, NULL, TRUE);
} else {
/* we are reducing the max-interval to a shorter interval that we have currently
@@ -2381,14 +2389,14 @@ concheck_periodic_schedule_set (NMDevice *self,
* However, since the last time we scheduled the check, not even the new max-interval
* expired. All we need to do, is reschedule the timer to expire sooner. The cur_basetime
* is unchanged. */
- concheck_periodic_schedule_do (self, cur_expiry - now_ns);
+ concheck_periodic_schedule_do (self, now_ns);
}
return;
case CONCHECK_SCHEDULE_CHECK_EXTERNAL:
/* a external connectivity check delays our periodic check. We reset the counter. */
priv->concheck_p_cur_basetime_ns = nm_utils_get_monotonic_timestamp_ns_cached (&now_ns);
- concheck_periodic_schedule_do (self, priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND);
+ concheck_periodic_schedule_do (self, now_ns);
return;
case CONCHECK_SCHEDULE_CHECK_PERIODIC:
@@ -2421,15 +2429,16 @@ concheck_periodic_schedule_set (NMDevice *self,
new_expiry = exp_expiry + (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND);
tdiff = NM_MAX (new_expiry - now_ns, 0);
priv->concheck_p_cur_basetime_ns = (now_ns + tdiff) - (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND);
- concheck_periodic_schedule_do (self, tdiff);
- handle = concheck_start (self, NULL, NULL, TRUE);
- if (old_interval != priv->concheck_p_cur_interval) {
- /* we just bumped the interval already when scheduling this check.
- * When the handle returns, don't bump a second time.
- *
- * But if we reach the timeout again before the handle returns (this
- * code here) we will still bump the interval. */
- handle->is_periodic_bump_on_complete = FALSE;
+ if (concheck_periodic_schedule_do (self, now_ns)) {
+ handle = concheck_start (self, NULL, NULL, TRUE);
+ if (old_interval != priv->concheck_p_cur_interval) {
+ /* we just bumped the interval already when scheduling this check.
+ * When the handle returns, don't bump a second time.
+ *
+ * But if we reach the timeout again before the handle returns (this
+ * code here) we will still bump the interval. */
+ handle->is_periodic_bump_on_complete = FALSE;
+ }
}
return;
}
@@ -2456,7 +2465,7 @@ concheck_periodic_schedule_set (NMDevice *self,
new_expiry = priv->concheck_p_cur_basetime_ns + (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND);
tdiff = NM_MAX (new_expiry - nm_utils_get_monotonic_timestamp_ns_cached (&now_ns), 0);
priv->concheck_p_cur_basetime_ns = now_ns + tdiff - (priv->concheck_p_cur_interval * NM_UTILS_NS_PER_SECOND);
- concheck_periodic_schedule_do (self, tdiff);
+ concheck_periodic_schedule_do (self, now_ns);
}
static void
@@ -2475,7 +2484,8 @@ concheck_update_interval (NMDevice *self, gboolean check_now)
}
if (!new_interval) {
- /* this will cancel any potentially pending timeout. */
+ /* this will cancel any potentially pending timeout because max-interval is zero.
+ * But it logs a nice message... */
concheck_periodic_schedule_do (self, 0);
/* also update the fake connectivity state. */