Discussion:
[Linuxptp-devel] [PATCHv2 1/3] Add options to tag ptp4l and phc2sys log messages.
Miroslav Lichvar
2017-01-17 13:17:39 UTC
Permalink
When running multiple instances of ptp4l or phc2sys, it's difficult to
tell which log message belongs to which instance. Add new options to
ptp4l and phc2sys which can specify a tag for all messages printed to
the standard output or system log, so messages from different instances
can have different tags.

Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
config.c | 1 +
phc2sys.8 | 4 ++++
phc2sys.c | 9 +++++++--
print.c | 18 ++++++++++++++----
print.h | 1 +
ptp4l.8 | 6 ++++++
ptp4l.c | 1 +
7 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/config.c b/config.c
index b19f3ad..5afffd9 100644
--- a/config.c
+++ b/config.c
@@ -199,6 +199,7 @@ struct config_item config_tab[] = {
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_STR("message_tag", NULL),
GLOB_ITEM_STR("manufacturerIdentity", "00:00:00"),
GLOB_ITEM_INT("max_frequency", 900000000, 0, INT_MAX),
PORT_ITEM_INT("min_neighbor_prop_delay", -20000000, INT_MIN, -1),
diff --git a/phc2sys.8 b/phc2sys.8
index 22d02c2..2559c74 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -206,6 +206,10 @@ The default is /var/run/ptp4l.
Set the maximum syslog level of messages which should be printed or sent to
the system logger. The default is 6 (LOG_INFO).
.TP
+.BI \-t " message-tag"
+Specify the tag which is added to all messages printed to the standard output
+or system log. The default is an empty string.
+.TP
.B \-m
Print messages to the standard output.
.TP
diff --git a/phc2sys.c b/phc2sys.c
index 35cf6fa..aa4186b 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1209,6 +1209,7 @@ static void usage(char *progname)
" -x apply leap seconds by servo instead of kernel\n"
" -z [path] server address for UDS (/var/run/ptp4l)\n"
" -l [num] set the logging level to 'num' (6)\n"
+ " -t [tag] add tag to log messages\n"
" -m print messages to stdout\n"
" -q do not print messages to the syslog\n"
" -v prints the software version and exits\n"
@@ -1219,7 +1220,7 @@ static void usage(char *progname)

int main(int argc, char *argv[])
{
- char *progname;
+ char *progname, *message_tag = NULL;
char *src_name = NULL, *dst_name = NULL;
struct clock *src, *dst;
struct config *cfg;
@@ -1251,7 +1252,7 @@ int main(int argc, char *argv[])
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
while (EOF != (c = getopt(argc, argv,
- "arc:d:s:E:P:I:S:F:R:N:O:L:M:i:u:wn:xz:l:mqvh"))) {
+ "arc:d:s:E:P:I:S:F:R:N:O:L:M:i:u:wn:xz:l:t:mqvh"))) {
switch (c) {
case 'a':
autocfg = 1;
@@ -1363,6 +1364,9 @@ int main(int argc, char *argv[])
PRINT_LEVEL_MIN, PRINT_LEVEL_MAX))
goto end;
break;
+ case 't':
+ message_tag = optarg;
+ break;
case 'm':
verbose = 1;
break;
@@ -1405,6 +1409,7 @@ int main(int argc, char *argv[])
}

print_set_progname(progname);
+ print_set_tag(message_tag);
print_set_verbose(verbose);
print_set_syslog(use_syslog);
print_set_level(print_level);
diff --git a/print.c b/print.c
index a82d0e7..6c48e1e 100644
--- a/print.c
+++ b/print.c
@@ -28,12 +28,18 @@ static int verbose = 0;
static int print_level = LOG_INFO;
static int use_syslog = 1;
static const char *progname;
+static const char *message_tag;

void print_set_progname(const char *name)
{
progname = name;
}

+void print_set_tag(const char *tag)
+{
+ message_tag = tag;
+}
+
void print_set_syslog(int value)
{
use_syslog = value ? 1 : 0;
@@ -67,13 +73,17 @@ void print(int level, char const *format, ...)

if (verbose) {
f = level >= LOG_NOTICE ? stdout : stderr;
- fprintf(f, "%s[%ld.%03ld]: %s\n",
+ fprintf(f, "%s[%ld.%03ld]: %s%s%s\n",
progname ? progname : "",
- ts.tv_sec, ts.tv_nsec / 1000000, buf);
+ ts.tv_sec, ts.tv_nsec / 1000000,
+ message_tag ? message_tag : "", message_tag ? " " : "",
+ buf);
fflush(f);
}
if (use_syslog) {
- syslog(level, "[%ld.%03ld] %s",
- ts.tv_sec, ts.tv_nsec / 1000000, buf);
+ syslog(level, "[%ld.%03ld] %s%s%s",
+ ts.tv_sec, ts.tv_nsec / 1000000,
+ message_tag ? message_tag : "", message_tag ? " " : "",
+ buf);
}
}
diff --git a/print.h b/print.h
index e8f2c8e..1723d8a 100644
--- a/print.h
+++ b/print.h
@@ -33,6 +33,7 @@ __attribute__ ((format (printf, 2, 3)))
void print(int level, char const *format, ...);

void print_set_progname(const char *name);
+void print_set_tag(const char *tag);
void print_set_syslog(int value);
void print_set_level(int level);
void print_set_verbose(int value);
diff --git a/ptp4l.8 b/ptp4l.8
index f53fc6e..a709e58 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -481,6 +481,12 @@ is 0.
The maximum logging level of messages which should be printed.
The default is 6 (LOG_INFO).
.TP
+.B message_tag
+The tag which is added to all messages printed to the standard output or system
+log.
+The default is an empty string (which cannot be set in the configuration file
+as the option requires an argument).
+.TP
.B verbose
Print messages to the standard output if enabled.
The default is 0 (disabled).
diff --git a/ptp4l.c b/ptp4l.c
index e90fcb2..f01ff6f 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -183,6 +183,7 @@ int main(int argc, char *argv[])
}

print_set_progname(progname);
+ print_set_tag(config_get_string(cfg, NULL, "message_tag"));
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.9.3
Miroslav Lichvar
2017-01-17 13:17:40 UTC
Permalink
Use the new options of ptp4l and phc2sys to tag their log messages with
the PTP domain number and name(s) of interface(s) in the domain.

Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
timemaster.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/timemaster.c b/timemaster.c
index 66ac521..880b2ab 100644
--- a/timemaster.c
+++ b/timemaster.c
@@ -599,7 +599,8 @@ static char **get_ptp4l_command(struct program_config *config,
}

static char **get_phc2sys_command(struct program_config *config, int domain,
- int poll, int shm_segment, char *uds_path)
+ int poll, int shm_segment, char *uds_path,
+ char *message_tag)
{
char **command = (char **)parray_new();

@@ -610,6 +611,7 @@ static char **get_phc2sys_command(struct program_config *config, int domain,
xstrdup("-R"), string_newf("%.2f", poll > 0 ?
1.0 / (1 << poll) : 1 << -poll),
xstrdup("-z"), xstrdup(uds_path),
+ xstrdup("-t"), xstrdup(message_tag),
xstrdup("-n"), string_newf("%d", domain),
xstrdup("-E"), xstrdup("ntpshm"),
xstrdup("-M"), string_newf("%d", shm_segment), NULL);
@@ -671,7 +673,7 @@ static int add_ptp_source(struct ptp_domain *source,
struct script *script)
{
struct config_file *config_file;
- char **command, *uds_path, **interfaces;
+ char **command, *uds_path, **interfaces, *message_tag;
int i, j, num_interfaces, *phc, *phcs, hw_ts;
struct sk_ts_info ts_info;

@@ -749,6 +751,12 @@ static int add_ptp_source(struct ptp_domain *source,
uds_path = string_newf("%s/ptp4l.%d.socket",
config->rundir, *shm_segment);

+ message_tag = string_newf("[%d", source->domain);
+ for (j = 0; interfaces[j]; j++)
+ string_appendf(&message_tag, "%s%s", j ? "+" : ":",
+ interfaces[j]);
+ string_appendf(&message_tag, "]");
+
config_file = xmalloc(sizeof(*config_file));
config_file->path = string_newf("%s/ptp4l.%d.conf",
config->rundir, *shm_segment);
@@ -760,8 +768,9 @@ static int add_ptp_source(struct ptp_domain *source,
string_appendf(&config_file->content,
"slaveOnly 1\n"
"domainNumber %d\n"
- "uds_address %s\n",
- source->domain, uds_path);
+ "uds_address %s\n"
+ "message_tag %s\n",
+ source->domain, uds_path, message_tag);

if (phcs[i] >= 0) {
/* HW time stamping */
@@ -772,7 +781,8 @@ static int add_ptp_source(struct ptp_domain *source,
command = get_phc2sys_command(&config->phc2sys,
source->domain,
source->phc2sys_poll,
- *shm_segment, uds_path);
+ *shm_segment, uds_path,
+ message_tag);
parray_append((void ***)&script->commands, command);
} else {
/* SW time stamping */
@@ -793,6 +803,7 @@ static int add_ptp_source(struct ptp_domain *source,

(*shm_segment)++;

+ free(message_tag);
free(uds_path);
free(interfaces);
}
--
2.9.3
Miroslav Lichvar
2017-01-17 13:17:41 UTC
Permalink
When an interface doesn't support HW time stamping, before falling back
to SW time stamping, check if it's actually supported and exit with an
error message if not.

Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
timemaster.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/timemaster.c b/timemaster.c
index 880b2ab..cda2d90 100644
--- a/timemaster.c
+++ b/timemaster.c
@@ -674,13 +674,15 @@ static int add_ptp_source(struct ptp_domain *source,
{
struct config_file *config_file;
char **command, *uds_path, **interfaces, *message_tag;
- int i, j, num_interfaces, *phc, *phcs, hw_ts;
+ int i, j, num_interfaces, *phc, *phcs, hw_ts, sw_ts;
struct sk_ts_info ts_info;

pr_debug("adding PTP domain %d", source->domain);

hw_ts = SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE |
SOF_TIMESTAMPING_RAW_HARDWARE;
+ sw_ts = SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_RX_SOFTWARE |
+ SOF_TIMESTAMPING_SOFTWARE;

for (num_interfaces = 0;
source->interfaces[num_interfaces]; num_interfaces++)
@@ -702,9 +704,14 @@ static int add_ptp_source(struct ptp_domain *source,
return 1;
}

- if (!ts_info.valid ||
- ((ts_info.so_timestamping & hw_ts) != hw_ts)) {
+ if (((ts_info.so_timestamping & hw_ts) != hw_ts)) {
pr_debug("interface %s: no PHC", source->interfaces[i]);
+ if ((ts_info.so_timestamping & sw_ts) != sw_ts) {
+ pr_err("time stamping not supported on %s",
+ source->interfaces[i]);
+ free(phcs);
+ return 1;
+ }
continue;
}
--
2.9.3
Richard Cochran
2017-02-05 16:04:12 UTC
Permalink
- rename options to use "tag" instead of "prefix"
- don't add short command-line option to ptp4l
Series applied.

Thanks,
Richard

Loading...