Skip to content

Commit

Permalink
Add options to configure delay filter.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Oct 30, 2013
1 parent ed9e0fa commit 85a1bcf
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "ds.h"
#include "dm.h"
#include "filter.h"
#include "transport.h"
#include "servo.h"
#include "sk.h"
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
3 changes: 3 additions & 0 deletions ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "ddt.h"
#include "fault.h"
#include "filter.h"

/* clock data sets */

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions gPTP.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "util.h"

#define ALLOWED_LOST_RESPONSES 3
#define PORT_MAVE_LENGTH 10

enum syfu_state {
SF_EMPTY,
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions ptp4l.8
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 85a1bcf

Please sign in to comment.