Use the timeout table for the delay request messages.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2011-11-26 09:26:59 +01:00
parent 1d6737b75c
commit 68aea3058c
2 changed files with 11 additions and 3 deletions

View File

@ -18,6 +18,7 @@
*/ */
#include <errno.h> #include <errno.h>
#include <poll.h> #include <poll.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -156,6 +157,8 @@ struct clock *clock_create(char *phc, struct interface *iface, int count,
int i, max_adj; int i, max_adj;
struct clock *c = &the_clock; struct clock *c = &the_clock;
srandom(time(NULL));
if (c->nports) if (c->nports)
clock_destroy(c); clock_destroy(c);

11
port.c
View File

@ -19,6 +19,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
#include <malloc.h> #include <malloc.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/timerfd.h> #include <sys/timerfd.h>
#include <unistd.h> #include <unistd.h>
@ -28,6 +29,7 @@
#include "msg.h" #include "msg.h"
#include "port.h" #include "port.h"
#include "print.h" #include "print.h"
#include "tmtab.h"
#include "util.h" #include "util.h"
#define PTP_VERSION 2 #define PTP_VERSION 2
@ -49,6 +51,7 @@ struct port {
struct ptp_message *last_sync; struct ptp_message *last_sync;
struct ptp_message *delay_req; struct ptp_message *delay_req;
UInteger16 seqnum; UInteger16 seqnum;
struct tmtab tmtab;
/* portDS */ /* portDS */
struct PortIdentity portIdentity; struct PortIdentity portIdentity;
enum port_state state; /*portState*/ enum port_state state; /*portState*/
@ -232,9 +235,8 @@ static int port_set_delay_tmo(struct port *p)
struct itimerspec tmo = { struct itimerspec tmo = {
{0, 0}, {0, 0} {0, 0}, {0, 0}
}; };
int index = random() % TMTAB_MAX;
tmo.it_value.tv_sec = 1 << (p->logMinDelayReqInterval + 1); tmo.it_value = p->tmtab.ts[index];
return timerfd_settime(p->fda.fd[FD_DELAY_TIMER], 0, &tmo, NULL); return timerfd_settime(p->fda.fd[FD_DELAY_TIMER], 0, &tmo, NULL);
} }
@ -288,6 +290,8 @@ static int port_initialize(struct port *p)
p->logSyncInterval = LOG_SYNC_INTERVAL; p->logSyncInterval = LOG_SYNC_INTERVAL;
p->logMinPdelayReqInterval = LOG_MIN_PDELAY_REQ_INTERVAL; p->logMinPdelayReqInterval = LOG_MIN_PDELAY_REQ_INTERVAL;
tmtab_init(&p->tmtab, 1 + p->logMinDelayReqInterval);
fd1 = timerfd_create(CLOCK_MONOTONIC, 0); fd1 = timerfd_create(CLOCK_MONOTONIC, 0);
if (fd1 < 0) { if (fd1 < 0) {
pr_err("timerfd_create: %s", strerror(errno)); pr_err("timerfd_create: %s", strerror(errno));
@ -447,6 +451,7 @@ static void process_delay_resp(struct port *p, struct ptp_message *m)
p->logMinDelayReqInterval = rsp->hdr.logMessageInterval; p->logMinDelayReqInterval = rsp->hdr.logMessageInterval;
pr_info("port %hu: minimum delay request interval 2^%d", pr_info("port %hu: minimum delay request interval 2^%d",
portnum(p), p->logMinDelayReqInterval); portnum(p), p->logMinDelayReqInterval);
tmtab_init(&p->tmtab, 1 + p->logMinDelayReqInterval);
} }
} }