Re: [Linuxptp-users] The ptp4l is not sync sometimes.
PTP IEEE 1588 stack for Linux
Brought to you by:
rcochran
From: Richard C. <ric...@gm...> - 2012-03-10 07:30:03
|
On Fri, Mar 09, 2012 at 10:55:38AM +0900, Takahiro Shimizu wrote: > > > 2. Is my modification correct? > > > > A better fix is to drop event packets with missing time stamps in > > port.c. > The ptp4l program should really complain about missing time stamps on event messages. This will make the synchronization more robust and will help you track down your driver/hw issues. Please try the following patch. Thanks, Richard --- diff --git a/msg.c b/msg.c index e51bcbe..b3e5bf1 100644 --- a/msg.c +++ b/msg.c @@ -23,6 +23,7 @@ #include <asm/byteorder.h> #include "msg.h" +#include "print.h" #define VERSION_MASK 0x0f #define VERSION 0x02 @@ -192,6 +193,12 @@ int msg_post_recv(struct ptp_message *m, int cnt) default: return -1; } + + if (msg_sots_missing(m)) { + pr_err("received %s without timestamp", msg_type_string(type)); + return -1; + } + return 0; } @@ -273,3 +280,24 @@ void msg_put(struct ptp_message *m) if (!m) TAILQ_INSERT_HEAD(&msg_pool, m, list); } + +int msg_sots_missing(struct ptp_message *m) +{ + int type = msg_type(m); + switch (type) { + case SYNC: + case DELAY_REQ: + case PDELAY_REQ: + case PDELAY_RESP: + break; + case FOLLOW_UP: + case DELAY_RESP: + case PDELAY_RESP_FOLLOW_UP: + case ANNOUNCE: + case SIGNALING: + case MANAGEMENT: + default: + return 0; + } + return (!m->hwts.ts.tv_sec && !m->hwts.ts.tv_nsec) ? 1 : 0; +} diff --git a/msg.h b/msg.h index fab5907..89d99e0 100644 --- a/msg.h +++ b/msg.h @@ -237,6 +237,13 @@ void msg_print(struct ptp_message *m, FILE *fp); void msg_put(struct ptp_message *m); /** + * Test whether an event message received a valid SO_TIMESTAMPING time stamp. + * @param m Message to test. + * @return One if the message is an event without a time stamp, zero otherwise. + */ +int msg_sots_missing(struct ptp_message *m); + +/** * Test whether a message is one-step message. * @param m Message to test. * @return One if the message is a one-step, zero otherwise. diff --git a/port.c b/port.c index 82c6166..978fca3 100644 --- a/port.c +++ b/port.c @@ -356,6 +356,10 @@ static int port_delay_request(struct port *p) pr_err("port %hu: send delay request failed", portnum(p)); goto out; } + if (msg_sots_missing(msg)) { + pr_err("missing timestamp on transmitted delay request"); + goto out; + } if (p->delay_req) msg_put(p->delay_req); @@ -466,6 +470,11 @@ static int port_tx_sync(struct port *p) err = -1; goto out; } + if (msg_sots_missing(msg)) { + pr_err("missing timestamp on transmitted sync"); + err = -1; + goto out; + } /* * Send the follow up message right away. |