phc2sys: add selecting clock by name.

This allows synchronization of a PHC to the system clock.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2012-11-01 15:15:35 +01:00 committed by Richard Cochran
parent 2f3b9f718f
commit d0714a9fac
2 changed files with 15 additions and 5 deletions

View File

@ -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.

View File

@ -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;