|
|
5a725fc |
From 1cdb867fa07aa9a1fa698dd4eb8fa26e145eecf1 Mon Sep 17 00:00:00 2001
|
|
|
5a725fc |
From: Michal Schmidt <mschmidt@redhat.com>
|
|
|
5a725fc |
Date: Wed, 10 Sep 2014 19:12:50 +0200
|
|
|
5a725fc |
Subject: [PATCH] timesyncd: get kernel timestamp in nanoseconds
|
|
|
5a725fc |
|
|
|
5a725fc |
Upstream commit:
|
|
|
5a725fc |
commit 487a36821ea214a73e1d0dcbd6d84123b50d1135
|
|
|
5a725fc |
Author: Miroslav Lichvar <mlichvar@redhat.com>
|
|
|
5a725fc |
Date: Wed Aug 27 16:47:19 2014 +0200
|
|
|
5a725fc |
|
|
|
5a725fc |
timesyncd: get kernel timestamp in nanoseconds
|
|
|
5a725fc |
---
|
|
|
5a725fc |
src/timesync/timesyncd.c | 14 +++++---------
|
|
|
5a725fc |
1 file changed, 5 insertions(+), 9 deletions(-)
|
|
|
5a725fc |
|
|
|
5a725fc |
diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
|
|
|
5a725fc |
index d123f0a3fc..436aeaea56 100644
|
|
|
5a725fc |
--- a/src/timesync/timesyncd.c
|
|
|
5a725fc |
+++ b/src/timesync/timesyncd.c
|
|
|
5a725fc |
@@ -144,10 +144,6 @@ static double ts_to_d(const struct timespec *ts) {
|
|
|
5a725fc |
return ts->tv_sec + (1.0e-9 * ts->tv_nsec);
|
|
|
5a725fc |
}
|
|
|
5a725fc |
|
|
|
5a725fc |
-static double tv_to_d(const struct timeval *tv) {
|
|
|
5a725fc |
- return tv->tv_sec + (1.0e-6 * tv->tv_usec);
|
|
|
5a725fc |
-}
|
|
|
5a725fc |
-
|
|
|
5a725fc |
static double square(double d) {
|
|
|
5a725fc |
return d * d;
|
|
|
5a725fc |
}
|
|
|
5a725fc |
@@ -565,7 +561,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
|
|
|
5a725fc |
.msg_namelen = sizeof(server_addr),
|
|
|
5a725fc |
};
|
|
|
5a725fc |
struct cmsghdr *cmsg;
|
|
|
5a725fc |
- struct timeval *recv_time;
|
|
|
5a725fc |
+ struct timespec *recv_time;
|
|
|
5a725fc |
ssize_t len;
|
|
|
5a725fc |
double origin, receive, trans, dest;
|
|
|
5a725fc |
double delay, offset;
|
|
|
5a725fc |
@@ -608,8 +604,8 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
|
|
|
5a725fc |
continue;
|
|
|
5a725fc |
|
|
|
5a725fc |
switch (cmsg->cmsg_type) {
|
|
|
5a725fc |
- case SCM_TIMESTAMP:
|
|
|
5a725fc |
- recv_time = (struct timeval *) CMSG_DATA(cmsg);
|
|
|
5a725fc |
+ case SCM_TIMESTAMPNS:
|
|
|
5a725fc |
+ recv_time = (struct timespec *) CMSG_DATA(cmsg);
|
|
|
5a725fc |
break;
|
|
|
5a725fc |
}
|
|
|
5a725fc |
}
|
|
|
5a725fc |
@@ -680,7 +676,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
|
|
|
5a725fc |
origin = ts_to_d(&m->trans_time) + OFFSET_1900_1970;
|
|
|
5a725fc |
receive = ntp_ts_to_d(&ntpmsg.recv_time);
|
|
|
5a725fc |
trans = ntp_ts_to_d(&ntpmsg.trans_time);
|
|
|
5a725fc |
- dest = tv_to_d(recv_time) + OFFSET_1900_1970;
|
|
|
5a725fc |
+ dest = ts_to_d(recv_time) + OFFSET_1900_1970;
|
|
|
5a725fc |
|
|
|
5a725fc |
offset = ((receive - origin) + (trans - dest)) / 2;
|
|
|
5a725fc |
delay = (dest - origin) - (trans - receive);
|
|
|
5a725fc |
@@ -762,7 +758,7 @@ static int manager_listen_setup(Manager *m) {
|
|
|
5a725fc |
if (r < 0)
|
|
|
5a725fc |
return -errno;
|
|
|
5a725fc |
|
|
|
5a725fc |
- r = setsockopt(m->server_socket, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on));
|
|
|
5a725fc |
+ r = setsockopt(m->server_socket, SOL_SOCKET, SO_TIMESTAMPNS, &on, sizeof(on));
|
|
|
5a725fc |
if (r < 0)
|
|
|
5a725fc |
return -errno;
|
|
|
5a725fc |
|