Add options to configure delay filter.

Add new options delay_filter and delay_filter_length to select the
filter and its length. They set both the clock delay filter and the port
peer delay filter. The default is now moving median with 10 samples.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2013-10-29 11:58:20 +01:00 committed by Richard Cochran
parent ed9e0fa975
commit 85a1bcfa8e
9 changed files with 58 additions and 4 deletions

View File

@ -41,7 +41,6 @@
#define CLK_N_PORTS (MAX_PORTS + 1) /* plus one for the UDS interface */ #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 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 POW2_41 ((double)(1ULL << 41))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #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; return NULL;
} }
c->servo_state = SERVO_UNLOCKED; 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) { if (!c->delay_filter) {
pr_err("Failed to create delay filter"); pr_err("Failed to create delay filter");
return NULL; return NULL;

View File

@ -159,6 +159,7 @@ static enum parser_result parse_port_setting(const char *option,
int p) int p)
{ {
enum parser_result r; enum parser_result r;
int val;
r = parse_pod_setting(option, value, &cfg->iface[p].pod); r = parse_pod_setting(option, value, &cfg->iface[p].pod);
if (r != NOT_PARSED) if (r != NOT_PARSED)
@ -183,6 +184,21 @@ static enum parser_result parse_port_setting(const char *option,
cfg->iface[p].dm = DM_P2P; cfg->iface[p].dm = DM_P2P;
else else
return BAD_VALUE; 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 } else
return NOT_PARSED; return NOT_PARSED;
@ -510,6 +526,20 @@ static enum parser_result parse_global_setting(const char *option,
return r; return r;
cfg->dds.time_source = val; 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 } else
return NOT_PARSED; return NOT_PARSED;
@ -667,6 +697,9 @@ int config_create_interface(char *name, struct config *cfg)
sk_get_ts_info(name, &iface->ts_info); 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++; cfg->nports++;
return i; return i;

View File

@ -22,6 +22,7 @@
#include "ds.h" #include "ds.h"
#include "dm.h" #include "dm.h"
#include "filter.h"
#include "transport.h" #include "transport.h"
#include "servo.h" #include "servo.h"
#include "sk.h" #include "sk.h"
@ -36,6 +37,8 @@ struct interface {
enum transport_type transport; enum transport_type transport;
struct port_defaults pod; struct port_defaults pod;
struct sk_ts_info ts_info; struct sk_ts_info ts_info;
enum filter_type delay_filter;
int delay_filter_length;
}; };
#define CFG_IGNORE_DM (1 << 0) #define CFG_IGNORE_DM (1 << 0)

View File

@ -67,6 +67,8 @@ uds_address /var/run/ptp4l
network_transport UDPv4 network_transport UDPv4
delay_mechanism E2E delay_mechanism E2E
time_stamping hardware time_stamping hardware
delay_filter moving_median
delay_filter_length 10
# #
# Clock description # Clock description
# #

3
ds.h
View File

@ -22,6 +22,7 @@
#include "ddt.h" #include "ddt.h"
#include "fault.h" #include "fault.h"
#include "filter.h"
/* clock data sets */ /* clock data sets */
@ -57,6 +58,8 @@ struct default_ds {
int sanity_freq_limit; int sanity_freq_limit;
int time_source; int time_source;
struct clock_description clock_desc; struct clock_description clock_desc;
enum filter_type delay_filter;
int delay_filter_length;
}; };
struct dataset { struct dataset {

View File

@ -65,3 +65,5 @@ uds_address /var/run/ptp4l
network_transport L2 network_transport L2
delay_mechanism P2P delay_mechanism P2P
time_stamping hardware time_stamping hardware
delay_filter moving_median
delay_filter_length 10

4
port.c
View File

@ -37,7 +37,6 @@
#include "util.h" #include "util.h"
#define ALLOWED_LOST_RESPONSES 3 #define ALLOWED_LOST_RESPONSES 3
#define PORT_MAVE_LENGTH 10
enum syfu_state { enum syfu_state {
SF_EMPTY, SF_EMPTY,
@ -2306,7 +2305,8 @@ struct port *port_open(int phc_index,
p->delayMechanism = interface->dm; p->delayMechanism = interface->dm;
p->versionNumber = PTP_VERSION; 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) { if (!p->delay_filter) {
pr_err("Failed to create delay filter"); pr_err("Failed to create delay filter");
transport_destroy(p->trp); transport_destroy(p->trp);

View File

@ -192,6 +192,15 @@ The default is UDPv4.
.B neighborPropDelayThresh .B neighborPropDelayThresh
Upper limit for peer delay in nanoseconds. If the estimated peer delay is 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. 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 .SH PROGRAM AND CLOCK OPTIONS

View File

@ -71,6 +71,8 @@ static struct config cfg_settings = {
.userDescription = { .max_symbols = 128 }, .userDescription = { .max_symbols = 128 },
.manufacturerIdentity = { 0, 0, 0 }, .manufacturerIdentity = { 0, 0, 0 },
}, },
.delay_filter = FILTER_MOVING_MEDIAN,
.delay_filter_length = 10,
}, },
.pod = { .pod = {