[systemd-commits] 4 commits - src/timesync
Kay Sievers
kay at kemper.freedesktop.org
Tue Sep 2 05:43:13 PDT 2014
src/timesync/timesyncd-manager.c | 68 ++++++++++++++++++++++++---------------
src/timesync/timesyncd-manager.h | 3 +
2 files changed, 45 insertions(+), 26 deletions(-)
New commits:
commit 80cd2606b91ce2735a0609c6f964917cf12685aa
Author: Kay Sievers <kay at vrfy.org>
Date: Tue Sep 2 14:33:59 2014 +0200
timesyncd: don't reset polling interval when reselecting server
Original patch from: Miroslav Lichvar <mlichvar at redhat.com>
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index a66852d..3261bc1 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -721,7 +721,8 @@ static int manager_begin(Manager *m) {
assert_return(m->current_server_address, -EHOSTUNREACH);
m->missed_replies = NTP_MAX_MISSED_REPLIES;
- m->poll_interval_usec = NTP_POLL_INTERVAL_MIN_SEC * USEC_PER_SEC;
+ if (m->poll_interval_usec == 0)
+ m->poll_interval_usec = NTP_POLL_INTERVAL_MIN_SEC * USEC_PER_SEC;
server_address_pretty(m->current_server_address, &pretty);
log_info("Using NTP server %s (%s).", strna(pretty), m->current_server_name->string);
commit e8206972be6a7ebeb198cd0d400bc7a94a6a5fc5
Author: Miroslav Lichvar <mlichvar at redhat.com>
Date: Tue Sep 2 14:29:51 2014 +0200
timesyncd: allow two missed replies before reselecting server
After receiving a reply from the server, allow two missed replies before
switching to another server to avoid unnecessary clock hopping when
packets are getting lost in the network.
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index 19a28f3..a66852d 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -92,6 +92,9 @@
/* Maximum acceptable root distance in seconds. */
#define NTP_MAX_ROOT_DISTANCE 5.0
+/* Maximum number of missed replies before selecting another source. */
+#define NTP_MAX_MISSED_REPLIES 2
+
/*
* "NTP timestamps are represented as a 64-bit unsigned fixed-point number,
* in seconds relative to 0h on 1 January 1900."
@@ -206,15 +209,18 @@ static int manager_send_request(Manager *m) {
return manager_connect(m);
}
- r = sd_event_add_time(
- m->event,
- &m->event_timeout,
- clock_boottime_or_monotonic(),
- now(clock_boottime_or_monotonic()) + TIMEOUT_USEC, 0,
- manager_timeout, m);
- if (r < 0) {
- log_error("Failed to arm timeout timer: %s", strerror(-r));
- return r;
+ m->missed_replies++;
+ if (m->missed_replies > NTP_MAX_MISSED_REPLIES) {
+ r = sd_event_add_time(
+ m->event,
+ &m->event_timeout,
+ clock_boottime_or_monotonic(),
+ now(clock_boottime_or_monotonic()) + TIMEOUT_USEC, 0,
+ manager_timeout, m);
+ if (r < 0) {
+ log_error("Failed to arm timeout timer: %s", strerror(-r));
+ return r;
+ }
}
return 0;
@@ -549,6 +555,8 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
return 0;
}
+ m->missed_replies = 0;
+
/* check our "time cookie" (we just stored nanoseconds in the fraction field) */
if (be32toh(ntpmsg.origin_time.sec) != m->trans_time.tv_sec + OFFSET_1900_1970 ||
be32toh(ntpmsg.origin_time.frac) != m->trans_time.tv_nsec) {
@@ -712,6 +720,7 @@ static int manager_begin(Manager *m) {
assert_return(m->current_server_name, -EHOSTUNREACH);
assert_return(m->current_server_address, -EHOSTUNREACH);
+ m->missed_replies = NTP_MAX_MISSED_REPLIES;
m->poll_interval_usec = NTP_POLL_INTERVAL_MIN_SEC * USEC_PER_SEC;
server_address_pretty(m->current_server_address, &pretty);
diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h
index 0ac0e17..8296d41 100644
--- a/src/timesync/timesyncd-manager.h
+++ b/src/timesync/timesyncd-manager.h
@@ -53,6 +53,7 @@ struct Manager {
ServerName *current_server_name;
ServerAddress *current_server_address;
int server_socket;
+ int missed_replies;
uint64_t packet_count;
sd_event_source *event_timeout;
commit 665c6a9eab46b0b253af6566ca9fc70c866b3fcd
Author: Kay Sievers <kay at vrfy.org>
Date: Tue Sep 2 14:27:00 2014 +0200
timesyncd: remove retry_timer logic which is covered by the server timeout
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index b7b39ef..19a28f3 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -206,19 +206,6 @@ static int manager_send_request(Manager *m) {
return manager_connect(m);
}
- /* re-arm timer with increasing timeout, in case the packets never arrive back */
- if (m->retry_interval > 0) {
- if (m->retry_interval < NTP_POLL_INTERVAL_MAX_SEC * USEC_PER_SEC)
- m->retry_interval *= 2;
- } else
- m->retry_interval = NTP_POLL_INTERVAL_MIN_SEC * USEC_PER_SEC;
-
- r = manager_arm_timer(m, m->retry_interval);
- if (r < 0) {
- log_error("Failed to rearm timer: %s", strerror(-r));
- return r;
- }
-
r = sd_event_add_time(
m->event,
&m->event_timeout,
@@ -601,7 +588,6 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
/* valid packet */
m->pending = false;
- m->retry_interval = 0;
/* announce leap seconds */
if (NTP_FIELD_LEAP(ntpmsg.field) & NTP_LEAP_PLUSSEC)
diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h
index bb3e509..0ac0e17 100644
--- a/src/timesync/timesyncd-manager.h
+++ b/src/timesync/timesyncd-manager.h
@@ -59,7 +59,6 @@ struct Manager {
/* last sent packet */
struct timespec trans_time_mon;
struct timespec trans_time;
- usec_t retry_interval;
bool pending;
/* poll timer */
commit 63463bf091949e0178b749016828ec400c106582
Author: Miroslav Lichvar <mlichvar at redhat.com>
Date: Wed Aug 27 16:47:24 2014 +0200
timesyncd: wait before reconnecting to first server
When all servers are exhausted, wait for one poll interval before trying
to connect again to the first server in the list. Also, keep increasing
the polling interval to make sure a client not getting any valid replies
will not send requests to any server more frequently than is allowed by
the maximum polling interval.
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index 696dd10..b7b39ef 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -875,6 +875,7 @@ int manager_connect(Manager *m) {
manager_set_server_name(m, m->current_server_name->names_next);
else {
ServerName *f;
+ bool restart = true;
/* Our current server name list is exhausted,
* let's find the next one to iterate. First
@@ -891,6 +892,8 @@ int manager_connect(Manager *m) {
f = m->link_servers;
if (!f)
f = m->system_servers;
+ else
+ restart = false;
}
if (!f)
@@ -902,6 +905,25 @@ int manager_connect(Manager *m) {
return 0;
}
+ if (restart && !m->exhausted_servers && m->poll_interval_usec) {
+ log_debug("Waiting after exhausting servers.");
+ r = sd_event_add_time(m->event, &m->event_retry, clock_boottime_or_monotonic(), now(clock_boottime_or_monotonic()) + m->poll_interval_usec, 0, manager_retry_connect, m);
+ if (r < 0) {
+ log_error("Failed to create retry timer: %s", strerror(-r));
+ return r;
+ }
+
+ m->exhausted_servers = true;
+
+ /* Increase the polling interval */
+ if (m->poll_interval_usec < NTP_POLL_INTERVAL_MAX_SEC * USEC_PER_SEC)
+ m->poll_interval_usec *= 2;
+
+ return 0;
+ }
+
+ m->exhausted_servers = false;
+
manager_set_server_name(m, f);
}
@@ -1042,7 +1064,7 @@ static int manager_network_event_handler(sd_event_source *s, int fd, uint32_t re
online = network_is_online();
/* check if the client is currently connected */
- connected = m->server_socket >= 0 || m->resolve_query;
+ connected = m->server_socket >= 0 || m->resolve_query || m->exhausted_servers;
if (connected && !online) {
log_info("No network connectivity, watching for changes.");
diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h
index 2345bf8..bb3e509 100644
--- a/src/timesync/timesyncd-manager.h
+++ b/src/timesync/timesyncd-manager.h
@@ -41,6 +41,7 @@ struct Manager {
LIST_HEAD(ServerName, fallback_servers);
RateLimit ratelimit;
+ bool exhausted_servers;
/* network */
sd_event_source *network_event_source;
More information about the systemd-commits
mailing list