A new option has been added, -d. This will allow the user to pass a path to ptp4l to a POSIX clock. If software mode is enabled, and the path is set, ptp4l will try to open the path as a POSIX clock. This allows for custom clocks to implement the posix clock interface and still be able to utilize ptp time synchronization.
Signed-off-by: Dimitrios Katsaros <[email protected]> --- clock.c | 13 +++++++++++-- clock.h | 4 +++- ptp4l.c | 12 +++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/clock.c b/clock.c index ec3f0fd..068cb4b 100644 --- a/clock.c +++ b/clock.c @@ -851,7 +851,7 @@ static void ensure_ts_label(struct interface *iface) } struct clock *clock_create(enum clock_type type, struct config *config, - const char *phc_device) + const char *phc_device, const char *swc_device) { enum servo_type servo = config_get_int(config, NULL, "clock_servo"); enum timestamp_type timestamping; @@ -1053,7 +1053,16 @@ struct clock *clock_create(enum clock_type type, struct config *config, } clockadj_init(c->clkid); } else { - c->clkid = CLOCK_REALTIME; + if (swc_device) { + c->clkid = posix_clock_open(swc_device); + if (c->clkid == CLOCK_INVALID) { + pr_err("Failed to open clock at %s", + swc_device); + return NULL; + } + } else { + c->clkid = CLOCK_REALTIME; + } c->utc_timescale = 1; clockadj_init(c->clkid); max_adj = sysclk_max_freq(); diff --git a/clock.h b/clock.h index 07aba18..b7f4578 100644 --- a/clock.h +++ b/clock.h @@ -102,10 +102,12 @@ int clock_required_modes(struct clock *c); * @param config Pointer to the configuration database. * @param phc_device PTP hardware clock device to use. Pass NULL for automatic * selection based on the network interface. + * @param swc_device A software clock device to use. Pass null for + * CLOCK_REALTIME. * @return A pointer to the single global clock instance. */ struct clock *clock_create(enum clock_type type, struct config *config, - const char *phc_device); + const char *phc_device, const char *swc_device); /** * Obtains a clock's default data set. diff --git a/ptp4l.c b/ptp4l.c index 3a9f084..84599bd 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -58,6 +58,8 @@ static void usage(char *progname) " (may be specified multiple times)\n" " -p [dev] PTP hardware clock device to use, default auto\n" " (ignored for SOFTWARE/LEGACY HW time stamping)\n" + " -d [dev] POSIX software clock to use, default CLOCK_REALTIME\n" + " (only used for software timestamping)\n" " -s slave only mode (overrides configuration file)\n" " -t transparent clock\n" " -l [num] set the logging level to 'num'\n" @@ -71,7 +73,8 @@ static void usage(char *progname) int main(int argc, char *argv[]) { - char *config = NULL, *req_phc = NULL, *progname; + char *config = NULL, *req_phc = NULL, *progname, + *swc_dev = NULL; enum clock_type type = CLOCK_TYPE_ORDINARY; int c, err = -1, index, print_level; struct clock *clock = NULL; @@ -90,7 +93,7 @@ int main(int argc, char *argv[]) /* Process the command line arguments. */ progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; - while (EOF != (c = getopt_long(argc, argv, "AEP246HSLf:i:p:sl:mqvh", + while (EOF != (c = getopt_long(argc, argv, "AEP246HSLf:i:p:sl:mqvhd:", opts, &index))) { switch (c) { case 0: @@ -146,6 +149,9 @@ int main(int argc, char *argv[]) case 'p': req_phc = optarg; break; + case 'd': + swc_dev = optarg; + break; case 's': if (config_set_int(cfg, "slaveOnly", 1)) { goto out; @@ -241,7 +247,7 @@ int main(int argc, char *argv[]) goto out; } - clock = clock_create(type, cfg, req_phc); + clock = clock_create(type, cfg, req_phc, swc_dev); if (!clock) { fprintf(stderr, "failed to create a clock\n"); goto out; -- 2.17.1 _______________________________________________ Linuxptp-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
