clock: simplify the create method.

With the new configuration API, there is no need to pass the default data
set.  Instead, the clock code can read the configuration directly.  This
patch simplifies the clock create method by removing the 'dds' parameter
and moving the code that initialized the data set into the clock module.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-10-18 17:19:43 +02:00
parent 2fc2af97d8
commit 9b27664cfc
4 changed files with 86 additions and 98 deletions

90
clock.c
View File

@ -799,8 +799,7 @@ static void clock_remove_port(struct clock *c, struct port *p)
} }
struct clock *clock_create(struct config *config, int phc_index, struct clock *clock_create(struct config *config, int phc_index,
struct interfaces_head *ifaces, struct interfaces_head *ifaces)
struct default_ds *dds)
{ {
enum timestamp_type timestamping = enum timestamp_type timestamping =
config_get_int(config, NULL, "time_stamping"); config_get_int(config, NULL, "time_stamping");
@ -808,9 +807,10 @@ struct clock *clock_create(struct config *config, int phc_index,
enum servo_type servo = config_get_int(config, NULL, "clock_servo"); enum servo_type servo = config_get_int(config, NULL, "clock_servo");
struct clock *c = &the_clock; struct clock *c = &the_clock;
struct port *p; struct port *p;
char phc[32]; unsigned char oui[OUI_LEN];
char phc[32], *tmp;
struct interface *udsif = &c->uds_interface; struct interface *udsif = &c->uds_interface;
struct interface *iface; struct interface *iface = STAILQ_FIRST(ifaces);
struct timespec ts; struct timespec ts;
int sfl; int sfl;
@ -820,6 +820,85 @@ struct clock *clock_create(struct config *config, int phc_index,
if (c->nports) if (c->nports)
clock_destroy(c); clock_destroy(c);
/* Initialize the defaultDS. */
c->dds.clockQuality.clockClass =
config_get_int(config, NULL, "clockClass");
c->dds.clockQuality.clockAccuracy =
config_get_int(config, NULL, "clockAccuracy");
c->dds.clockQuality.offsetScaledLogVariance =
config_get_int(config, NULL, "offsetScaledLogVariance");
c->desc.productDescription.max_symbols = 64;
c->desc.revisionData.max_symbols = 32;
c->desc.userDescription.max_symbols = 128;
tmp = config_get_string(config, NULL, "productDescription");
if (count_char(tmp, ';') != 2 ||
static_ptp_text_set(&c->desc.productDescription, tmp)) {
pr_err("invalid productDescription '%s'", tmp);
return NULL;
}
tmp = config_get_string(config, NULL, "revisionData");
if (count_char(tmp, ';') != 2 ||
static_ptp_text_set(&c->desc.revisionData, tmp)) {
pr_err("invalid revisionData '%s'", tmp);
return NULL;
}
tmp = config_get_string(config, NULL, "userDescription");
if (static_ptp_text_set(&c->desc.userDescription, tmp)) {
pr_err("invalid userDescription '%s'", tmp);
return NULL;
}
tmp = config_get_string(config, NULL, "manufacturerIdentity");
if (OUI_LEN != sscanf(tmp, "%hhx:%hhx:%hhx", &oui[0], &oui[1], &oui[2])) {
pr_err("invalid manufacturerIdentity '%s'", tmp);
return NULL;
}
memcpy(c->desc.manufacturerIdentity, oui, OUI_LEN);
c->dds.domainNumber = config_get_int(config, NULL, "domainNumber");
if (config_get_int(config, NULL, "slaveOnly")) {
c->dds.flags |= DDS_SLAVE_ONLY;
}
if (config_get_int(config, NULL, "twoStepFlag")) {
c->dds.flags |= DDS_TWO_STEP_FLAG;
}
c->dds.priority1 = config_get_int(config, NULL, "priority1");
c->dds.priority2 = config_get_int(config, NULL, "priority2");
if (!config_get_int(config, NULL, "gmCapable") &&
c->dds.flags & DDS_SLAVE_ONLY) {
pr_err("Cannot mix 1588 slaveOnly with 802.1AS !gmCapable");
return NULL;
}
if (!config_get_int(config, NULL, "gmCapable") ||
c->dds.flags & DDS_SLAVE_ONLY) {
c->dds.clockQuality.clockClass = 255;
}
if (!(c->dds.flags & DDS_TWO_STEP_FLAG)) {
switch (config_get_int(config, NULL, "time_stamping")) {
case TS_SOFTWARE:
case TS_LEGACY_HW:
pr_err("one step is only possible "
"with hardware time stamping");
return NULL;
case TS_HARDWARE:
if (config_set_int(config, "time_stamping", TS_ONESTEP))
return NULL;
break;
case TS_ONESTEP:
break;
}
}
if (generate_clock_identity(&c->dds.clockIdentity, iface->name)) {
pr_err("failed to generate a clock identity");
return NULL;
}
/* Configure the UDS. */
snprintf(udsif->name, sizeof(udsif->name), "%s", snprintf(udsif->name, sizeof(udsif->name), "%s",
config_get_string(config, NULL, "uds_address")); config_get_string(config, NULL, "uds_address"));
if (config_set_section_int(config, udsif->name, if (config_set_section_int(config, udsif->name,
@ -841,7 +920,6 @@ struct clock *clock_create(struct config *config, int phc_index,
c->kernel_leap = config_get_int(config, NULL, "kernel_leap"); c->kernel_leap = config_get_int(config, NULL, "kernel_leap");
c->utc_offset = CURRENT_UTC_OFFSET; c->utc_offset = CURRENT_UTC_OFFSET;
c->time_source = config_get_int(config, NULL, "timeSource"); c->time_source = config_get_int(config, NULL, "timeSource");
c->desc = dds->clock_desc;
if (c->free_running) { if (c->free_running) {
c->clkid = CLOCK_INVALID; c->clkid = CLOCK_INVALID;
@ -911,8 +989,6 @@ struct clock *clock_create(struct config *config, int phc_index,
} }
} }
c->dds = dds->dds;
/* Initialize the parentDS. */ /* Initialize the parentDS. */
clock_update_grandmaster(c); clock_update_grandmaster(c);
c->dad.pds.parentStats = 0; c->dad.pds.parentStats = 0;

View File

@ -72,12 +72,10 @@ struct config *clock_config(struct clock *c);
* @param phc_index PTP hardware clock device to use. * @param phc_index PTP hardware clock device to use.
* Pass -1 to select CLOCK_REALTIME. * Pass -1 to select CLOCK_REALTIME.
* @param ifaces A queue of network interfaces. * @param ifaces A queue of network interfaces.
* @param dds A pointer to a default data set for the clock.
* @return A pointer to the single global clock instance. * @return A pointer to the single global clock instance.
*/ */
struct clock *clock_create(struct config *config, int phc_index, struct clock *clock_create(struct config *config, int phc_index,
struct interfaces_head *ifaces, struct interfaces_head *ifaces);
struct default_ds *dds);
/** /**
* Obtains a clock's default data set. * Obtains a clock's default data set.

5
ds.h
View File

@ -50,11 +50,6 @@ struct clock_description {
Octet manufacturerIdentity[OUI_LEN]; Octet manufacturerIdentity[OUI_LEN];
}; };
struct default_ds {
struct defaultDS dds;
struct clock_description clock_desc;
};
struct dataset { struct dataset {
UInteger8 priority1; UInteger8 priority1;
struct ClockIdentity identity; struct ClockIdentity identity;

85
ptp4l.c
View File

@ -39,8 +39,6 @@
int assume_two_step = 0; int assume_two_step = 0;
static struct default_ds ptp4l_dds;
static void usage(char *progname) static void usage(char *progname)
{ {
fprintf(stderr, fprintf(stderr,
@ -75,15 +73,12 @@ static void usage(char *progname)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *config = NULL, *req_phc = NULL, *progname, *tmp; char *config = NULL, *req_phc = NULL, *progname;
int c, err = -1; int c, err = -1;
struct interface *iface; struct interface *iface;
struct clock *clock = NULL; struct clock *clock = NULL;
struct config *cfg; struct config *cfg;
struct default_ds *dds = &ptp4l_dds;
struct defaultDS *ds = &ptp4l_dds.dds;
int phc_index = -1, print_level, required_modes = 0; int phc_index = -1, print_level, required_modes = 0;
unsigned char oui[OUI_LEN];
if (handle_term_signals()) if (handle_term_signals())
return -1; return -1;
@ -192,61 +187,6 @@ int main(int argc, char *argv[])
sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync"); sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync");
sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout"); sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");
ds->clockQuality.clockClass = config_get_int(cfg, NULL, "clockClass");
ds->clockQuality.clockAccuracy = config_get_int(cfg, NULL, "clockAccuracy");
ds->clockQuality.offsetScaledLogVariance =
config_get_int(cfg, NULL, "offsetScaledLogVariance");
dds->clock_desc.productDescription.max_symbols = 64;
dds->clock_desc.revisionData.max_symbols = 32;
dds->clock_desc.userDescription.max_symbols = 128;
tmp = config_get_string(cfg, NULL, "productDescription");
if (count_char(tmp, ';') != 2 ||
static_ptp_text_set(&dds->clock_desc.productDescription, tmp)) {
fprintf(stderr, "invalid productDescription '%s'.\n", tmp);
goto out;
}
tmp = config_get_string(cfg, NULL, "revisionData");
if (count_char(tmp, ';') != 2 ||
static_ptp_text_set(&dds->clock_desc.revisionData, tmp)) {
fprintf(stderr, "invalid revisionData '%s'.\n", tmp);
goto out;
}
tmp = config_get_string(cfg, NULL, "userDescription");
if (static_ptp_text_set(&dds->clock_desc.userDescription, tmp)) {
fprintf(stderr, "invalid userDescription '%s'.\n", tmp);
goto out;
}
tmp = config_get_string(cfg, NULL, "manufacturerIdentity");
if (OUI_LEN != sscanf(tmp, "%hhx:%hhx:%hhx", &oui[0], &oui[1], &oui[2])) {
fprintf(stderr, "invalid manufacturerIdentity '%s'.\n", tmp);
goto out;
}
memcpy(dds->clock_desc.manufacturerIdentity, oui, OUI_LEN);
ds->domainNumber = config_get_int(cfg, NULL, "domainNumber");
if (config_get_int(cfg, NULL, "slaveOnly")) {
ds->flags |= DDS_SLAVE_ONLY;
ds->clockQuality.clockClass = 248;
}
if (config_get_int(cfg, NULL, "twoStepFlag")) {
ds->flags |= DDS_TWO_STEP_FLAG;
}
ds->priority1 = config_get_int(cfg, NULL, "priority1");
ds->priority2 = config_get_int(cfg, NULL, "priority2");
if (!config_get_int(cfg, NULL, "gmCapable") &&
ds->flags & DDS_SLAVE_ONLY) {
fprintf(stderr,
"Cannot mix 1588 slaveOnly with 802.1AS !gmCapable.\n");
goto out;
}
if (!config_get_int(cfg, NULL, "gmCapable") ||
ds->flags & DDS_SLAVE_ONLY) {
ds->clockQuality.clockClass = 255;
}
if (config_get_int(cfg, NULL, "clock_servo") == CLOCK_SERVO_NTPSHM) { if (config_get_int(cfg, NULL, "clock_servo") == CLOCK_SERVO_NTPSHM) {
config_set_int(cfg, "kernel_leap", 0); config_set_int(cfg, "kernel_leap", 0);
config_set_int(cfg, "sanity_freq_limit", 0); config_set_int(cfg, "sanity_freq_limit", 0);
@ -258,22 +198,6 @@ int main(int argc, char *argv[])
goto out; goto out;
} }
if (!(ds->flags & DDS_TWO_STEP_FLAG)) {
switch (config_get_int(cfg, NULL, "time_stamping")) {
case TS_SOFTWARE:
case TS_LEGACY_HW:
fprintf(stderr, "one step is only possible "
"with hardware time stamping\n");
goto out;
case TS_HARDWARE:
if (config_set_int(cfg, "time_stamping", TS_ONESTEP))
goto out;
break;
case TS_ONESTEP:
break;
}
}
switch (config_get_int(cfg, NULL, "time_stamping")) { switch (config_get_int(cfg, NULL, "time_stamping")) {
case TS_SOFTWARE: case TS_SOFTWARE:
required_modes |= SOF_TIMESTAMPING_TX_SOFTWARE | required_modes |= SOF_TIMESTAMPING_TX_SOFTWARE |
@ -330,12 +254,7 @@ int main(int argc, char *argv[])
pr_info("selected /dev/ptp%d as PTP clock", phc_index); pr_info("selected /dev/ptp%d as PTP clock", phc_index);
} }
if (generate_clock_identity(&ds->clockIdentity, iface->name)) { clock = clock_create(cfg, phc_index, &cfg->interfaces);
fprintf(stderr, "failed to generate a clock identity\n");
goto out;
}
clock = clock_create(cfg, phc_index, &cfg->interfaces, &ptp4l_dds);
if (!clock) { if (!clock) {
fprintf(stderr, "failed to create a clock\n"); fprintf(stderr, "failed to create a clock\n");
goto out; goto out;