diff --git a/include/hooks.h b/include/hooks.h index 13b366f8a..9914ffd65 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -106,6 +106,9 @@ int hook_convert(struct path *p, struct hook *h, int when); /** Example hook: overwrite timestamp of message. */ int hook_ts(struct path *p, struct hook *h, int when); +/** Internal hook: add missing timestamps for node types which do not include a valid TS (ex. GTFPGA) */ +int hook_fix_ts(struct path *p, struct hook *h, int when); + /** Example hook: Finite-Impulse-Response (FIR) filter. */ int hook_fir(struct path *p, struct hook *h, int when); diff --git a/include/path.h b/include/path.h index efdbb12d2..c2b5904fd 100644 --- a/include/path.h +++ b/include/path.h @@ -70,9 +70,11 @@ struct path struct hist hist_gap_recv; /**< Histogram for inter message arrival time (as seen by this instance) */ struct hist hist_gap_seq; /**< Histogram of sequence number displacement of received messages */ - struct timespec ts_recv; /**< Last message received */ - struct timespec ts_sent; /**< Last message sent */ - struct timespec ts_last; /**< Previous message received (old value of path::ts_recv) */ + struct { + struct timespec recv; /**< Last message received */ + struct timespec sent; /**< Last message sent */ + struct timespec last; /**< Previous message received (old value of path::ts__recv) */ + } ts; unsigned int sent; /**< Counter for sent messages to all outgoing nodes */ unsigned int received; /**< Counter for received messages from all incoming nodes */ diff --git a/lib/hooks.c b/lib/hooks.c index 02eb639b7..e50955fc4 100644 --- a/lib/hooks.c +++ b/lib/hooks.c @@ -29,7 +29,7 @@ REGISTER_HOOK("print", 99, hook_print, HOOK_MSG) int hook_print(struct path *p, struct hook *h, int when) { struct msg *m = p->current; - double offset = time_delta(&MSG_TS(m), &p->ts_recv); + double offset = time_delta(&MSG_TS(m), &p->ts.recv); int flags = MSG_PRINT_ALL; /* We dont show the offset if its to large */ @@ -46,8 +46,20 @@ int hook_ts(struct path *p, struct hook *h, int when) { struct msg *m = p->current; - m->ts.sec = p->ts_recv.tv_sec; - m->ts.nsec = p->ts_recv.tv_nsec; + m->ts.sec = p->ts.recv.tv_sec; + m->ts.nsec = p->ts.recv.tv_nsec; + + return 0; +} + +REGISTER_HOOK("fix_ts", 0, hook_fix_ts, HOOK_INTERNAL | HOOK_MSG) +int hook_fix_ts(struct path *p, struct hook *h, int when) +{ + struct msg *m = p->current; + + if ((m->ts.sec == 0 && m->ts.nsec == 0) || + (m->ts.sec == -1 && m->ts.nsec == -1)) + hook_ts(p, h, when); return 0; } @@ -250,7 +262,7 @@ int hook_skip_first(struct path *p, struct hook *h, int when) break; case HOOK_PATH_RESTART: - private->started = p->ts_recv; + private->started = p->ts.recv; break; case HOOK_PATH_START: @@ -258,7 +270,7 @@ int hook_skip_first(struct path *p, struct hook *h, int when) break; case HOOK_POST: { - double delta = time_delta(&private->started, &p->ts_recv); + double delta = time_delta(&private->started, &p->ts.recv); return delta < private->wait ? -1 /* skip */ : 0; /* send */ @@ -336,7 +348,7 @@ int hook_stats(struct path *p, struct hook *h, int when) case HOOK_PRE: /* Exclude first message from statistics */ if (p->received > 0) { - double gap = time_delta(&p->ts_last, &p->ts_recv); + double gap = time_delta(&p->ts.last, &p->ts.recv); hist_put(&p->hist_gap_recv, gap); } @@ -347,7 +359,7 @@ int hook_stats(struct path *p, struct hook *h, int when) /* Exclude first message from statistics */ if (p->received > 0) { int dist = cur->sequence - (int32_t) prev->sequence; - double delay = time_delta(&MSG_TS(cur), &p->ts_recv); + double delay = time_delta(&MSG_TS(cur), &p->ts.recv); double gap = time_delta(&MSG_TS(prev), &MSG_TS(cur)); hist_put(&p->hist_gap_msg, gap); diff --git a/lib/path.c b/lib/path.c index 95b72745d..493718b60 100644 --- a/lib/path.c +++ b/lib/path.c @@ -29,7 +29,7 @@ static void path_write(struct path *p) debug(15, "Sent %u messages to node %s", sent, node_name(n)); p->sent += sent; - p->ts_sent = time_now(); /** @todo use hardware timestamps for socket node type */ + p->ts.sent = time_now(); /** @todo use hardware timestamps for socket node type */ } } @@ -94,8 +94,8 @@ static void * path_run(void *arg) continue; /** @todo Replace this timestamp by hardware timestamping */ - p->ts_last = p->ts_recv; - p->ts_recv = time_now(); + p->ts.last = p->ts.recv; + p->ts.recv = time_now(); debug(15, "Received %u messages from node %s", recv, node_name(p->in));