Commit c8fd61ad authored by Alessandro Rubini's avatar Alessandro Rubini

Merge branch 'wrs-4.1.2-fixes-rebased'

parents 0250bb3b 4179fcdc
......@@ -268,6 +268,8 @@ int wr_servo_update(struct pp_instance *ppi)
got_sync = 0;
s->mu = ts_sub(ts_sub(s->t4, s->t1), ts_sub(s->t3, s->t2));
if (__PP_DIAG_ALLOW(ppi, pp_dt_servo, 1)) {
dump_timestamp(ppi, "servo:t1", s->t1);
dump_timestamp(ppi, "servo:t2", s->t2);
......@@ -276,7 +278,6 @@ int wr_servo_update(struct pp_instance *ppi)
dump_timestamp(ppi, "->mdelay", s->mu);
}
s->mu = ts_sub(ts_sub(s->t4, s->t1), ts_sub(s->t3, s->t2));
s->picos_mu = ts_to_picos(s->mu);
big_delta_fix = s->delta_tx_m + s->delta_tx_s
+ s->delta_rx_m + s->delta_rx_s;
......
......@@ -49,6 +49,8 @@ static inline int __send_and_log(struct pp_instance *ppi, int msglen,
(int)(ppi->last_snt_time.seconds),
(int)(ppi->last_snt_time.nanoseconds),
pp_msg_names[msgtype]);
if (ppi->last_snt_time.correct == 0)
return -1;
return 0;
}
......
......@@ -25,20 +25,22 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
}
if (pp_timeout_z(ppi, PP_TO_SYNC)) {
/* Restart the timeout for next time */
pp_timeout_rand(ppi, PP_TO_SYNC, DSPOR(ppi)->logSyncInterval);
if ((e = msg_issue_sync_followup(ppi) < 0))
goto out;
/* Restart the timeout for next time */
pp_timeout_rand(ppi, PP_TO_SYNC, DSPOR(ppi)->logSyncInterval);
}
if (pp_timeout_z(ppi, PP_TO_ANN_INTERVAL)) {
if ((e = msg_issue_announce(ppi) < 0))
goto out;
/* Restart the timeout for next time */
pp_timeout_rand(ppi, PP_TO_ANN_INTERVAL,
DSPOR(ppi)->logAnnounceInterval);
if ((e = msg_issue_announce(ppi) < 0))
goto out;
}
if (plen == 0)
......
......@@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
......@@ -274,11 +275,10 @@ int wrs_net_recv(struct pp_instance *ppi, void *pkt, int len,
}
/* Waits for the transmission timestamp and stores it in t (if not null). */
static void poll_tx_timestamp(struct pp_instance *ppi,
static void poll_tx_timestamp(struct pp_instance *ppi, void *pkt, int len,
struct wrs_socket *s, int fd, TimeInternal *t)
{
char data[16384];
struct msghdr msg;
struct iovec entry;
struct sockaddr_ll from_addr;
......@@ -287,7 +287,8 @@ static void poll_tx_timestamp(struct pp_instance *ppi,
char control[1024];
} control;
struct cmsghdr *cmsg;
int res;
struct pollfd pfd;
int res, retry = 0;;
struct sock_extended_err *serr = NULL;
struct scm_timestamping *sts = NULL;
......@@ -302,12 +303,36 @@ static void poll_tx_timestamp(struct pp_instance *ppi,
msg.msg_control = &control;
msg.msg_controllen = sizeof(control);
res = recvmsg(fd, &msg, MSG_ERRQUEUE);
if (t)
t->correct = 0;
if (t) /* poison the stamp */
t->seconds = t->correct = 0;
pfd.fd = fd;
pfd.events = POLLIN;
while (1) { /* Not forever: we break after a few runs */
errno = 0;
res = poll(&pfd, 1, 20 /* ms */);
if (res != 1) {
pp_diag(ppi, time, 1, "%s: poll() = %i (%s)\n",
__func__, res, strerror(errno));
return;
}
if (res <= 0 || !t)
res = recvmsg(fd, &msg, MSG_ERRQUEUE);
if (res <= 0) {
pp_diag(ppi, time, 1, "%s: recvmsg() = %i (%s)\n",
__func__, res, strerror(errno));
return;
}
/* Now, check if this frame is our frame. If not, retry */
if (!memcmp(data, pkt, len))
break;
pp_diag(ppi, time, 1, "%s: recvmsg(): not our frame\n",
__func__);
/* We won't pop out wrong stamps forever... */
if (retry++ > 5)
return;
}
if (!t) /* maybe caller is not interested, though we popped it out */
return;
/*
......@@ -373,7 +398,7 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
ppi->t_ops->get(ppi, t);
ret = send(fd, hdr, len, 0);
poll_tx_timestamp(ppi, s, fd, t);
poll_tx_timestamp(ppi, pkt, len, s, fd, t);
if (drop) /* avoid messaging about stamps that are not used */
goto drop_msg;
......@@ -395,7 +420,7 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
addr.sin_port = 3200;
ret = sendto(fd, pkt, len, 0,
(struct sockaddr *)&addr, sizeof(struct sockaddr_in));
poll_tx_timestamp(ppi, s, fd, t);
poll_tx_timestamp(ppi, pkt, len, s, fd, t);
if (drop) /* like above: skil messages about timestamps */
goto drop_msg;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment