Discussion:
[Linuxptp-devel] [PATCH RFC v4 00/69] New configuration implementation
Richard Cochran
2015-08-20 18:14:06 UTC
Permalink
Changes in V4:
- Added missing calls to config_get_double() for:
"pi_integral_exponent"
"pi_integral_norm_max"
"pi_integral_scale"
"pi_proportional_exponent"
"pi_proportional_norm_max"

Changes in V3:
- Reduced interface to two types, double and int
(enums are accessed like ints)
- Converted almost everything

Changes in V2:
- API is much simpler to use
- numerous details in the implementation have been improved
- half dozen legacy options converted

Now this series passes the linuxptp-testsuite. I pushed the branch to
github in the hopes that people will pull and test it.

repo: ***@github.com:richardcochran/linuxptp-as.git
branch: config-v4

(BTW buggy branch config-v3 has been deleted from github.)

Patches 1-4 and 12 provide changes allowing passing of the configuration.
Patches 5 and 6 add a simple hash table.
Patch 7 adds the bulk of the new implementation.
Patch 8 lets the UDP transport use the new TTL option.
Patch 13 adds a way to "lock" options from the command line.
Patch 37 cleans up a useless variable.
Patch 54 removes a now empty structure.
Patch 62 adds enumerated types.
Patch 69 tweaks ptp4l's logging configuration.

All the *other* patches convert individual options.

Review and comments are most welcome.

Thanks,
Richard

Richard Cochran (69):
clock: store the configuration in the clock data structure.
clock: add a method to obtain the configuration.
pmc: require a configuration for creating a PMC instance.
transport: store the configuration in the transport data structure.
Introduce a simple hash table implementation.
config: Add a hash table into the data structure.
config: introduce a new API for reading configuration settings.
udp: configure the socket with the TTL option.
config: convert the 'assume_two_step' option to the new scheme.
config: convert 'tx_timestamp_timeout' to the new scheme.
config: convert the 'check_fup_sync' option to the new scheme.
servo: store the configuration in the servo data structure.
config: add methods to set values taken from the command line.
config: convert the 'step_threshold' option to the new scheme.
config: convert the 'first_step_threshold' option to the new scheme.
config: convert the 'max_frequency' option to the new scheme.
config: convert 'logging_level' to the new scheme.
config: convert 'use_syslog' to the new scheme.
config: convert 'verbose' to the new scheme.
config: convert 'pi_proportional_const' to the new scheme.
config: convert 'pi_integral_const' to the new scheme.
config: convert 'pi_proportional_scale' to the new scheme.
config: convert 'pi_proportional_exponent' to the new scheme.
config: convert 'pi_proportional_norm_max' to the new scheme.
config: convert 'pi_integral_scale' to the new scheme.
config: convert 'pi_integral_exponent' to the new scheme.
config: convert 'pi_integral_norm_max' to the new scheme.
config: convert 'ntpshm_segment' to the new scheme.
config: port: convert 'delayAsymmetry' to the new scheme.
config: port: convert 'logAnnounceInterval' to the new scheme.
config: port: convert 'logSyncInterval' to the new scheme.
config: port: convert 'logMinDelayReqInterval' to the new scheme.
config: port: convert 'logMinPdelayReqInterval' to the new scheme.
config: port: convert 'announceReceiptTimeout' to the new scheme.
config: port: convert 'syncReceiptTimeout' to the new scheme.
config: prot: convert 'transportSpecific' to the new scheme.
port: change 'announce_span' into a macro.
config: port: convert 'path_trace_enabled' to the new scheme.
config: port: convert 'follow_up_info' to the new scheme.
config: clock, port: convert 'freq_est_interval' to the new scheme.
config: port: convert 'neighborPropDelayThresh' to new scheme.
config: port: convert 'min_neighbor_prop_delay' to the new scheme.
config: port: convert 'egressLatency' to the new scheme.
config: port: convert 'ingressLatency' to the new scheme.
config: port: convert 'delay_filter_length' to the new scheme.
config: clock, port: convert 'boundary_clock_jbod' to the new scheme.
config: convert 'free_running' to the new scheme.
config: convert 'gmCapable' to the new scheme.
config: convert 'summary_interval' to the new scheme.
config: convert 'kernel_leap' to the new scheme.
config: convert 'sanity_freq_limit' to the new scheme.
config: convert 'timeSource' to the new scheme.
config: convert the fault interval options to the new scheme.
config: remove the 'port_defaults' structure.
config: convert 'udp6_scope' to the new scheme.
config: convert 'slaveOnly' and 'twoStepFlag' to the new scheme.
config: convert 'priority1' and 'priority2' to the new scheme.
config: convert 'clockClass' to the new scheme.
config: convert 'clockAccuracy' to the new scheme.
config: convert 'offsetScaledLogVariance' to the new scheme.
config: convert 'domainNumber' to the new scheme.
config: add support for enumerated types with string labels.
config: convert 'network_transport' to the new scheme.
config: convert 'delay_mechanism' to the new scheme.
config: convert 'tsproc_mode' to the new scheme.
config: convert 'delay_filter' to the new scheme.
config: convert 'time_stamping' to the new scheme.
config: convert 'clock_servo' to the new scheme.
ptp4l: set print levels earlier.

clock.c | 52 ++-
clock.h | 16 +-
config.c | 956 +++++++++++++++++++++++++---------------------------
config.h | 71 ++--
ds.h | 31 --
hash.c | 113 +++++++
hash.h | 59 ++++
makefile | 12 +-
ntpshm.c | 9 +-
ntpshm.h | 7 +-
phc2sys.c | 48 ++-
pi.c | 73 ++--
pi.h | 58 +---
pmc.c | 7 +-
pmc_common.c | 9 +-
pmc_common.h | 8 +-
port.c | 105 ++++--
ptp4l.c | 199 +++++------
servo.c | 20 +-
servo.h | 27 +-
transport.c | 7 +-
transport.h | 6 +-
transport_private.h | 1 +
udp.c | 15 +-
udp6.c | 5 +-
udp6.h | 6 -
26 files changed, 995 insertions(+), 925 deletions(-)
create mode 100644 hash.c
create mode 100644 hash.h
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:08 UTC
Permalink
This function allows the ports to read configuration variables without
changing the port method signatures.

Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 5 +++++
clock.h | 7 +++++++
2 files changed, 12 insertions(+)

diff --git a/clock.c b/clock.c
index 1569108..a47e1e9 100644
--- a/clock.c
+++ b/clock.c
@@ -755,6 +755,11 @@ UInteger8 clock_class(struct clock *c)
return c->dds.clockQuality.clockClass;
}

+struct config *clock_config(struct clock *c)
+{
+ return c->config;
+}
+
static int clock_add_port(struct clock *c, int phc_index,
enum timestamp_type timestamping,
struct interface *iface)
diff --git a/clock.h b/clock.h
index 1e6cd98..d7377fe 100644
--- a/clock.h
+++ b/clock.h
@@ -58,6 +58,13 @@ struct port *clock_best_port(struct clock *c);
UInteger8 clock_class(struct clock *c);

/**
+ * Obtains a reference to the configuration database.
+ * @param c The clock instance.
+ * @return A pointer to the configuration, without fail.
+ */
+struct config *clock_config(struct clock *c);
+
+/**
* Create a clock instance. There can only be one clock in any system,
* so subsequent calls will destroy the previous clock instance.
*
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:07 UTC
Permalink
This will help us to simplify the passing of parameters between the main
program. clock, and ports.

Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 9 ++++++---
clock.h | 8 +++++---
ptp4l.c | 3 ++-
3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/clock.c b/clock.c
index 9e9feba..1569108 100644
--- a/clock.c
+++ b/clock.c
@@ -73,6 +73,7 @@ struct clock_subscriber {
};

struct clock {
+ struct config *config;
clockid_t clkid;
struct servo *servo;
enum servo_type servo_type;
@@ -792,9 +793,10 @@ static void clock_remove_port(struct clock *c, struct port *p)
port_close(p);
}

-struct clock *clock_create(int phc_index, struct interfaces_head *ifaces,
- enum timestamp_type timestamping, struct default_ds *dds,
- enum servo_type servo)
+struct clock *clock_create(struct config *config, int phc_index,
+ struct interfaces_head *ifaces,
+ enum timestamp_type timestamping,
+ struct default_ds *dds, enum servo_type servo)
{
int fadj = 0, max_adj = 0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
struct clock *c = &the_clock;
@@ -814,6 +816,7 @@ struct clock *clock_create(int phc_index, struct interfaces_head *ifaces,
udsif->transport = TRANS_UDS;
udsif->delay_filter_length = 1;

+ c->config = config;
c->free_running = dds->free_running;
c->freq_est_interval = dds->freq_est_interval;
c->grand_master_capable = dds->grand_master_capable;
diff --git a/clock.h b/clock.h
index a8286dd..1e6cd98 100644
--- a/clock.h
+++ b/clock.h
@@ -61,6 +61,7 @@ UInteger8 clock_class(struct clock *c);
* Create a clock instance. There can only be one clock in any system,
* so subsequent calls will destroy the previous clock instance.
*
+ * @param config Pointer to the configuration database.
* @param phc_index PTP hardware clock device to use.
* Pass -1 to select CLOCK_REALTIME.
* @param ifaces A queue of network interfaces.
@@ -69,9 +70,10 @@ UInteger8 clock_class(struct clock *c);
* @param servo The servo that this clock will use.
* @return A pointer to the single global clock instance.
*/
-struct clock *clock_create(int phc_index, struct interfaces_head *ifaces,
- enum timestamp_type timestamping, struct default_ds *dds,
- enum servo_type servo);
+struct clock *clock_create(struct config *config, int phc_index,
+ struct interfaces_head *ifaces,
+ enum timestamp_type timestamping,
+ struct default_ds *dds, enum servo_type servo);

/**
* Obtains a clock's default data set.
diff --git a/ptp4l.c b/ptp4l.c
index 61c5854..56cb8bd 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -377,7 +377,8 @@ int main(int argc, char *argv[])
return -1;
}

- clock = clock_create(phc_index, &cfg_settings.interfaces,
+ clock = clock_create(&cfg_settings,
+ phc_index, &cfg_settings.interfaces,
*timestamping, &cfg_settings.dds,
cfg_settings.clock_servo);
if (!clock) {
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:09 UTC
Permalink
In the near future, the transports will need to consult the configuration
database in order to obtain various options. This patch also introduces
the idea of a configuration file into the phc2sys and pmc programs.

Signed-off-by: Richard Cochran <***@gmail.com>
---
phc2sys.c | 10 ++++++----
pmc.c | 3 ++-
pmc_common.c | 7 ++++---
pmc_common.h | 8 +++++---
4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/phc2sys.c b/phc2sys.c
index 9ff5bf9..5ba99c3 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -119,6 +119,8 @@ struct node {
struct clock *master;
};

+static struct config phc2sys_config;
+
static int update_pmc(struct node *node, int subscribe);
static int clock_handle_leap(struct node *node, struct clock *clock,
int64_t offset, uint64_t ts);
@@ -777,13 +779,13 @@ static void send_subscription(struct node *node)
pmc_send_set_action(node->pmc, TLV_SUBSCRIBE_EVENTS_NP, &sen, sizeof(sen));
}

-static int init_pmc(struct node *node, int domain_number)
+static int init_pmc(struct config *cfg, struct node *node, int domain_number)
{
char uds_local[MAX_IFNAME_SIZE + 1];

snprintf(uds_local, sizeof(uds_local), "/var/run/phc2sys.%d",
getpid());
- node->pmc = pmc_create(TRANS_UDS, uds_local, 0, domain_number, 0, 1);
+ node->pmc = pmc_create(cfg, TRANS_UDS, uds_local, 0, domain_number, 0, 1);
if (!node->pmc) {
pr_err("failed to create pmc");
return -1;
@@ -1395,7 +1397,7 @@ int main(int argc, char *argv[])
print_set_level(print_level);

if (autocfg) {
- if (init_pmc(&node, domain_number))
+ if (init_pmc(&phc2sys_config, &node, domain_number))
return -1;
if (auto_init_ports(&node, rt) < 0)
return -1;
@@ -1431,7 +1433,7 @@ int main(int argc, char *argv[])
r = -1;

if (wait_sync) {
- if (init_pmc(&node, domain_number))
+ if (init_pmc(&phc2sys_config, &node, domain_number))
goto end;

while (is_running()) {
diff --git a/pmc.c b/pmc.c
index 0774f88..1fe8183 100644
--- a/pmc.c
+++ b/pmc.c
@@ -42,6 +42,7 @@
#define P41 ((double)(1ULL << 41))

static struct pmc *pmc;
+static struct config pmc_config;

static void do_get_action(int action, int index, char *str);
static void do_set_action(int action, int index, char *str);
@@ -816,7 +817,7 @@ int main(int argc, char *argv[])
print_set_syslog(1);
print_set_verbose(1);

- pmc = pmc_create(transport_type, iface_name, boundary_hops,
+ pmc = pmc_create(&pmc_config, transport_type, iface_name, boundary_hops,
domain_number, transport_specific, zero_datalen);
if (!pmc) {
fprintf(stderr, "failed to create pmc\n");
diff --git a/pmc_common.c b/pmc_common.c
index afd6e5f..0a365f5 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -61,9 +61,10 @@ struct pmc {
int zero_length_gets;
};

-struct pmc *pmc_create(enum transport_type transport_type, const char *iface_name,
- UInteger8 boundary_hops, UInteger8 domain_number,
- UInteger8 transport_specific, int zero_datalen)
+struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
+ const char *iface_name, UInteger8 boundary_hops,
+ UInteger8 domain_number, UInteger8 transport_specific,
+ int zero_datalen)
{
struct pmc *pmc;

diff --git a/pmc_common.h b/pmc_common.h
index 9adb9d1..bb3a1f1 100644
--- a/pmc_common.h
+++ b/pmc_common.h
@@ -21,14 +21,16 @@
#ifndef HAVE_PMC_COMMON_H
#define HAVE_PMC_COMMON_H

+#include "config.h"
#include "msg.h"
#include "transport.h"

struct pmc;

-struct pmc *pmc_create(enum transport_type transport_type, const char *iface_name,
- UInteger8 boundary_hops, UInteger8 domain_number,
- UInteger8 transport_specific, int zero_datalen);
+struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
+ const char *iface_name, UInteger8 boundary_hops,
+ UInteger8 domain_number, UInteger8 transport_specific,
+ int zero_datalen);

void pmc_destroy(struct pmc *pmc);
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:10 UTC
Permalink
This will allow modules to read out various user options.

Signed-off-by: Richard Cochran <***@gmail.com>
---
pmc_common.c | 2 +-
port.c | 3 ++-
transport.c | 7 +++++--
transport.h | 6 +++++-
transport_private.h | 1 +
5 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/pmc_common.c b/pmc_common.c
index 0a365f5..d92b0cd 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -85,7 +85,7 @@ struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
pmc->domain_number = domain_number;
pmc->transport_specific = transport_specific;

- pmc->transport = transport_create(transport_type);
+ pmc->transport = transport_create(cfg, transport_type);
if (!pmc->transport) {
pr_err("failed to create transport");
goto failed;
diff --git a/port.c b/port.c
index 3ed5e7b..028df32 100644
--- a/port.c
+++ b/port.c
@@ -2495,6 +2495,7 @@ struct port *port_open(int phc_index,
struct interface *interface,
struct clock *clock)
{
+ struct config *cfg = clock_config(clock);
struct port *p = malloc(sizeof(*p));

if (!p)
@@ -2524,7 +2525,7 @@ struct port *port_open(int phc_index,
p->pod = interface->pod;
p->name = interface->name;
p->clock = clock;
- p->trp = transport_create(interface->transport);
+ p->trp = transport_create(cfg, interface->transport);
if (!p->trp)
goto err_port;
p->timestamping = timestamping;
diff --git a/transport.c b/transport.c
index fc18740..d24c05b 100644
--- a/transport.c
+++ b/transport.c
@@ -87,7 +87,8 @@ enum transport_type transport_type(struct transport *t)
return t->type;
}

-struct transport *transport_create(enum transport_type type)
+struct transport *transport_create(struct config *cfg,
+ enum transport_type type)
{
struct transport *t = NULL;
switch (type) {
@@ -108,8 +109,10 @@ struct transport *transport_create(enum transport_type type)
case TRANS_PROFINET:
break;
}
- if (t)
+ if (t) {
t->type = type;
+ t->cfg = cfg;
+ }
return t;
}

diff --git a/transport.h b/transport.h
index 8e0d421..5d6ba98 100644
--- a/transport.h
+++ b/transport.h
@@ -26,6 +26,8 @@
#include "fd.h"
#include "msg.h"

+struct config;
+
/* Values from networkProtocol enumeration 7.4.1 Table 3 */
enum transport_type {
/* 0 is Reserved in spec. Use it for UDS */
@@ -123,10 +125,12 @@ int transport_protocol_addr(struct transport *t, uint8_t *addr);

/**
* Allocate an instance of the specified transport.
+ * @param config Pointer to the configuration database.
* @param type Which transport to obtain.
* @return Pointer to a transport instance on success, NULL otherwise.
*/
-struct transport *transport_create(enum transport_type type);
+struct transport *transport_create(struct config *cfg,
+ enum transport_type type);

/**
* Free an instance of a transport.
diff --git a/transport_private.h b/transport_private.h
index 3e0ba9a..b54f32a 100644
--- a/transport_private.h
+++ b/transport_private.h
@@ -28,6 +28,7 @@

struct transport {
enum transport_type type;
+ struct config *cfg;

int (*close)(struct transport *t, struct fdarray *fda);
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:11 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
hash.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hash.h | 59 +++++++++++++++++++++++++++++++++
makefile | 2 +-
3 files changed, 173 insertions(+), 1 deletion(-)
create mode 100644 hash.c
create mode 100644 hash.h

diff --git a/hash.c b/hash.c
new file mode 100644
index 0000000..e768692
--- /dev/null
+++ b/hash.c
@@ -0,0 +1,113 @@
+/**
+ * @file hash.c
+ * @brief Implements a simple hash table.
+ * @note Copyright (C) 2015 Richard Cochran <***@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "hash.h"
+
+#define HASH_TABLE_SIZE 200
+
+struct node {
+ char *key;
+ void *data;
+ struct node *next;
+};
+
+struct hash {
+ struct node *table[HASH_TABLE_SIZE];
+};
+
+static unsigned int hash_function(const char* s)
+{
+ unsigned int i;
+
+ for (i = 0; *s; s++) {
+ i = 131 * i + *s;
+ }
+ return i % HASH_TABLE_SIZE;
+}
+
+struct hash *hash_create(void)
+{
+ struct hash *ht = calloc(1, sizeof(*ht));
+ return ht;
+}
+
+void hash_destroy(struct hash *ht, void (*func)(void *))
+{
+ unsigned int i;
+ struct node *n, *next, **table = ht->table;
+
+ for (i = 0; i < HASH_TABLE_SIZE; i++) {
+ for (n = table[i] ; n; n = next) {
+ next = n->next;
+ if (func) {
+ func(n->data);
+ }
+ free(n->key);
+ free(n);
+ }
+ }
+
+ free(ht);
+}
+
+int hash_insert(struct hash *ht, const char* key, void *data)
+{
+ unsigned int h;
+ struct node *n, **table = ht->table;
+
+ h = hash_function(key);
+
+ for (n = table[h] ; n; n = n->next) {
+ if (!strcmp(n->key, key)) {
+ /* reject duplicate keys */
+ return -1;
+ }
+ }
+ n = calloc(1, sizeof(*n));
+ if (!n) {
+ return -1;
+ }
+ n->key = strdup(key);
+ if (!n->key) {
+ free(n);
+ return -1;
+ }
+ n->data = data;
+ n->next = table[h];
+ table[h] = n;
+ return 0;
+}
+
+void *hash_lookup(struct hash *ht, const char* key)
+{
+ unsigned int h;
+ struct node *n, **table = ht->table;
+
+ h = hash_function(key);
+
+ for (n = table[h] ; n; n = n->next) {
+ if (!strcmp(n->key, key)) {
+ return n->data;
+ }
+ }
+ return NULL;
+}
diff --git a/hash.h b/hash.h
new file mode 100644
index 0000000..74aae0b
--- /dev/null
+++ b/hash.h
@@ -0,0 +1,59 @@
+/**
+ * @file hash.h
+ * @brief Implements a simple hash table.
+ * @note Copyright (C) 2015 Richard Cochran <***@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef HAVE_HASH_H
+#define HAVE_HASH_H
+
+struct hash;
+
+/**
+ * Create a new hash table.
+ * @return A pointer to a new hash table on success, NULL otherwise.
+ */
+struct hash *hash_create(void);
+
+/**
+ * Destroy an instance of a hash table.
+ * @param ht Pointer to a hash table obtained via @ref hash_create().
+ * @param func Callback function, possibly NULL, to apply to the
+ * data of each element in the table.
+ */
+void hash_destroy(struct hash *ht, void (*func)(void *));
+
+/**
+ * Inserts an element into a hash table.
+ * @param ht Hash table into which the element is to be stored.
+ * @param key Key that identifies the element.
+ * @param data Pointer to the user data to be stored.
+ * @return Zero on success and non-zero on error. Attempting to
+ * insert a duplicate key will fail with an error.
+ */
+int hash_insert(struct hash *ht, const char* key, void *data);
+
+/**
+ * Looks up an element from the hash table.
+ * @param ht Hash table to consult.
+ * @param key Key identifying the element of interest.
+ * @return Pointer to the element's data, or NULL if the key is not found.
+ */
+void *hash_lookup(struct hash *ht, const char* key);
+
+#endif
+
+
diff --git a/makefile b/makefile
index a8e5ce8..922769b 100644
--- a/makefile
+++ b/makefile
@@ -24,7 +24,7 @@ CFLAGS = -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS)
LDLIBS = -lm -lrt $(EXTRA_LDFLAGS)
PRG = ptp4l pmc phc2sys hwstamp_ctl phc_ctl timemaster
OBJ = bmc.o clock.o clockadj.o clockcheck.o config.o fault.o \
- filter.o fsm.o linreg.o mave.o mmedian.o msg.o ntpshm.o nullf.o phc.o \
+ filter.o fsm.o hash.o linreg.o mave.o mmedian.o msg.o ntpshm.o nullf.o phc.o \
pi.o port.o print.o ptp4l.o raw.o servo.o sk.o stats.o tlv.o \
transport.o tsproc.o udp.o udp6.o uds.o util.o version.o
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:12 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 11 +++++++++++
config.h | 4 ++++
2 files changed, 15 insertions(+)

diff --git a/config.c b/config.c
index 934caa2..9ef8be1 100644
--- a/config.c
+++ b/config.c
@@ -24,6 +24,7 @@
#include <string.h>
#include "config.h"
#include "ether.h"
+#include "hash.h"
#include "print.h"
#include "util.h"

@@ -803,6 +804,15 @@ void config_init_interface(struct interface *iface, struct config *cfg)
iface->boundary_clock_jbod = cfg->dds.boundary_clock_jbod;
}

+int config_init(struct config *cfg)
+{
+ cfg->htab = hash_create();
+ if (!cfg->htab) {
+ return -1;
+ }
+ return 0;
+}
+
void config_destroy(struct config *cfg)
{
struct interface *iface;
@@ -811,4 +821,5 @@ void config_destroy(struct config *cfg)
STAILQ_REMOVE_HEAD(&cfg->interfaces, list);
free(iface);
}
+ hash_destroy(cfg->htab, free);
}
diff --git a/config.h b/config.h
index 7bff11f..222883a 100644
--- a/config.h
+++ b/config.h
@@ -60,6 +60,10 @@ struct config {
/* configured interfaces */
STAILQ_HEAD(interfaces_head, interface) interfaces;

+ /* hash of all non-legacy items */
+ struct hash *htab;
+
+ /* the rest are legacy fields */
enum timestamp_type timestamping;
enum transport_type transport;
enum delay_mechanism dm;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:14 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
udp.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/udp.c b/udp.c
index b100dbf..b8aa76a 100644
--- a/udp.c
+++ b/udp.c
@@ -30,6 +30,7 @@
#include <unistd.h>

#include "address.h"
+#include "config.h"
#include "contain.h"
#include "print.h"
#include "sk.h"
@@ -92,7 +93,8 @@ static int udp_close(struct transport *t, struct fdarray *fda)
return 0;
}

-static int open_socket(const char *name, struct in_addr mc_addr[2], short port)
+static int open_socket(const char *name, struct in_addr mc_addr[2], short port,
+ int ttl)
{
struct sockaddr_in addr;
int fd, index, on = 1;
@@ -123,6 +125,10 @@ static int open_socket(const char *name, struct in_addr mc_addr[2], short port)
pr_err("setsockopt SO_BINDTODEVICE failed: %m");
goto no_option;
}
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl))) {
+ pr_err("setsockopt IP_MULTICAST_TTL failed: %m");
+ goto no_option;
+ }
addr.sin_addr = mc_addr[0];
if (mcast_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
pr_err("mcast_join failed");
@@ -151,8 +157,9 @@ static int udp_open(struct transport *t, const char *name, struct fdarray *fda,
enum timestamp_type ts_type)
{
struct udp *udp = container_of(t, struct udp, t);
- int efd, gfd;
+ int efd, gfd, ttl;

+ ttl = config_get_int(t->cfg, name, "udp_ttl");
udp->mac.len = 0;
sk_interface_macaddr(name, &udp->mac);

@@ -165,11 +172,11 @@ static int udp_open(struct transport *t, const char *name, struct fdarray *fda,
if (!inet_aton(PTP_PDELAY_MCAST_IPADDR, &mcast_addr[MC_PDELAY]))
return -1;

- efd = open_socket(name, mcast_addr, EVENT_PORT);
+ efd = open_socket(name, mcast_addr, EVENT_PORT, ttl);
if (efd < 0)
goto no_event;

- gfd = open_socket(name, mcast_addr, GENERAL_PORT);
+ gfd = open_socket(name, mcast_addr, GENERAL_PORT, ttl);
if (gfd < 0)
goto no_general;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:13 UTC
Permalink
This patch introduces generic code for adding and parsing new options.
The public 'get' methods return option values directly. Although the
API is easy to use, it does not provide error checking in case the
option does not exist or if there is a type mismatch.

Therefore the code performs a BIST to ensure that the options are
properly populated. In addition, the code terminates the program in
case of missing options or type mismatches. This heavy handed
approach is meant to catch errors during development and should never
trigger during normal usage.

As a first element, we include an option for specifying the UDP TTL.

Users are required to call 'config_init', and so this patch add that into
all three programs, ptp4l, phc2sys and pmc.

Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
config.h | 10 +++
makefile | 10 +--
phc2sys.c | 4 +
pmc.c | 4 +
ptp4l.c | 4 +
6 files changed, 265 insertions(+), 12 deletions(-)

diff --git a/config.c b/config.c
index 9ef8be1..d3c19e5 100644
--- a/config.c
+++ b/config.c
@@ -34,6 +34,116 @@ enum config_section {
UNKNOWN_SECTION,
};

+enum config_type {
+ CFG_TYPE_INT,
+ CFG_TYPE_DOUBLE,
+};
+
+typedef union {
+ int i;
+ double d;
+} any_t;
+
+#define CONFIG_LABEL_SIZE 32
+
+#define CFG_ITEM_STATIC (1 << 0) /* statically allocated, not to be freed */
+#define CFG_ITEM_LOCKED (1 << 1) /* command line value, may not be changed */
+#define CFG_ITEM_PORT (1 << 2) /* item may appear in port sections */
+
+struct config_item {
+ char label[CONFIG_LABEL_SIZE];
+ enum config_type type;
+ unsigned int flags;
+ any_t val;
+ any_t min;
+ any_t max;
+};
+
+#define N_CONFIG_ITEMS (sizeof(config_tab) / sizeof(config_tab[0]))
+
+#define CONFIG_ITEM_INT(_label, _port, _default, _min, _max) { \
+ .label = _label, \
+ .type = CFG_TYPE_INT, \
+ .flags = _port ? CFG_ITEM_PORT : 0, \
+ .val.i = _default, \
+ .min.i = _min, \
+ .max.i = _max, \
+}
+
+#define GLOB_ITEM_INT(label, _default, min, max) \
+ CONFIG_ITEM_INT(label, 0, _default, min, max)
+
+#define PORT_ITEM_INT(label, _default, min, max) \
+ CONFIG_ITEM_INT(label, 1, _default, min, max)
+
+struct config_item config_tab[] = {
+ PORT_ITEM_INT("udp_ttl", 1, 1, 255),
+};
+
+static struct config_item *config_section_item(struct config *cfg,
+ const char *section,
+ const char *name)
+{
+ char buf[CONFIG_LABEL_SIZE + MAX_IFNAME_SIZE];
+
+ snprintf(buf, sizeof(buf), "%s.%s", section, name);
+ return hash_lookup(cfg->htab, buf);
+}
+
+static struct config_item *config_global_item(struct config *cfg,
+ const char *name)
+{
+ return config_section_item(cfg, "global", name);
+}
+
+static struct config_item *config_find_item(struct config *cfg,
+ const char *section,
+ const char *name)
+{
+ struct config_item *ci;
+ if (section) {
+ ci = config_section_item(cfg, section, name);
+ if (ci) {
+ return ci;
+ }
+ }
+ return config_global_item(cfg, name);
+}
+
+static struct config_item *config_item_alloc(struct config *cfg,
+ const char *section,
+ const char *name,
+ enum config_type type)
+{
+ struct config_item *ci;
+ char buf[CONFIG_LABEL_SIZE + MAX_IFNAME_SIZE];
+
+ ci = calloc(1, sizeof(*ci));
+ if (!ci) {
+ fprintf(stderr, "low memory\n");
+ return NULL;
+ }
+ strncpy(ci->label, name, CONFIG_LABEL_SIZE - 1);
+ ci->type = type;
+
+ snprintf(buf, sizeof(buf), "%s.%s", section, ci->label);
+ if (hash_insert(cfg->htab, buf, ci)) {
+ fprintf(stderr, "low memory or duplicate item %s\n", name);
+ free(ci);
+ return NULL;
+ }
+
+ return ci;
+}
+
+static void config_item_free(void *ptr)
+{
+ struct config_item *ci = ptr;
+ if (ci->flags & CFG_ITEM_STATIC)
+ return;
+ free(ci);
+}
+
static enum parser_result parse_section_line(char *s, enum config_section *section)
{
if (!strcasecmp(s, "[global]")) {
@@ -52,6 +162,65 @@ static enum parser_result parse_section_line(char *s, enum config_section *secti
return PARSED_OK;
}

+static enum parser_result parse_item(struct config *cfg,
+ const char *section,
+ const char *option,
+ const char *value)
+{
+ struct config_item *cgi, *dst;
+ enum parser_result r = BAD_VALUE;
+ double df;
+ int val;
+
+ /* If there is no default value, then the option is bogus. */
+ cgi = config_global_item(cfg, option);
+ if (!cgi) {
+ return NOT_PARSED;
+ }
+
+ switch (cgi->type) {
+ case CFG_TYPE_INT:
+ r = get_ranged_int(value, &val, cgi->min.i, cgi->max.i);
+ break;
+ case CFG_TYPE_DOUBLE:
+ r = get_ranged_double(value, &df, cgi->min.d, cgi->max.d);
+ break;
+ }
+ if (r != PARSED_OK) {
+ return r;
+ }
+
+ if (section) {
+ if (!(cgi->flags & CFG_ITEM_PORT)) {
+ return NOT_PARSED;
+ }
+ /* Create or update this port specific item. */
+ dst = config_section_item(cfg, section, option);
+ if (!dst) {
+ dst = config_item_alloc(cfg, section, option, cgi->type);
+ if (!dst) {
+ return NOT_PARSED;
+ }
+ }
+ } else if (cgi->flags & CFG_ITEM_LOCKED) {
+ /* This global option was set on the command line. */
+ return PARSED_OK;
+ } else {
+ /* Update the global default value. */
+ dst = cgi;
+ }
+
+ switch (dst->type) {
+ case CFG_TYPE_INT:
+ dst->val.i = val;
+ break;
+ case CFG_TYPE_DOUBLE:
+ dst->val.d = df;
+ break;
+ }
+ return PARSED_OK;
+}
+
static enum parser_result parse_pod_setting(const char *option,
const char *value,
struct port_defaults *pod)
@@ -173,9 +342,10 @@ static enum parser_result parse_pod_setting(const char *option,
return PARSED_OK;
}

-static enum parser_result parse_port_setting(const char *option,
- const char *value,
- struct interface *iface)
+static enum parser_result parse_port_setting(struct config *cfg,
+ const char *option,
+ const char *value,
+ struct interface *iface)
{
enum parser_result r;
int val;
@@ -237,7 +407,7 @@ static enum parser_result parse_port_setting(const char *option,
iface->boundary_clock_jbod = val;

} else
- return NOT_PARSED;
+ return parse_item(cfg, iface->name, option, value);

return PARSED_OK;
}
@@ -614,7 +784,7 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.boundary_clock_jbod = val;

} else
- return NOT_PARSED;
+ return parse_item(cfg, NULL, option, value);

return PARSED_OK;
}
@@ -727,7 +897,7 @@ int config_read(char *name, struct config *cfg)
if (current_section == GLOBAL_SECTION)
parser_res = parse_global_setting(option, value, cfg);
else
- parser_res = parse_port_setting(option, value, current_port);
+ parser_res = parse_port_setting(cfg, option, value, current_port);

switch (parser_res) {
case PARSED_OK:
@@ -806,11 +976,40 @@ void config_init_interface(struct interface *iface, struct config *cfg)

int config_init(struct config *cfg)
{
+ char buf[CONFIG_LABEL_SIZE + 8];
+ struct config_item *ci;
+ int i;
+
cfg->htab = hash_create();
if (!cfg->htab) {
return -1;
}
+
+ /* Populate the hash table with global defaults. */
+ for (i = 0; i < N_CONFIG_ITEMS; i++) {
+ ci = &config_tab[i];
+ ci->flags |= CFG_ITEM_STATIC;
+ snprintf(buf, sizeof(buf), "global.%s", ci->label);
+ if (hash_insert(cfg->htab, buf, ci)) {
+ fprintf(stderr, "duplicate item %s\n", ci->label);
+ goto fail;
+ }
+ }
+
+ /* Perform a Built In Self Test.*/
+ for (i = 0; i < N_CONFIG_ITEMS; i++) {
+ ci = &config_tab[i];
+ ci = config_global_item(cfg, ci->label);
+ if (ci != &config_tab[i]) {
+ fprintf(stderr, "config BIST failed at %s\n",
+ config_tab[i].label);
+ goto fail;
+ }
+ }
return 0;
+fail:
+ hash_destroy(cfg->htab, NULL);
+ return -1;
}

void config_destroy(struct config *cfg)
@@ -821,5 +1020,37 @@ void config_destroy(struct config *cfg)
STAILQ_REMOVE_HEAD(&cfg->interfaces, list);
free(iface);
}
- hash_destroy(cfg->htab, free);
+ hash_destroy(cfg->htab, config_item_free);
+}
+
+double config_get_double(struct config *cfg, const char *section,
+ const char *option)
+{
+ struct config_item *ci = config_find_item(cfg, section, option);
+
+ if (!ci || ci->type != CFG_TYPE_DOUBLE) {
+ pr_err("bug: config option %s missing or invalid!", option);
+ exit(-1);
+ }
+ pr_debug("config item %s.%s is %f", section, option, ci->val.d);
+ return ci->val.d;
+}
+
+int config_get_int(struct config *cfg, const char *section, const char *option)
+{
+ struct config_item *ci = config_find_item(cfg, section, option);
+
+ if (!ci) {
+ pr_err("bug: config option %s missing!", option);
+ exit(-1);
+ }
+ switch (ci->type) {
+ case CFG_TYPE_DOUBLE:
+ pr_err("bug: config option %s type mismatch!", option);
+ exit(-1);
+ case CFG_TYPE_INT:
+ break;
+ }
+ pr_debug("config item %s.%s is %d", section, option, ci->val.i);
+ return ci->val.i;
}
diff --git a/config.h b/config.h
index 222883a..f722ea6 100644
--- a/config.h
+++ b/config.h
@@ -105,4 +105,14 @@ struct interface *config_create_interface(char *name, struct config *cfg);
void config_init_interface(struct interface *iface, struct config *cfg);
void config_destroy(struct config *cfg);

+/* New, hash table based methods: */
+
+int config_init(struct config *cfg);
+
+double config_get_double(struct config *cfg, const char *section,
+ const char *option);
+
+int config_get_int(struct config *cfg, const char *section,
+ const char *option);
+
#endif
diff --git a/makefile b/makefile
index 922769b..bcdbb92 100644
--- a/makefile
+++ b/makefile
@@ -46,13 +46,13 @@ all: $(PRG)

ptp4l: $(OBJ)

-pmc: msg.o pmc.o pmc_common.o print.o raw.o sk.o tlv.o transport.o udp.o \
- udp6.o uds.o util.o version.o
-
-phc2sys: clockadj.o clockcheck.o linreg.o msg.o ntpshm.o nullf.o phc.o \
- phc2sys.o pi.o pmc_common.o print.o raw.o servo.o sk.o stats.o sysoff.o tlv.o \
+pmc: config.o hash.o msg.o pmc.o pmc_common.o print.o raw.o sk.o tlv.o \
transport.o udp.o udp6.o uds.o util.o version.o

+phc2sys: clockadj.o clockcheck.o config.o hash.o linreg.o msg.o ntpshm.o \
+ nullf.o phc.o phc2sys.o pi.o pmc_common.o print.o raw.o servo.o sk.o stats.o \
+ sysoff.o tlv.o transport.o udp.o udp6.o uds.o util.o version.o
+
hwstamp_ctl: hwstamp_ctl.o version.o

phc_ctl: phc_ctl.o phc.o sk.o util.o clockadj.o sysoff.o print.o version.o
diff --git a/phc2sys.c b/phc2sys.c
index 5ba99c3..92af7ad 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1236,6 +1236,10 @@ int main(int argc, char *argv[])

handle_term_signals();

+ if (config_init(&phc2sys_config)) {
+ return -1;
+ }
+
configured_pi_kp = KP;
configured_pi_ki = KI;

diff --git a/pmc.c b/pmc.c
index 1fe8183..65ea0cf 100644
--- a/pmc.c
+++ b/pmc.c
@@ -744,6 +744,10 @@ int main(int argc, char *argv[])

handle_term_signals();

+ if (config_init(&pmc_config)) {
+ return -1;
+ }
+
/* Process the command line arguments. */
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
diff --git a/ptp4l.c b/ptp4l.c
index 56cb8bd..e2482c8 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -182,6 +182,10 @@ int main(int argc, char *argv[])
if (handle_term_signals())
return -1;

+ if (config_init(&cfg_settings)) {
+ return -1;
+ }
+
/* Set fault timeouts to a default value */
for (i = 0; i < FT_CNT; i++) {
cfg_settings.pod.flt_interval_pertype[i].type = FTMO_LOG2_SECONDS;
--
2.1.4


------------------------------------------------------------------------------
Keller, Jacob E
2015-08-20 22:25:23 UTC
Permalink
Post by Richard Cochran
Therefore the code performs a BIST to ensure that the options are
properly populated. In addition, the code terminates the program in
case of missing options or type mismatches. This heavy handed
approach is meant to catch errors during development and should never
trigger during normal usage.
If I understand this correctly, this means that a user passing a
configuration file missing any option the program reads we will
terminate the whole program instead of selecting the default?

I think this is the safest approach but we will want to ensure we
document that you can't leave items out if you use a configuration file
as I suspect that will not be necessarily expected behavior.

Or do I mis-understand this?

Regards,
Jake
------------------------------------------------------------------------------
Richard Cochran
2015-08-21 08:38:00 UTC
Permalink
Post by Keller, Jacob E
If I understand this correctly, this means that a user passing a
configuration file missing any option the program reads we will
terminate the whole program instead of selecting the default?
No, that is not how it works.

The function, config_init(), must be called before calling
config_read(file). [1] In config_init, the items in the 'config_tab'
are loaded into the hash table. The BIST is simply a built in unit
test to confirm that the hash table is working properly.

After that, all *correct* calls to config_get_int/_double cannot
fail. However, if new call sites misspell the option string or mix up
the types, we have to somehow throw an error. Any such error can only
be a programming error, never a user configuration error.

Example: In pi.c, if the developer were to write

s->configured_pi_ki_norm_max =
config_get_int(cfg, NULL, "pi_integral_norm_max");

instead of

s->configured_pi_ki_norm_max =
config_get_double(cfg, NULL, "pi_integral_norm_max");

then the log would show:

ptp4l[1829.910]: config item (null).pi_integral_scale is 0.000000
ptp4l[1829.910]: config item (null).pi_integral_exponent is 0.400000
ptp4l[1829.910]: bug: config option pi_integral_norm_max type mismatch!


In the interest of keeping the config_get_ API clean and simple, I did
not provide a return code to the caller. Instead, we simply bail out
of the program altogether. That is good enough for catching errors
during development.

Thanks,
Richard


1. Once all of the legacy stuff is gone, then config_init() can
allocate the structure and return a pointer to it.

------------------------------------------------------------------------------
Keller, Jacob E
2015-08-21 15:42:08 UTC
Permalink
Post by Richard Cochran
Post by Keller, Jacob E
If I understand this correctly, this means that a user passing a
configuration file missing any option the program reads we will
terminate the whole program instead of selecting the default?
No, that is not how it works.
So, what happens in the case of a configuration file that is missing a
field? ie: a user provides a configuration file which doesn't have the
item in it?

Regards,
Jake
------------------------------------------------------------------------------
Richard Cochran
2015-08-21 18:29:51 UTC
Permalink
Post by Keller, Jacob E
So, what happens in the case of a configuration file that is missing a
field? ie: a user provides a configuration file which doesn't have the
item in it?
Then the default value from the 'config_tab' table is used.

Thanks,
Richard

------------------------------------------------------------------------------
Keller, Jacob E
2015-08-21 20:49:36 UTC
Permalink
Post by Richard Cochran
Post by Keller, Jacob E
So, what happens in the case of a configuration file that is
missing a
field? ie: a user provides a configuration file which doesn't have the
item in it?
Then the default value from the 'config_tab' table is used.
Thanks,
Richard
Oh I see that now. I must have missed it. Thanks that's great :)

Regards,
Jake
------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:15 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
ptp4l.c | 5 ++++-
3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/config.c b/config.c
index d3c19e5..871e277 100644
--- a/config.c
+++ b/config.c
@@ -77,6 +77,7 @@ struct config_item {
CONFIG_ITEM_INT(label, 1, _default, min, max)

struct config_item config_tab[] = {
+ GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
};

@@ -518,12 +519,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "assume_two_step")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- *cfg->assume_two_step = val;
-
} else if (!strcmp(option, "tx_timestamp_timeout")) {
r = get_ranged_int(value, &val, 1, INT_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index f722ea6..9811ebe 100644
--- a/config.h
+++ b/config.h
@@ -70,7 +70,6 @@ struct config {

struct default_ds dds;
struct port_defaults pod;
- int *assume_two_step;
int *tx_timestamp_timeout;
int *check_fup_sync;

diff --git a/ptp4l.c b/ptp4l.c
index e2482c8..f52963e 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -102,7 +102,6 @@ static struct config cfg_settings = {
.dm = DM_E2E,
.transport = TRANS_UDP_IPV4,

- .assume_two_step = &assume_two_step,
.tx_timestamp_timeout = &sk_tx_timeout,
.check_fup_sync = &sk_check_fupsync,

@@ -176,6 +175,7 @@ int main(int argc, char *argv[])
enum transport_type *transport = &cfg_settings.transport;
enum timestamp_type *timestamping = &cfg_settings.timestamping;
struct clock *clock;
+ struct config *cfg = &cfg_settings;
struct defaultDS *ds = &cfg_settings.dds.dds;
int phc_index = -1, required_modes = 0;

@@ -279,6 +279,9 @@ int main(int argc, char *argv[])
if (config && (c = config_read(config, &cfg_settings))) {
return c;
}
+
+ assume_two_step = config_get_int(cfg, NULL, "assume_two_step");
+
if (!cfg_settings.dds.grand_master_capable &&
ds->flags & DDS_SLAVE_ONLY) {
fprintf(stderr,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:17 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 2 --
ptp4l.c | 4 +---
3 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/config.c b/config.c
index ad398c1..2cd2788 100644
--- a/config.c
+++ b/config.c
@@ -78,6 +78,7 @@ struct config_item {

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_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
};
@@ -520,12 +521,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "check_fup_sync")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- *cfg->check_fup_sync = val;
-
} else if (!strcmp(option, "pi_proportional_const")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 8e95561..b200c8c 100644
--- a/config.h
+++ b/config.h
@@ -70,8 +70,6 @@ struct config {

struct default_ds dds;
struct port_defaults pod;
- int *check_fup_sync;
-
enum servo_type clock_servo;

double *step_threshold;
diff --git a/ptp4l.c b/ptp4l.c
index 439058c..b2ac0d5 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -101,9 +101,6 @@ static struct config cfg_settings = {
.timestamping = TS_HARDWARE,
.dm = DM_E2E,
.transport = TRANS_UDP_IPV4,
-
- .check_fup_sync = &sk_check_fupsync,
-
.clock_servo = CLOCK_SERVO_PI,

.step_threshold = &servo_step_threshold,
@@ -280,6 +277,7 @@ int main(int argc, char *argv[])
}

assume_two_step = config_get_int(cfg, NULL, "assume_two_step");
+ sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync");
sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");

if (!cfg_settings.dds.grand_master_capable &&
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:16 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
ptp4l.c | 2 +-
3 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/config.c b/config.c
index 871e277..ad398c1 100644
--- a/config.c
+++ b/config.c
@@ -78,6 +78,7 @@ struct config_item {

struct config_item config_tab[] = {
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
+ GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
};

@@ -519,12 +520,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "tx_timestamp_timeout")) {
- r = get_ranged_int(value, &val, 1, INT_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->tx_timestamp_timeout = val;
-
} else if (!strcmp(option, "check_fup_sync")) {
r = get_ranged_int(value, &val, 0, 1);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 9811ebe..8e95561 100644
--- a/config.h
+++ b/config.h
@@ -70,7 +70,6 @@ struct config {

struct default_ds dds;
struct port_defaults pod;
- int *tx_timestamp_timeout;
int *check_fup_sync;

enum servo_type clock_servo;
diff --git a/ptp4l.c b/ptp4l.c
index f52963e..439058c 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -102,7 +102,6 @@ static struct config cfg_settings = {
.dm = DM_E2E,
.transport = TRANS_UDP_IPV4,

- .tx_timestamp_timeout = &sk_tx_timeout,
.check_fup_sync = &sk_check_fupsync,

.clock_servo = CLOCK_SERVO_PI,
@@ -281,6 +280,7 @@ int main(int argc, char *argv[])
}

assume_two_step = config_get_int(cfg, NULL, "assume_two_step");
+ sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");

if (!cfg_settings.dds.grand_master_capable &&
ds->flags & DDS_SLAVE_ONLY) {
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:19 UTC
Permalink
This patch adds functions that will set and lock a certain value. The
intended use of these methods is to give command line options priority
over the configuration file.

Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
config.h | 11 +++++++++++
2 files changed, 61 insertions(+)

diff --git a/config.c b/config.c
index 2cd2788..aa856ad 100644
--- a/config.c
+++ b/config.c
@@ -1039,3 +1039,53 @@ int config_get_int(struct config *cfg, const char *section, const char *option)
pr_debug("config item %s.%s is %d", section, option, ci->val.i);
return ci->val.i;
}
+
+int config_set_double(struct config *cfg, const char *option, double val)
+{
+ struct config_item *ci = config_find_item(cfg, NULL, option);
+
+ if (!ci || ci->type != CFG_TYPE_DOUBLE) {
+ pr_err("bug: config option %s missing or invalid!", option);
+ return -1;
+ }
+ ci->flags |= CFG_ITEM_LOCKED;
+ ci->val.d = val;
+ pr_debug("locked item global.%s as %f", option, ci->val.d);
+ return 0;
+}
+
+int config_set_section_int(struct config *cfg, const char *section,
+ const char *option, int val)
+{
+ struct config_item *cgi, *dst;
+
+ cgi = config_find_item(cfg, NULL, option);
+ if (!cgi) {
+ pr_err("bug: config option %s missing!", option);
+ return -1;
+ }
+ switch (cgi->type) {
+ case CFG_TYPE_DOUBLE:
+ pr_err("bug: config option %s type mismatch!", option);
+ return -1;
+ case CFG_TYPE_INT:
+ break;
+ }
+ if (!section) {
+ cgi->flags |= CFG_ITEM_LOCKED;
+ cgi->val.i = val;
+ pr_debug("locked item global.%s as %d", option, cgi->val.i);
+ return 0;
+ }
+ /* Create or update this port specific item. */
+ dst = config_section_item(cfg, section, option);
+ if (!dst) {
+ dst = config_item_alloc(cfg, section, option, cgi->type);
+ if (!dst) {
+ return -1;
+ }
+ }
+ dst->val.i = val;
+ pr_debug("section item %s.%s now %d", section, option, dst->val.i);
+ return 0;
+}
diff --git a/config.h b/config.h
index b200c8c..4538b4e 100644
--- a/config.h
+++ b/config.h
@@ -111,4 +111,15 @@ double config_get_double(struct config *cfg, const char *section,
int config_get_int(struct config *cfg, const char *section,
const char *option);

+int config_set_double(struct config *cfg, const char *option, double val);
+
+int config_set_section_int(struct config *cfg, const char *section,
+ const char *option, int val);
+
+static inline int config_set_int(struct config *cfg,
+ const char *option, int val)
+{
+ return config_set_section_int(cfg, NULL, option, val);
+}
+
#endif
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:21 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
phc2sys.c | 5 +++--
ptp4l.c | 1 -
servo.c | 5 ++++-
servo.h | 9 ---------
6 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/config.c b/config.c
index 6732b23..d539a5b 100644
--- a/config.c
+++ b/config.c
@@ -93,6 +93,7 @@ struct config_item {
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("first_step_threshold", 0.00002, 0.0, DBL_MAX),
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),
@@ -584,12 +585,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
*cfg->pi_integral_norm_max = df;

- } else if (!strcmp(option, "first_step_threshold")) {
- r = get_ranged_double(value, &df, 0.0, DBL_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->first_step_threshold = df;
-
} else if (!strcmp(option, "max_frequency")) {
r = get_ranged_int(value, &val, 0, INT_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 45805de..b8781fa 100644
--- a/config.h
+++ b/config.h
@@ -72,7 +72,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *first_step_threshold;
int *max_frequency;

double *pi_proportional_const;
diff --git a/phc2sys.c b/phc2sys.c
index fa75607..44ba1fc 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1305,8 +1305,9 @@ int main(int argc, char *argv[])
return -1;
break;
case 'F':
- if (get_arg_val_d(c, optarg, &servo_first_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, "first_step_threshold", tmp))
return -1;
break;
case 'R':
diff --git a/ptp4l.c b/ptp4l.c
index 3b913c0..575ee0c 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .first_step_threshold = &servo_first_step_threshold,
.max_frequency = &servo_max_frequency,

.pi_proportional_const = &configured_pi_kp,
diff --git a/servo.c b/servo.c
index f1eddc8..4f26ea6 100644
--- a/servo.c
+++ b/servo.c
@@ -27,12 +27,12 @@

#define NSEC_PER_SEC 1000000000

-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_first_step_threshold;
double servo_step_threshold;
struct servo *servo;

@@ -60,6 +60,9 @@ struct servo *servo_create(struct config *cfg, enum servo_type type,
servo->step_threshold = 0.0;
}

+ servo_first_step_threshold =
+ config_get_double(cfg, NULL, "first_step_threshold");
+
if (servo_first_step_threshold > 0.0) {
servo->first_step_threshold =
servo_first_step_threshold * NSEC_PER_SEC;
diff --git a/servo.h b/servo.h
index 88d926b..b5252df 100644
--- a/servo.h
+++ b/servo.h
@@ -25,15 +25,6 @@
struct config;

/**
- * 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
- * the offset is bigger than the threshold.
- *
- * Note that this variable is measured in seconds, and allows fractional values.
- */
-extern double servo_first_step_threshold;
-
-/**
* When set to a non-zero value, this variable sets an additional limit for
* the frequency adjustment of the clock. It's in ppb.
*/
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:18 UTC
Permalink
This will allow removing the code that passes configuration options via
global variables.

Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 4 ++--
phc2sys.c | 3 ++-
servo.c | 3 ++-
servo.h | 5 ++++-
4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/clock.c b/clock.c
index a47e1e9..8a5ef05 100644
--- a/clock.c
+++ b/clock.c
@@ -866,7 +866,7 @@ struct clock *clock_create(struct config *config, int phc_index,
the actual frequency of the clock. */
clockadj_set_freq(c->clkid, fadj);
}
- c->servo = servo_create(servo, -fadj, max_adj, sw_ts);
+ c->servo = servo_create(c->config, servo, -fadj, max_adj, sw_ts);
if (!c->servo) {
pr_err("Failed to create clock servo");
return NULL;
@@ -1356,7 +1356,7 @@ int clock_switch_phc(struct clock *c, int phc_index)
}
fadj = (int) clockadj_get_freq(clkid);
clockadj_set_freq(clkid, fadj);
- servo = servo_create(c->servo_type, -fadj, max_adj, 0);
+ servo = servo_create(c->config, c->servo_type, -fadj, max_adj, 0);
if (!servo) {
pr_err("Switching PHC, failed to create clock servo");
phc_close(clkid);
diff --git a/phc2sys.c b/phc2sys.c
index 92af7ad..45ae363 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -224,7 +224,8 @@ static struct clock *clock_add(struct node *node, char *device)
}
}

- c->servo = servo_create(node->servo_type, -ppb, max_ppb, 0);
+ c->servo = servo_create(&phc2sys_config, node->servo_type,
+ -ppb, max_ppb, 0);
servo_sync_interval(c->servo, node->phc_interval);

if (clkid != CLOCK_REALTIME)
diff --git a/servo.c b/servo.c
index b936a85..aa71b21 100644
--- a/servo.c
+++ b/servo.c
@@ -30,7 +30,8 @@ double servo_step_threshold = 0.0;
double servo_first_step_threshold = 0.00002; /* 20 microseconds */
int servo_max_frequency = 900000000;

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

diff --git a/servo.h b/servo.h
index 0a182a4..cc0b098 100644
--- a/servo.h
+++ b/servo.h
@@ -22,6 +22,8 @@

#include <stdint.h>

+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
@@ -92,7 +94,8 @@ enum servo_state {
* and the servo should use more aggressive filtering.
* @return A pointer to a new servo on success, NULL otherwise.
*/
-struct servo *servo_create(enum servo_type type, int fadj, int max_ppb, int sw_ts);
+struct servo *servo_create(struct config *cfg, enum servo_type type,
+ int fadj, int max_ppb, int sw_ts);

/**
* Destroy an instance of a clock servo.
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:22 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 2 --
ptp4l.c | 2 --
servo.c | 4 ++--
servo.h | 6 ------
5 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/config.c b/config.c
index d539a5b..08508be 100644
--- a/config.c
+++ b/config.c
@@ -94,6 +94,7 @@ 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("first_step_threshold", 0.00002, 0.0, DBL_MAX),
+ GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
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),
@@ -585,12 +586,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
*cfg->pi_integral_norm_max = df;

- } else if (!strcmp(option, "max_frequency")) {
- r = get_ranged_int(value, &val, 0, INT_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->max_frequency = val;
-
} else if (!strcmp(option, "sanity_freq_limit")) {
r = get_ranged_int(value, &val, 0, INT_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index b8781fa..a297e85 100644
--- a/config.h
+++ b/config.h
@@ -72,8 +72,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- int *max_frequency;
-
double *pi_proportional_const;
double *pi_integral_const;
double *pi_proportional_scale;
diff --git a/ptp4l.c b/ptp4l.c
index 575ee0c..ca62370 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,8 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .max_frequency = &servo_max_frequency,
-
.pi_proportional_const = &configured_pi_kp,
.pi_integral_const = &configured_pi_ki,
.pi_proportional_scale = &configured_pi_kp_scale,
diff --git a/servo.c b/servo.c
index 4f26ea6..2e82ebe 100644
--- a/servo.c
+++ b/servo.c
@@ -27,13 +27,12 @@

#define NSEC_PER_SEC 1000000000

-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_first_step_threshold;
double servo_step_threshold;
+ int servo_max_frequency;
struct servo *servo;

switch (type) {
@@ -70,6 +69,7 @@ struct servo *servo_create(struct config *cfg, enum servo_type type,
servo->first_step_threshold = 0.0;
}

+ servo_max_frequency = config_get_int(cfg, NULL, "max_frequency");
servo->max_frequency = max_ppb;
if (servo_max_frequency && servo->max_frequency > servo_max_frequency) {
servo->max_frequency = servo_max_frequency;
diff --git a/servo.h b/servo.h
index b5252df..f90befd 100644
--- a/servo.h
+++ b/servo.h
@@ -24,12 +24,6 @@

struct config;

-/**
- * 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 servo_max_frequency;
-
/** Opaque type */
struct servo;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:20 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 21 +++++++++++++++------
config.h | 1 -
phc2sys.c | 9 ++++++---
ptp4l.c | 1 -
servo.c | 4 +++-
servo.h | 9 ---------
6 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/config.c b/config.c
index aa856ad..6732b23 100644
--- a/config.c
+++ b/config.c
@@ -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, \
@@ -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),
};
@@ -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)
diff --git a/config.h b/config.h
index 4538b4e..45805de 100644
--- a/config.h
+++ b/config.h
@@ -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;

diff --git a/phc2sys.c b/phc2sys.c
index 45ae363..fa75607 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -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,
@@ -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;
@@ -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':
diff --git a/ptp4l.c b/ptp4l.c
index b2ac0d5..3b913c0 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -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,

diff --git a/servo.c b/servo.c
index aa71b21..f1eddc8 100644
--- a/servo.c
+++ b/servo.c
@@ -18,6 +18,7 @@
*/
#include <string.h>

+#include "config.h"
#include "linreg.h"
#include "ntpshm.h"
#include "nullf.h"
@@ -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) {
@@ -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 {
diff --git a/servo.h b/servo.h
index cc0b098..88d926b 100644
--- a/servo.h
+++ b/servo.h
@@ -25,15 +25,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
* the offset is bigger than the threshold.
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:23 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 10 +---------
config.h | 2 --
ptp4l.c | 9 ++++-----
3 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/config.c b/config.c
index 08508be..143d9db 100644
--- a/config.c
+++ b/config.c
@@ -94,6 +94,7 @@ 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("first_step_threshold", 0.00002, 0.0, DBL_MAX),
+ GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
@@ -623,15 +624,6 @@ static enum parser_result parse_global_setting(const char *option,
return OUT_OF_RANGE;
strncpy(cfg->uds_address, value, MAX_IFNAME_SIZE);

- } else if (!strcmp(option, "logging_level")) {
- r = get_ranged_int(value, &val,
- PRINT_LEVEL_MIN, PRINT_LEVEL_MAX);
- if (r != PARSED_OK)
- return r;
- if (!(cfg_ignore & CFG_IGNORE_PRINT_LEVEL)) {
- cfg->print_level = val;
- }
-
} else if (!strcmp(option, "verbose")) {
r = get_ranged_int(value, &val, 0, 1);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index a297e85..0b7c291 100644
--- a/config.h
+++ b/config.h
@@ -49,7 +49,6 @@ struct interface {
#define CFG_IGNORE_TRANSPORT (1 << 1)
#define CFG_IGNORE_TIMESTAMPING (1 << 2)
#define CFG_IGNORE_SLAVEONLY (1 << 3)
-#define CFG_IGNORE_PRINT_LEVEL (1 << 4)
#define CFG_IGNORE_USE_SYSLOG (1 << 5)
#define CFG_IGNORE_VERBOSE (1 << 6)

@@ -87,7 +86,6 @@ struct config {
unsigned char *udp6_scope;
char *uds_address;

- int print_level;
int use_syslog;
int verbose;
};
diff --git a/ptp4l.c b/ptp4l.c
index ca62370..068b1f3 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -118,7 +118,6 @@ static struct config cfg_settings = {
.udp6_scope = &udp6_scope,
.uds_address = uds_path,

- .print_level = LOG_INFO,
.use_syslog = 1,
.verbose = 0,

@@ -169,7 +168,7 @@ int main(int argc, char *argv[])
struct clock *clock;
struct config *cfg = &cfg_settings;
struct defaultDS *ds = &cfg_settings.dds.dds;
- int phc_index = -1, required_modes = 0;
+ int phc_index = -1, print_level, required_modes = 0;

if (handle_term_signals())
return -1;
@@ -240,10 +239,10 @@ int main(int argc, char *argv[])
*cfg_ignore |= CFG_IGNORE_SLAVEONLY;
break;
case 'l':
- if (get_arg_val_i(c, optarg, &cfg_settings.print_level,
+ if (get_arg_val_i(c, optarg, &print_level,
PRINT_LEVEL_MIN, PRINT_LEVEL_MAX))
return -1;
- *cfg_ignore |= CFG_IGNORE_PRINT_LEVEL;
+ config_set_int(cfg, "logging_level", print_level);
break;
case 'm':
cfg_settings.verbose = 1;
@@ -294,7 +293,7 @@ int main(int argc, char *argv[])
print_set_progname(progname);
print_set_verbose(cfg_settings.verbose);
print_set_syslog(cfg_settings.use_syslog);
- print_set_level(cfg_settings.print_level);
+ print_set_level(config_get_int(cfg, NULL, "logging_level"));

if (STAILQ_EMPTY(&cfg_settings.interfaces)) {
fprintf(stderr, "no interface specified\n");
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:24 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 8 +-------
config.h | 2 --
ptp4l.c | 6 ++----
3 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/config.c b/config.c
index 143d9db..90d7659 100644
--- a/config.c
+++ b/config.c
@@ -99,6 +99,7 @@ struct config_item config_tab[] = {
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),
+ GLOB_ITEM_INT("use_syslog", 1, 0, 1),
};

static struct config_item *config_section_item(struct config *cfg,
@@ -631,13 +632,6 @@ static enum parser_result parse_global_setting(const char *option,
if (!(cfg_ignore & CFG_IGNORE_VERBOSE))
cfg->verbose = val;

- } else if (!strcmp(option, "use_syslog")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- if (!(cfg_ignore & CFG_IGNORE_USE_SYSLOG))
- cfg->use_syslog = val;
-
} else if (!strcmp(option, "time_stamping")) {
if (!(cfg_ignore & CFG_IGNORE_TIMESTAMPING)) {
if (0 == strcasecmp("hardware", value))
diff --git a/config.h b/config.h
index 0b7c291..c456ea0 100644
--- a/config.h
+++ b/config.h
@@ -49,7 +49,6 @@ struct interface {
#define CFG_IGNORE_TRANSPORT (1 << 1)
#define CFG_IGNORE_TIMESTAMPING (1 << 2)
#define CFG_IGNORE_SLAVEONLY (1 << 3)
-#define CFG_IGNORE_USE_SYSLOG (1 << 5)
#define CFG_IGNORE_VERBOSE (1 << 6)

struct config {
@@ -86,7 +85,6 @@ struct config {
unsigned char *udp6_scope;
char *uds_address;

- int use_syslog;
int verbose;
};

diff --git a/ptp4l.c b/ptp4l.c
index 068b1f3..3e34079 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -118,7 +118,6 @@ static struct config cfg_settings = {
.udp6_scope = &udp6_scope,
.uds_address = uds_path,

- .use_syslog = 1,
.verbose = 0,

.cfg_ignore = 0,
@@ -249,8 +248,7 @@ int main(int argc, char *argv[])
*cfg_ignore |= CFG_IGNORE_VERBOSE;
break;
case 'q':
- cfg_settings.use_syslog = 0;
- *cfg_ignore |= CFG_IGNORE_USE_SYSLOG;
+ config_set_int(cfg, "use_syslog", 0);
break;
case 'v':
version_show(stdout);
@@ -292,7 +290,7 @@ int main(int argc, char *argv[])

print_set_progname(progname);
print_set_verbose(cfg_settings.verbose);
- print_set_syslog(cfg_settings.use_syslog);
+ print_set_syslog(config_get_int(cfg, NULL, "use_syslog"));
print_set_level(config_get_int(cfg, NULL, "logging_level"));

if (STAILQ_EMPTY(&cfg_settings.interfaces)) {
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:25 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 8 +-------
config.h | 3 ---
ptp4l.c | 7 ++-----
3 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/config.c b/config.c
index 90d7659..b649cf0 100644
--- a/config.c
+++ b/config.c
@@ -100,6 +100,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
GLOB_ITEM_INT("use_syslog", 1, 0, 1),
+ GLOB_ITEM_INT("verbose", 0, 0, 1),
};

static struct config_item *config_section_item(struct config *cfg,
@@ -625,13 +626,6 @@ static enum parser_result parse_global_setting(const char *option,
return OUT_OF_RANGE;
strncpy(cfg->uds_address, value, MAX_IFNAME_SIZE);

- } else if (!strcmp(option, "verbose")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- if (!(cfg_ignore & CFG_IGNORE_VERBOSE))
- cfg->verbose = val;
-
} else if (!strcmp(option, "time_stamping")) {
if (!(cfg_ignore & CFG_IGNORE_TIMESTAMPING)) {
if (0 == strcasecmp("hardware", value))
diff --git a/config.h b/config.h
index c456ea0..db7963f 100644
--- a/config.h
+++ b/config.h
@@ -49,7 +49,6 @@ struct interface {
#define CFG_IGNORE_TRANSPORT (1 << 1)
#define CFG_IGNORE_TIMESTAMPING (1 << 2)
#define CFG_IGNORE_SLAVEONLY (1 << 3)
-#define CFG_IGNORE_VERBOSE (1 << 6)

struct config {
/* configuration override */
@@ -84,8 +83,6 @@ struct config {
unsigned char *p2p_dst_mac;
unsigned char *udp6_scope;
char *uds_address;
-
- int verbose;
};

int config_read(char *name, struct config *cfg);
diff --git a/ptp4l.c b/ptp4l.c
index 3e34079..78261a9 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -118,8 +118,6 @@ static struct config cfg_settings = {
.udp6_scope = &udp6_scope,
.uds_address = uds_path,

- .verbose = 0,
-
.cfg_ignore = 0,
};

@@ -244,8 +242,7 @@ int main(int argc, char *argv[])
config_set_int(cfg, "logging_level", print_level);
break;
case 'm':
- cfg_settings.verbose = 1;
- *cfg_ignore |= CFG_IGNORE_VERBOSE;
+ config_set_int(cfg, "verbose", 1);
break;
case 'q':
config_set_int(cfg, "use_syslog", 0);
@@ -289,7 +286,7 @@ int main(int argc, char *argv[])
}

print_set_progname(progname);
- print_set_verbose(cfg_settings.verbose);
+ print_set_verbose(config_get_int(cfg, NULL, "verbose"));
print_set_syslog(config_get_int(cfg, NULL, "use_syslog"));
print_set_level(config_get_int(cfg, NULL, "logging_level"));
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:26 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
phc2sys.c | 7 ++++---
pi.c | 11 +++++++----
pi.h | 8 +-------
ptp4l.c | 1 -
servo.c | 2 +-
7 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/config.c b/config.c
index b649cf0..3bd98da 100644
--- a/config.c
+++ b/config.c
@@ -96,6 +96,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
+ GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
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),
@@ -541,12 +542,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "pi_proportional_const")) {
- r = get_ranged_double(value, &df, 0.0, DBL_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->pi_proportional_const = df;
-
} else if (!strcmp(option, "pi_integral_const")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index db7963f..4f24f51 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *pi_proportional_const;
double *pi_integral_const;
double *pi_proportional_scale;
double *pi_proportional_exponent;
diff --git a/phc2sys.c b/phc2sys.c
index 44ba1fc..76f161a 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1243,7 +1243,7 @@ int main(int argc, char *argv[])
}
cfg = &phc2sys_config;

- configured_pi_kp = KP;
+ config_set_double(cfg, "pi_proportional_const", KP);
configured_pi_ki = KI;

/* Process the command line arguments. */
@@ -1289,8 +1289,9 @@ int main(int argc, char *argv[])
}
break;
case 'P':
- if (get_arg_val_d(c, optarg, &configured_pi_kp,
- 0.0, DBL_MAX))
+ if (get_arg_val_d(c, optarg, &tmp, 0.0, DBL_MAX))
+ return -1;
+ if (config_set_double(cfg, "pi_proportional_const", tmp))
return -1;
break;
case 'I':
diff --git a/pi.c b/pi.c
index e0116fe..7549dd6 100644
--- a/pi.c
+++ b/pi.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <math.h>

+#include "config.h"
#include "pi.h"
#include "print.h"
#include "servo_private.h"
@@ -35,7 +36,6 @@
#define FREQ_EST_MARGIN 0.001

/* 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_kp_scale = 0.0;
double configured_pi_kp_exponent = -0.3;
@@ -53,6 +53,8 @@ struct pi_servo {
double ki;
double last_freq;
int count;
+ /* configuration: */
+ double configured_pi_kp;
};

static void pi_destroy(struct servo *servo)
@@ -177,7 +179,7 @@ static void pi_reset(struct servo *servo)
s->count = 0;
}

-struct servo *pi_servo_create(int fadj, int sw_ts)
+struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
{
struct pi_servo *s;

@@ -193,12 +195,13 @@ struct servo *pi_servo_create(int fadj, int sw_ts)
s->last_freq = fadj;
s->kp = 0.0;
s->ki = 0.0;
+ s->configured_pi_kp = config_get_double(cfg, NULL, "pi_proportional_const");

- if (configured_pi_kp && configured_pi_ki) {
+ if (s->configured_pi_kp && configured_pi_ki) {
/* Use the constants as configured by the user without
adjusting for sync interval unless they make the servo
unstable. */
- configured_pi_kp_scale = configured_pi_kp;
+ configured_pi_kp_scale = s->configured_pi_kp;
configured_pi_ki_scale = configured_pi_ki;
configured_pi_kp_exponent = 0.0;
configured_pi_ki_exponent = 0.0;
diff --git a/pi.h b/pi.h
index 7b092a0..cd3c74f 100644
--- a/pi.h
+++ b/pi.h
@@ -23,12 +23,6 @@

/**
* When set to a non-zero value, this variable determines the
- * proportional constant for the PI controller.
- */
-extern double configured_pi_kp;
-
-/**
- * When set to a non-zero value, this variable determines the
* integral constant for the PI controller.
*/
extern double configured_pi_ki;
@@ -77,6 +71,6 @@ extern double configured_pi_ki_exponent;
*/
extern double configured_pi_ki_norm_max;

-struct servo *pi_servo_create(int fadj, int sw_ts);
+struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts);

#endif
diff --git a/ptp4l.c b/ptp4l.c
index 78261a9..5c23ddf 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .pi_proportional_const = &configured_pi_kp,
.pi_integral_const = &configured_pi_ki,
.pi_proportional_scale = &configured_pi_kp_scale,
.pi_proportional_exponent = &configured_pi_kp_exponent,
diff --git a/servo.c b/servo.c
index 2e82ebe..0449223 100644
--- a/servo.c
+++ b/servo.c
@@ -37,7 +37,7 @@ struct servo *servo_create(struct config *cfg, enum servo_type type,

switch (type) {
case CLOCK_SERVO_PI:
- servo = pi_servo_create(fadj, sw_ts);
+ servo = pi_servo_create(cfg, fadj, sw_ts);
break;
case CLOCK_SERVO_LINREG:
servo = linreg_servo_create(fadj);
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:28 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
pi.c | 13 +++++++------
pi.h | 8 --------
ptp4l.c | 1 -
5 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/config.c b/config.c
index 2437ec0..07cb016 100644
--- a/config.c
+++ b/config.c
@@ -98,6 +98,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
+ GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
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),
@@ -543,12 +544,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "pi_proportional_scale")) {
- r = get_ranged_double(value, &df, 0.0, DBL_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->pi_proportional_scale = df;
-
} else if (!strcmp(option, "pi_proportional_exponent")) {
r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 4b7bd74..4b8a4a2 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *pi_proportional_scale;
double *pi_proportional_exponent;
double *pi_proportional_norm_max;
double *pi_integral_scale;
diff --git a/pi.c b/pi.c
index dc3ccfd..8fe847a 100644
--- a/pi.c
+++ b/pi.c
@@ -36,7 +36,6 @@
#define FREQ_EST_MARGIN 0.001

/* These take their values from the configuration file. (see ptp4l.c) */
-double configured_pi_kp_scale = 0.0;
double configured_pi_kp_exponent = -0.3;
double configured_pi_kp_norm_max = 0.7;
double configured_pi_ki_scale = 0.0;
@@ -55,6 +54,7 @@ struct pi_servo {
/* configuration: */
double configured_pi_kp;
double configured_pi_ki;
+ double configured_pi_kp_scale;
};

static void pi_destroy(struct servo *servo)
@@ -160,7 +160,7 @@ static void pi_sync_interval(struct servo *servo, double interval)
{
struct pi_servo *s = container_of(servo, struct pi_servo, servo);

- s->kp = configured_pi_kp_scale * pow(interval, configured_pi_kp_exponent);
+ s->kp = s->configured_pi_kp_scale * pow(interval, configured_pi_kp_exponent);
if (s->kp > configured_pi_kp_norm_max / interval)
s->kp = configured_pi_kp_norm_max / interval;

@@ -197,23 +197,24 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
s->ki = 0.0;
s->configured_pi_kp = config_get_double(cfg, NULL, "pi_proportional_const");
s->configured_pi_ki = config_get_double(cfg, NULL, "pi_integral_const");
+ s->configured_pi_kp_scale = config_get_double(cfg, NULL, "pi_proportional_scale");

if (s->configured_pi_kp && s->configured_pi_ki) {
/* Use the constants as configured by the user without
adjusting for sync interval unless they make the servo
unstable. */
- configured_pi_kp_scale = s->configured_pi_kp;
+ s->configured_pi_kp_scale = s->configured_pi_kp;
configured_pi_ki_scale = s->configured_pi_ki;
configured_pi_kp_exponent = 0.0;
configured_pi_ki_exponent = 0.0;
configured_pi_kp_norm_max = MAX_KP_NORM_MAX;
configured_pi_ki_norm_max = MAX_KI_NORM_MAX;
- } else if (!configured_pi_kp_scale || !configured_pi_ki_scale) {
+ } else if (!s->configured_pi_kp_scale || !configured_pi_ki_scale) {
if (sw_ts) {
- configured_pi_kp_scale = SWTS_KP_SCALE;
+ s->configured_pi_kp_scale = SWTS_KP_SCALE;
configured_pi_ki_scale = SWTS_KI_SCALE;
} else {
- configured_pi_kp_scale = HWTS_KP_SCALE;
+ s->configured_pi_kp_scale = HWTS_KP_SCALE;
configured_pi_ki_scale = HWTS_KI_SCALE;
}
}
diff --git a/pi.h b/pi.h
index 9993ab2..d3e541e 100644
--- a/pi.h
+++ b/pi.h
@@ -22,14 +22,6 @@
#include "servo.h"

/**
- * When set to a non-zero value, this variable determines the scale in the
- * formula used to set the proportional constant of the PI controller from the
- * sync interval.
- * kp = min(kp_scale * sync^kp_exponent, kp_norm_max / sync)
- */
-extern double configured_pi_kp_scale;
-
-/**
* This variable determines the exponent in the formula used to set the
* proportional constant of the PI controller from the sync interval.
* kp = min(kp_scale * sync^kp_exponent, kp_norm_max / sync)
diff --git a/ptp4l.c b/ptp4l.c
index 88f1180..b96bee3 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .pi_proportional_scale = &configured_pi_kp_scale,
.pi_proportional_exponent = &configured_pi_kp_exponent,
.pi_proportional_norm_max = &configured_pi_kp_norm_max,
.pi_integral_scale = &configured_pi_ki_scale,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:27 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
phc2sys.c | 7 ++++---
pi.c | 7 ++++---
pi.h | 6 ------
ptp4l.c | 1 -
6 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/config.c b/config.c
index 3bd98da..2437ec0 100644
--- a/config.c
+++ b/config.c
@@ -96,6 +96,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
+ GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
@@ -542,12 +543,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "pi_integral_const")) {
- r = get_ranged_double(value, &df, 0.0, DBL_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->pi_integral_const = df;
-
} else if (!strcmp(option, "pi_proportional_scale")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 4f24f51..4b7bd74 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *pi_integral_const;
double *pi_proportional_scale;
double *pi_proportional_exponent;
double *pi_proportional_norm_max;
diff --git a/phc2sys.c b/phc2sys.c
index 76f161a..c2c611b 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1244,7 +1244,7 @@ int main(int argc, char *argv[])
cfg = &phc2sys_config;

config_set_double(cfg, "pi_proportional_const", KP);
- configured_pi_ki = KI;
+ config_set_double(cfg, "pi_integral_const", KI);

/* Process the command line arguments. */
progname = strrchr(argv[0], '/');
@@ -1295,8 +1295,9 @@ int main(int argc, char *argv[])
return -1;
break;
case 'I':
- if (get_arg_val_d(c, optarg, &configured_pi_ki,
- 0.0, DBL_MAX))
+ if (get_arg_val_d(c, optarg, &tmp, 0.0, DBL_MAX))
+ return -1;
+ if (config_set_double(cfg, "pi_integral_const", tmp))
return -1;
break;
case 'S':
diff --git a/pi.c b/pi.c
index 7549dd6..dc3ccfd 100644
--- a/pi.c
+++ b/pi.c
@@ -36,7 +36,6 @@
#define FREQ_EST_MARGIN 0.001

/* These take their values from the configuration file. (see ptp4l.c) */
-double configured_pi_ki = 0.0;
double configured_pi_kp_scale = 0.0;
double configured_pi_kp_exponent = -0.3;
double configured_pi_kp_norm_max = 0.7;
@@ -55,6 +54,7 @@ struct pi_servo {
int count;
/* configuration: */
double configured_pi_kp;
+ double configured_pi_ki;
};

static void pi_destroy(struct servo *servo)
@@ -196,13 +196,14 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
s->kp = 0.0;
s->ki = 0.0;
s->configured_pi_kp = config_get_double(cfg, NULL, "pi_proportional_const");
+ s->configured_pi_ki = config_get_double(cfg, NULL, "pi_integral_const");

- if (s->configured_pi_kp && configured_pi_ki) {
+ if (s->configured_pi_kp && s->configured_pi_ki) {
/* Use the constants as configured by the user without
adjusting for sync interval unless they make the servo
unstable. */
configured_pi_kp_scale = s->configured_pi_kp;
- configured_pi_ki_scale = configured_pi_ki;
+ configured_pi_ki_scale = s->configured_pi_ki;
configured_pi_kp_exponent = 0.0;
configured_pi_ki_exponent = 0.0;
configured_pi_kp_norm_max = MAX_KP_NORM_MAX;
diff --git a/pi.h b/pi.h
index cd3c74f..9993ab2 100644
--- a/pi.h
+++ b/pi.h
@@ -22,12 +22,6 @@
#include "servo.h"

/**
- * When set to a non-zero value, this variable determines the
- * integral constant for the PI controller.
- */
-extern double configured_pi_ki;
-
-/**
* When set to a non-zero value, this variable determines the scale in the
* formula used to set the proportional constant of the PI controller from the
* sync interval.
diff --git a/ptp4l.c b/ptp4l.c
index 5c23ddf..88f1180 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .pi_integral_const = &configured_pi_ki,
.pi_proportional_scale = &configured_pi_kp_scale,
.pi_proportional_exponent = &configured_pi_kp_exponent,
.pi_proportional_norm_max = &configured_pi_kp_norm_max,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:29 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
pi.c | 8 +++++---
pi.h | 7 -------
ptp4l.c | 1 -
5 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/config.c b/config.c
index 07cb016..43f96fe 100644
--- a/config.c
+++ b/config.c
@@ -98,6 +98,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
+ GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
@@ -544,12 +545,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "pi_proportional_exponent")) {
- r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->pi_proportional_exponent = df;
-
} else if (!strcmp(option, "pi_proportional_norm_max")) {
r = get_ranged_double(value, &df, DBL_MIN, 1.0);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 4b8a4a2..afd7142 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *pi_proportional_exponent;
double *pi_proportional_norm_max;
double *pi_integral_scale;
double *pi_integral_exponent;
diff --git a/pi.c b/pi.c
index 8fe847a..b340963 100644
--- a/pi.c
+++ b/pi.c
@@ -36,7 +36,6 @@
#define FREQ_EST_MARGIN 0.001

/* These take their values from the configuration file. (see ptp4l.c) */
-double configured_pi_kp_exponent = -0.3;
double configured_pi_kp_norm_max = 0.7;
double configured_pi_ki_scale = 0.0;
double configured_pi_ki_exponent = 0.4;
@@ -55,6 +54,7 @@ struct pi_servo {
double configured_pi_kp;
double configured_pi_ki;
double configured_pi_kp_scale;
+ double configured_pi_kp_exponent;
};

static void pi_destroy(struct servo *servo)
@@ -160,7 +160,7 @@ static void pi_sync_interval(struct servo *servo, double interval)
{
struct pi_servo *s = container_of(servo, struct pi_servo, servo);

- s->kp = s->configured_pi_kp_scale * pow(interval, configured_pi_kp_exponent);
+ s->kp = s->configured_pi_kp_scale * pow(interval, s->configured_pi_kp_exponent);
if (s->kp > configured_pi_kp_norm_max / interval)
s->kp = configured_pi_kp_norm_max / interval;

@@ -198,6 +198,8 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
s->configured_pi_kp = config_get_double(cfg, NULL, "pi_proportional_const");
s->configured_pi_ki = config_get_double(cfg, NULL, "pi_integral_const");
s->configured_pi_kp_scale = config_get_double(cfg, NULL, "pi_proportional_scale");
+ s->configured_pi_kp_exponent =
+ config_get_double(cfg, NULL, "pi_proportional_exponent");

if (s->configured_pi_kp && s->configured_pi_ki) {
/* Use the constants as configured by the user without
@@ -205,7 +207,7 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
unstable. */
s->configured_pi_kp_scale = s->configured_pi_kp;
configured_pi_ki_scale = s->configured_pi_ki;
- configured_pi_kp_exponent = 0.0;
+ s->configured_pi_kp_exponent = 0.0;
configured_pi_ki_exponent = 0.0;
configured_pi_kp_norm_max = MAX_KP_NORM_MAX;
configured_pi_ki_norm_max = MAX_KI_NORM_MAX;
diff --git a/pi.h b/pi.h
index d3e541e..27a64b1 100644
--- a/pi.h
+++ b/pi.h
@@ -22,13 +22,6 @@
#include "servo.h"

/**
- * This variable determines the exponent in the formula used to set the
- * proportional constant of the PI controller from the sync interval.
- * kp = min(kp_scale * sync^kp_exponent, kp_norm_max / sync)
- */
-extern double configured_pi_kp_exponent;
-
-/**
* This variable determines the normalized maximum in the formula used to set
* the proportional constant of the PI controller from the sync interval.
* kp = min(kp_scale * sync^kp_exponent, kp_norm_max / sync)
diff --git a/ptp4l.c b/ptp4l.c
index b96bee3..43dd977 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .pi_proportional_exponent = &configured_pi_kp_exponent,
.pi_proportional_norm_max = &configured_pi_kp_norm_max,
.pi_integral_scale = &configured_pi_ki_scale,
.pi_integral_exponent = &configured_pi_ki_exponent,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:30 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
pi.c | 10 ++++++----
pi.h | 7 -------
ptp4l.c | 1 -
5 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/config.c b/config.c
index 43f96fe..5775272 100644
--- a/config.c
+++ b/config.c
@@ -99,6 +99,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX),
+ GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
@@ -545,12 +546,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "pi_proportional_norm_max")) {
- r = get_ranged_double(value, &df, DBL_MIN, 1.0);
- if (r != PARSED_OK)
- return r;
- *cfg->pi_proportional_norm_max = df;
-
} else if (!strcmp(option, "pi_integral_scale")) {
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index afd7142..37e540d 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *pi_proportional_norm_max;
double *pi_integral_scale;
double *pi_integral_exponent;
double *pi_integral_norm_max;
diff --git a/pi.c b/pi.c
index b340963..ef3c619 100644
--- a/pi.c
+++ b/pi.c
@@ -36,7 +36,6 @@
#define FREQ_EST_MARGIN 0.001

/* These take their values from the configuration file. (see ptp4l.c) */
-double configured_pi_kp_norm_max = 0.7;
double configured_pi_ki_scale = 0.0;
double configured_pi_ki_exponent = 0.4;
double configured_pi_ki_norm_max = 0.3;
@@ -55,6 +54,7 @@ struct pi_servo {
double configured_pi_ki;
double configured_pi_kp_scale;
double configured_pi_kp_exponent;
+ double configured_pi_kp_norm_max;
};

static void pi_destroy(struct servo *servo)
@@ -161,8 +161,8 @@ static void pi_sync_interval(struct servo *servo, double interval)
struct pi_servo *s = container_of(servo, struct pi_servo, servo);

s->kp = s->configured_pi_kp_scale * pow(interval, s->configured_pi_kp_exponent);
- if (s->kp > configured_pi_kp_norm_max / interval)
- s->kp = configured_pi_kp_norm_max / interval;
+ if (s->kp > s->configured_pi_kp_norm_max / interval)
+ s->kp = s->configured_pi_kp_norm_max / interval;

s->ki = configured_pi_ki_scale * pow(interval, configured_pi_ki_exponent);
if (s->ki > configured_pi_ki_norm_max / interval)
@@ -200,6 +200,8 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
s->configured_pi_kp_scale = config_get_double(cfg, NULL, "pi_proportional_scale");
s->configured_pi_kp_exponent =
config_get_double(cfg, NULL, "pi_proportional_exponent");
+ s->configured_pi_kp_norm_max =
+ config_get_double(cfg, NULL, "pi_proportional_norm_max");

if (s->configured_pi_kp && s->configured_pi_ki) {
/* Use the constants as configured by the user without
@@ -209,7 +211,7 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
configured_pi_ki_scale = s->configured_pi_ki;
s->configured_pi_kp_exponent = 0.0;
configured_pi_ki_exponent = 0.0;
- configured_pi_kp_norm_max = MAX_KP_NORM_MAX;
+ s->configured_pi_kp_norm_max = MAX_KP_NORM_MAX;
configured_pi_ki_norm_max = MAX_KI_NORM_MAX;
} else if (!s->configured_pi_kp_scale || !configured_pi_ki_scale) {
if (sw_ts) {
diff --git a/pi.h b/pi.h
index 27a64b1..514186c 100644
--- a/pi.h
+++ b/pi.h
@@ -22,13 +22,6 @@
#include "servo.h"

/**
- * This variable determines the normalized maximum in the formula used to set
- * the proportional constant of the PI controller from the sync interval.
- * kp = min(kp_scale * sync^kp_exponent, kp_norm_max / sync)
- */
-extern double configured_pi_kp_norm_max;
-
-/**
* When set to a non-zero value, this variable determines the scale in the
* formula used to set the integral constant of the PI controller from the
* sync interval.
diff --git a/ptp4l.c b/ptp4l.c
index 43dd977..b60e531 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .pi_proportional_norm_max = &configured_pi_kp_norm_max,
.pi_integral_scale = &configured_pi_ki_scale,
.pi_integral_exponent = &configured_pi_ki_exponent,
.pi_integral_norm_max = &configured_pi_ki_norm_max,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:31 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
pi.c | 14 ++++++++------
pi.h | 8 --------
ptp4l.c | 1 -
5 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/config.c b/config.c
index 5775272..fc7dd23 100644
--- a/config.c
+++ b/config.c
@@ -97,6 +97,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
+ GLOB_ITEM_DBL("pi_integral_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
@@ -546,12 +547,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "pi_integral_scale")) {
- r = get_ranged_double(value, &df, 0.0, DBL_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->pi_integral_scale = df;
-
} else if (!strcmp(option, "pi_integral_exponent")) {
r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 37e540d..d6f2b8f 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *pi_integral_scale;
double *pi_integral_exponent;
double *pi_integral_norm_max;
int *ntpshm_segment;
diff --git a/pi.c b/pi.c
index ef3c619..dba141c 100644
--- a/pi.c
+++ b/pi.c
@@ -36,7 +36,6 @@
#define FREQ_EST_MARGIN 0.001

/* These take their values from the configuration file. (see ptp4l.c) */
-double configured_pi_ki_scale = 0.0;
double configured_pi_ki_exponent = 0.4;
double configured_pi_ki_norm_max = 0.3;

@@ -55,6 +54,7 @@ struct pi_servo {
double configured_pi_kp_scale;
double configured_pi_kp_exponent;
double configured_pi_kp_norm_max;
+ double configured_pi_ki_scale;
};

static void pi_destroy(struct servo *servo)
@@ -164,7 +164,7 @@ static void pi_sync_interval(struct servo *servo, double interval)
if (s->kp > s->configured_pi_kp_norm_max / interval)
s->kp = s->configured_pi_kp_norm_max / interval;

- s->ki = configured_pi_ki_scale * pow(interval, configured_pi_ki_exponent);
+ s->ki = s->configured_pi_ki_scale * pow(interval, configured_pi_ki_exponent);
if (s->ki > configured_pi_ki_norm_max / interval)
s->ki = configured_pi_ki_norm_max / interval;

@@ -202,24 +202,26 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
config_get_double(cfg, NULL, "pi_proportional_exponent");
s->configured_pi_kp_norm_max =
config_get_double(cfg, NULL, "pi_proportional_norm_max");
+ s->configured_pi_ki_scale =
+ config_get_double(cfg, NULL, "pi_integral_scale");

if (s->configured_pi_kp && s->configured_pi_ki) {
/* Use the constants as configured by the user without
adjusting for sync interval unless they make the servo
unstable. */
s->configured_pi_kp_scale = s->configured_pi_kp;
- configured_pi_ki_scale = s->configured_pi_ki;
+ s->configured_pi_ki_scale = s->configured_pi_ki;
s->configured_pi_kp_exponent = 0.0;
configured_pi_ki_exponent = 0.0;
s->configured_pi_kp_norm_max = MAX_KP_NORM_MAX;
configured_pi_ki_norm_max = MAX_KI_NORM_MAX;
- } else if (!s->configured_pi_kp_scale || !configured_pi_ki_scale) {
+ } else if (!s->configured_pi_kp_scale || !s->configured_pi_ki_scale) {
if (sw_ts) {
s->configured_pi_kp_scale = SWTS_KP_SCALE;
- configured_pi_ki_scale = SWTS_KI_SCALE;
+ s->configured_pi_ki_scale = SWTS_KI_SCALE;
} else {
s->configured_pi_kp_scale = HWTS_KP_SCALE;
- configured_pi_ki_scale = HWTS_KI_SCALE;
+ s->configured_pi_ki_scale = HWTS_KI_SCALE;
}
}

diff --git a/pi.h b/pi.h
index 514186c..915034c 100644
--- a/pi.h
+++ b/pi.h
@@ -22,14 +22,6 @@
#include "servo.h"

/**
- * When set to a non-zero value, this variable determines the scale in the
- * formula used to set the integral constant of the PI controller from the
- * sync interval.
- * ki = min(ki_scale * sync^ki_exponent, ki_norm_max / sync)
- */
-extern double configured_pi_ki_scale;
-
-/**
* This variable determines the exponent in the formula used to set the
* integral constant of the PI controller from the sync interval.
* ki = min(ki_scale * sync^ki_exponent, ki_norm_max / sync)
diff --git a/ptp4l.c b/ptp4l.c
index b60e531..d67a34d 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .pi_integral_scale = &configured_pi_ki_scale,
.pi_integral_exponent = &configured_pi_ki_exponent,
.pi_integral_norm_max = &configured_pi_ki_norm_max,
.ntpshm_segment = &ntpshm_segment,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:32 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
pi.c | 8 +++++---
pi.h | 7 -------
ptp4l.c | 1 -
5 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/config.c b/config.c
index fc7dd23..2f184dd 100644
--- a/config.c
+++ b/config.c
@@ -97,6 +97,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
+ GLOB_ITEM_DBL("pi_integral_exponent", 0.4, -DBL_MAX, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX),
@@ -547,12 +548,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "pi_integral_exponent")) {
- r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->pi_integral_exponent = df;
-
} else if (!strcmp(option, "pi_integral_norm_max")) {
r = get_ranged_double(value, &df, DBL_MIN, 2.0);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index d6f2b8f..9b9535f 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *pi_integral_exponent;
double *pi_integral_norm_max;
int *ntpshm_segment;

diff --git a/pi.c b/pi.c
index dba141c..0f34f31 100644
--- a/pi.c
+++ b/pi.c
@@ -36,7 +36,6 @@
#define FREQ_EST_MARGIN 0.001

/* These take their values from the configuration file. (see ptp4l.c) */
-double configured_pi_ki_exponent = 0.4;
double configured_pi_ki_norm_max = 0.3;

struct pi_servo {
@@ -55,6 +54,7 @@ struct pi_servo {
double configured_pi_kp_exponent;
double configured_pi_kp_norm_max;
double configured_pi_ki_scale;
+ double configured_pi_ki_exponent;
};

static void pi_destroy(struct servo *servo)
@@ -164,7 +164,7 @@ static void pi_sync_interval(struct servo *servo, double interval)
if (s->kp > s->configured_pi_kp_norm_max / interval)
s->kp = s->configured_pi_kp_norm_max / interval;

- s->ki = s->configured_pi_ki_scale * pow(interval, configured_pi_ki_exponent);
+ s->ki = s->configured_pi_ki_scale * pow(interval, s->configured_pi_ki_exponent);
if (s->ki > configured_pi_ki_norm_max / interval)
s->ki = configured_pi_ki_norm_max / interval;

@@ -204,6 +204,8 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
config_get_double(cfg, NULL, "pi_proportional_norm_max");
s->configured_pi_ki_scale =
config_get_double(cfg, NULL, "pi_integral_scale");
+ s->configured_pi_ki_exponent =
+ config_get_double(cfg, NULL, "pi_integral_exponent");

if (s->configured_pi_kp && s->configured_pi_ki) {
/* Use the constants as configured by the user without
@@ -212,7 +214,7 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
s->configured_pi_kp_scale = s->configured_pi_kp;
s->configured_pi_ki_scale = s->configured_pi_ki;
s->configured_pi_kp_exponent = 0.0;
- configured_pi_ki_exponent = 0.0;
+ s->configured_pi_ki_exponent = 0.0;
s->configured_pi_kp_norm_max = MAX_KP_NORM_MAX;
configured_pi_ki_norm_max = MAX_KI_NORM_MAX;
} else if (!s->configured_pi_kp_scale || !s->configured_pi_ki_scale) {
diff --git a/pi.h b/pi.h
index 915034c..ff16506 100644
--- a/pi.h
+++ b/pi.h
@@ -22,13 +22,6 @@
#include "servo.h"

/**
- * This variable determines the exponent in the formula used to set the
- * integral constant of the PI controller from the sync interval.
- * ki = min(ki_scale * sync^ki_exponent, ki_norm_max / sync)
- */
-extern double configured_pi_ki_exponent;
-
-/**
* This variable determines the normalized maximum in the formula used to set
* the integral constant of the PI controller from the sync interval.
* ki = min(ki_scale * sync^ki_exponent, ki_norm_max / sync)
diff --git a/ptp4l.c b/ptp4l.c
index d67a34d..c4d1ce8 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .pi_integral_exponent = &configured_pi_ki_exponent,
.pi_integral_norm_max = &configured_pi_ki_norm_max,
.ntpshm_segment = &ntpshm_segment,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:35 UTC
Permalink
This post might be inappropriate. Click to display it.
Richard Cochran
2015-08-20 18:14:36 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 3 ++-
ptp4l.c | 1 -
4 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index 678471a..4ebe1b8 100644
--- a/config.c
+++ b/config.c
@@ -95,6 +95,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
+ PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
@@ -263,13 +264,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "logAnnounceInterval")) {
- r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
- if (r != PARSED_OK)
- return r;
- pod->logAnnounceInterval = val;
-
- } else if (!strcmp(option, "logSyncInterval")) {
+ if (!strcmp(option, "logSyncInterval")) {
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index fc3487d..156eea6 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- Integer8 logAnnounceInterval;
Integer8 logSyncInterval;
Integer8 logMinDelayReqInterval;
Integer8 logMinPdelayReqInterval;
diff --git a/port.c b/port.c
index bad7acc..2527055 100644
--- a/port.c
+++ b/port.c
@@ -1438,6 +1438,7 @@ static void port_disable(struct port *p)

static int port_initialize(struct port *p)
{
+ struct config *cfg = clock_config(p->clock);
int fd[N_TIMER_FDS], i;

p->multiple_seq_pdr_count = 0;
@@ -1445,7 +1446,7 @@ static int port_initialize(struct port *p)
p->last_fault_type = FT_UNSPECIFIED;
p->logMinDelayReqInterval = p->pod.logMinDelayReqInterval;
p->peerMeanPathDelay = 0;
- p->logAnnounceInterval = p->pod.logAnnounceInterval;
+ p->logAnnounceInterval = config_get_int(cfg, p->name, "logAnnounceInterval");
p->announceReceiptTimeout = p->pod.announceReceiptTimeout;
p->syncReceiptTimeout = p->pod.syncReceiptTimeout;
p->transportSpecific = p->pod.transportSpecific;
diff --git a/ptp4l.c b/ptp4l.c
index b9982c8..c633495 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .logAnnounceInterval = 1,
.logSyncInterval = 0,
.logMinDelayReqInterval = 0,
.logMinPdelayReqInterval = 0,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:34 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 2 --
ntpshm.c | 9 +++------
ntpshm.h | 7 +------
phc2sys.c | 3 +++
ptp4l.c | 2 --
servo.c | 2 +-
7 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/config.c b/config.c
index 1ae564f..c1d5aeb 100644
--- a/config.c
+++ b/config.c
@@ -96,6 +96,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
+ GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_exponent", 0.4, -DBL_MAX, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_norm_max", 0.3, DBL_MIN, 2.0),
@@ -554,12 +555,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
cfg->dds.sanity_freq_limit = val;

- } else if (!strcmp(option, "ntpshm_segment")) {
- r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
- if (r != PARSED_OK)
- return r;
- *cfg->ntpshm_segment = 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 bdfead7..c1ada46 100644
--- a/config.h
+++ b/config.h
@@ -69,8 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- int *ntpshm_segment;
-
unsigned char *ptp_dst_mac;
unsigned char *p2p_dst_mac;
unsigned char *udp6_scope;
diff --git a/ntpshm.c b/ntpshm.c
index 8b18e2d..3b62a3f 100644
--- a/ntpshm.c
+++ b/ntpshm.c
@@ -22,12 +22,11 @@
#include <sys/types.h>
#include <sys/shm.h>

+#include "config.h"
#include "print.h"
#include "ntpshm.h"
#include "servo_private.h"

-#define NS_PER_SEC 1000000000
-
/* NTP leap values */
#define LEAP_NORMAL 0x0
#define LEAP_INSERT 0x1
@@ -36,9 +35,6 @@
/* Key of the first SHM segment */
#define SHMKEY 0x4e545030

-/* Number of the SHM segment to be used */
-int ntpshm_segment = 0;
-
/* Declaration of the SHM segment from ntp (ntpd/refclock_shm.c) */
struct shmTime {
int mode; /* 0 - if valid set
@@ -134,9 +130,10 @@ static void ntpshm_leap(struct servo *servo, int leap)
s->leap = leap;
}

-struct servo *ntpshm_servo_create(void)
+struct servo *ntpshm_servo_create(struct config *cfg)
{
struct ntpshm_servo *s;
+ int ntpshm_segment = config_get_int(cfg, NULL, "ntpshm_segment");
int shmid;

s = calloc(1, sizeof(*s));
diff --git a/ntpshm.h b/ntpshm.h
index ea54a54..80934e0 100644
--- a/ntpshm.h
+++ b/ntpshm.h
@@ -21,11 +21,6 @@

#include "servo.h"

-/**
- * The number of the SHM segment that will be used by newly created servo
- */
-extern int ntpshm_segment;
-
-struct servo *ntpshm_servo_create(void);
+struct servo *ntpshm_servo_create(struct config *cfg);

#endif
diff --git a/phc2sys.c b/phc2sys.c
index c2c611b..4088a91 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1227,6 +1227,7 @@ int main(int argc, char *argv[])
int c, domain_number = 0, pps_fd = -1;
int r, wait_sync = 0;
int print_level = LOG_INFO, use_syslog = 1, verbose = 0;
+ int ntpshm_segment;
double phc_rate, tmp;
struct node node = {
.sanity_freq_limit = 200000000,
@@ -1334,6 +1335,8 @@ int main(int argc, char *argv[])
case 'M':
if (get_arg_val_i(c, optarg, &ntpshm_segment, INT_MIN, INT_MAX))
return -1;
+ if (config_set_int(cfg, "ntpshm_segment", ntpshm_segment))
+ return -1;
break;
case 'u':
if (get_arg_val_ui(c, optarg, &node.stats_max_count,
diff --git a/ptp4l.c b/ptp4l.c
index b74cda6..b9982c8 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,8 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .ntpshm_segment = &ntpshm_segment,
-
.ptp_dst_mac = ptp_dst_mac,
.p2p_dst_mac = p2p_dst_mac,
.udp6_scope = &udp6_scope,
diff --git a/servo.c b/servo.c
index 0449223..9aab7f2 100644
--- a/servo.c
+++ b/servo.c
@@ -43,7 +43,7 @@ struct servo *servo_create(struct config *cfg, enum servo_type type,
servo = linreg_servo_create(fadj);
break;
case CLOCK_SERVO_NTPSHM:
- servo = ntpshm_servo_create();
+ servo = ntpshm_servo_create(cfg);
break;
case CLOCK_SERVO_NULLF:
servo = nullf_servo_create();
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:37 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 1 -
4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index 4ebe1b8..0cd26e2 100644
--- a/config.c
+++ b/config.c
@@ -96,6 +96,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
+ PORT_ITEM_INT("logSyncInterval", 0, INT8_MIN, INT8_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
@@ -264,13 +265,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "logSyncInterval")) {
- r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
- if (r != PARSED_OK)
- return r;
- pod->logSyncInterval = val;
-
- } else if (!strcmp(option, "logMinDelayReqInterval")) {
+ if (!strcmp(option, "logMinDelayReqInterval")) {
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index 156eea6..58451d8 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- Integer8 logSyncInterval;
Integer8 logMinDelayReqInterval;
Integer8 logMinPdelayReqInterval;
UInteger8 announceReceiptTimeout;
diff --git a/port.c b/port.c
index 2527055..a941cb7 100644
--- a/port.c
+++ b/port.c
@@ -1450,7 +1450,7 @@ static int port_initialize(struct port *p)
p->announceReceiptTimeout = p->pod.announceReceiptTimeout;
p->syncReceiptTimeout = p->pod.syncReceiptTimeout;
p->transportSpecific = p->pod.transportSpecific;
- p->logSyncInterval = p->pod.logSyncInterval;
+ p->logSyncInterval = config_get_int(cfg, p->name, "logSyncInterval");
p->logMinPdelayReqInterval = p->pod.logMinPdelayReqInterval;
p->neighborPropDelayThresh = p->pod.neighborPropDelayThresh;
p->min_neighbor_prop_delay = p->pod.min_neighbor_prop_delay;
diff --git a/ptp4l.c b/ptp4l.c
index c633495..911baca 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .logSyncInterval = 0,
.logMinDelayReqInterval = 0,
.logMinPdelayReqInterval = 0,
.announceReceiptTimeout = 3,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:33 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 8 +-------
config.h | 1 -
pi.c | 12 ++++++------
pi.h | 7 -------
ptp4l.c | 1 -
5 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/config.c b/config.c
index 2f184dd..1ae564f 100644
--- a/config.c
+++ b/config.c
@@ -98,6 +98,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_exponent", 0.4, -DBL_MAX, DBL_MAX),
+ GLOB_ITEM_DBL("pi_integral_norm_max", 0.3, DBL_MIN, 2.0),
GLOB_ITEM_DBL("pi_integral_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX),
@@ -457,7 +458,6 @@ static enum parser_result parse_global_setting(const char *option,
const char *value,
struct config *cfg)
{
- double df;
int i, val, cfg_ignore = cfg->cfg_ignore;
unsigned int uval;
unsigned char mac[MAC_LEN];
@@ -548,12 +548,6 @@ static enum parser_result parse_global_setting(const char *option,
cfg->dds.freq_est_interval = val;
pod->freq_est_interval = val;

- } else if (!strcmp(option, "pi_integral_norm_max")) {
- r = get_ranged_double(value, &df, DBL_MIN, 2.0);
- if (r != PARSED_OK)
- return r;
- *cfg->pi_integral_norm_max = df;
-
} else if (!strcmp(option, "sanity_freq_limit")) {
r = get_ranged_int(value, &val, 0, INT_MAX);
if (r != PARSED_OK)
diff --git a/config.h b/config.h
index 9b9535f..bdfead7 100644
--- a/config.h
+++ b/config.h
@@ -69,7 +69,6 @@ struct config {
struct port_defaults pod;
enum servo_type clock_servo;

- double *pi_integral_norm_max;
int *ntpshm_segment;

unsigned char *ptp_dst_mac;
diff --git a/pi.c b/pi.c
index 0f34f31..35556e1 100644
--- a/pi.c
+++ b/pi.c
@@ -35,9 +35,6 @@

#define FREQ_EST_MARGIN 0.001

-/* These take their values from the configuration file. (see ptp4l.c) */
-double configured_pi_ki_norm_max = 0.3;
-
struct pi_servo {
struct servo servo;
int64_t offset[2];
@@ -55,6 +52,7 @@ struct pi_servo {
double configured_pi_kp_norm_max;
double configured_pi_ki_scale;
double configured_pi_ki_exponent;
+ double configured_pi_ki_norm_max;
};

static void pi_destroy(struct servo *servo)
@@ -165,8 +163,8 @@ static void pi_sync_interval(struct servo *servo, double interval)
s->kp = s->configured_pi_kp_norm_max / interval;

s->ki = s->configured_pi_ki_scale * pow(interval, s->configured_pi_ki_exponent);
- if (s->ki > configured_pi_ki_norm_max / interval)
- s->ki = configured_pi_ki_norm_max / interval;
+ if (s->ki > s->configured_pi_ki_norm_max / interval)
+ s->ki = s->configured_pi_ki_norm_max / interval;

pr_debug("PI servo: sync interval %.3f kp %.3f ki %.6f",
interval, s->kp, s->ki);
@@ -206,6 +204,8 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
config_get_double(cfg, NULL, "pi_integral_scale");
s->configured_pi_ki_exponent =
config_get_double(cfg, NULL, "pi_integral_exponent");
+ s->configured_pi_ki_norm_max =
+ config_get_double(cfg, NULL, "pi_integral_norm_max");

if (s->configured_pi_kp && s->configured_pi_ki) {
/* Use the constants as configured by the user without
@@ -216,7 +216,7 @@ struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts)
s->configured_pi_kp_exponent = 0.0;
s->configured_pi_ki_exponent = 0.0;
s->configured_pi_kp_norm_max = MAX_KP_NORM_MAX;
- configured_pi_ki_norm_max = MAX_KI_NORM_MAX;
+ s->configured_pi_ki_norm_max = MAX_KI_NORM_MAX;
} else if (!s->configured_pi_kp_scale || !s->configured_pi_ki_scale) {
if (sw_ts) {
s->configured_pi_kp_scale = SWTS_KP_SCALE;
diff --git a/pi.h b/pi.h
index ff16506..feb3ebe 100644
--- a/pi.h
+++ b/pi.h
@@ -21,13 +21,6 @@

#include "servo.h"

-/**
- * This variable determines the normalized maximum in the formula used to set
- * the integral constant of the PI controller from the sync interval.
- * ki = min(ki_scale * sync^ki_exponent, ki_norm_max / sync)
- */
-extern double configured_pi_ki_norm_max;
-
struct servo *pi_servo_create(struct config *cfg, int fadj, int sw_ts);

#endif
diff --git a/ptp4l.c b/ptp4l.c
index c4d1ce8..b74cda6 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -103,7 +103,6 @@ static struct config cfg_settings = {
.transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

- .pi_integral_norm_max = &configured_pi_ki_norm_max,
.ntpshm_segment = &ntpshm_segment,

.ptp_dst_mac = ptp_dst_mac,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:38 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 1 -
4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index 0cd26e2..56a86e9 100644
--- a/config.c
+++ b/config.c
@@ -96,6 +96,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
+ PORT_ITEM_INT("logMinDelayReqInterval", 0, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logSyncInterval", 0, INT8_MIN, INT8_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
@@ -265,13 +266,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "logMinDelayReqInterval")) {
- r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
- if (r != PARSED_OK)
- return r;
- pod->logMinDelayReqInterval = val;
-
- } else if (!strcmp(option, "logMinPdelayReqInterval")) {
+ if (!strcmp(option, "logMinPdelayReqInterval")) {
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index 58451d8..f83490b 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- Integer8 logMinDelayReqInterval;
Integer8 logMinPdelayReqInterval;
UInteger8 announceReceiptTimeout;
UInteger8 syncReceiptTimeout;
diff --git a/port.c b/port.c
index a941cb7..00e654e 100644
--- a/port.c
+++ b/port.c
@@ -1444,7 +1444,7 @@ static int port_initialize(struct port *p)
p->multiple_seq_pdr_count = 0;
p->multiple_pdr_detected = 0;
p->last_fault_type = FT_UNSPECIFIED;
- p->logMinDelayReqInterval = p->pod.logMinDelayReqInterval;
+ p->logMinDelayReqInterval = config_get_int(cfg, p->name, "logMinDelayReqInterval");
p->peerMeanPathDelay = 0;
p->logAnnounceInterval = config_get_int(cfg, p->name, "logAnnounceInterval");
p->announceReceiptTimeout = p->pod.announceReceiptTimeout;
diff --git a/ptp4l.c b/ptp4l.c
index 911baca..2b58b13 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .logMinDelayReqInterval = 0,
.logMinPdelayReqInterval = 0,
.announceReceiptTimeout = 3,
.syncReceiptTimeout = 0,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:39 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 1 -
4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index 56a86e9..833d894 100644
--- a/config.c
+++ b/config.c
@@ -97,6 +97,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinDelayReqInterval", 0, INT8_MIN, INT8_MAX),
+ PORT_ITEM_INT("logMinPdelayReqInterval", 0, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logSyncInterval", 0, INT8_MIN, INT8_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
@@ -266,13 +267,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "logMinPdelayReqInterval")) {
- r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
- if (r != PARSED_OK)
- return r;
- pod->logMinPdelayReqInterval = val;
-
- } else if (!strcmp(option, "announceReceiptTimeout")) {
+ if (!strcmp(option, "announceReceiptTimeout")) {
r = get_ranged_uint(value, &uval, 2, UINT8_MAX);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index f83490b..94db41b 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- Integer8 logMinPdelayReqInterval;
UInteger8 announceReceiptTimeout;
UInteger8 syncReceiptTimeout;
UInteger8 transportSpecific;
diff --git a/port.c b/port.c
index 00e654e..304b25c 100644
--- a/port.c
+++ b/port.c
@@ -1451,7 +1451,7 @@ static int port_initialize(struct port *p)
p->syncReceiptTimeout = p->pod.syncReceiptTimeout;
p->transportSpecific = p->pod.transportSpecific;
p->logSyncInterval = config_get_int(cfg, p->name, "logSyncInterval");
- p->logMinPdelayReqInterval = p->pod.logMinPdelayReqInterval;
+ p->logMinPdelayReqInterval = config_get_int(cfg, p->name, "logMinPdelayReqInterval");
p->neighborPropDelayThresh = p->pod.neighborPropDelayThresh;
p->min_neighbor_prop_delay = p->pod.min_neighbor_prop_delay;

diff --git a/ptp4l.c b/ptp4l.c
index 2b58b13..8b9531e 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .logMinPdelayReqInterval = 0,
.announceReceiptTimeout = 3,
.syncReceiptTimeout = 0,
.transportSpecific = 0,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:41 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 1 -
4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index 6401e44..c17ab73 100644
--- a/config.c
+++ b/config.c
@@ -112,6 +112,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
+ PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
GLOB_ITEM_INT("use_syslog", 1, 0, 1),
@@ -268,13 +269,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "syncReceiptTimeout")) {
- r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
- if (r != PARSED_OK)
- return r;
- pod->syncReceiptTimeout = uval;
-
- } else if (!strcmp(option, "transportSpecific")) {
+ if (!strcmp(option, "transportSpecific")) {
r = get_ranged_uint(value, &uval, 0, 0x0F);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index 7652632..5f4d035 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- UInteger8 syncReceiptTimeout;
UInteger8 transportSpecific;
int announce_span;
int path_trace_enabled;
diff --git a/port.c b/port.c
index aa8572d..9d4fe7c 100644
--- a/port.c
+++ b/port.c
@@ -1448,7 +1448,7 @@ static int port_initialize(struct port *p)
p->peerMeanPathDelay = 0;
p->logAnnounceInterval = config_get_int(cfg, p->name, "logAnnounceInterval");
p->announceReceiptTimeout = config_get_int(cfg, p->name, "announceReceiptTimeout");
- p->syncReceiptTimeout = p->pod.syncReceiptTimeout;
+ p->syncReceiptTimeout = config_get_int(cfg, p->name, "syncReceiptTimeout");
p->transportSpecific = p->pod.transportSpecific;
p->logSyncInterval = config_get_int(cfg, p->name, "logSyncInterval");
p->logMinPdelayReqInterval = config_get_int(cfg, p->name, "logMinPdelayReqInterval");
diff --git a/ptp4l.c b/ptp4l.c
index cc20236..2ceb484 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .syncReceiptTimeout = 0,
.transportSpecific = 0,
.announce_span = 1,
.path_trace_enabled = 0,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:40 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 1 -
4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index 833d894..6401e44 100644
--- a/config.c
+++ b/config.c
@@ -91,6 +91,7 @@ struct config_item {
CONFIG_ITEM_INT(label, 1, _default, min, max)

struct config_item config_tab[] = {
+ PORT_ITEM_INT("announceReceiptTimeout", 3, 2, UINT8_MAX),
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
@@ -267,13 +268,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "announceReceiptTimeout")) {
- r = get_ranged_uint(value, &uval, 2, UINT8_MAX);
- if (r != PARSED_OK)
- return r;
- pod->announceReceiptTimeout = uval;
-
- } else if (!strcmp(option, "syncReceiptTimeout")) {
+ if (!strcmp(option, "syncReceiptTimeout")) {
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index 94db41b..7652632 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- UInteger8 announceReceiptTimeout;
UInteger8 syncReceiptTimeout;
UInteger8 transportSpecific;
int announce_span;
diff --git a/port.c b/port.c
index 304b25c..aa8572d 100644
--- a/port.c
+++ b/port.c
@@ -1447,7 +1447,7 @@ static int port_initialize(struct port *p)
p->logMinDelayReqInterval = config_get_int(cfg, p->name, "logMinDelayReqInterval");
p->peerMeanPathDelay = 0;
p->logAnnounceInterval = config_get_int(cfg, p->name, "logAnnounceInterval");
- p->announceReceiptTimeout = p->pod.announceReceiptTimeout;
+ p->announceReceiptTimeout = config_get_int(cfg, p->name, "announceReceiptTimeout");
p->syncReceiptTimeout = p->pod.syncReceiptTimeout;
p->transportSpecific = p->pod.transportSpecific;
p->logSyncInterval = config_get_int(cfg, p->name, "logSyncInterval");
diff --git a/ptp4l.c b/ptp4l.c
index 8b9531e..cc20236 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .announceReceiptTimeout = 3,
.syncReceiptTimeout = 0,
.transportSpecific = 0,
.announce_span = 1,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:43 UTC
Permalink
This probably should not have been a variable in the first place.

Signed-off-by: Richard Cochran <***@gmail.com>
---
ds.h | 1 -
port.c | 3 ++-
ptp4l.c | 1 -
3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/ds.h b/ds.h
index f9a5d7b..d30c418 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- int announce_span;
int path_trace_enabled;
int follow_up_info;
int freq_est_interval; /*log seconds*/
diff --git a/port.c b/port.c
index c1e6151..7c7b73b 100644
--- a/port.c
+++ b/port.c
@@ -39,6 +39,7 @@
#include "util.h"

#define ALLOWED_LOST_RESPONSES 3
+#define ANNOUNCE_SPAN 1

enum syfu_state {
SF_EMPTY,
@@ -950,7 +951,7 @@ static int port_set_announce_tmo(struct port *p)
{
return set_tmo_random(p->fda.fd[FD_ANNOUNCE_TIMER],
p->announceReceiptTimeout,
- p->pod.announce_span, p->logAnnounceInterval);
+ ANNOUNCE_SPAN, p->logAnnounceInterval);
}

static int port_set_delay_tmo(struct port *p)
diff --git a/ptp4l.c b/ptp4l.c
index 0734549..f31cec8 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .announce_span = 1,
.path_trace_enabled = 0,
.follow_up_info = 0,
.freq_est_interval = 1,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:42 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 3 ++-
ptp4l.c | 1 -
4 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index c17ab73..2c97002 100644
--- a/config.c
+++ b/config.c
@@ -113,6 +113,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
+ PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
GLOB_ITEM_INT("use_syslog", 1, 0, 1),
@@ -269,13 +270,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "transportSpecific")) {
- r = get_ranged_uint(value, &uval, 0, 0x0F);
- if (r != PARSED_OK)
- return r;
- pod->transportSpecific = uval << 4;
-
- } else if (!strcmp(option, "path_trace_enabled")) {
+ if (!strcmp(option, "path_trace_enabled")) {
r = get_ranged_int(value, &val, 0, 1);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index 5f4d035..f9a5d7b 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- UInteger8 transportSpecific;
int announce_span;
int path_trace_enabled;
int follow_up_info;
diff --git a/port.c b/port.c
index 9d4fe7c..c1e6151 100644
--- a/port.c
+++ b/port.c
@@ -1449,7 +1449,8 @@ static int port_initialize(struct port *p)
p->logAnnounceInterval = config_get_int(cfg, p->name, "logAnnounceInterval");
p->announceReceiptTimeout = config_get_int(cfg, p->name, "announceReceiptTimeout");
p->syncReceiptTimeout = config_get_int(cfg, p->name, "syncReceiptTimeout");
- p->transportSpecific = p->pod.transportSpecific;
+ p->transportSpecific = config_get_int(cfg, p->name, "transportSpecific");
+ p->transportSpecific <<= 4;
p->logSyncInterval = config_get_int(cfg, p->name, "logSyncInterval");
p->logMinPdelayReqInterval = config_get_int(cfg, p->name, "logMinPdelayReqInterval");
p->neighborPropDelayThresh = p->pod.neighborPropDelayThresh;
diff --git a/ptp4l.c b/ptp4l.c
index 2ceb484..0734549 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .transportSpecific = 0,
.announce_span = 1,
.path_trace_enabled = 0,
.follow_up_info = 0,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:44 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 8 +++++---
ptp4l.c | 1 -
4 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/config.c b/config.c
index 2c97002..2c10158 100644
--- a/config.c
+++ b/config.c
@@ -103,6 +103,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
+ PORT_ITEM_INT("path_trace_enabled", 0, 0, 1),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_exponent", 0.4, -DBL_MAX, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_norm_max", 0.3, DBL_MIN, 2.0),
@@ -270,13 +271,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "path_trace_enabled")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- pod->path_trace_enabled = val;
-
- } else if (!strcmp(option, "follow_up_info")) {
+ if (!strcmp(option, "follow_up_info")) {
r = get_ranged_int(value, &val, 0, 1);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index d30c418..f1a0170 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- int path_trace_enabled;
int follow_up_info;
int freq_est_interval; /*log seconds*/
struct fault_interval flt_interval_pertype[FT_CNT];
diff --git a/port.c b/port.c
index 7c7b73b..bb1fd4b 100644
--- a/port.c
+++ b/port.c
@@ -111,6 +111,7 @@ struct port {
Integer8 logMinPdelayReqInterval;
UInteger32 neighborPropDelayThresh;
int min_neighbor_prop_delay;
+ int path_trace_enabled;
enum fault_type last_fault_type;
unsigned int versionNumber; /*UInteger4*/
/* foreignMasterDS */
@@ -484,7 +485,7 @@ static int path_trace_ignore(struct port *p, struct ptp_message *m)
struct path_trace_tlv *ptt;
int i, cnt;

- if (!p->pod.path_trace_enabled) {
+ if (!p->path_trace_enabled) {
return 0;
}
if (msg_type(m) != ANNOUNCE) {
@@ -1249,7 +1250,7 @@ static int port_tx_announce(struct port *p)
pdulen = sizeof(struct announce_msg);
msg->hwts.type = p->timestamping;

- if (p->pod.path_trace_enabled)
+ if (p->path_trace_enabled)
pdulen += path_trace_append(p, msg, dad);

msg->header.tsmt = ANNOUNCE | p->transportSpecific;
@@ -1529,7 +1530,7 @@ static int update_current_master(struct port *p, struct ptp_message *m)
tds.timeSource = m->announce.timeSource;
clock_update_time_properties(p->clock, tds);
}
- if (p->pod.path_trace_enabled) {
+ if (p->path_trace_enabled) {
ptt = (struct path_trace_tlv *) m->announce.suffix;
dad = clock_parent_ds(p->clock);
memcpy(dad->ptl, ptt->cid, ptt->length);
@@ -2530,6 +2531,7 @@ struct port *port_open(int phc_index,
p->name = interface->name;
p->asymmetry = config_get_int(cfg, p->name, "delayAsymmetry");
p->asymmetry <<= 16;
+ p->path_trace_enabled = config_get_int(cfg, p->name, "path_trace_enabled");
p->clock = clock;
p->trp = transport_create(cfg, interface->transport);
if (!p->trp)
diff --git a/ptp4l.c b/ptp4l.c
index f31cec8..ba189a4 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .path_trace_enabled = 0,
.follow_up_info = 0,
.freq_est_interval = 1,
/* Default to very a large neighborPropDelay threshold */
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:45 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 10 ++++++----
ptp4l.c | 1 -
4 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/config.c b/config.c
index 2c10158..7cc3ca5 100644
--- a/config.c
+++ b/config.c
@@ -96,6 +96,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
+ PORT_ITEM_INT("follow_up_info", 0, 0, 1),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinDelayReqInterval", 0, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinPdelayReqInterval", 0, INT8_MIN, INT8_MAX),
@@ -271,13 +272,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "follow_up_info")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- pod->follow_up_info = val;
-
- } else if (!strcmp(option, "neighborPropDelayThresh")) {
+ if (!strcmp(option, "neighborPropDelayThresh")) {
r = get_ranged_uint(value, &uval, 0, UINT32_MAX);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index f1a0170..eae0fd1 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- int follow_up_info;
int freq_est_interval; /*log seconds*/
struct fault_interval flt_interval_pertype[FT_CNT];
UInteger32 neighborPropDelayThresh; /*nanoseconds*/
diff --git a/port.c b/port.c
index bb1fd4b..f186917 100644
--- a/port.c
+++ b/port.c
@@ -110,6 +110,7 @@ struct port {
Enumeration8 delayMechanism;
Integer8 logMinPdelayReqInterval;
UInteger32 neighborPropDelayThresh;
+ int follow_up_info;
int min_neighbor_prop_delay;
int path_trace_enabled;
enum fault_type last_fault_type;
@@ -654,7 +655,7 @@ static int port_sync_incapable(struct port *p)

static int port_is_ieee8021as(struct port *p)
{
- return p->pod.follow_up_info ? 1 : 0;
+ return p->follow_up_info ? 1 : 0;
}

static void port_management_send_error(struct port *p, struct port *ingress,
@@ -1334,7 +1335,7 @@ static int port_tx_sync(struct port *p)
pdulen = sizeof(struct follow_up_msg);
fup->hwts.type = p->timestamping;

- if (p->pod.follow_up_info)
+ if (p->follow_up_info)
pdulen += follow_up_info_append(p, fup);

fup->header.tsmt = FOLLOW_UP | p->transportSpecific;
@@ -1687,7 +1688,7 @@ static void process_follow_up(struct port *p, struct ptp_message *m)
if (memcmp(&master, &m->header.sourcePortIdentity, sizeof(master)))
return;

- if (p->pod.follow_up_info) {
+ if (p->follow_up_info) {
struct follow_up_info_tlv *fui = follow_up_info_extract(m);
if (!fui)
return;
@@ -1861,7 +1862,7 @@ calc:

p->peerMeanPathDelay = tmv_to_TimeInterval(p->peer_delay);

- if (p->pod.follow_up_info)
+ if (p->follow_up_info)
port_nrate_calculate(p, t3c, t4);

if (p->state == PS_UNCALIBRATED || p->state == PS_SLAVE) {
@@ -2531,6 +2532,7 @@ struct port *port_open(int phc_index,
p->name = interface->name;
p->asymmetry = config_get_int(cfg, p->name, "delayAsymmetry");
p->asymmetry <<= 16;
+ p->follow_up_info = config_get_int(cfg, p->name, "follow_up_info");
p->path_trace_enabled = config_get_int(cfg, p->name, "path_trace_enabled");
p->clock = clock;
p->trp = transport_create(cfg, interface->transport);
diff --git a/ptp4l.c b/ptp4l.c
index ba189a4..faa13da 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -80,7 +80,6 @@ static struct config cfg_settings = {
},

.pod = {
- .follow_up_info = 0,
.freq_est_interval = 1,
/* Default to very a large neighborPropDelay threshold */
.neighborPropDelayThresh = 20000000,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:46 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 2 +-
config.c | 8 +-------
ds.h | 2 --
port.c | 4 +++-
ptp4l.c | 2 --
5 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/clock.c b/clock.c
index 8a5ef05..0856f81 100644
--- a/clock.c
+++ b/clock.c
@@ -823,7 +823,7 @@ struct clock *clock_create(struct config *config, int phc_index,

c->config = config;
c->free_running = dds->free_running;
- c->freq_est_interval = dds->freq_est_interval;
+ c->freq_est_interval = config_get_int(config, NULL, "freq_est_interval");
c->grand_master_capable = dds->grand_master_capable;
c->kernel_leap = dds->kernel_leap;
c->utc_offset = CURRENT_UTC_OFFSET;
diff --git a/config.c b/config.c
index 7cc3ca5..4c5182e 100644
--- a/config.c
+++ b/config.c
@@ -97,6 +97,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
+ PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinDelayReqInterval", 0, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinPdelayReqInterval", 0, INT8_MIN, INT8_MAX),
@@ -492,13 +493,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
cfg->dds.free_running = val;

- } else if (!strcmp(option, "freq_est_interval")) {
- r = get_ranged_int(value, &val, 0, INT_MAX);
- if (r != PARSED_OK)
- return r;
- cfg->dds.freq_est_interval = val;
- pod->freq_est_interval = val;
-
} else if (!strcmp(option, "sanity_freq_limit")) {
r = get_ranged_int(value, &val, 0, INT_MAX);
if (r != PARSED_OK)
diff --git a/ds.h b/ds.h
index eae0fd1..9ab07e3 100644
--- a/ds.h
+++ b/ds.h
@@ -53,7 +53,6 @@ struct clock_description {
struct default_ds {
struct defaultDS dds;
int free_running;
- int freq_est_interval; /*log seconds*/
int grand_master_capable; /*802.1AS only*/
int stats_interval; /*log seconds*/
int kernel_leap;
@@ -125,7 +124,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- int freq_est_interval; /*log seconds*/
struct fault_interval flt_interval_pertype[FT_CNT];
UInteger32 neighborPropDelayThresh; /*nanoseconds*/
int min_neighbor_prop_delay; /*nanoseconds*/
diff --git a/port.c b/port.c
index f186917..96422bb 100644
--- a/port.c
+++ b/port.c
@@ -111,6 +111,7 @@ struct port {
Integer8 logMinPdelayReqInterval;
UInteger32 neighborPropDelayThresh;
int follow_up_info;
+ int freq_est_interval;
int min_neighbor_prop_delay;
int path_trace_enabled;
enum fault_type last_fault_type;
@@ -926,7 +927,7 @@ static void port_nrate_calculate(struct port *p, tmv_t origin, tmv_t ingress)

static void port_nrate_initialize(struct port *p)
{
- int shift = p->pod.freq_est_interval - p->logMinPdelayReqInterval;
+ int shift = p->freq_est_interval - p->logMinPdelayReqInterval;

if (shift < 0)
shift = 0;
@@ -2533,6 +2534,7 @@ struct port *port_open(int phc_index,
p->asymmetry = config_get_int(cfg, p->name, "delayAsymmetry");
p->asymmetry <<= 16;
p->follow_up_info = config_get_int(cfg, p->name, "follow_up_info");
+ p->freq_est_interval = config_get_int(cfg, p->name, "freq_est_interval");
p->path_trace_enabled = config_get_int(cfg, p->name, "path_trace_enabled");
p->clock = clock;
p->trp = transport_create(cfg, interface->transport);
diff --git a/ptp4l.c b/ptp4l.c
index faa13da..0eff87d 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -53,7 +53,6 @@ static struct config cfg_settings = {
.domainNumber = 0,
},
.free_running = 0,
- .freq_est_interval = 1,
.grand_master_capable = 1,
.stats_interval = 0,
.kernel_leap = 1,
@@ -80,7 +79,6 @@ static struct config cfg_settings = {
},

.pod = {
- .freq_est_interval = 1,
/* Default to very a large neighborPropDelay threshold */
.neighborPropDelayThresh = 20000000,
.min_neighbor_prop_delay = -20000000,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:47 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 11 ++---------
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 3 ---
4 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/config.c b/config.c
index 4c5182e..d8ce1e2 100644
--- a/config.c
+++ b/config.c
@@ -104,6 +104,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("logSyncInterval", 0, INT8_MIN, INT8_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
+ PORT_ITEM_INT("neighborPropDelayThresh", 20000000, 0, INT_MAX),
GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("path_trace_enabled", 0, 0, 1),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
@@ -269,17 +270,9 @@ static enum parser_result parse_pod_setting(const char *option,
struct port_defaults *pod)
{
int val;
- unsigned int uval;
-
enum parser_result r;

- if (!strcmp(option, "neighborPropDelayThresh")) {
- r = get_ranged_uint(value, &uval, 0, UINT32_MAX);
- if (r != PARSED_OK)
- return r;
- pod->neighborPropDelayThresh = uval;
-
- } else if (!strcmp(option, "min_neighbor_prop_delay")) {
+ if (!strcmp(option, "min_neighbor_prop_delay")) {
r = get_ranged_int(value, &val, INT_MIN, -1);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index 9ab07e3..fb91d00 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {

struct port_defaults {
struct fault_interval flt_interval_pertype[FT_CNT];
- UInteger32 neighborPropDelayThresh; /*nanoseconds*/
int min_neighbor_prop_delay; /*nanoseconds*/
int tx_timestamp_offset; /*nanoseconds*/
int rx_timestamp_offset; /*nanoseconds*/
diff --git a/port.c b/port.c
index 96422bb..1e01a78 100644
--- a/port.c
+++ b/port.c
@@ -1457,7 +1457,7 @@ static int port_initialize(struct port *p)
p->transportSpecific <<= 4;
p->logSyncInterval = config_get_int(cfg, p->name, "logSyncInterval");
p->logMinPdelayReqInterval = config_get_int(cfg, p->name, "logMinPdelayReqInterval");
- p->neighborPropDelayThresh = p->pod.neighborPropDelayThresh;
+ p->neighborPropDelayThresh = config_get_int(cfg, p->name, "neighborPropDelayThresh");
p->min_neighbor_prop_delay = p->pod.min_neighbor_prop_delay;

for (i = 0; i < N_TIMER_FDS; i++) {
diff --git a/ptp4l.c b/ptp4l.c
index 0eff87d..713bd4e 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -79,9 +79,6 @@ static struct config cfg_settings = {
},

.pod = {
- /* Default to very a large neighborPropDelay threshold */
- .neighborPropDelayThresh = 20000000,
- .min_neighbor_prop_delay = -20000000,
.tx_timestamp_offset = 0,
.rx_timestamp_offset = 0,
},
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:48 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 2 +-
3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/config.c b/config.c
index d8ce1e2..a4282f8 100644
--- a/config.c
+++ b/config.c
@@ -104,6 +104,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("logSyncInterval", 0, INT8_MIN, INT8_MAX),
GLOB_ITEM_INT("logging_level", LOG_INFO, PRINT_LEVEL_MIN, PRINT_LEVEL_MAX),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
+ PORT_ITEM_INT("min_neighbor_prop_delay", -20000000, INT_MIN, -1),
PORT_ITEM_INT("neighborPropDelayThresh", 20000000, 0, INT_MAX),
GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("path_trace_enabled", 0, 0, 1),
@@ -272,13 +273,7 @@ static enum parser_result parse_pod_setting(const char *option,
int val;
enum parser_result r;

- if (!strcmp(option, "min_neighbor_prop_delay")) {
- r = get_ranged_int(value, &val, INT_MIN, -1);
- if (r != PARSED_OK)
- return r;
- pod->min_neighbor_prop_delay = val;
-
- } else if (!strcmp(option, "egressLatency")) {
+ if (!strcmp(option, "egressLatency")) {
r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index fb91d00..23e5033 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {

struct port_defaults {
struct fault_interval flt_interval_pertype[FT_CNT];
- int min_neighbor_prop_delay; /*nanoseconds*/
int tx_timestamp_offset; /*nanoseconds*/
int rx_timestamp_offset; /*nanoseconds*/
};
diff --git a/port.c b/port.c
index 1e01a78..d01ff73 100644
--- a/port.c
+++ b/port.c
@@ -1458,7 +1458,7 @@ static int port_initialize(struct port *p)
p->logSyncInterval = config_get_int(cfg, p->name, "logSyncInterval");
p->logMinPdelayReqInterval = config_get_int(cfg, p->name, "logMinPdelayReqInterval");
p->neighborPropDelayThresh = config_get_int(cfg, p->name, "neighborPropDelayThresh");
- p->min_neighbor_prop_delay = p->pod.min_neighbor_prop_delay;
+ p->min_neighbor_prop_delay = config_get_int(cfg, p->name, "min_neighbor_prop_delay");

for (i = 0; i < N_TIMER_FDS; i++) {
fd[i] = -1;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:49 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 6 ++++--
ptp4l.c | 1 -
4 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/config.c b/config.c
index a4282f8..20a0d89 100644
--- a/config.c
+++ b/config.c
@@ -95,6 +95,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
+ PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
@@ -273,13 +274,7 @@ static enum parser_result parse_pod_setting(const char *option,
int val;
enum parser_result r;

- if (!strcmp(option, "egressLatency")) {
- r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
- if (r != PARSED_OK)
- return r;
- pod->tx_timestamp_offset = val;
-
- } else if (!strcmp(option, "ingressLatency")) {
+ if (!strcmp(option, "ingressLatency")) {
r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
if (r != PARSED_OK)
return r;
diff --git a/ds.h b/ds.h
index 23e5033..f36543e 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {

struct port_defaults {
struct fault_interval flt_interval_pertype[FT_CNT];
- int tx_timestamp_offset; /*nanoseconds*/
int rx_timestamp_offset; /*nanoseconds*/
};

diff --git a/port.c b/port.c
index d01ff73..8aabbfa 100644
--- a/port.c
+++ b/port.c
@@ -114,6 +114,7 @@ struct port {
int freq_est_interval;
int min_neighbor_prop_delay;
int path_trace_enabled;
+ int tx_timestamp_offset;
enum fault_type last_fault_type;
unsigned int versionNumber; /*UInteger4*/
/* foreignMasterDS */
@@ -521,7 +522,7 @@ static int peer_prepare_and_send(struct port *p, struct ptp_message *msg,
return -1;
}
if (msg_sots_valid(msg)) {
- ts_add(&msg->hwts.ts, p->pod.tx_timestamp_offset);
+ ts_add(&msg->hwts.ts, p->tx_timestamp_offset);
}
return 0;
}
@@ -2311,7 +2312,7 @@ int port_prepare_and_send(struct port *p, struct ptp_message *msg, int event)
return -1;
}
if (msg_sots_valid(msg)) {
- ts_add(&msg->hwts.ts, p->pod.tx_timestamp_offset);
+ ts_add(&msg->hwts.ts, p->tx_timestamp_offset);
}
return 0;
}
@@ -2536,6 +2537,7 @@ struct port *port_open(int phc_index,
p->follow_up_info = config_get_int(cfg, p->name, "follow_up_info");
p->freq_est_interval = config_get_int(cfg, p->name, "freq_est_interval");
p->path_trace_enabled = config_get_int(cfg, p->name, "path_trace_enabled");
+ p->tx_timestamp_offset = config_get_int(cfg, p->name, "egressLatency");
p->clock = clock;
p->trp = transport_create(cfg, interface->transport);
if (!p->trp)
diff --git a/ptp4l.c b/ptp4l.c
index 713bd4e..e092b08 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -79,7 +79,6 @@ static struct config cfg_settings = {
},

.pod = {
- .tx_timestamp_offset = 0,
.rx_timestamp_offset = 0,
},
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:50 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 4 +++-
ptp4l.c | 4 ----
4 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/config.c b/config.c
index 20a0d89..b3ca2b9 100644
--- a/config.c
+++ b/config.c
@@ -99,6 +99,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
+ PORT_ITEM_INT("ingressLatency", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinDelayReqInterval", 0, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinPdelayReqInterval", 0, INT8_MIN, INT8_MAX),
@@ -274,13 +275,7 @@ static enum parser_result parse_pod_setting(const char *option,
int val;
enum parser_result r;

- if (!strcmp(option, "ingressLatency")) {
- r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
- if (r != PARSED_OK)
- return r;
- pod->rx_timestamp_offset = val;
-
- } else if (!strcmp(option, "fault_badpeernet_interval")) {
+ if (!strcmp(option, "fault_badpeernet_interval")) {
pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].type = FTMO_LINEAR_SECONDS;
if (!strcasecmp("ASAP", value)) {
pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].val = 0;
diff --git a/ds.h b/ds.h
index f36543e..678136f 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {

struct port_defaults {
struct fault_interval flt_interval_pertype[FT_CNT];
- int rx_timestamp_offset; /*nanoseconds*/
};

#endif
diff --git a/port.c b/port.c
index 8aabbfa..b527492 100644
--- a/port.c
+++ b/port.c
@@ -114,6 +114,7 @@ struct port {
int freq_est_interval;
int min_neighbor_prop_delay;
int path_trace_enabled;
+ int rx_timestamp_offset;
int tx_timestamp_offset;
enum fault_type last_fault_type;
unsigned int versionNumber; /*UInteger4*/
@@ -2238,7 +2239,7 @@ enum fsm_event port_event(struct port *p, int fd_index)
return EV_NONE;
}
if (msg_sots_valid(msg)) {
- ts_add(&msg->hwts.ts, -p->pod.rx_timestamp_offset);
+ ts_add(&msg->hwts.ts, -p->rx_timestamp_offset);
clock_check_ts(p->clock, msg->hwts.ts);
}
if (port_ignore(p, msg)) {
@@ -2537,6 +2538,7 @@ struct port *port_open(int phc_index,
p->follow_up_info = config_get_int(cfg, p->name, "follow_up_info");
p->freq_est_interval = config_get_int(cfg, p->name, "freq_est_interval");
p->path_trace_enabled = config_get_int(cfg, p->name, "path_trace_enabled");
+ p->rx_timestamp_offset = config_get_int(cfg, p->name, "ingressLatency");
p->tx_timestamp_offset = config_get_int(cfg, p->name, "egressLatency");
p->clock = clock;
p->trp = transport_create(cfg, interface->transport);
diff --git a/ptp4l.c b/ptp4l.c
index e092b08..b7a1ef1 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -78,10 +78,6 @@ static struct config cfg_settings = {
.boundary_clock_jbod = 0,
},

- .pod = {
- .rx_timestamp_offset = 0,
- },
-
.timestamping = TS_HARDWARE,
.dm = DM_E2E,
.transport = TRANS_UDP_IPV4,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:52 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 15 +--------------
config.h | 1 -
ds.h | 1 -
port.c | 4 ++--
ptp4l.c | 1 -
5 files changed, 3 insertions(+), 19 deletions(-)

diff --git a/config.c b/config.c
index f9d5777..d0451e3 100644
--- a/config.c
+++ b/config.c
@@ -93,6 +93,7 @@ struct config_item {
struct config_item config_tab[] = {
PORT_ITEM_INT("announceReceiptTimeout", 3, 2, UINT8_MAX),
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
+ PORT_ITEM_INT("boundary_clock_jbod", 0, 0, 1),
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
@@ -310,7 +311,6 @@ static enum parser_result parse_port_setting(struct config *cfg,
struct interface *iface)
{
enum parser_result r;
- int val;

r = parse_pod_setting(option, value, &iface->pod);
if (r != NOT_PARSED)
@@ -356,12 +356,6 @@ static enum parser_result parse_port_setting(struct config *cfg,
else
return BAD_VALUE;

- } else if (!strcmp(option, "boundary_clock_jbod")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- iface->boundary_clock_jbod = val;
-
} else
return parse_item(cfg, iface->name, option, value);

@@ -606,12 +600,6 @@ static enum parser_result parse_global_setting(const char *option,
else
return BAD_VALUE;

- } else if (!strcmp(option, "boundary_clock_jbod")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- cfg->dds.boundary_clock_jbod = val;
-
} else
return parse_item(cfg, NULL, option, value);

@@ -799,7 +787,6 @@ void config_init_interface(struct interface *iface, struct config *cfg)
sk_get_ts_info(iface->name, &iface->ts_info);

iface->delay_filter = cfg->dds.delay_filter;
- iface->boundary_clock_jbod = cfg->dds.boundary_clock_jbod;
}

int config_init(struct config *cfg)
diff --git a/config.h b/config.h
index df7b733..30a6803 100644
--- a/config.h
+++ b/config.h
@@ -41,7 +41,6 @@ struct interface {
struct sk_ts_info ts_info;
enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
- int boundary_clock_jbod;
};

#define CFG_IGNORE_DM (1 << 0)
diff --git a/ds.h b/ds.h
index 30d33d8..b252f39 100644
--- a/ds.h
+++ b/ds.h
@@ -61,7 +61,6 @@ struct default_ds {
struct clock_description clock_desc;
enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
- int boundary_clock_jbod;
};

struct dataset {
diff --git a/port.c b/port.c
index ba3108d..42714a6 100644
--- a/port.c
+++ b/port.c
@@ -2513,14 +2513,14 @@ struct port *port_open(int phc_index,
memset(p, 0, sizeof(*p));

p->phc_index = phc_index;
- p->jbod = interface->boundary_clock_jbod;
+ p->jbod = config_get_int(cfg, interface->name, "boundary_clock_jbod");

if (interface->transport == TRANS_UDS)
; /* UDS cannot have a PHC. */
else if (!interface->ts_info.valid)
pr_warning("port %d: get_ts_info not supported", number);
else if (phc_index >= 0 && phc_index != interface->ts_info.phc_index) {
- if (interface->boundary_clock_jbod) {
+ if (p->jbod) {
pr_warning("port %d: just a bunch of devices", number);
p->phc_index = interface->ts_info.phc_index;
} else {
diff --git a/ptp4l.c b/ptp4l.c
index c68fd60..0da5b1a 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -74,7 +74,6 @@ static struct config cfg_settings = {
},
.tsproc_mode = TSPROC_FILTER,
.delay_filter = FILTER_MOVING_MEDIAN,
- .boundary_clock_jbod = 0,
},

.timestamping = TS_HARDWARE,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:51 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 6 ++++--
config.c | 14 +-------------
config.h | 1 -
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 1 -
6 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/clock.c b/clock.c
index 0856f81..73cf016 100644
--- a/clock.c
+++ b/clock.c
@@ -819,7 +819,9 @@ struct clock *clock_create(struct config *config, int phc_index,

snprintf(udsif->name, sizeof(udsif->name), "%s", uds_path);
udsif->transport = TRANS_UDS;
- udsif->delay_filter_length = 1;
+ if (config_set_section_int(config, udsif->name, "delay_filter_length", 1)) {
+ return NULL;
+ }

c->config = config;
c->free_running = dds->free_running;
@@ -874,7 +876,7 @@ struct clock *clock_create(struct config *config, int phc_index,
c->servo_state = SERVO_UNLOCKED;
c->servo_type = servo;
c->tsproc = tsproc_create(dds->tsproc_mode, dds->delay_filter,
- dds->delay_filter_length);
+ config_get_int(config, NULL, "delay_filter_length"));
if (!c->tsproc) {
pr_err("Failed to create time stamp processor");
return NULL;
diff --git a/config.c b/config.c
index b3ca2b9..f9d5777 100644
--- a/config.c
+++ b/config.c
@@ -95,6 +95,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
+ PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
@@ -355,12 +356,6 @@ static enum parser_result parse_port_setting(struct config *cfg,
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;
- iface->delay_filter_length = val;
-
} else if (!strcmp(option, "boundary_clock_jbod")) {
r = get_ranged_int(value, &val, 0, 1);
if (r != PARSED_OK)
@@ -611,12 +606,6 @@ static enum parser_result parse_global_setting(const char *option,
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 if (!strcmp(option, "boundary_clock_jbod")) {
r = get_ranged_int(value, &val, 0, 1);
if (r != PARSED_OK)
@@ -810,7 +799,6 @@ void config_init_interface(struct interface *iface, struct config *cfg)
sk_get_ts_info(iface->name, &iface->ts_info);

iface->delay_filter = cfg->dds.delay_filter;
- iface->delay_filter_length = cfg->dds.delay_filter_length;
iface->boundary_clock_jbod = cfg->dds.boundary_clock_jbod;
}

diff --git a/config.h b/config.h
index c1ada46..df7b733 100644
--- a/config.h
+++ b/config.h
@@ -41,7 +41,6 @@ struct interface {
struct sk_ts_info ts_info;
enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
- int delay_filter_length;
int boundary_clock_jbod;
};

diff --git a/ds.h b/ds.h
index 678136f..30d33d8 100644
--- a/ds.h
+++ b/ds.h
@@ -61,7 +61,6 @@ struct default_ds {
struct clock_description clock_desc;
enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
- int delay_filter_length;
int boundary_clock_jbod;
};

diff --git a/port.c b/port.c
index b527492..ba3108d 100644
--- a/port.c
+++ b/port.c
@@ -2553,7 +2553,7 @@ struct port *port_open(int phc_index,

p->tsproc = tsproc_create(interface->tsproc_mode,
interface->delay_filter,
- interface->delay_filter_length);
+ config_get_int(cfg, p->name, "delay_filter_length"));
if (!p->tsproc) {
pr_err("Failed to create time stamp processor");
goto err_transport;
diff --git a/ptp4l.c b/ptp4l.c
index b7a1ef1..c68fd60 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -74,7 +74,6 @@ static struct config cfg_settings = {
},
.tsproc_mode = TSPROC_FILTER,
.delay_filter = FILTER_MOVING_MEDIAN,
- .delay_filter_length = 10,
.boundary_clock_jbod = 0,
},
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:54 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 2 +-
config.c | 7 +------
ds.h | 1 -
ptp4l.c | 5 ++---
4 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/clock.c b/clock.c
index 8c20d64..f31ae42 100644
--- a/clock.c
+++ b/clock.c
@@ -826,7 +826,7 @@ struct clock *clock_create(struct config *config, int phc_index,
c->config = config;
c->free_running = config_get_int(config, NULL, "free_running");
c->freq_est_interval = config_get_int(config, NULL, "freq_est_interval");
- c->grand_master_capable = dds->grand_master_capable;
+ c->grand_master_capable = config_get_int(config, NULL, "gmCapable");
c->kernel_leap = dds->kernel_leap;
c->utc_offset = CURRENT_UTC_OFFSET;
c->time_source = dds->time_source;
diff --git a/config.c b/config.c
index 8049045..24774af 100644
--- a/config.c
+++ b/config.c
@@ -102,6 +102,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
GLOB_ITEM_INT("free_running", 0, 0, 1),
PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
+ GLOB_ITEM_INT("gmCapable", 1, 0, 1),
PORT_ITEM_INT("ingressLatency", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinDelayReqInterval", 0, INT8_MIN, INT8_MAX),
@@ -412,12 +413,6 @@ static enum parser_result parse_global_setting(const char *option,
dds->flags &= ~DDS_SLAVE_ONLY;
}

- } else if (!strcmp(option, "gmCapable")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- cfg->dds.grand_master_capable = val;
-
} else if (!strcmp(option, "priority1")) {
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
if (r != PARSED_OK)
diff --git a/ds.h b/ds.h
index 963a033..1248b7c 100644
--- a/ds.h
+++ b/ds.h
@@ -52,7 +52,6 @@ struct clock_description {

struct default_ds {
struct defaultDS dds;
- int grand_master_capable; /*802.1AS only*/
int stats_interval; /*log seconds*/
int kernel_leap;
int sanity_freq_limit;
diff --git a/ptp4l.c b/ptp4l.c
index b6cd815..1070d44 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -52,7 +52,6 @@ static struct config cfg_settings = {
.priority2 = 128,
.domainNumber = 0,
},
- .grand_master_capable = 1,
.stats_interval = 0,
.kernel_leap = 1,
.sanity_freq_limit = 200000000,
@@ -237,13 +236,13 @@ int main(int argc, char *argv[])
sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync");
sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");

- if (!cfg_settings.dds.grand_master_capable &&
+ if (!config_get_int(cfg, NULL, "gmCapable") &&
ds->flags & DDS_SLAVE_ONLY) {
fprintf(stderr,
"Cannot mix 1588 slaveOnly with 802.1AS !gmCapable.\n");
return -1;
}
- if (!cfg_settings.dds.grand_master_capable ||
+ if (!config_get_int(cfg, NULL, "gmCapable") ||
ds->flags & DDS_SLAVE_ONLY) {
ds->clockQuality.clockClass = 255;
}
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:55 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 2 +-
config.c | 7 +------
ds.h | 1 -
ptp4l.c | 1 -
4 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/clock.c b/clock.c
index f31ae42..c64fdaa 100644
--- a/clock.c
+++ b/clock.c
@@ -882,7 +882,7 @@ struct clock *clock_create(struct config *config, int phc_index,
return NULL;
}
c->nrr = 1.0;
- c->stats_interval = dds->stats_interval;
+ c->stats_interval = config_get_int(config, NULL, "summary_interval");
c->stats.offset = stats_create();
c->stats.freq = stats_create();
c->stats.delay = stats_create();
diff --git a/config.c b/config.c
index 24774af..f97cd2d 100644
--- a/config.c
+++ b/config.c
@@ -123,6 +123,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
+ GLOB_ITEM_INT("summary_interval", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
@@ -552,12 +553,6 @@ static enum parser_result parse_global_setting(const char *option,
for (i = 0; i < OUI_LEN; i++)
cfg->dds.clock_desc.manufacturerIdentity[i] = oui[i];

- } else if (!strcmp(option, "summary_interval")) {
- r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
- if (r != PARSED_OK)
- return r;
- cfg->dds.stats_interval = val;
-
} else if (!strcmp(option, "kernel_leap")) {
r = get_ranged_int(value, &val, 0, 1);
if (r != PARSED_OK)
diff --git a/ds.h b/ds.h
index 1248b7c..b2802cf 100644
--- a/ds.h
+++ b/ds.h
@@ -52,7 +52,6 @@ struct clock_description {

struct default_ds {
struct defaultDS dds;
- int stats_interval; /*log seconds*/
int kernel_leap;
int sanity_freq_limit;
int time_source;
diff --git a/ptp4l.c b/ptp4l.c
index 1070d44..30c43a9 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -52,7 +52,6 @@ static struct config cfg_settings = {
.priority2 = 128,
.domainNumber = 0,
},
- .stats_interval = 0,
.kernel_leap = 1,
.sanity_freq_limit = 200000000,
.time_source = INTERNAL_OSCILLATOR,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:56 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 2 +-
config.c | 7 +------
ds.h | 1 -
ptp4l.c | 3 +--
4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/clock.c b/clock.c
index c64fdaa..1d5e2b6 100644
--- a/clock.c
+++ b/clock.c
@@ -827,7 +827,7 @@ struct clock *clock_create(struct config *config, int phc_index,
c->free_running = config_get_int(config, NULL, "free_running");
c->freq_est_interval = config_get_int(config, NULL, "freq_est_interval");
c->grand_master_capable = config_get_int(config, NULL, "gmCapable");
- c->kernel_leap = dds->kernel_leap;
+ c->kernel_leap = config_get_int(config, NULL, "kernel_leap");
c->utc_offset = CURRENT_UTC_OFFSET;
c->time_source = dds->time_source;
c->desc = dds->clock_desc;
diff --git a/config.c b/config.c
index f97cd2d..3ad052f 100644
--- a/config.c
+++ b/config.c
@@ -104,6 +104,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
GLOB_ITEM_INT("gmCapable", 1, 0, 1),
PORT_ITEM_INT("ingressLatency", 0, INT_MIN, INT_MAX),
+ GLOB_ITEM_INT("kernel_leap", 1, 0, 1),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinDelayReqInterval", 0, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("logMinPdelayReqInterval", 0, INT8_MIN, INT8_MAX),
@@ -553,12 +554,6 @@ static enum parser_result parse_global_setting(const char *option,
for (i = 0; i < OUI_LEN; i++)
cfg->dds.clock_desc.manufacturerIdentity[i] = oui[i];

- } else if (!strcmp(option, "kernel_leap")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- cfg->dds.kernel_leap = val;
-
} else if (!strcmp(option, "timeSource")) {
r = get_ranged_int(value, &val, 0x10, 0xfe);
if (r != PARSED_OK)
diff --git a/ds.h b/ds.h
index b2802cf..1f48cc1 100644
--- a/ds.h
+++ b/ds.h
@@ -52,7 +52,6 @@ struct clock_description {

struct default_ds {
struct defaultDS dds;
- int kernel_leap;
int sanity_freq_limit;
int time_source;
struct clock_description clock_desc;
diff --git a/ptp4l.c b/ptp4l.c
index 30c43a9..43a5523 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -52,7 +52,6 @@ static struct config cfg_settings = {
.priority2 = 128,
.domainNumber = 0,
},
- .kernel_leap = 1,
.sanity_freq_limit = 200000000,
.time_source = INTERNAL_OSCILLATOR,
.clock_desc = {
@@ -246,7 +245,7 @@ int main(int argc, char *argv[])
ds->clockQuality.clockClass = 255;
}
if (cfg_settings.clock_servo == CLOCK_SERVO_NTPSHM) {
- cfg_settings.dds.kernel_leap = 0;
+ config_set_int(cfg, "kernel_leap", 0);
cfg_settings.dds.sanity_freq_limit = 0;
}
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:53 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 2 +-
config.c | 7 +------
ds.h | 1 -
ptp4l.c | 3 +--
4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/clock.c b/clock.c
index 73cf016..8c20d64 100644
--- a/clock.c
+++ b/clock.c
@@ -824,7 +824,7 @@ struct clock *clock_create(struct config *config, int phc_index,
}

c->config = config;
- c->free_running = dds->free_running;
+ c->free_running = config_get_int(config, NULL, "free_running");
c->freq_est_interval = config_get_int(config, NULL, "freq_est_interval");
c->grand_master_capable = dds->grand_master_capable;
c->kernel_leap = dds->kernel_leap;
diff --git a/config.c b/config.c
index d0451e3..8049045 100644
--- a/config.c
+++ b/config.c
@@ -100,6 +100,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
+ GLOB_ITEM_INT("free_running", 0, 0, 1),
PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
PORT_ITEM_INT("ingressLatency", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
@@ -454,12 +455,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
dds->clockQuality.offsetScaledLogVariance = uval;

- } else if (!strcmp(option, "free_running")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- cfg->dds.free_running = val;
-
} else if (!strcmp(option, "sanity_freq_limit")) {
r = get_ranged_int(value, &val, 0, INT_MAX);
if (r != PARSED_OK)
diff --git a/ds.h b/ds.h
index b252f39..963a033 100644
--- a/ds.h
+++ b/ds.h
@@ -52,7 +52,6 @@ struct clock_description {

struct default_ds {
struct defaultDS dds;
- int free_running;
int grand_master_capable; /*802.1AS only*/
int stats_interval; /*log seconds*/
int kernel_leap;
diff --git a/ptp4l.c b/ptp4l.c
index 0da5b1a..b6cd815 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -52,7 +52,6 @@ static struct config cfg_settings = {
.priority2 = 128,
.domainNumber = 0,
},
- .free_running = 0,
.grand_master_capable = 1,
.stats_interval = 0,
.kernel_leap = 1,
@@ -313,7 +312,7 @@ int main(int argc, char *argv[])

/* determine PHC Clock index */
iface = STAILQ_FIRST(&cfg_settings.interfaces);
- if (cfg_settings.dds.free_running) {
+ if (config_get_int(cfg, NULL, "free_running")) {
phc_index = -1;
} else if (*timestamping == TS_SOFTWARE || *timestamping == TS_LEGACY_HW) {
phc_index = -1;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:57 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 6 ++++--
config.c | 7 +------
ds.h | 1 -
ptp4l.c | 3 +--
4 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/clock.c b/clock.c
index 1d5e2b6..ee20a3c 100644
--- a/clock.c
+++ b/clock.c
@@ -810,6 +810,7 @@ struct clock *clock_create(struct config *config, int phc_index,
struct interface *udsif = &c->uds_interface;
struct interface *iface;
struct timespec ts;
+ int sfl;

clock_gettime(CLOCK_REALTIME, &ts);
srandom(ts.tv_sec ^ ts.tv_nsec);
@@ -890,8 +891,9 @@ struct clock *clock_create(struct config *config, int phc_index,
pr_err("failed to create stats");
return NULL;
}
- if (dds->sanity_freq_limit) {
- c->sanity_check = clockcheck_create(dds->sanity_freq_limit);
+ sfl = config_get_int(config, NULL, "sanity_freq_limit");
+ if (sfl) {
+ c->sanity_check = clockcheck_create(sfl);
if (!c->sanity_check) {
pr_err("Failed to create clock sanity check");
return NULL;
diff --git a/config.c b/config.c
index 3ad052f..1007a27 100644
--- a/config.c
+++ b/config.c
@@ -123,6 +123,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
+ GLOB_ITEM_INT("sanity_freq_limit", 200000000, 0, INT_MAX),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("summary_interval", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
@@ -452,12 +453,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
dds->clockQuality.offsetScaledLogVariance = uval;

- } else if (!strcmp(option, "sanity_freq_limit")) {
- r = get_ranged_int(value, &val, 0, INT_MAX);
- if (r != PARSED_OK)
- return r;
- cfg->dds.sanity_freq_limit = 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/ds.h b/ds.h
index 1f48cc1..505dc76 100644
--- a/ds.h
+++ b/ds.h
@@ -52,7 +52,6 @@ struct clock_description {

struct default_ds {
struct defaultDS dds;
- int sanity_freq_limit;
int time_source;
struct clock_description clock_desc;
enum tsproc_mode tsproc_mode;
diff --git a/ptp4l.c b/ptp4l.c
index 43a5523..fcddd99 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -52,7 +52,6 @@ static struct config cfg_settings = {
.priority2 = 128,
.domainNumber = 0,
},
- .sanity_freq_limit = 200000000,
.time_source = INTERNAL_OSCILLATOR,
.clock_desc = {
.productDescription = {
@@ -246,7 +245,7 @@ int main(int argc, char *argv[])
}
if (cfg_settings.clock_servo == CLOCK_SERVO_NTPSHM) {
config_set_int(cfg, "kernel_leap", 0);
- cfg_settings.dds.sanity_freq_limit = 0;
+ config_set_int(cfg, "sanity_freq_limit", 0);
}

print_set_progname(progname);
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:58 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 2 +-
config.c | 7 +------
ds.h | 1 -
ptp4l.c | 1 -
4 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/clock.c b/clock.c
index ee20a3c..ab048f5 100644
--- a/clock.c
+++ b/clock.c
@@ -830,7 +830,7 @@ struct clock *clock_create(struct config *config, int phc_index,
c->grand_master_capable = config_get_int(config, NULL, "gmCapable");
c->kernel_leap = config_get_int(config, NULL, "kernel_leap");
c->utc_offset = CURRENT_UTC_OFFSET;
- c->time_source = dds->time_source;
+ c->time_source = config_get_int(config, NULL, "timeSource");
c->desc = dds->clock_desc;

if (c->free_running) {
diff --git a/config.c b/config.c
index 1007a27..71d96e5 100644
--- a/config.c
+++ b/config.c
@@ -127,6 +127,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("summary_interval", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
+ GLOB_ITEM_INT("timeSource", INTERNAL_OSCILLATOR, 0x10, 0xfe),
PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
@@ -549,12 +550,6 @@ static enum parser_result parse_global_setting(const char *option,
for (i = 0; i < OUI_LEN; i++)
cfg->dds.clock_desc.manufacturerIdentity[i] = oui[i];

- } else if (!strcmp(option, "timeSource")) {
- r = get_ranged_int(value, &val, 0x10, 0xfe);
- if (r != PARSED_OK)
- return r;
- cfg->dds.time_source = val;
-
} else if (!strcmp(option, "tsproc_mode")) {
if (!strcasecmp("filter", value))
cfg->dds.tsproc_mode = TSPROC_FILTER;
diff --git a/ds.h b/ds.h
index 505dc76..f32a26c 100644
--- a/ds.h
+++ b/ds.h
@@ -52,7 +52,6 @@ struct clock_description {

struct default_ds {
struct defaultDS dds;
- int time_source;
struct clock_description clock_desc;
enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
diff --git a/ptp4l.c b/ptp4l.c
index fcddd99..461f39d 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -52,7 +52,6 @@ static struct config cfg_settings = {
.priority2 = 128,
.domainNumber = 0,
},
- .time_source = INTERNAL_OSCILLATOR,
.clock_desc = {
.productDescription = {
.max_symbols = 64,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:14:59 UTC
Permalink
This conversion is not straightforward due to the fact that these options
can take a value of "ASAP" or a number. We check for the special ASAP
case in a helper function and leave the numbers to the generic code.

Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 66 ++++++++++++++++++++++++++++++----------------------------------
ds.h | 1 -
port.c | 18 ++++++++++++++++--
ptp4l.c | 8 +-------
4 files changed, 48 insertions(+), 45 deletions(-)

diff --git a/config.c b/config.c
index 71d96e5..ee91a40 100644
--- a/config.c
+++ b/config.c
@@ -98,6 +98,8 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
+ PORT_ITEM_INT("fault_badpeernet_interval", 16, INT32_MIN, INT32_MAX),
+ PORT_ITEM_INT("fault_reset_interval", 4, INT8_MIN, INT8_MAX),
GLOB_ITEM_DBL("first_step_threshold", 0.00002, 0.0, DBL_MAX),
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
GLOB_ITEM_INT("free_running", 0, 0, 1),
@@ -276,39 +278,35 @@ static enum parser_result parse_item(struct config *cfg,
return PARSED_OK;
}

-static enum parser_result parse_pod_setting(const char *option,
- const char *value,
- struct port_defaults *pod)
+static enum parser_result parse_fault_interval(struct config *cfg,
+ const char *section,
+ const char *option,
+ const char *value)
{
- int val;
- enum parser_result r;
-
- if (!strcmp(option, "fault_badpeernet_interval")) {
- pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].type = FTMO_LINEAR_SECONDS;
- if (!strcasecmp("ASAP", value)) {
- pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].val = 0;
- } else {
- r = get_ranged_int(value, &val, INT32_MIN, INT32_MAX);
- if (r != PARSED_OK)
- return r;
- pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].val = val;
- }
-
- } else if (!strcmp(option, "fault_reset_interval")) {
- pod->flt_interval_pertype[FT_UNSPECIFIED].type = FTMO_LOG2_SECONDS;
- if (!strcasecmp("ASAP", value)) {
- pod->flt_interval_pertype[FT_UNSPECIFIED].val = FRI_ASAP;
- } else {
- r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
- if (r != PARSED_OK)
- return r;
- pod->flt_interval_pertype[FT_UNSPECIFIED].val = val;
- }
-
- } else
+ int i, val;
+ const char *str, *fault_options[2] = {
+ "fault_badpeernet_interval",
+ "fault_reset_interval",
+ };
+ int fault_values[2] = {
+ 0, FRI_ASAP,
+ };
+
+ if (strcasecmp("ASAP", value)) {
return NOT_PARSED;
-
- return PARSED_OK;
+ }
+ for (i = 0; i < 2; i++) {
+ str = fault_options[i];
+ val = fault_values[i];
+ if (!strcmp(option, str)) {
+ if (config_set_section_int(cfg, section, str, val)) {
+ pr_err("bug: failed to set option %s!", option);
+ exit(-1);
+ }
+ return PARSED_OK;
+ }
+ }
+ return NOT_PARSED;
}

static enum parser_result parse_port_setting(struct config *cfg,
@@ -318,7 +316,7 @@ static enum parser_result parse_port_setting(struct config *cfg,
{
enum parser_result r;

- r = parse_pod_setting(option, value, &iface->pod);
+ r = parse_fault_interval(cfg, iface->name, option, value);
if (r != NOT_PARSED)
return r;

@@ -389,11 +387,9 @@ static enum parser_result parse_global_setting(const char *option,
unsigned char oui[OUI_LEN];

struct defaultDS *dds = &cfg->dds.dds;
- struct port_defaults *pod = &cfg->pod;
-
enum parser_result r;

- r = parse_pod_setting(option, value, pod);
+ r = parse_fault_interval(cfg, NULL, option, value);
if (r != NOT_PARSED)
return r;

diff --git a/ds.h b/ds.h
index f32a26c..d17fb12 100644
--- a/ds.h
+++ b/ds.h
@@ -116,7 +116,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- struct fault_interval flt_interval_pertype[FT_CNT];
};

#endif
diff --git a/port.c b/port.c
index 42714a6..11fce75 100644
--- a/port.c
+++ b/port.c
@@ -116,6 +116,7 @@ struct port {
int path_trace_enabled;
int rx_timestamp_offset;
int tx_timestamp_offset;
+ struct fault_interval flt_interval_pertype[FT_CNT];
enum fault_type last_fault_type;
unsigned int versionNumber; /*UInteger4*/
/* foreignMasterDS */
@@ -202,8 +203,8 @@ int fault_interval(struct port *port, enum fault_type ft,
return -EINVAL;
if (ft < 0 || ft >= FT_CNT)
return -EINVAL;
- i->type = port->pod.flt_interval_pertype[ft].type;
- i->val = port->pod.flt_interval_pertype[ft].val;
+ i->type = port->flt_interval_pertype[ft].type;
+ i->val = port->flt_interval_pertype[ft].val;
return 0;
}

@@ -2506,6 +2507,7 @@ struct port *port_open(int phc_index,
{
struct config *cfg = clock_config(clock);
struct port *p = malloc(sizeof(*p));
+ int i;

if (!p)
return NULL;
@@ -2551,6 +2553,18 @@ struct port *port_open(int phc_index,
p->delayMechanism = interface->dm;
p->versionNumber = PTP_VERSION;

+ /* Set fault timeouts to a default value */
+ for (i = 0; i < FT_CNT; i++) {
+ p->flt_interval_pertype[i].type = FTMO_LOG2_SECONDS;
+ p->flt_interval_pertype[i].val = 4;
+ }
+ p->flt_interval_pertype[FT_BAD_PEER_NETWORK].type = FTMO_LINEAR_SECONDS;
+ p->flt_interval_pertype[FT_BAD_PEER_NETWORK].val =
+ config_get_int(cfg, p->name, "fault_badpeernet_interval");
+
+ p->flt_interval_pertype[FT_UNSPECIFIED].val =
+ config_get_int(cfg, p->name, "fault_reset_interval");
+
p->tsproc = tsproc_create(interface->tsproc_mode,
interface->delay_filter,
config_get_int(cfg, p->name, "delay_filter_length"));
diff --git a/ptp4l.c b/ptp4l.c
index 461f39d..0ddf6c1 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -118,7 +118,7 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
char *config = NULL, *req_phc = NULL, *progname;
- int c, i;
+ int c;
struct interface *iface;
int *cfg_ignore = &cfg_settings.cfg_ignore;
enum delay_mechanism *dm = &cfg_settings.dm;
@@ -136,12 +136,6 @@ int main(int argc, char *argv[])
return -1;
}

- /* Set fault timeouts to a default value */
- for (i = 0; i < FT_CNT; i++) {
- cfg_settings.pod.flt_interval_pertype[i].type = FTMO_LOG2_SECONDS;
- cfg_settings.pod.flt_interval_pertype[i].val = 4;
- }
-
/* Process the command line arguments. */
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:00 UTC
Permalink
This definition is now empty and can serve no purpose any more.

Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 3 ---
config.h | 2 --
ds.h | 3 ---
port.c | 2 --
4 files changed, 10 deletions(-)

diff --git a/config.c b/config.c
index ee91a40..e1eac73 100644
--- a/config.c
+++ b/config.c
@@ -748,10 +748,7 @@ void config_init_interface(struct interface *iface, struct config *cfg)
{
iface->dm = cfg->dm;
iface->transport = cfg->transport;
- memcpy(&iface->pod, &cfg->pod, sizeof(cfg->pod));
-
sk_get_ts_info(iface->name, &iface->ts_info);
-
iface->delay_filter = cfg->dds.delay_filter;
}

diff --git a/config.h b/config.h
index 30a6803..88120e4 100644
--- a/config.h
+++ b/config.h
@@ -37,7 +37,6 @@ struct interface {
char name[MAX_IFNAME_SIZE + 1];
enum delay_mechanism dm;
enum transport_type transport;
- struct port_defaults pod;
struct sk_ts_info ts_info;
enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
@@ -64,7 +63,6 @@ struct config {
enum delay_mechanism dm;

struct default_ds dds;
- struct port_defaults pod;
enum servo_type clock_servo;

unsigned char *ptp_dst_mac;
diff --git a/ds.h b/ds.h
index d17fb12..a431616 100644
--- a/ds.h
+++ b/ds.h
@@ -115,7 +115,4 @@ struct portDS {

#define FRI_ASAP (-128)

-struct port_defaults {
-};
-
#endif
diff --git a/port.c b/port.c
index 11fce75..2299831 100644
--- a/port.c
+++ b/port.c
@@ -95,7 +95,6 @@ struct port {
unsigned int multiple_seq_pdr_count;
unsigned int multiple_pdr_detected;
/* portDS */
- struct port_defaults pod;
struct PortIdentity portIdentity;
enum port_state state; /*portState*/
Integer64 asymmetry;
@@ -2533,7 +2532,6 @@ struct port *port_open(int phc_index,
}
}

- p->pod = interface->pod;
p->name = interface->name;
p->asymmetry = config_get_int(cfg, p->name, "delayAsymmetry");
p->asymmetry <<= 16;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:01 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
config.h | 1 -
ptp4l.c | 1 -
udp6.c | 5 ++---
udp6.h | 6 ------
5 files changed, 3 insertions(+), 17 deletions(-)

diff --git a/config.c b/config.c
index e1eac73..1c4421b 100644
--- a/config.c
+++ b/config.c
@@ -133,6 +133,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
+ PORT_ITEM_INT("udp6_scope", 0x0E, 0x00, 0x0F),
GLOB_ITEM_INT("use_syslog", 1, 0, 1),
GLOB_ITEM_INT("verbose", 0, 0, 1),
};
@@ -464,12 +465,6 @@ static enum parser_result parse_global_setting(const char *option,
for (i = 0; i < MAC_LEN; i++)
cfg->p2p_dst_mac[i] = mac[i];

- } else if (!strcmp(option, "udp6_scope")) {
- r = get_ranged_uint(value, &uval, 0x00, 0x0F);
- if (r != PARSED_OK)
- return r;
- *cfg->udp6_scope = uval;
-
} else if (!strcmp(option, "uds_address")) {
if (strlen(value) > MAX_IFNAME_SIZE)
return OUT_OF_RANGE;
diff --git a/config.h b/config.h
index 88120e4..0ccb3ea 100644
--- a/config.h
+++ b/config.h
@@ -67,7 +67,6 @@ struct config {

unsigned char *ptp_dst_mac;
unsigned char *p2p_dst_mac;
- unsigned char *udp6_scope;
char *uds_address;
};

diff --git a/ptp4l.c b/ptp4l.c
index 0ddf6c1..08f7512 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -77,7 +77,6 @@ static struct config cfg_settings = {

.ptp_dst_mac = ptp_dst_mac,
.p2p_dst_mac = p2p_dst_mac,
- .udp6_scope = &udp6_scope,
.uds_address = uds_path,

.cfg_ignore = 0,
diff --git a/udp6.c b/udp6.c
index f098b8c..fdf5799 100644
--- a/udp6.c
+++ b/udp6.c
@@ -30,6 +30,7 @@
#include <unistd.h>

#include "address.h"
+#include "config.h"
#include "contain.h"
#include "print.h"
#include "sk.h"
@@ -42,8 +43,6 @@
#define PTP_PRIMARY_MCAST_IP6ADDR "FF0E:0:0:0:0:0:0:181"
#define PTP_PDELAY_MCAST_IP6ADDR "FF02:0:0:0:0:0:0:6B"

-unsigned char udp6_scope = 0x0E;
-
struct udp6 {
struct transport t;
int index;
@@ -172,7 +171,7 @@ static int udp6_open(struct transport *t, const char *name, struct fdarray *fda,
if (1 != inet_pton(AF_INET6, PTP_PRIMARY_MCAST_IP6ADDR, &mc6_addr[MC_PRIMARY]))
return -1;

- mc6_addr[MC_PRIMARY].s6_addr[1] = udp6_scope;
+ mc6_addr[MC_PRIMARY].s6_addr[1] = config_get_int(t->cfg, name, "udp6_scope");

if (1 != inet_pton(AF_INET6, PTP_PDELAY_MCAST_IP6ADDR, &mc6_addr[MC_PDELAY]))
return -1;
diff --git a/udp6.h b/udp6.h
index e451262..8613da5 100644
--- a/udp6.h
+++ b/udp6.h
@@ -24,12 +24,6 @@
#include "transport.h"

/**
- * The desired scope for the multicast messages. This will be used as
- * the second byte of the primary IPv6 address. See RFC 4291.
- */
-extern unsigned char udp6_scope;
-
-/**
* Allocate an instance of a UDP/IPv6 transport.
* @return Pointer to a new transport instance on success, NULL otherwise.
*/
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:02 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 29 +++++------------------------
config.h | 1 -
ptp4l.c | 14 +++++++++++---
3 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/config.c b/config.c
index 1c4421b..87d944f 100644
--- a/config.c
+++ b/config.c
@@ -126,11 +126,13 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("sanity_freq_limit", 200000000, 0, INT_MAX),
+ GLOB_ITEM_INT("slaveOnly", 0, 0, 1),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_INT("summary_interval", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
GLOB_ITEM_INT("timeSource", INTERNAL_OSCILLATOR, 0x10, 0xfe),
PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F),
+ GLOB_ITEM_INT("twoStepFlag", 1, 0, 1),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
PORT_ITEM_INT("udp6_scope", 0x0E, 0x00, 0x0F),
@@ -382,7 +384,7 @@ static enum parser_result parse_global_setting(const char *option,
const char *value,
struct config *cfg)
{
- int i, val, cfg_ignore = cfg->cfg_ignore;
+ int i, cfg_ignore = cfg->cfg_ignore;
unsigned int uval;
unsigned char mac[MAC_LEN];
unsigned char oui[OUI_LEN];
@@ -394,27 +396,7 @@ static enum parser_result parse_global_setting(const char *option,
if (r != NOT_PARSED)
return r;

- if (!strcmp(option, "twoStepFlag")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- if (val)
- dds->flags |= DDS_TWO_STEP_FLAG;
- else
- dds->flags &= ~DDS_TWO_STEP_FLAG;
-
- } else if (!strcmp(option, "slaveOnly")) {
- r = get_ranged_int(value, &val, 0, 1);
- if (r != PARSED_OK)
- return r;
- if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY)) {
- if (val)
- dds->flags |= DDS_SLAVE_ONLY;
- else
- dds->flags &= ~DDS_SLAVE_ONLY;
- }
-
- } else if (!strcmp(option, "priority1")) {
+ if (!strcmp(option, "priority1")) {
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
if (r != PARSED_OK)
return r;
@@ -436,8 +418,7 @@ static enum parser_result parse_global_setting(const char *option,
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
if (r != PARSED_OK)
return r;
- if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY))
- dds->clockQuality.clockClass = uval;
+ dds->clockQuality.clockClass = uval;

} else if (!strcmp(option, "clockAccuracy")) {
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
diff --git a/config.h b/config.h
index 0ccb3ea..9100083 100644
--- a/config.h
+++ b/config.h
@@ -45,7 +45,6 @@ struct interface {
#define CFG_IGNORE_DM (1 << 0)
#define CFG_IGNORE_TRANSPORT (1 << 1)
#define CFG_IGNORE_TIMESTAMPING (1 << 2)
-#define CFG_IGNORE_SLAVEONLY (1 << 3)

struct config {
/* configuration override */
diff --git a/ptp4l.c b/ptp4l.c
index 08f7512..89a659d 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -44,7 +44,6 @@ static struct config cfg_settings = {

.dds = {
.dds = {
- .flags = DDS_TWO_STEP_FLAG,
.priority1 = 128,
.clockQuality.clockClass = 248,
.clockQuality.clockAccuracy = 0xfe,
@@ -187,8 +186,9 @@ int main(int argc, char *argv[])
req_phc = optarg;
break;
case 's':
- ds->flags |= DDS_SLAVE_ONLY;
- *cfg_ignore |= CFG_IGNORE_SLAVEONLY;
+ if (config_set_int(cfg, "slaveOnly", 1)) {
+ return -1;
+ }
break;
case 'l':
if (get_arg_val_i(c, optarg, &print_level,
@@ -225,6 +225,14 @@ int main(int argc, char *argv[])
sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync");
sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");

+ if (config_get_int(cfg, NULL, "slaveOnly")) {
+ ds->flags |= DDS_SLAVE_ONLY;
+ ds->clockQuality.clockClass = 248;
+ }
+ if (config_get_int(cfg, NULL, "twoStepFlag")) {
+ ds->flags |= DDS_TWO_STEP_FLAG;
+ }
+
if (!config_get_int(cfg, NULL, "gmCapable") &&
ds->flags & DDS_SLAVE_ONLY) {
fprintf(stderr,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:03 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 16 +++-------------
ptp4l.c | 4 ++--
2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/config.c b/config.c
index 87d944f..683eee5 100644
--- a/config.c
+++ b/config.c
@@ -125,6 +125,8 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX),
GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
+ GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
+ GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
GLOB_ITEM_INT("sanity_freq_limit", 200000000, 0, INT_MAX),
GLOB_ITEM_INT("slaveOnly", 0, 0, 1),
GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX),
@@ -396,19 +398,7 @@ static enum parser_result parse_global_setting(const char *option,
if (r != NOT_PARSED)
return r;

- if (!strcmp(option, "priority1")) {
- r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
- if (r != PARSED_OK)
- return r;
- dds->priority1 = uval;
-
- } else if (!strcmp(option, "priority2")) {
- r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
- if (r != PARSED_OK)
- return r;
- dds->priority2 = uval;
-
- } else if (!strcmp(option, "domainNumber")) {
+ if (!strcmp(option, "domainNumber")) {
r = get_ranged_uint(value, &uval, 0, 127);
if (r != PARSED_OK)
return r;
diff --git a/ptp4l.c b/ptp4l.c
index 89a659d..de3af43 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -44,11 +44,9 @@ static struct config cfg_settings = {

.dds = {
.dds = {
- .priority1 = 128,
.clockQuality.clockClass = 248,
.clockQuality.clockAccuracy = 0xfe,
.clockQuality.offsetScaledLogVariance = 0xffff,
- .priority2 = 128,
.domainNumber = 0,
},
.clock_desc = {
@@ -232,6 +230,8 @@ int main(int argc, char *argv[])
if (config_get_int(cfg, NULL, "twoStepFlag")) {
ds->flags |= DDS_TWO_STEP_FLAG;
}
+ ds->priority1 = config_get_int(cfg, NULL, "priority1");
+ ds->priority2 = config_get_int(cfg, NULL, "priority2");

if (!config_get_int(cfg, NULL, "gmCapable") &&
ds->flags & DDS_SLAVE_ONLY) {
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:05 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
ptp4l.c | 2 +-
2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/config.c b/config.c
index 516ce7a..e14156b 100644
--- a/config.c
+++ b/config.c
@@ -95,6 +95,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
PORT_ITEM_INT("boundary_clock_jbod", 0, 0, 1),
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
+ GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
@@ -405,12 +406,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
dds->domainNumber = uval;

- } else if (!strcmp(option, "clockAccuracy")) {
- r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
- if (r != PARSED_OK)
- return r;
- dds->clockQuality.clockAccuracy = uval;
-
} else if (!strcmp(option, "offsetScaledLogVariance")) {
r = get_ranged_uint(value, &uval, 0, UINT16_MAX);
if (r != PARSED_OK)
diff --git a/ptp4l.c b/ptp4l.c
index 8ec52cc..f3df299 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -44,7 +44,6 @@ static struct config cfg_settings = {

.dds = {
.dds = {
- .clockQuality.clockAccuracy = 0xfe,
.clockQuality.offsetScaledLogVariance = 0xffff,
.domainNumber = 0,
},
@@ -223,6 +222,7 @@ int main(int argc, char *argv[])
sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");

ds->clockQuality.clockClass = config_get_int(cfg, NULL, "clockClass");
+ ds->clockQuality.clockAccuracy = config_get_int(cfg, NULL, "clockAccuracy");

if (config_get_int(cfg, NULL, "slaveOnly")) {
ds->flags |= DDS_SLAVE_ONLY;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:04 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
ptp4l.c | 3 ++-
2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/config.c b/config.c
index 683eee5..516ce7a 100644
--- a/config.c
+++ b/config.c
@@ -95,6 +95,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
PORT_ITEM_INT("boundary_clock_jbod", 0, 0, 1),
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
+ GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
@@ -404,12 +405,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
dds->domainNumber = uval;

- } else if (!strcmp(option, "clockClass")) {
- r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
- if (r != PARSED_OK)
- return r;
- dds->clockQuality.clockClass = uval;
-
} else if (!strcmp(option, "clockAccuracy")) {
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
if (r != PARSED_OK)
diff --git a/ptp4l.c b/ptp4l.c
index de3af43..8ec52cc 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -44,7 +44,6 @@ static struct config cfg_settings = {

.dds = {
.dds = {
- .clockQuality.clockClass = 248,
.clockQuality.clockAccuracy = 0xfe,
.clockQuality.offsetScaledLogVariance = 0xffff,
.domainNumber = 0,
@@ -223,6 +222,8 @@ int main(int argc, char *argv[])
sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync");
sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");

+ ds->clockQuality.clockClass = config_get_int(cfg, NULL, "clockClass");
+
if (config_get_int(cfg, NULL, "slaveOnly")) {
ds->flags |= DDS_SLAVE_ONLY;
ds->clockQuality.clockClass = 248;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:06 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 7 +------
ptp4l.c | 3 ++-
2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/config.c b/config.c
index e14156b..afb3879 100644
--- a/config.c
+++ b/config.c
@@ -118,6 +118,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("min_neighbor_prop_delay", -20000000, INT_MIN, -1),
PORT_ITEM_INT("neighborPropDelayThresh", 20000000, 0, INT_MAX),
GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
+ GLOB_ITEM_INT("offsetScaledLogVariance", 0xffff, 0, UINT16_MAX),
PORT_ITEM_INT("path_trace_enabled", 0, 0, 1),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_exponent", 0.4, -DBL_MAX, DBL_MAX),
@@ -406,12 +407,6 @@ static enum parser_result parse_global_setting(const char *option,
return r;
dds->domainNumber = uval;

- } else if (!strcmp(option, "offsetScaledLogVariance")) {
- r = get_ranged_uint(value, &uval, 0, UINT16_MAX);
- if (r != PARSED_OK)
- return r;
- dds->clockQuality.offsetScaledLogVariance = uval;
-
} 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/ptp4l.c b/ptp4l.c
index f3df299..32c022d 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -44,7 +44,6 @@ static struct config cfg_settings = {

.dds = {
.dds = {
- .clockQuality.offsetScaledLogVariance = 0xffff,
.domainNumber = 0,
},
.clock_desc = {
@@ -223,6 +222,8 @@ int main(int argc, char *argv[])

ds->clockQuality.clockClass = config_get_int(cfg, NULL, "clockClass");
ds->clockQuality.clockAccuracy = config_get_int(cfg, NULL, "clockAccuracy");
+ ds->clockQuality.offsetScaledLogVariance =
+ config_get_int(cfg, NULL, "offsetScaledLogVariance");

if (config_get_int(cfg, NULL, "slaveOnly")) {
ds->flags |= DDS_SLAVE_ONLY;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:07 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 12 ++----------
ptp4l.c | 5 ++---
2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/config.c b/config.c
index afb3879..3f4014c 100644
--- a/config.c
+++ b/config.c
@@ -99,6 +99,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
+ GLOB_ITEM_INT("domainNumber", 0, 0, 127),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("fault_badpeernet_interval", 16, INT32_MIN, INT32_MAX),
PORT_ITEM_INT("fault_reset_interval", 4, INT8_MIN, INT8_MAX),
@@ -390,24 +391,15 @@ static enum parser_result parse_global_setting(const char *option,
struct config *cfg)
{
int i, cfg_ignore = cfg->cfg_ignore;
- unsigned int uval;
unsigned char mac[MAC_LEN];
unsigned char oui[OUI_LEN];
-
- struct defaultDS *dds = &cfg->dds.dds;
enum parser_result r;

r = parse_fault_interval(cfg, NULL, option, value);
if (r != NOT_PARSED)
return r;

- if (!strcmp(option, "domainNumber")) {
- r = get_ranged_uint(value, &uval, 0, 127);
- if (r != PARSED_OK)
- return r;
- dds->domainNumber = uval;
-
- } else if (!strcmp(option, "ptp_dst_mac")) {
+ 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]))
return BAD_VALUE;
diff --git a/ptp4l.c b/ptp4l.c
index 32c022d..b448d55 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -43,9 +43,6 @@ static struct config cfg_settings = {
.interfaces = STAILQ_HEAD_INITIALIZER(cfg_settings.interfaces),

.dds = {
- .dds = {
- .domainNumber = 0,
- },
.clock_desc = {
.productDescription = {
.max_symbols = 64,
@@ -225,6 +222,8 @@ int main(int argc, char *argv[])
ds->clockQuality.offsetScaledLogVariance =
config_get_int(cfg, NULL, "offsetScaledLogVariance");

+ ds->domainNumber = config_get_int(cfg, NULL, "domainNumber");
+
if (config_get_int(cfg, NULL, "slaveOnly")) {
ds->flags |= DDS_SLAVE_ONLY;
ds->clockQuality.clockClass = 248;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:09 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 5 ++++-
config.c | 33 +++++++++------------------------
config.h | 3 ---
port.c | 6 ++++--
ptp4l.c | 17 +++++++++--------
5 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/clock.c b/clock.c
index ab048f5..d0298f4 100644
--- a/clock.c
+++ b/clock.c
@@ -819,7 +819,10 @@ struct clock *clock_create(struct config *config, int phc_index,
clock_destroy(c);

snprintf(udsif->name, sizeof(udsif->name), "%s", uds_path);
- udsif->transport = TRANS_UDS;
+ if (config_set_section_int(config, udsif->name,
+ "network_transport", TRANS_UDS)) {
+ return NULL;
+ }
if (config_set_section_int(config, udsif->name, "delay_filter_length", 1)) {
return NULL;
}
diff --git a/config.c b/config.c
index 2e975d5..66d6954 100644
--- a/config.c
+++ b/config.c
@@ -110,6 +110,13 @@ struct config_item {
#define PORT_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 1, _default, min, max)

+static struct config_enum nw_trans_enu[] = {
+ { "L2", TRANS_IEEE_802_3 },
+ { "UDPv4", TRANS_UDP_IPV4 },
+ { "UDPv6", TRANS_UDP_IPV6 },
+ { NULL, 0 },
+};
+
struct config_item config_tab[] = {
PORT_ITEM_INT("announceReceiptTimeout", 3, 2, UINT8_MAX),
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
@@ -138,6 +145,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
PORT_ITEM_INT("min_neighbor_prop_delay", -20000000, INT_MIN, -1),
PORT_ITEM_INT("neighborPropDelayThresh", 20000000, 0, INT_MAX),
+ PORT_ITEM_ENU("network_transport", TRANS_UDP_IPV4, nw_trans_enu),
GLOB_ITEM_INT("ntpshm_segment", 0, INT_MIN, INT_MAX),
GLOB_ITEM_INT("offsetScaledLogVariance", 0xffff, 0, UINT16_MAX),
PORT_ITEM_INT("path_trace_enabled", 0, 0, 1),
@@ -359,17 +367,7 @@ static enum parser_result parse_port_setting(struct config *cfg,
if (r != NOT_PARSED)
return r;

- if (!strcmp(option, "network_transport")) {
- if (!strcasecmp("L2", value))
- iface->transport = TRANS_IEEE_802_3;
- else if (!strcasecmp("UDPv4", value))
- iface->transport = TRANS_UDP_IPV4;
- else if (!strcasecmp("UDPv6", value))
- iface->transport = TRANS_UDP_IPV6;
- else
- return BAD_VALUE;
-
- } else if (!strcmp(option, "delay_mechanism")) {
+ if (!strcmp(option, "delay_mechanism")) {
if (!strcasecmp("Auto", value))
iface->dm = DM_AUTO;
else if (!strcasecmp("E2E", value))
@@ -472,18 +470,6 @@ static enum parser_result parse_global_setting(const char *option,
return BAD_VALUE;
}

- } else if (!strcmp(option, "network_transport")) {
- if (!(cfg_ignore & CFG_IGNORE_TRANSPORT)) {
- if (!strcasecmp("UDPv4", value))
- cfg->transport = TRANS_UDP_IPV4;
- else if (!strcasecmp("UDPv6", value))
- cfg->transport = TRANS_UDP_IPV6;
- else if (!strcasecmp("L2", value))
- cfg->transport = TRANS_IEEE_802_3;
- else
- return BAD_VALUE;
- }
-
} else if (!strcmp(option, "clock_servo")) {
if (!strcasecmp("pi", value))
cfg->clock_servo = CLOCK_SERVO_PI;
@@ -720,7 +706,6 @@ struct interface *config_create_interface(char *name, struct config *cfg)
void config_init_interface(struct interface *iface, struct config *cfg)
{
iface->dm = cfg->dm;
- iface->transport = cfg->transport;
sk_get_ts_info(iface->name, &iface->ts_info);
iface->delay_filter = cfg->dds.delay_filter;
}
diff --git a/config.h b/config.h
index 9100083..3cfc6ac 100644
--- a/config.h
+++ b/config.h
@@ -36,14 +36,12 @@ struct interface {
STAILQ_ENTRY(interface) list;
char name[MAX_IFNAME_SIZE + 1];
enum delay_mechanism dm;
- enum transport_type transport;
struct sk_ts_info ts_info;
enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
};

#define CFG_IGNORE_DM (1 << 0)
-#define CFG_IGNORE_TRANSPORT (1 << 1)
#define CFG_IGNORE_TIMESTAMPING (1 << 2)

struct config {
@@ -58,7 +56,6 @@ struct config {

/* the rest are legacy fields */
enum timestamp_type timestamping;
- enum transport_type transport;
enum delay_mechanism dm;

struct default_ds dds;
diff --git a/port.c b/port.c
index 2299831..706183f 100644
--- a/port.c
+++ b/port.c
@@ -2506,6 +2506,7 @@ struct port *port_open(int phc_index,
{
struct config *cfg = clock_config(clock);
struct port *p = malloc(sizeof(*p));
+ enum transport_type transport;
int i;

if (!p)
@@ -2515,8 +2516,9 @@ struct port *port_open(int phc_index,

p->phc_index = phc_index;
p->jbod = config_get_int(cfg, interface->name, "boundary_clock_jbod");
+ transport = config_get_int(cfg, interface->name, "network_transport");

- if (interface->transport == TRANS_UDS)
+ if (transport == TRANS_UDS)
; /* UDS cannot have a PHC. */
else if (!interface->ts_info.valid)
pr_warning("port %d: get_ts_info not supported", number);
@@ -2541,7 +2543,7 @@ struct port *port_open(int phc_index,
p->rx_timestamp_offset = config_get_int(cfg, p->name, "ingressLatency");
p->tx_timestamp_offset = config_get_int(cfg, p->name, "egressLatency");
p->clock = clock;
- p->trp = transport_create(cfg, interface->transport);
+ p->trp = transport_create(cfg, transport);
if (!p->trp)
goto err_port;
p->timestamping = timestamping;
diff --git a/ptp4l.c b/ptp4l.c
index b448d55..52fff25 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -63,7 +63,6 @@ static struct config cfg_settings = {

.timestamping = TS_HARDWARE,
.dm = DM_E2E,
- .transport = TRANS_UDP_IPV4,
.clock_servo = CLOCK_SERVO_PI,

.ptp_dst_mac = ptp_dst_mac,
@@ -112,7 +111,6 @@ int main(int argc, char *argv[])
struct interface *iface;
int *cfg_ignore = &cfg_settings.cfg_ignore;
enum delay_mechanism *dm = &cfg_settings.dm;
- enum transport_type *transport = &cfg_settings.transport;
enum timestamp_type *timestamping = &cfg_settings.timestamping;
struct clock *clock;
struct config *cfg = &cfg_settings;
@@ -144,16 +142,19 @@ int main(int argc, char *argv[])
*cfg_ignore |= CFG_IGNORE_DM;
break;
case '2':
- *transport = TRANS_IEEE_802_3;
- *cfg_ignore |= CFG_IGNORE_TRANSPORT;
+ if (config_set_int(cfg, "network_transport",
+ TRANS_IEEE_802_3))
+ return -1;
break;
case '4':
- *transport = TRANS_UDP_IPV4;
- *cfg_ignore |= CFG_IGNORE_TRANSPORT;
+ if (config_set_int(cfg, "network_transport",
+ TRANS_UDP_IPV4))
+ return -1;
break;
case '6':
- *transport = TRANS_UDP_IPV6;
- *cfg_ignore |= CFG_IGNORE_TRANSPORT;
+ if (config_set_int(cfg, "network_transport",
+ TRANS_UDP_IPV6))
+ return -1;
break;
case 'H':
*timestamping = TS_HARDWARE;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:10 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 33 +++++++++------------------------
config.h | 4 ----
port.c | 2 +-
ptp4l.c | 14 ++++++--------
4 files changed, 16 insertions(+), 37 deletions(-)

diff --git a/config.c b/config.c
index 66d6954..3fce7d2 100644
--- a/config.c
+++ b/config.c
@@ -110,6 +110,13 @@ struct config_item {
#define PORT_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 1, _default, min, max)

+static struct config_enum delay_mech_enu[] = {
+ { "Auto", DM_AUTO },
+ { "E2E", DM_E2E },
+ { "P2P", DM_P2P },
+ { NULL, 0 },
+};
+
static struct config_enum nw_trans_enu[] = {
{ "L2", TRANS_IEEE_802_3 },
{ "UDPv4", TRANS_UDP_IPV4 },
@@ -126,6 +133,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
+ PORT_ITEM_ENU("delay_mechanism", DM_E2E, delay_mech_enu),
GLOB_ITEM_INT("domainNumber", 0, 0, 127),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("fault_badpeernet_interval", 16, INT32_MIN, INT32_MAX),
@@ -367,17 +375,7 @@ static enum parser_result parse_port_setting(struct config *cfg,
if (r != NOT_PARSED)
return r;

- if (!strcmp(option, "delay_mechanism")) {
- if (!strcasecmp("Auto", value))
- iface->dm = DM_AUTO;
- else if (!strcasecmp("E2E", value))
- iface->dm = DM_E2E;
- else if (!strcasecmp("P2P", value))
- iface->dm = DM_P2P;
- else
- return BAD_VALUE;
-
- } else if (!strcmp(option, "tsproc_mode")) {
+ if (!strcmp(option, "tsproc_mode")) {
if (!strcasecmp("filter", value))
iface->tsproc_mode = TSPROC_FILTER;
else if (!strcasecmp("raw", value))
@@ -458,18 +456,6 @@ static enum parser_result parse_global_setting(const char *option,
return BAD_VALUE;
}

- } else if (!strcmp(option, "delay_mechanism")) {
- if (!(cfg_ignore & CFG_IGNORE_DM)) {
- if (0 == strcasecmp("E2E", value))
- cfg->dm = DM_E2E;
- else if (0 == strcasecmp("P2P", value))
- cfg->dm = DM_P2P;
- else if (0 == strcasecmp("Auto", value))
- cfg->dm = DM_AUTO;
- else
- return BAD_VALUE;
- }
-
} else if (!strcmp(option, "clock_servo")) {
if (!strcasecmp("pi", value))
cfg->clock_servo = CLOCK_SERVO_PI;
@@ -705,7 +691,6 @@ struct interface *config_create_interface(char *name, struct config *cfg)

void config_init_interface(struct interface *iface, struct config *cfg)
{
- iface->dm = cfg->dm;
sk_get_ts_info(iface->name, &iface->ts_info);
iface->delay_filter = cfg->dds.delay_filter;
}
diff --git a/config.h b/config.h
index 3cfc6ac..e1c24e8 100644
--- a/config.h
+++ b/config.h
@@ -35,13 +35,11 @@
struct interface {
STAILQ_ENTRY(interface) list;
char name[MAX_IFNAME_SIZE + 1];
- enum delay_mechanism dm;
struct sk_ts_info ts_info;
enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
};

-#define CFG_IGNORE_DM (1 << 0)
#define CFG_IGNORE_TIMESTAMPING (1 << 2)

struct config {
@@ -56,8 +54,6 @@ struct config {

/* the rest are legacy fields */
enum timestamp_type timestamping;
- enum delay_mechanism dm;
-
struct default_ds dds;
enum servo_type clock_servo;

diff --git a/port.c b/port.c
index 706183f..8d48cf8 100644
--- a/port.c
+++ b/port.c
@@ -2550,7 +2550,7 @@ struct port *port_open(int phc_index,
p->portIdentity.clockIdentity = clock_identity(clock);
p->portIdentity.portNumber = number;
p->state = PS_INITIALIZING;
- p->delayMechanism = interface->dm;
+ p->delayMechanism = config_get_int(cfg, p->name, "delay_mechanism");
p->versionNumber = PTP_VERSION;

/* Set fault timeouts to a default value */
diff --git a/ptp4l.c b/ptp4l.c
index 52fff25..cd81944 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -62,7 +62,6 @@ static struct config cfg_settings = {
},

.timestamping = TS_HARDWARE,
- .dm = DM_E2E,
.clock_servo = CLOCK_SERVO_PI,

.ptp_dst_mac = ptp_dst_mac,
@@ -110,7 +109,6 @@ int main(int argc, char *argv[])
int c;
struct interface *iface;
int *cfg_ignore = &cfg_settings.cfg_ignore;
- enum delay_mechanism *dm = &cfg_settings.dm;
enum timestamp_type *timestamping = &cfg_settings.timestamping;
struct clock *clock;
struct config *cfg = &cfg_settings;
@@ -130,16 +128,16 @@ int main(int argc, char *argv[])
while (EOF != (c = getopt(argc, argv, "AEP246HSLf:i:p:sl:mqvh"))) {
switch (c) {
case 'A':
- *dm = DM_AUTO;
- *cfg_ignore |= CFG_IGNORE_DM;
+ if (config_set_int(cfg, "delay_mechanism", DM_AUTO))
+ return -1;
break;
case 'E':
- *dm = DM_E2E;
- *cfg_ignore |= CFG_IGNORE_DM;
+ if (config_set_int(cfg, "delay_mechanism", DM_E2E))
+ return -1;
break;
case 'P':
- *dm = DM_P2P;
- *cfg_ignore |= CFG_IGNORE_DM;
+ if (config_set_int(cfg, "delay_mechanism", DM_P2P))
+ return -1;
break;
case '2':
if (config_set_int(cfg, "network_transport",
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:11 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 3 ++-
config.c | 35 ++++++++++-------------------------
config.h | 1 -
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 1 -
6 files changed, 13 insertions(+), 30 deletions(-)

diff --git a/clock.c b/clock.c
index d0298f4..a923915 100644
--- a/clock.c
+++ b/clock.c
@@ -879,7 +879,8 @@ struct clock *clock_create(struct config *config, int phc_index,
}
c->servo_state = SERVO_UNLOCKED;
c->servo_type = servo;
- c->tsproc = tsproc_create(dds->tsproc_mode, dds->delay_filter,
+ c->tsproc = tsproc_create(config_get_int(config, NULL, "tsproc_mode"),
+ dds->delay_filter,
config_get_int(config, NULL, "delay_filter_length"));
if (!c->tsproc) {
pr_err("Failed to create time stamp processor");
diff --git a/config.c b/config.c
index 3fce7d2..4701e92 100644
--- a/config.c
+++ b/config.c
@@ -124,6 +124,14 @@ static struct config_enum nw_trans_enu[] = {
{ NULL, 0 },
};

+static struct config_enum tsproc_enu[] = {
+ { "filter", TSPROC_FILTER },
+ { "raw", TSPROC_RAW },
+ { "filter_weight", TSPROC_FILTER_WEIGHT },
+ { "raw_weight", TSPROC_RAW_WEIGHT },
+ { NULL, 0 },
+};
+
struct config_item config_tab[] = {
PORT_ITEM_INT("announceReceiptTimeout", 3, 2, UINT8_MAX),
GLOB_ITEM_INT("assume_two_step", 0, 0, 1),
@@ -174,6 +182,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
GLOB_ITEM_INT("timeSource", INTERNAL_OSCILLATOR, 0x10, 0xfe),
PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F),
+ PORT_ITEM_ENU("tsproc_mode", TSPROC_FILTER, tsproc_enu),
GLOB_ITEM_INT("twoStepFlag", 1, 0, 1),
GLOB_ITEM_INT("tx_timestamp_timeout", 1, 1, INT_MAX),
PORT_ITEM_INT("udp_ttl", 1, 1, 255),
@@ -375,19 +384,7 @@ static enum parser_result parse_port_setting(struct config *cfg,
if (r != NOT_PARSED)
return r;

- if (!strcmp(option, "tsproc_mode")) {
- if (!strcasecmp("filter", value))
- iface->tsproc_mode = TSPROC_FILTER;
- else if (!strcasecmp("raw", value))
- iface->tsproc_mode = TSPROC_RAW;
- else if (!strcasecmp("filter_weight", value))
- iface->tsproc_mode = TSPROC_FILTER_WEIGHT;
- else if (!strcasecmp("raw_weight", value))
- iface->tsproc_mode = TSPROC_RAW_WEIGHT;
- else
- return BAD_VALUE;
-
- } else if (!strcmp(option, "delay_filter")) {
+ if (!strcmp(option, "delay_filter")) {
if (!strcasecmp("moving_average", value))
iface->delay_filter = FILTER_MOVING_AVERAGE;
else if (!strcasecmp("moving_median", value))
@@ -491,18 +488,6 @@ static enum parser_result parse_global_setting(const char *option,
for (i = 0; i < OUI_LEN; i++)
cfg->dds.clock_desc.manufacturerIdentity[i] = oui[i];

- } else if (!strcmp(option, "tsproc_mode")) {
- if (!strcasecmp("filter", value))
- cfg->dds.tsproc_mode = TSPROC_FILTER;
- else if (!strcasecmp("raw", value))
- cfg->dds.tsproc_mode = TSPROC_RAW;
- else if (!strcasecmp("filter_weight", value))
- cfg->dds.tsproc_mode = TSPROC_FILTER_WEIGHT;
- else if (!strcasecmp("raw_weight", value))
- cfg->dds.tsproc_mode = TSPROC_RAW_WEIGHT;
- else
- return BAD_VALUE;
-
} else if (!strcmp(option, "delay_filter")) {
if (!strcasecmp("moving_average", value))
cfg->dds.delay_filter = FILTER_MOVING_AVERAGE;
diff --git a/config.h b/config.h
index e1c24e8..2e60706 100644
--- a/config.h
+++ b/config.h
@@ -36,7 +36,6 @@ struct interface {
STAILQ_ENTRY(interface) list;
char name[MAX_IFNAME_SIZE + 1];
struct sk_ts_info ts_info;
- enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
};

diff --git a/ds.h b/ds.h
index a431616..3a175a9 100644
--- a/ds.h
+++ b/ds.h
@@ -53,7 +53,6 @@ struct clock_description {
struct default_ds {
struct defaultDS dds;
struct clock_description clock_desc;
- enum tsproc_mode tsproc_mode;
enum filter_type delay_filter;
};

diff --git a/port.c b/port.c
index 8d48cf8..624a070 100644
--- a/port.c
+++ b/port.c
@@ -2565,7 +2565,7 @@ struct port *port_open(int phc_index,
p->flt_interval_pertype[FT_UNSPECIFIED].val =
config_get_int(cfg, p->name, "fault_reset_interval");

- p->tsproc = tsproc_create(interface->tsproc_mode,
+ p->tsproc = tsproc_create(config_get_int(cfg, p->name, "tsproc_mode"),
interface->delay_filter,
config_get_int(cfg, p->name, "delay_filter_length"));
if (!p->tsproc) {
diff --git a/ptp4l.c b/ptp4l.c
index cd81944..2e954d6 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -57,7 +57,6 @@ static struct config cfg_settings = {
.userDescription = { .max_symbols = 128 },
.manufacturerIdentity = { 0, 0, 0 },
},
- .tsproc_mode = TSPROC_FILTER,
.delay_filter = FILTER_MOVING_MEDIAN,
},
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:08 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/config.c b/config.c
index 3f4014c..2e975d5 100644
--- a/config.c
+++ b/config.c
@@ -37,6 +37,12 @@ enum config_section {
enum config_type {
CFG_TYPE_INT,
CFG_TYPE_DOUBLE,
+ CFG_TYPE_ENUM,
+};
+
+struct config_enum {
+ const char *label;
+ int value;
};

typedef union {
@@ -53,6 +59,7 @@ typedef union {
struct config_item {
char label[CONFIG_LABEL_SIZE];
enum config_type type;
+ struct config_enum *tab;
unsigned int flags;
any_t val;
any_t min;
@@ -69,6 +76,13 @@ struct config_item {
.min.d = _min, \
.max.d = _max, \
}
+#define CONFIG_ITEM_ENUM(_label, _port, _default, _table) { \
+ .label = _label, \
+ .type = CFG_TYPE_ENUM, \
+ .flags = _port ? CFG_ITEM_PORT : 0, \
+ .tab = _table, \
+ .val.i = _default, \
+}
#define CONFIG_ITEM_INT(_label, _port, _default, _min, _max) { \
.label = _label, \
.type = CFG_TYPE_INT, \
@@ -81,12 +95,18 @@ struct config_item {
#define GLOB_ITEM_DBL(label, _default, min, max) \
CONFIG_ITEM_DBL(label, 0, _default, min, max)

+#define GLOB_ITEM_ENU(label, _default, table) \
+ CONFIG_ITEM_ENUM(label, 0, _default, table)
+
#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_ENU(label, _default, table) \
+ CONFIG_ITEM_ENUM(label, 1, _default, table)
+
#define PORT_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 1, _default, min, max)

@@ -233,8 +253,9 @@ static enum parser_result parse_item(struct config *cfg,
const char *option,
const char *value)
{
- struct config_item *cgi, *dst;
enum parser_result r = BAD_VALUE;
+ struct config_item *cgi, *dst;
+ struct config_enum *cte;
double df;
int val;

@@ -251,6 +272,14 @@ static enum parser_result parse_item(struct config *cfg,
case CFG_TYPE_DOUBLE:
r = get_ranged_double(value, &df, cgi->min.d, cgi->max.d);
break;
+ case CFG_TYPE_ENUM:
+ for (cte = cgi->tab; cte->label; cte++) {
+ if (!strcasecmp(cte->label, value)) {
+ val = cte->value;
+ r = PARSED_OK;
+ break;
+ }
+ }
}
if (r != PARSED_OK) {
return r;
@@ -278,6 +307,7 @@ static enum parser_result parse_item(struct config *cfg,

switch (dst->type) {
case CFG_TYPE_INT:
+ case CFG_TYPE_ENUM:
dst->val.i = val;
break;
case CFG_TYPE_DOUBLE:
@@ -770,6 +800,7 @@ int config_get_int(struct config *cfg, const char *section, const char *option)
pr_err("bug: config option %s type mismatch!", option);
exit(-1);
case CFG_TYPE_INT:
+ case CFG_TYPE_ENUM:
break;
}
pr_debug("config item %s.%s is %d", section, option, ci->val.i);
@@ -805,6 +836,7 @@ int config_set_section_int(struct config *cfg, const char *section,
pr_err("bug: config option %s type mismatch!", option);
return -1;
case CFG_TYPE_INT:
+ case CFG_TYPE_ENUM:
break;
}
if (!section) {
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:12 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 2 +-
config.c | 29 ++++++++---------------------
config.h | 1 -
ds.h | 1 -
port.c | 2 +-
ptp4l.c | 1 -
6 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/clock.c b/clock.c
index a923915..91ed78d 100644
--- a/clock.c
+++ b/clock.c
@@ -880,7 +880,7 @@ struct clock *clock_create(struct config *config, int phc_index,
c->servo_state = SERVO_UNLOCKED;
c->servo_type = servo;
c->tsproc = tsproc_create(config_get_int(config, NULL, "tsproc_mode"),
- dds->delay_filter,
+ config_get_int(config, NULL, "delay_filter"),
config_get_int(config, NULL, "delay_filter_length"));
if (!c->tsproc) {
pr_err("Failed to create time stamp processor");
diff --git a/config.c b/config.c
index 4701e92..3b6fdc8 100644
--- a/config.c
+++ b/config.c
@@ -110,6 +110,12 @@ struct config_item {
#define PORT_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 1, _default, min, max)

+static struct config_enum delay_filter_enu[] = {
+ { "moving_average", FILTER_MOVING_AVERAGE },
+ { "moving_median", FILTER_MOVING_MEDIAN },
+ { NULL, 0 },
+};
+
static struct config_enum delay_mech_enu[] = {
{ "Auto", DM_AUTO },
{ "E2E", DM_E2E },
@@ -140,6 +146,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
+ PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
PORT_ITEM_ENU("delay_mechanism", DM_E2E, delay_mech_enu),
GLOB_ITEM_INT("domainNumber", 0, 0, 127),
@@ -384,18 +391,7 @@ static enum parser_result parse_port_setting(struct config *cfg,
if (r != NOT_PARSED)
return r;

- if (!strcmp(option, "delay_filter")) {
- if (!strcasecmp("moving_average", value))
- iface->delay_filter = FILTER_MOVING_AVERAGE;
- else if (!strcasecmp("moving_median", value))
- iface->delay_filter = FILTER_MOVING_MEDIAN;
- else
- return BAD_VALUE;
-
- } else
- return parse_item(cfg, iface->name, option, value);
-
- return PARSED_OK;
+ return parse_item(cfg, iface->name, option, value);
}

static int count_char(const char *str, char c)
@@ -488,14 +484,6 @@ static enum parser_result parse_global_setting(const char *option,
for (i = 0; i < OUI_LEN; i++)
cfg->dds.clock_desc.manufacturerIdentity[i] = oui[i];

- } 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
return parse_item(cfg, NULL, option, value);

@@ -677,7 +665,6 @@ struct interface *config_create_interface(char *name, struct config *cfg)
void config_init_interface(struct interface *iface, struct config *cfg)
{
sk_get_ts_info(iface->name, &iface->ts_info);
- iface->delay_filter = cfg->dds.delay_filter;
}

int config_init(struct config *cfg)
diff --git a/config.h b/config.h
index 2e60706..46767d8 100644
--- a/config.h
+++ b/config.h
@@ -36,7 +36,6 @@ struct interface {
STAILQ_ENTRY(interface) list;
char name[MAX_IFNAME_SIZE + 1];
struct sk_ts_info ts_info;
- enum filter_type delay_filter;
};

#define CFG_IGNORE_TIMESTAMPING (1 << 2)
diff --git a/ds.h b/ds.h
index 3a175a9..06286a8 100644
--- a/ds.h
+++ b/ds.h
@@ -53,7 +53,6 @@ struct clock_description {
struct default_ds {
struct defaultDS dds;
struct clock_description clock_desc;
- enum filter_type delay_filter;
};

struct dataset {
diff --git a/port.c b/port.c
index 624a070..3984b78 100644
--- a/port.c
+++ b/port.c
@@ -2566,7 +2566,7 @@ struct port *port_open(int phc_index,
config_get_int(cfg, p->name, "fault_reset_interval");

p->tsproc = tsproc_create(config_get_int(cfg, p->name, "tsproc_mode"),
- interface->delay_filter,
+ config_get_int(cfg, p->name, "delay_filter"),
config_get_int(cfg, p->name, "delay_filter_length"));
if (!p->tsproc) {
pr_err("Failed to create time stamp processor");
diff --git a/ptp4l.c b/ptp4l.c
index 2e954d6..3888e71 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -57,7 +57,6 @@ static struct config cfg_settings = {
.userDescription = { .max_symbols = 128 },
.manufacturerIdentity = { 0, 0, 0 },
},
- .delay_filter = FILTER_MOVING_MEDIAN,
},

.timestamping = TS_HARDWARE,
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:13 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 3 ++-
clock.h | 2 --
config.c | 22 +++++++++-------------
config.h | 6 ------
ptp4l.c | 29 +++++++++++++----------------
5 files changed, 24 insertions(+), 38 deletions(-)

diff --git a/clock.c b/clock.c
index 91ed78d..112d0a2 100644
--- a/clock.c
+++ b/clock.c
@@ -800,9 +800,10 @@ static void clock_remove_port(struct clock *c, struct port *p)

struct clock *clock_create(struct config *config, int phc_index,
struct interfaces_head *ifaces,
- enum timestamp_type timestamping,
struct default_ds *dds, enum servo_type servo)
{
+ enum timestamp_type timestamping =
+ config_get_int(config, NULL, "time_stamping");
int fadj = 0, max_adj = 0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
struct clock *c = &the_clock;
struct port *p;
diff --git a/clock.h b/clock.h
index d7377fe..ce83996 100644
--- a/clock.h
+++ b/clock.h
@@ -72,14 +72,12 @@ struct config *clock_config(struct clock *c);
* @param phc_index PTP hardware clock device to use.
* Pass -1 to select CLOCK_REALTIME.
* @param ifaces A queue of network interfaces.
- * @param timestamping The timestamping mode for this clock.
* @param dds A pointer to a default data set for the clock.
* @param servo The servo that this clock will use.
* @return A pointer to the single global clock instance.
*/
struct clock *clock_create(struct config *config, int phc_index,
struct interfaces_head *ifaces,
- enum timestamp_type timestamping,
struct default_ds *dds, enum servo_type servo);

/**
diff --git a/config.c b/config.c
index 3b6fdc8..673f218 100644
--- a/config.c
+++ b/config.c
@@ -130,6 +130,13 @@ static struct config_enum nw_trans_enu[] = {
{ NULL, 0 },
};

+static struct config_enum timestamping_enu[] = {
+ { "hardware", TS_HARDWARE },
+ { "software", TS_SOFTWARE },
+ { "legacy", TS_LEGACY_HW },
+ { NULL, 0 },
+};
+
static struct config_enum tsproc_enu[] = {
{ "filter", TSPROC_FILTER },
{ "raw", TSPROC_RAW },
@@ -188,6 +195,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("summary_interval", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
GLOB_ITEM_INT("timeSource", INTERNAL_OSCILLATOR, 0x10, 0xfe),
+ GLOB_ITEM_ENU("time_stamping", TS_HARDWARE, timestamping_enu),
PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F),
PORT_ITEM_ENU("tsproc_mode", TSPROC_FILTER, tsproc_enu),
GLOB_ITEM_INT("twoStepFlag", 1, 0, 1),
@@ -409,7 +417,7 @@ static enum parser_result parse_global_setting(const char *option,
const char *value,
struct config *cfg)
{
- int i, cfg_ignore = cfg->cfg_ignore;
+ int i;
unsigned char mac[MAC_LEN];
unsigned char oui[OUI_LEN];
enum parser_result r;
@@ -437,18 +445,6 @@ static enum parser_result parse_global_setting(const char *option,
return OUT_OF_RANGE;
strncpy(cfg->uds_address, value, MAX_IFNAME_SIZE);

- } else if (!strcmp(option, "time_stamping")) {
- if (!(cfg_ignore & CFG_IGNORE_TIMESTAMPING)) {
- if (0 == strcasecmp("hardware", value))
- cfg->timestamping = TS_HARDWARE;
- else if (0 == strcasecmp("software", value))
- cfg->timestamping = TS_SOFTWARE;
- else if (0 == strcasecmp("legacy", value))
- cfg->timestamping = TS_LEGACY_HW;
- else
- return BAD_VALUE;
- }
-
} else if (!strcmp(option, "clock_servo")) {
if (!strcasecmp("pi", value))
cfg->clock_servo = CLOCK_SERVO_PI;
diff --git a/config.h b/config.h
index 46767d8..948f792 100644
--- a/config.h
+++ b/config.h
@@ -38,12 +38,7 @@ struct interface {
struct sk_ts_info ts_info;
};

-#define CFG_IGNORE_TIMESTAMPING (1 << 2)
-
struct config {
- /* configuration override */
- int cfg_ignore;
-
/* configured interfaces */
STAILQ_HEAD(interfaces_head, interface) interfaces;

@@ -51,7 +46,6 @@ struct config {
struct hash *htab;

/* the rest are legacy fields */
- enum timestamp_type timestamping;
struct default_ds dds;
enum servo_type clock_servo;

diff --git a/ptp4l.c b/ptp4l.c
index 3888e71..0acc63d 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -59,14 +59,11 @@ static struct config cfg_settings = {
},
},

- .timestamping = TS_HARDWARE,
.clock_servo = CLOCK_SERVO_PI,

.ptp_dst_mac = ptp_dst_mac,
.p2p_dst_mac = p2p_dst_mac,
.uds_address = uds_path,
-
- .cfg_ignore = 0,
};

static void usage(char *progname)
@@ -106,8 +103,6 @@ int main(int argc, char *argv[])
char *config = NULL, *req_phc = NULL, *progname;
int c;
struct interface *iface;
- int *cfg_ignore = &cfg_settings.cfg_ignore;
- enum timestamp_type *timestamping = &cfg_settings.timestamping;
struct clock *clock;
struct config *cfg = &cfg_settings;
struct defaultDS *ds = &cfg_settings.dds.dds;
@@ -153,16 +148,16 @@ int main(int argc, char *argv[])
return -1;
break;
case 'H':
- *timestamping = TS_HARDWARE;
- *cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
+ if (config_set_int(cfg, "time_stamping", TS_HARDWARE))
+ return -1;
break;
case 'S':
- *timestamping = TS_SOFTWARE;
- *cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
+ if (config_set_int(cfg, "time_stamping", TS_SOFTWARE))
+ return -1;
break;
case 'L':
- *timestamping = TS_LEGACY_HW;
- *cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
+ if (config_set_int(cfg, "time_stamping", TS_LEGACY_HW))
+ return -1;
break;
case 'f':
config = optarg;
@@ -258,21 +253,22 @@ int main(int argc, char *argv[])
}

if (!(ds->flags & DDS_TWO_STEP_FLAG)) {
- switch (*timestamping) {
+ switch (config_get_int(cfg, NULL, "time_stamping")) {
case TS_SOFTWARE:
case TS_LEGACY_HW:
fprintf(stderr, "one step is only possible "
"with hardware time stamping\n");
return -1;
case TS_HARDWARE:
- *timestamping = TS_ONESTEP;
+ if (config_set_int(cfg, "time_stamping", TS_ONESTEP))
+ return -1;
break;
case TS_ONESTEP:
break;
}
}

- switch (*timestamping) {
+ switch (config_get_int(cfg, NULL, "time_stamping")) {
case TS_SOFTWARE:
required_modes |= SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_RX_SOFTWARE |
@@ -308,7 +304,8 @@ int main(int argc, char *argv[])
iface = STAILQ_FIRST(&cfg_settings.interfaces);
if (config_get_int(cfg, NULL, "free_running")) {
phc_index = -1;
- } else if (*timestamping == TS_SOFTWARE || *timestamping == TS_LEGACY_HW) {
+ } else if (config_get_int(cfg, NULL, "time_stamping") == TS_SOFTWARE ||
+ config_get_int(cfg, NULL, "time_stamping") == TS_LEGACY_HW) {
phc_index = -1;
} else if (req_phc) {
if (1 != sscanf(req_phc, "/dev/ptp%d", &phc_index)) {
@@ -335,7 +332,7 @@ int main(int argc, char *argv[])

clock = clock_create(&cfg_settings,
phc_index, &cfg_settings.interfaces,
- *timestamping, &cfg_settings.dds,
+ &cfg_settings.dds,
cfg_settings.clock_servo);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:14 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 3 ++-
clock.h | 3 +--
config.c | 21 +++++++++------------
config.h | 2 --
ptp4l.c | 7 ++-----
5 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/clock.c b/clock.c
index 112d0a2..320a84c 100644
--- a/clock.c
+++ b/clock.c
@@ -800,11 +800,12 @@ static void clock_remove_port(struct clock *c, struct port *p)

struct clock *clock_create(struct config *config, int phc_index,
struct interfaces_head *ifaces,
- struct default_ds *dds, enum servo_type servo)
+ struct default_ds *dds)
{
enum timestamp_type timestamping =
config_get_int(config, NULL, "time_stamping");
int fadj = 0, max_adj = 0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
+ enum servo_type servo = config_get_int(config, NULL, "clock_servo");
struct clock *c = &the_clock;
struct port *p;
char phc[32];
diff --git a/clock.h b/clock.h
index ce83996..9a1151f 100644
--- a/clock.h
+++ b/clock.h
@@ -73,12 +73,11 @@ struct config *clock_config(struct clock *c);
* Pass -1 to select CLOCK_REALTIME.
* @param ifaces A queue of network interfaces.
* @param dds A pointer to a default data set for the clock.
- * @param servo The servo that this clock will use.
* @return A pointer to the single global clock instance.
*/
struct clock *clock_create(struct config *config, int phc_index,
struct interfaces_head *ifaces,
- struct default_ds *dds, enum servo_type servo);
+ struct default_ds *dds);

/**
* Obtains a clock's default data set.
diff --git a/config.c b/config.c
index 673f218..3f92daf 100644
--- a/config.c
+++ b/config.c
@@ -110,6 +110,14 @@ struct config_item {
#define PORT_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 1, _default, min, max)

+static struct config_enum clock_servo_enu[] = {
+ { "pi", CLOCK_SERVO_PI },
+ { "linreg", CLOCK_SERVO_LINREG },
+ { "ntpshm", CLOCK_SERVO_NTPSHM },
+ { "nullf", CLOCK_SERVO_NULLF },
+ { NULL, 0 },
+};
+
static struct config_enum delay_filter_enu[] = {
{ "moving_average", FILTER_MOVING_AVERAGE },
{ "moving_median", FILTER_MOVING_MEDIAN },
@@ -152,6 +160,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
+ GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
@@ -445,18 +454,6 @@ static enum parser_result parse_global_setting(const char *option,
return OUT_OF_RANGE;
strncpy(cfg->uds_address, value, MAX_IFNAME_SIZE);

- } else if (!strcmp(option, "clock_servo")) {
- if (!strcasecmp("pi", value))
- cfg->clock_servo = CLOCK_SERVO_PI;
- else if (!strcasecmp("linreg", value))
- cfg->clock_servo = CLOCK_SERVO_LINREG;
- else if (!strcasecmp("ntpshm", value))
- cfg->clock_servo = CLOCK_SERVO_NTPSHM;
- else if (!strcasecmp("nullf", value))
- cfg->clock_servo = CLOCK_SERVO_NULLF;
- else
- return BAD_VALUE;
-
} else if (!strcmp(option, "productDescription")) {
if (count_char(value, ';') != 2)
return BAD_VALUE;
diff --git a/config.h b/config.h
index 948f792..c4bf875 100644
--- a/config.h
+++ b/config.h
@@ -47,8 +47,6 @@ struct config {

/* the rest are legacy fields */
struct default_ds dds;
- enum servo_type clock_servo;
-
unsigned char *ptp_dst_mac;
unsigned char *p2p_dst_mac;
char *uds_address;
diff --git a/ptp4l.c b/ptp4l.c
index 0acc63d..8ca49c0 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -59,8 +59,6 @@ static struct config cfg_settings = {
},
},

- .clock_servo = CLOCK_SERVO_PI,
-
.ptp_dst_mac = ptp_dst_mac,
.p2p_dst_mac = p2p_dst_mac,
.uds_address = uds_path,
@@ -236,7 +234,7 @@ int main(int argc, char *argv[])
ds->flags & DDS_SLAVE_ONLY) {
ds->clockQuality.clockClass = 255;
}
- if (cfg_settings.clock_servo == CLOCK_SERVO_NTPSHM) {
+ if (config_get_int(cfg, NULL, "clock_servo") == CLOCK_SERVO_NTPSHM) {
config_set_int(cfg, "kernel_leap", 0);
config_set_int(cfg, "sanity_freq_limit", 0);
}
@@ -332,8 +330,7 @@ int main(int argc, char *argv[])

clock = clock_create(&cfg_settings,
phc_index, &cfg_settings.interfaces,
- &cfg_settings.dds,
- cfg_settings.clock_servo);
+ &cfg_settings.dds);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");
return -1;
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-20 18:15:15 UTC
Permalink
Now we have debug messages in the configuration code. Therefore set up
the print levels immediately after parsing the command line and the file,
so that those messages have a chance to be seen.

Signed-off-by: Richard Cochran <***@gmail.com>
---
ptp4l.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/ptp4l.c b/ptp4l.c
index 8ca49c0..cc94f66 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -203,6 +203,11 @@ int main(int argc, char *argv[])
return c;
}

+ print_set_progname(progname);
+ print_set_verbose(config_get_int(cfg, NULL, "verbose"));
+ print_set_syslog(config_get_int(cfg, NULL, "use_syslog"));
+ print_set_level(config_get_int(cfg, NULL, "logging_level"));
+
assume_two_step = config_get_int(cfg, NULL, "assume_two_step");
sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync");
sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");
@@ -239,11 +244,6 @@ int main(int argc, char *argv[])
config_set_int(cfg, "sanity_freq_limit", 0);
}

- print_set_progname(progname);
- print_set_verbose(config_get_int(cfg, NULL, "verbose"));
- print_set_syslog(config_get_int(cfg, NULL, "use_syslog"));
- print_set_level(config_get_int(cfg, NULL, "logging_level"));
-
if (STAILQ_EMPTY(&cfg_settings.interfaces)) {
fprintf(stderr, "no interface specified\n");
usage(progname);
--
2.1.4


------------------------------------------------------------------------------
Keller, Jacob E
2015-08-20 22:32:35 UTC
Permalink
Hi Richard,
Post by Richard Cochran
"pi_integral_exponent"
"pi_integral_norm_max"
"pi_integral_scale"
"pi_proportional_exponent"
"pi_proportional_norm_max"
Besides my one comment on the BIST and the stopping of the program if
we try to read a value that doesn't exist, I think v4 looks excellent.
I think we may already document that behavior, but it would be worth
checking if we do or not.

Thanks!

Regards,
Jake
------------------------------------------------------------------------------
Loading...