The calculated ratio between the local clock and a peer should be nearly 1. If it is more than an order of magnitude then a measurement error has ocurred and the current calculated ratio should be ignored. This patch detects these errors and ignores the affected ratio values so that nothing else is affected.
The neighbor rate ratio is used during peer delay measurements. Erroneous measurements of this ratio can trigger the port to leave "asCapable" mode by generating peer delay values that violate the neighbour propagation delay limit. Filtering these errors prevents unnecessary state transitions. Note: Large master time changes are caused by GM changes when some of the GMs revert to an arbitrary timescale. Signed-off-by: Erik Hons <erik.h...@ni.com> --- port.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/port.c b/port.c index 58fbe66..21781c4 100644 --- a/port.c +++ b/port.c @@ -1012,6 +1012,7 @@ static int port_management_set(struct port *target, static void port_nrate_calculate(struct port *p, tmv_t origin, tmv_t ingress) { struct nrate_estimator *n = &p->nrate; + double ratio; /* * We experienced a successful exchanges of peer delay request @@ -1032,12 +1033,28 @@ static void port_nrate_calculate(struct port *p, tmv_t origin, tmv_t ingress) pr_warning("bad timestamps in nrate calculation"); return; } - n->ratio = - tmv_dbl(tmv_sub(origin, n->origin1)) / + + ratio = tmv_dbl(tmv_sub(origin, n->origin1)) / tmv_dbl(tmv_sub(ingress, n->ingress1)); + + /* + * Update ingress/origin/count regardless of ratio. + */ n->ingress1 = ingress; n->origin1 = origin; n->count = 0; + + /* + * The ratio should be nearly 1. If it is off by order of + * magnitude then we have clearly encounterd a time snap and + * should ignore this ratio measurment. + */ + if ((ratio >= 10) || (ratio <= -10)) { + pr_notice("port ignoring erroneous peer ratio %.9f", ratio); + return; + } + + n->ratio = ratio; n->ratio_valid = 1; } -- 2.20.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel