phc2sys: update open_clock and deprecate '-i' option
This patch modifies phc2sys to enable the use of interface names in clock_open rather than having to do that by hand. This enables cleaner use of the -s and -c options as they can accept interface names. This also enables the user to set the slave clock by network interface as well. -v2- * fix clock_open as it used device instead of phc_device in the final call to phc_open Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>master
parent
3ae0ff1f44
commit
73105bc65a
37
phc2sys.8
37
phc2sys.8
|
@ -4,18 +4,12 @@ phc2sys \- synchronize two clocks
|
||||||
|
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B phc2sys
|
.B phc2sys
|
||||||
{
|
|
||||||
.BI \-d " pps-device"
|
|
||||||
[
|
[
|
||||||
.BI \-s " phc-device"
|
.BI \-d " pps-device"
|
||||||
|
|
] [
|
||||||
.BI \-i " interface"
|
.BI \-s " device"
|
||||||
] |
|
] [
|
||||||
.BI \-s " phc-device"
|
.BI \-c " device"
|
||||||
|
|
|
||||||
.BI \-i " interface"
|
|
||||||
} [
|
|
||||||
.BI \-c " phc-device"
|
|
||||||
] [
|
] [
|
||||||
.BI \-P " kp"
|
.BI \-P " kp"
|
||||||
] [
|
] [
|
||||||
|
@ -71,21 +65,26 @@ is started or the
|
||||||
option should be used too. This option can be used only with the system clock as
|
option should be used too. This option can be used only with the system clock as
|
||||||
the slave clock.
|
the slave clock.
|
||||||
.TP
|
.TP
|
||||||
.BI \-s " phc-device"
|
.BI \-s " device"
|
||||||
Specify the master clock by device (e.g. /dev/ptp0) or name (e.g. CLOCK_REALTIME
|
Specify the master clock by device (e.g. dev/ptp0) or interface (e.g. eth0) or
|
||||||
for the system clock). When this option is used together with the
|
by name (e.g. CLOCK_REALTIME for the system clock). When this option is used
|
||||||
|
together with the
|
||||||
.B \-d
|
.B \-d
|
||||||
option, the master clock is used only to correct the offset by whole number of
|
option, the master clock is used only to correct the offset by whole number of
|
||||||
seconds, which cannot be fixed with PPS alone.
|
seconds, which cannot be fixed with PPS alone.
|
||||||
.TP
|
.TP
|
||||||
.BI \-i " interface"
|
.BI \-i " interface"
|
||||||
Similar to the
|
Performs the exact same function as
|
||||||
.B \-s
|
.B \-s
|
||||||
option, but specified by the interface which provides the master clock.
|
for compatibility reasons. Previously enabled specifying master clock by network
|
||||||
|
interface. However, this can now be done using
|
||||||
|
.B \-s
|
||||||
|
and this option is no longer necessary. As such it has been deprecated, and
|
||||||
|
should no longer be used.
|
||||||
.TP
|
.TP
|
||||||
.BI \-c " phc-device"
|
.BI \-c " device"
|
||||||
Specify the slave clock by device (e.g. /dev/ptp1) or name. The default is
|
Specify the slave clock by device (e.g. /dev/ptp1) or interface (e.g. eth1) or
|
||||||
CLOCK_REALTIME (the system clock).
|
by name. The default is CLOCK_REALTIME (the system clock).
|
||||||
.TP
|
.TP
|
||||||
.BI \-P " kp"
|
.BI \-P " kp"
|
||||||
Specify the proportional constant of the PI controller. The default is 0.7.
|
Specify the proportional constant of the PI controller. The default is 0.7.
|
||||||
|
|
48
phc2sys.c
48
phc2sys.c
|
@ -61,17 +61,32 @@ static int update_sync_offset(struct clock *clock, int64_t offset, uint64_t ts);
|
||||||
|
|
||||||
static clockid_t clock_open(char *device)
|
static clockid_t clock_open(char *device)
|
||||||
{
|
{
|
||||||
|
struct sk_ts_info ts_info;
|
||||||
|
char phc_device[16];
|
||||||
int clkid;
|
int clkid;
|
||||||
|
|
||||||
if (device[0] != '/') {
|
/* check if device is CLOCK_REALTIME */
|
||||||
if (!strcasecmp(device, "CLOCK_REALTIME"))
|
if (!strcasecmp(device, "CLOCK_REALTIME"))
|
||||||
return CLOCK_REALTIME;
|
return CLOCK_REALTIME;
|
||||||
|
|
||||||
fprintf(stderr, "unknown clock %s\n", device);
|
/* check if device is valid phc device */
|
||||||
|
clkid = phc_open(device);
|
||||||
|
if (clkid != CLOCK_INVALID)
|
||||||
|
return clkid;
|
||||||
|
|
||||||
|
/* check if device is a valid ethernet device */
|
||||||
|
if (sk_get_ts_info(device, &ts_info) || !ts_info.valid) {
|
||||||
|
fprintf(stderr, "unknown clock %s: %m\n", device);
|
||||||
return CLOCK_INVALID;
|
return CLOCK_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
clkid = phc_open(device);
|
if (ts_info.phc_index < 0) {
|
||||||
|
fprintf(stderr, "interface %s does not have a PHC\n", device);
|
||||||
|
return CLOCK_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(phc_device, "/dev/ptp%d", ts_info.phc_index);
|
||||||
|
clkid = phc_open(phc_device);
|
||||||
if (clkid == CLOCK_INVALID)
|
if (clkid == CLOCK_INVALID)
|
||||||
fprintf(stderr, "cannot open %s: %m\n", device);
|
fprintf(stderr, "cannot open %s: %m\n", device);
|
||||||
return clkid;
|
return clkid;
|
||||||
|
@ -535,7 +550,6 @@ static void usage(char *progname)
|
||||||
" -c [dev|name] slave clock (CLOCK_REALTIME)\n"
|
" -c [dev|name] slave clock (CLOCK_REALTIME)\n"
|
||||||
" -d [dev] master PPS device\n"
|
" -d [dev] master PPS device\n"
|
||||||
" -s [dev|name] master clock\n"
|
" -s [dev|name] master clock\n"
|
||||||
" -i [iface] master clock by network interface\n"
|
|
||||||
" -P [kp] proportional constant (0.7)\n"
|
" -P [kp] proportional constant (0.7)\n"
|
||||||
" -I [ki] integration constant (0.3)\n"
|
" -I [ki] integration constant (0.3)\n"
|
||||||
" -S [step] step threshold (disabled)\n"
|
" -S [step] step threshold (disabled)\n"
|
||||||
|
@ -557,7 +571,7 @@ static void usage(char *progname)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *progname, *ethdev = NULL;
|
char *progname;
|
||||||
clockid_t src = CLOCK_INVALID;
|
clockid_t src = CLOCK_INVALID;
|
||||||
int c, domain_number = 0, phc_readings = 5, pps_fd = -1;
|
int c, domain_number = 0, phc_readings = 5, pps_fd = -1;
|
||||||
int max_ppb, r, wait_sync = 0, forced_sync_offset = 0;
|
int max_ppb, r, wait_sync = 0, forced_sync_offset = 0;
|
||||||
|
@ -590,6 +604,9 @@ int main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
fprintf(stderr,
|
||||||
|
"'-i' has been deprecated. please use '-s' instead.\n");
|
||||||
case 's':
|
case 's':
|
||||||
src = clock_open(optarg);
|
src = clock_open(optarg);
|
||||||
break;
|
break;
|
||||||
|
@ -613,9 +630,6 @@ int main(int argc, char *argv[])
|
||||||
dst_clock.sync_offset_direction = -1;
|
dst_clock.sync_offset_direction = -1;
|
||||||
forced_sync_offset = 1;
|
forced_sync_offset = 1;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
|
||||||
ethdev = optarg;
|
|
||||||
break;
|
|
||||||
case 'u':
|
case 'u':
|
||||||
dst_clock.stats_max_count = atoi(optarg);
|
dst_clock.stats_max_count = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
@ -649,20 +663,6 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src == CLOCK_INVALID && ethdev) {
|
|
||||||
struct sk_ts_info ts_info;
|
|
||||||
char phc_device[16];
|
|
||||||
if (sk_get_ts_info(ethdev, &ts_info) || !ts_info.valid) {
|
|
||||||
fprintf(stderr, "can't autodiscover PHC device\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (ts_info.phc_index < 0) {
|
|
||||||
fprintf(stderr, "interface %s doesn't have a PHC\n", ethdev);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
sprintf(phc_device, "/dev/ptp%d", ts_info.phc_index);
|
|
||||||
src = clock_open(phc_device);
|
|
||||||
}
|
|
||||||
if (!(pps_fd >= 0 || src != CLOCK_INVALID) ||
|
if (!(pps_fd >= 0 || src != CLOCK_INVALID) ||
|
||||||
dst_clock.clkid == CLOCK_INVALID ||
|
dst_clock.clkid == CLOCK_INVALID ||
|
||||||
(pps_fd >= 0 && dst_clock.clkid != CLOCK_REALTIME)) {
|
(pps_fd >= 0 && dst_clock.clkid != CLOCK_REALTIME)) {
|
||||||
|
|
Loading…
Reference in New Issue