Skip to content

Commit

Permalink
config: convert the 'step_threshold' option to the new scheme.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Aug 23, 2015
1 parent 28fbc39 commit df57813
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
21 changes: 15 additions & 6 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ struct config_item {

#define N_CONFIG_ITEMS (sizeof(config_tab) / sizeof(config_tab[0]))

#define CONFIG_ITEM_DBL(_label, _port, _default, _min, _max) { \
.label = _label, \
.type = CFG_TYPE_DOUBLE, \
.flags = _port ? CFG_ITEM_PORT : 0, \
.val.d = _default, \
.min.d = _min, \
.max.d = _max, \
}
#define CONFIG_ITEM_INT(_label, _port, _default, _min, _max) { \
.label = _label, \
.type = CFG_TYPE_INT, \
Expand All @@ -70,15 +78,22 @@ struct config_item {
.max.i = _max, \
}

#define GLOB_ITEM_DBL(label, _default, min, max) \
CONFIG_ITEM_DBL(label, 0, _default, min, max)

#define GLOB_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 0, _default, min, max)

#define PORT_ITEM_DBL(label, _default, min, max) \
CONFIG_ITEM_DBL(label, 1, _default, min, max)

#define PORT_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 1, _default, min, max)

struct config_item config_tab[] = {
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
};
Expand Down Expand Up @@ -569,12 +584,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
*cfg->pi_integral_norm_max = df;

} else if (!strcmp(option, "step_threshold")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK)
return r;
*cfg->step_threshold = df;

} else if (!strcmp(option, "first_step_threshold")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK)
Expand Down
1 change: 0 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

double *step_threshold;
double *first_step_threshold;
int *max_frequency;

Expand Down
9 changes: 6 additions & 3 deletions phc2sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,11 +1222,12 @@ int main(int argc, char *argv[])
char *progname;
char *src_name = NULL, *dst_name = NULL;
struct clock *src, *dst;
struct config *cfg;
int autocfg = 0, rt = 0;
int c, domain_number = 0, pps_fd = -1;
int r, wait_sync = 0;
int print_level = LOG_INFO, use_syslog = 1, verbose = 0;
double phc_rate;
double phc_rate, tmp;
struct node node = {
.sanity_freq_limit = 200000000,
.servo_type = CLOCK_SERVO_PI,
Expand All @@ -1240,6 +1241,7 @@ int main(int argc, char *argv[])
if (config_init(&phc2sys_config)) {
return -1;
}
cfg = &phc2sys_config;

configured_pi_kp = KP;
configured_pi_ki = KI;
Expand Down Expand Up @@ -1297,8 +1299,9 @@ int main(int argc, char *argv[])
return -1;
break;
case 'S':
if (get_arg_val_d(c, optarg, &servo_step_threshold,
0.0, DBL_MAX))
if (get_arg_val_d(c, optarg, &tmp, 0.0, DBL_MAX))
return -1;
if (config_set_double(cfg, "step_threshold", tmp))
return -1;
break;
case 'F':
Expand Down
1 change: 0 additions & 1 deletion ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

.step_threshold = &servo_step_threshold,
.first_step_threshold = &servo_first_step_threshold,
.max_frequency = &servo_max_frequency,

Expand Down
4 changes: 3 additions & 1 deletion servo.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
#include <string.h>

#include "config.h"
#include "linreg.h"
#include "ntpshm.h"
#include "nullf.h"
Expand All @@ -26,13 +27,13 @@

#define NSEC_PER_SEC 1000000000

double servo_step_threshold = 0.0;
double servo_first_step_threshold = 0.00002; /* 20 microseconds */
int servo_max_frequency = 900000000;

struct servo *servo_create(struct config *cfg, enum servo_type type,
int fadj, int max_ppb, int sw_ts)
{
double servo_step_threshold;
struct servo *servo;

switch (type) {
Expand All @@ -52,6 +53,7 @@ struct servo *servo_create(struct config *cfg, enum servo_type type,
return NULL;
}

servo_step_threshold = config_get_double(cfg, NULL, "step_threshold");
if (servo_step_threshold > 0.0) {
servo->step_threshold = servo_step_threshold * NSEC_PER_SEC;
} else {
Expand Down
9 changes: 0 additions & 9 deletions servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@

struct config;

/**
* When set to a non-zero value, this variable controls the maximum allowed
* offset before a clock jump occurs instead of the default clock-slewing
* mechanism.
*
* Note that this variable is measured in seconds, and allows fractional values.
*/
extern double servo_step_threshold;

/**
* When set to zero, the clock is not stepped on start. When set to a non-zero
* value, the value bahaves as a threshold and the clock is stepped on start if
Expand Down

0 comments on commit df57813

Please sign in to comment.