From 3012cf05400676a7c58d50341c8b6ec8c8d475db Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 10 Apr 2013 20:07:48 +0200 Subject: [PATCH] Add option to set maximum frequency adjustment. The option sets an additional limit to the hardware limit. It's disabled if set to zero. The default is 900000000 ppb. Signed-off-by: Miroslav Lichvar --- config.c | 5 +++++ config.h | 1 + default.cfg | 1 + gPTP.cfg | 1 + pi.c | 7 ++++++- pi.h | 6 ++++++ ptp4l.8 | 6 ++++++ ptp4l.c | 1 + 8 files changed, 27 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 08a134f..e056652 100644 --- a/config.c +++ b/config.c @@ -290,6 +290,11 @@ static enum parser_result parse_global_setting(const char *option, return BAD_VALUE; *cfg->pi_offset_const = df; + } else if (!strcmp(option, "pi_max_frequency")) { + if (1 != sscanf(value, "%d", &val) || !(val >= 0)) + return BAD_VALUE; + *cfg->pi_max_frequency = val; + } else if (!strcmp(option, "ptp_dst_mac")) { if (MAC_LEN != sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5])) diff --git a/config.h b/config.h index e7f1f50..901b50a 100644 --- a/config.h +++ b/config.h @@ -68,6 +68,7 @@ struct config { double *pi_proportional_const; double *pi_integral_const; double *pi_offset_const; + int *pi_max_frequency; unsigned char *ptp_dst_mac; unsigned char *p2p_dst_mac; diff --git a/default.cfg b/default.cfg index 4694e32..7cb7566 100644 --- a/default.cfg +++ b/default.cfg @@ -41,6 +41,7 @@ kernel_leap 1 pi_proportional_const 0.0 pi_integral_const 0.0 pi_offset_const 0.0 +pi_max_frequency 900000000 clock_servo pi # # Transport options diff --git a/gPTP.cfg b/gPTP.cfg index 83a44bf..7f27911 100644 --- a/gPTP.cfg +++ b/gPTP.cfg @@ -40,6 +40,7 @@ kernel_leap 1 pi_proportional_const 0.0 pi_integral_const 0.0 pi_offset_const 0.0 +pi_max_frequency 900000000 clock_servo pi # # Transport options diff --git a/pi.c b/pi.c index ec7e456..427cb3e 100644 --- a/pi.c +++ b/pi.c @@ -31,10 +31,11 @@ #define NSEC_PER_SEC 1000000000 -/* These two take their values from the configuration file. (see ptp4l.c) */ +/* These take their values from the configuration file. (see ptp4l.c) */ double configured_pi_kp = 0.0; double configured_pi_ki = 0.0; double configured_pi_offset = 0.0; +int configured_pi_max_freq = 900000000; struct pi_servo { struct servo servo; @@ -150,5 +151,9 @@ struct servo *pi_servo_create(int fadj, int max_ppb, int sw_ts) s->max_offset = 0.0; } + if (configured_pi_max_freq && s->maxppb > configured_pi_max_freq) { + s->maxppb = configured_pi_max_freq; + } + return &s->servo; } diff --git a/pi.h b/pi.h index eff90aa..954f495 100644 --- a/pi.h +++ b/pi.h @@ -42,6 +42,12 @@ extern double configured_pi_ki; */ extern double configured_pi_offset; +/** + * When set to a non-zero value, this variable sets an additional limit for + * the frequency adjustment of the clock. It's in ppb. + */ +extern int configured_pi_max_freq; + struct servo *pi_servo_create(int fadj, int max_ppb, int sw_ts); #endif diff --git a/ptp4l.8 b/ptp4l.8 index ee9cccd..11b1b6f 100644 --- a/ptp4l.8 +++ b/ptp4l.8 @@ -292,6 +292,12 @@ frequency instead of stepping the clock. When set to 0.0, the controller will never step the clock. The default is 0.0. .TP +.B pi_max_frequency +The maximum allowed frequency adjustment of the clock in parts per billion +(ppb). This is an additional limit to the maximum allowed by the hardware. When +set to 0, the hardware limit will be used. +The default is 900000000 (90%). +.TP .B ptp_dst_mac The MAC address where should be PTP messages sent. Relevant only with L2 transport. The default is 01:1B:19:00:00:00. diff --git a/ptp4l.c b/ptp4l.c index 3bf1f86..3792375 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -96,6 +96,7 @@ static struct config cfg_settings = { .pi_proportional_const = &configured_pi_kp, .pi_integral_const = &configured_pi_ki, .pi_offset_const = &configured_pi_offset, + .pi_max_frequency = &configured_pi_max_freq, .ptp_dst_mac = ptp_dst_mac, .p2p_dst_mac = p2p_dst_mac,