Discussion:
[Linuxptp-devel] [PATCH RFC v4 00/83] New configuration implementation
Richard Cochran
2015-08-23 19:57:02 UTC
Permalink
Changes in V5:
- Add a string type
- Convert every last option
- Lightly refactor the pasring code

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

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-v5

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.
Patches 71 and 76 add string parsing utilities.
Patches 81 and 82 refactor config.c a bit.
Patch 83 finally changes config_init() into config_create().

All the *other* patches convert individual options.

Review and comments are most welcome.

Thanks,
Richard


Richard Cochran (83):
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.
config: introduce a string type.
util: add a helper function to scan a MAC address.
config: convert 'ptp_dst_mac', letting it be a per-port option.
config: convert 'p2p_dst_mac', letting it be a per-port option.
config: convert 'uds_address' to the new scheme.
util: provide the 'count_char' helper function.
config: convert 'productDescription' to the new scheme.
config: convert 'revisionData' to the new scheme.
config: convert 'userDescription' to the new scheme.
config: convert 'manufacturerIdentity' to the new scheme.
config: remove the last remaining legacy item.
config: save a block from falling off the RHS of the page.
config: refactor the parsing code.
config: introduce a proper creation method.

clock.c | 55 ++-
clock.h | 16 +-
config.c | 1168 +++++++++++++++++++++++++--------------------------
config.h | 81 ++--
ds.h | 31 --
ether.h | 2 -
hash.c | 113 +++++
hash.h | 59 +++
makefile | 12 +-
ntpshm.c | 9 +-
ntpshm.h | 7 +-
phc2sys.c | 90 ++--
pi.c | 73 ++--
pi.h | 58 +--
pmc.c | 21 +-
pmc_common.c | 9 +-
pmc_common.h | 8 +-
port.c | 105 +++--
ptp4l.8 | 16 +-
ptp4l.c | 306 ++++++--------
raw.c | 25 +-
raw.h | 10 -
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 -
uds.c | 3 +-
uds.h | 5 -
util.c | 24 ++
util.h | 18 +
34 files changed, 1269 insertions(+), 1142 deletions(-)
create mode 100644 hash.c
create mode 100644 hash.h
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-23 19:57:04 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-23 19:57:03 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-23 19:57:05 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-23 19:57:06 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-23 19:57:07 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-23 19:57:08 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-23 19:57:10 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-23 19:57:09 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 | 13 +++-
ptp4l.c | 4 +
6 files changed, 272 insertions(+), 14 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..b5cfd4c 100644
--- a/pmc.c
+++ b/pmc.c
@@ -739,11 +739,16 @@ int main(int argc, char *argv[])
enum transport_type transport_type = TRANS_UDP_IPV4;
UInteger8 boundary_hops = 1, domain_number = 0, transport_specific = 0;
struct ptp_message *msg;
+ struct config *cfg = &pmc_config;
#define N_FD 2
struct pollfd pollfd[N_FD];

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];
@@ -774,6 +779,7 @@ int main(int argc, char *argv[])
if (strlen(optarg) > MAX_IFNAME_SIZE) {
fprintf(stderr, "path %s too long, max is %d\n",
optarg, MAX_IFNAME_SIZE);
+ config_destroy(cfg);
return -1;
}
strncpy(uds_path, optarg, MAX_IFNAME_SIZE);
@@ -784,18 +790,19 @@ int main(int argc, char *argv[])
break;
case 'v':
version_show(stdout);
+ config_destroy(cfg);
return 0;
case 'z':
zero_datalen = 1;
break;
case 'h':
usage(progname);
+ config_destroy(cfg);
return 0;
case '?':
- usage(progname);
- return -1;
default:
usage(progname);
+ config_destroy(cfg);
return -1;
}
}
@@ -821,6 +828,7 @@ int main(int argc, char *argv[])
domain_number, transport_specific, zero_datalen);
if (!pmc) {
fprintf(stderr, "failed to create pmc\n");
+ config_destroy(cfg);
return -1;
}

@@ -896,5 +904,6 @@ int main(int argc, char *argv[])

pmc_destroy(pmc);
msg_cleanup();
+ config_destroy(cfg);
return ret;
}
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


------------------------------------------------------------------------------
Richard Cochran
2015-08-23 19:57:11 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-23 19:57:12 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-23 19:57:13 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-23 19:57:14 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-23 19:57:15 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-23 19:57:16 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-23 19:57:17 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-23 19:57:18 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-23 19:57:19 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-23 19:57:20 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-23 19:57:21 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-23 19:57:22 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-23 19:57:24 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-23 19:57:23 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-23 19:57:27 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-23 19:57:29 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-23 19:57:30 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-23 19:57:31 UTC
Permalink
Signed-off-by: Richard Cochran <***@gmail.com>
---
config.c | 9 ++-------
ds.h | 1 -
port.c | 11 +++++++----
3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/config.c b/config.c
index c1d5aeb..678471a 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),
+ PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
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),
@@ -262,13 +263,7 @@ static enum parser_result parse_pod_setting(const char *option,

enum parser_result r;

- if (!strcmp(option, "delayAsymmetry")) {
- r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
- if (r != PARSED_OK)
- return r;
- pod->asymmetry = (Integer64) val << 16;
-
- } else if (!strcmp(option, "logAnnounceInterval")) {
+ if (!strcmp(option, "logAnnounceInterval")) {
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 162687a..fc3487d 100644
--- a/ds.h
+++ b/ds.h
@@ -125,7 +125,6 @@ struct portDS {
#define FRI_ASAP (-128)

struct port_defaults {
- Integer64 asymmetry;
Integer8 logAnnounceInterval;
Integer8 logSyncInterval;
Integer8 logMinDelayReqInterval;
diff --git a/port.c b/port.c
index 028df32..bad7acc 100644
--- a/port.c
+++ b/port.c
@@ -97,6 +97,7 @@ struct port {
struct port_defaults pod;
struct PortIdentity portIdentity;
enum port_state state; /*portState*/
+ Integer64 asymmetry;
int asCapable;
Integer8 logMinDelayReqInterval;
TimeInterval peerMeanPathDelay;
@@ -1148,7 +1149,7 @@ static int port_pdelay_request(struct port *p)
msg->header.ver = PTP_VERSION;
msg->header.messageLength = sizeof(struct pdelay_req_msg);
msg->header.domainNumber = clock_domain_number(p->clock);
- msg->header.correction = -p->pod.asymmetry;
+ msg->header.correction = -p->asymmetry;
msg->header.sourcePortIdentity = p->portIdentity;
msg->header.sequenceId = p->seqnum.delayreq++;
msg->header.control = CTL_OTHER;
@@ -1205,7 +1206,7 @@ static int port_delay_request(struct port *p)
msg->header.ver = PTP_VERSION;
msg->header.messageLength = sizeof(struct delay_req_msg);
msg->header.domainNumber = clock_domain_number(p->clock);
- msg->header.correction = -p->pod.asymmetry;
+ msg->header.correction = -p->asymmetry;
msg->header.sourcePortIdentity = p->portIdentity;
msg->header.sequenceId = p->seqnum.delayreq++;
msg->header.control = CTL_DELAY_REQ;
@@ -1817,7 +1818,7 @@ static void port_peer_delay(struct port *p)

t1 = timespec_to_tmv(req->hwts.ts);
t4 = timespec_to_tmv(rsp->hwts.ts);
- c1 = correction_to_tmv(rsp->header.correction + p->pod.asymmetry);
+ c1 = correction_to_tmv(rsp->header.correction + p->asymmetry);

/* Process one-step response immediately. */
if (one_step(rsp)) {
@@ -1953,7 +1954,7 @@ static void process_sync(struct port *p, struct ptp_message *m)
clock_sync_interval(p->clock, p->log_sync_interval);
}

- m->header.correction += p->pod.asymmetry;
+ m->header.correction += p->asymmetry;

if (one_step(m)) {
port_synchronize(p, m->hwts.ts, m->ts.pdu,
@@ -2524,6 +2525,8 @@ 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;
p->clock = clock;
p->trp = transport_create(cfg, interface->transport);
if (!p->trp)
--
2.1.4


------------------------------------------------------------------------------
Richard Cochran
2015-08-23 19:57:32 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-23 19:57:33 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-23 19:57:34 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-23 19:57:35 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-23 19:57: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 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-23 19:57:38 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-23 19:57:42 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-23 19:57:43 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-23 19:57:36 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-23 19:57:25 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-23 19:57:39 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-23 19:57:26 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-23 19:57:40 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-23 19:57:28 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-23 19:57:41 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-23 20:02:47 UTC
Permalink
I screwed up the subject line with V4 instead of V5. I'll resend the
bunch.

Sorry,
Richard


------------------------------------------------------------------------------
Loading...