diff --git a/clock.c b/clock.c index cf2f7524..1563ba9d 100644 --- a/clock.c +++ b/clock.c @@ -41,7 +41,6 @@ #define CLK_N_PORTS (MAX_PORTS + 1) /* plus one for the UDS interface */ #define N_CLOCK_PFD (N_POLLFD + 1) /* one extra per port, for the fault timer */ -#define MAVE_LENGTH 10 #define POW2_41 ((double)(1ULL << 41)) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -632,7 +631,8 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count, return NULL; } c->servo_state = SERVO_UNLOCKED; - c->delay_filter = filter_create(FILTER_MOVING_AVERAGE, MAVE_LENGTH); + c->delay_filter = filter_create(dds->delay_filter, + dds->delay_filter_length); if (!c->delay_filter) { pr_err("Failed to create delay filter"); return NULL; diff --git a/config.c b/config.c index 7b7534fd..c86ab015 100644 --- a/config.c +++ b/config.c @@ -159,6 +159,7 @@ static enum parser_result parse_port_setting(const char *option, int p) { enum parser_result r; + int val; r = parse_pod_setting(option, value, &cfg->iface[p].pod); if (r != NOT_PARSED) @@ -183,6 +184,21 @@ static enum parser_result parse_port_setting(const char *option, cfg->iface[p].dm = DM_P2P; else return BAD_VALUE; + + } else if (!strcmp(option, "delay_filter")) { + if (!strcasecmp("moving_average", value)) + cfg->iface[p].delay_filter = FILTER_MOVING_AVERAGE; + else if (!strcasecmp("moving_median", value)) + cfg->iface[p].delay_filter = FILTER_MOVING_MEDIAN; + else + return BAD_VALUE; + + } else if (!strcmp(option, "delay_filter_length")) { + r = get_ranged_int(value, &val, 1, INT_MAX); + if (r != PARSED_OK) + return r; + cfg->iface[p].delay_filter_length = val; + } else return NOT_PARSED; @@ -510,6 +526,20 @@ static enum parser_result parse_global_setting(const char *option, return r; cfg->dds.time_source = val; + } else if (!strcmp(option, "delay_filter")) { + if (!strcasecmp("moving_average", value)) + cfg->dds.delay_filter = FILTER_MOVING_AVERAGE; + else if (!strcasecmp("moving_median", value)) + cfg->dds.delay_filter = FILTER_MOVING_MEDIAN; + else + return BAD_VALUE; + + } else if (!strcmp(option, "delay_filter_length")) { + r = get_ranged_int(value, &val, 1, INT_MAX); + if (r != PARSED_OK) + return r; + cfg->dds.delay_filter_length = val; + } else return NOT_PARSED; @@ -667,6 +697,9 @@ int config_create_interface(char *name, struct config *cfg) sk_get_ts_info(name, &iface->ts_info); + iface->delay_filter = cfg->dds.delay_filter; + iface->delay_filter_length = cfg->dds.delay_filter_length; + cfg->nports++; return i; diff --git a/config.h b/config.h index 6c57bc96..a3800371 100644 --- a/config.h +++ b/config.h @@ -22,6 +22,7 @@ #include "ds.h" #include "dm.h" +#include "filter.h" #include "transport.h" #include "servo.h" #include "sk.h" @@ -36,6 +37,8 @@ struct interface { enum transport_type transport; struct port_defaults pod; struct sk_ts_info ts_info; + enum filter_type delay_filter; + int delay_filter_length; }; #define CFG_IGNORE_DM (1 << 0) diff --git a/default.cfg b/default.cfg index 87945965..80c20b98 100644 --- a/default.cfg +++ b/default.cfg @@ -67,6 +67,8 @@ uds_address /var/run/ptp4l network_transport UDPv4 delay_mechanism E2E time_stamping hardware +delay_filter moving_median +delay_filter_length 10 # # Clock description # diff --git a/ds.h b/ds.h index e8e94ada..6e2ac61d 100644 --- a/ds.h +++ b/ds.h @@ -22,6 +22,7 @@ #include "ddt.h" #include "fault.h" +#include "filter.h" /* clock data sets */ @@ -57,6 +58,8 @@ struct default_ds { int sanity_freq_limit; int time_source; struct clock_description clock_desc; + enum filter_type delay_filter; + int delay_filter_length; }; struct dataset { diff --git a/gPTP.cfg b/gPTP.cfg index a94bd010..3c0842ca 100644 --- a/gPTP.cfg +++ b/gPTP.cfg @@ -65,3 +65,5 @@ uds_address /var/run/ptp4l network_transport L2 delay_mechanism P2P time_stamping hardware +delay_filter moving_median +delay_filter_length 10 diff --git a/port.c b/port.c index e8448b86..94c5cacb 100644 --- a/port.c +++ b/port.c @@ -37,7 +37,6 @@ #include "util.h" #define ALLOWED_LOST_RESPONSES 3 -#define PORT_MAVE_LENGTH 10 enum syfu_state { SF_EMPTY, @@ -2306,7 +2305,8 @@ struct port *port_open(int phc_index, p->delayMechanism = interface->dm; p->versionNumber = PTP_VERSION; - p->delay_filter = filter_create(FILTER_MOVING_AVERAGE, PORT_MAVE_LENGTH); + p->delay_filter = filter_create(interface->delay_filter, + interface->delay_filter_length); if (!p->delay_filter) { pr_err("Failed to create delay filter"); transport_destroy(p->trp); diff --git a/ptp4l.8 b/ptp4l.8 index 01438b31..c59b6e79 100644 --- a/ptp4l.8 +++ b/ptp4l.8 @@ -192,6 +192,15 @@ The default is UDPv4. .B neighborPropDelayThresh Upper limit for peer delay in nanoseconds. If the estimated peer delay is greater than this value the port is marked as not 802.1AS capable. +.TP +.B delay_filter +Select the algorithm used to filter the measured delay and peer delay. Possible +values are moving_average and moving_median. +The default is moving_median. +.TP +.B delay_filter_length +The length of the delay filter in samples. +The default is 10. .SH PROGRAM AND CLOCK OPTIONS diff --git a/ptp4l.c b/ptp4l.c index c828bb41..5d8749a7 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -71,6 +71,8 @@ static struct config cfg_settings = { .userDescription = { .max_symbols = 128 }, .manufacturerIdentity = { 0, 0, 0 }, }, + .delay_filter = FILTER_MOVING_MEDIAN, + .delay_filter_length = 10, }, .pod = {