Discussion:
[Linuxptp-devel] [PATCH 1/2] phc2sys: add selecting clock by name.
Miroslav Lichvar
2012-11-01 14:15:35 UTC
Permalink
This allows synchronization of a PHC to the system clock.

Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
phc2sys.8 | 8 ++++----
phc2sys.c | 12 +++++++++++-
2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/phc2sys.8 b/phc2sys.8
index 26b37a8..ad1bfa2 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -53,8 +53,8 @@ is started or the
option should be used too.
.TP
.BI \-s " phc-device"
-Specify the device of the master clock (e.g. /dev/ptp0). When this option is
-used together with the
+Specify the master clock by device (e.g. /dev/ptp0) or name (e.g. CLOCK_REALTIME
+for the system clock). When this option is used together with the
.B \-d
option, the master clock is read only on start to fix an offset over 0.5
seconds which cannot be fixed with PPS alone.
@@ -65,8 +65,8 @@ Similar to the
option, but specified by the interface which provides the master clock.
.TP
.BI \-c " phc-device"
-Specify the device of the slave clock (e.g. /dev/ptp1). The default slave clock
-is the system clock (CLOCK_REALTIME).
+Specify the slave clock by device (e.g. /dev/ptp1) or name. The default is
+CLOCK_REALTIME (the system clock).
.TP
.BI \-P " kp"
Specify the proportional constant of the PI controller. The default is 0.7.
diff --git a/phc2sys.c b/phc2sys.c
index 26a0c2b..7bafbed 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -44,7 +44,17 @@

static clockid_t clock_open(char *device)
{
- int fd = open(device, O_RDWR);
+ int fd;
+
+ if (device[0] != '/') {
+ if (!strcasecmp(device, "CLOCK_REALTIME"))
+ return CLOCK_REALTIME;
+
+ fprintf(stderr, "unknown clock %s\n", device);
+ return CLOCK_INVALID;
+ }
+
+ fd = open(device, O_RDWR);
if (fd < 0) {
fprintf(stderr, "cannot open %s: %m\n", device);
return CLOCK_INVALID;
--
1.7.11.7
Loading...