msg: Represent hw_timestamp "ts" field as tmv_t

Convert a hardware timestamp to the internal tmv_t representation at
the earliest possible opportunity.  This allows us to:

- eliminate multiple redundant calls to timespec_to_tmv()

- use tmv_add() instead of open-coded manipulation of a struct
  timespec in ts_add()

- use tmv_to_Timestamp() instead of open-coded manipulation of a
  struct timespec and struct Timestamp in ts_to_Timestamp()

- use tmv_is_zero() instead of open-coded manipulation of a struct
  timespec in msg_sots_valid()

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
master
Michael Brown 2018-03-12 12:36:30 +00:00 committed by Richard Cochran
parent 5a23ccddf6
commit 29a99ad513
4 changed files with 17 additions and 30 deletions

4
msg.h
View File

@ -64,7 +64,7 @@ enum timestamp_type {
struct hw_timestamp {
enum timestamp_type type;
struct timespec ts;
tmv_t ts;
struct timespec sw;
};
@ -369,7 +369,7 @@ int msg_sots_missing(struct ptp_message *m);
*/
static inline int msg_sots_valid(struct ptp_message *m)
{
return (m->hwts.ts.tv_sec || m->hwts.ts.tv_nsec) ? 1 : 0;
return !tmv_is_zero(m->hwts.ts);
}
/**

4
nsm.c
View File

@ -96,8 +96,8 @@ static int64_t nsm_compute_offset(struct tsproc *tsp,
c3 = correction_to_tmv(resp->header.correction);
t1 = timestamp_to_tmv(fup->ts.pdu);
t2 = timespec_to_tmv(syn->hwts.ts);
t3 = timespec_to_tmv(req->hwts.ts);
t2 = syn->hwts.ts;
t3 = req->hwts.ts;
t4 = timestamp_to_tmv(resp->ts.pdu);
t1c = tmv_add(t1, tmv_add(c1, c2));

33
port.c
View File

@ -377,29 +377,17 @@ static void fc_prune(struct foreign_clock *fc)
}
}
static void ts_add(struct timespec *ts, Integer64 correction)
static void ts_add(tmv_t *ts, Integer64 correction)
{
if (!correction) {
return;
}
ts->tv_nsec += tmv_to_nanoseconds(correction_to_tmv(correction));
while (ts->tv_nsec < 0) {
ts->tv_nsec += (long) NS_PER_SEC;
ts->tv_sec--;
}
while (ts->tv_nsec >= (long) NS_PER_SEC) {
ts->tv_nsec -= (long) NS_PER_SEC;
ts->tv_sec++;
}
*ts = tmv_add(*ts, correction_to_tmv(correction));
}
static struct Timestamp ts_to_Timestamp(struct timespec src)
static struct Timestamp ts_to_Timestamp(tmv_t src)
{
struct Timestamp dst;
dst.seconds_lsb = src.tv_sec;
dst.seconds_msb = 0;
dst.nanoseconds = src.tv_nsec;
return dst;
return tmv_to_Timestamp(src);
}
/*
@ -1165,7 +1153,7 @@ static void port_slave_priority_warning(struct port *p)
}
static void port_synchronize(struct port *p,
struct timespec ingress_ts,
tmv_t ingress_ts,
struct timestamp origin_ts,
Integer64 correction1, Integer64 correction2)
{
@ -1175,7 +1163,7 @@ static void port_synchronize(struct port *p,
port_set_sync_rx_tmo(p);
t1 = timestamp_to_tmv(origin_ts);
t2 = timespec_to_tmv(ingress_ts);
t2 = ingress_ts;
c1 = correction_to_tmv(correction1);
c2 = correction_to_tmv(correction2);
t1c = tmv_add(t1, tmv_add(c1, c2));
@ -1855,7 +1843,7 @@ static void process_delay_resp(struct port *p, struct ptp_message *m)
return;
c3 = correction_to_tmv(m->header.correction);
t3 = timespec_to_tmv(p->delay_req->hwts.ts);
t3 = p->delay_req->hwts.ts;
t4 = timestamp_to_tmv(m->ts.pdu);
t4c = tmv_sub(t4, c3);
@ -2035,8 +2023,8 @@ static void port_peer_delay(struct port *p)
if (rsp->header.sequenceId != ntohs(req->header.sequenceId))
return;
t1 = timespec_to_tmv(req->hwts.ts);
t4 = timespec_to_tmv(rsp->hwts.ts);
t1 = req->hwts.ts;
t4 = rsp->hwts.ts;
c1 = correction_to_tmv(rsp->header.correction + p->asymmetry);
/* Process one-step response immediately. */
@ -2521,8 +2509,7 @@ enum fsm_event port_event(struct port *p, int fd_index)
}
if (msg_sots_valid(msg)) {
ts_add(&msg->hwts.ts, -p->rx_timestamp_offset);
clock_check_ts(p->clock,
tmv_to_nanoseconds(timespec_to_tmv(msg->hwts.ts)));
clock_check_ts(p->clock, tmv_to_nanoseconds(msg->hwts.ts));
}
if (port_ignore(p, msg)) {
msg_put(msg);

6
sk.c
View File

@ -355,14 +355,14 @@ int sk_receive(int fd, void *buf, int buflen,
switch (hwts->type) {
case TS_SOFTWARE:
hwts->ts = ts[0];
hwts->ts = timespec_to_tmv(ts[0]);
break;
case TS_HARDWARE:
case TS_ONESTEP:
hwts->ts = ts[2];
hwts->ts = timespec_to_tmv(ts[2]);
break;
case TS_LEGACY_HW:
hwts->ts = ts[1];
hwts->ts = timespec_to_tmv(ts[1]);
break;
}
return cnt;