Discussion:
[Linuxptp-devel] [RFC PATCH] phc2sys: add sk.o to phc2sys for sk_interface_phc
Jacob Keller
2012-09-24 23:37:16 UTC
Permalink
this patch adds support for -i to phc2sys in order to allow autolookup using
ethtool if it's supported, allowing users to use the ethernet device instead.

Signed-off-by: Jacob Keller <***@intel.com>
---
makefile | 2 +-
phc2sys.c | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/makefile b/makefile
index fd032f5..0ddc6fb 100644
--- a/makefile
+++ b/makefile
@@ -43,7 +43,7 @@ ptp4l: $(OBJ)

pmc: pmc.o msg.o print.o raw.o sk.o tlv.o transport.o udp.o udp6.o uds.o util.o

-phc2sys: phc2sys.o
+phc2sys: phc2sys.o sk.o print.o

hwstamp_ctl: hwstamp_ctl.o

diff --git a/phc2sys.c b/phc2sys.c
index ee5cbaf..bb459ec 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -33,6 +33,7 @@
#include <linux/ptp_clock.h>

#include "missing.h"
+#include "sk.h"

#define KP 0.7
#define KI 0.3
@@ -202,6 +203,7 @@ static void usage(char *progname)
" -h prints this message and exits\n"
" -r [val] reading the PHC device takes 'val' nanoseconds\n"
" -s [device] set the time from this PHC device\n"
+ " -i [device] set the time from PHC connected to this eth device\n"
" -P [val] set proportional constant to 'val'\n"
" -I [val] set integration constant to 'val'\n"
" -R [val] set PHC update rate to 'val' Hz\n"
@@ -213,7 +215,7 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
double kp = KP, ki = KI;
- char *device = NULL, *progname;
+ char *device = NULL, *progname, *ethdev;
clockid_t src = CLOCK_INVALID, dst = CLOCK_REALTIME;
uint64_t pps_ts, phc_ts;
int64_t pps_offset, phc_offset;
@@ -222,7 +224,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(argc, argv, "c:d:hr:s:P:I:R:N:"))) {
+ while (EOF != (c = getopt(argc, argv, "c:d:hr:s:P:I:R:N:i:"))) {
switch (c) {
case 'c':
dst = clock_open(optarg);
@@ -248,6 +250,9 @@ int main(int argc, char *argv[])
case 'N':
phc_readings = atoi(optarg);
break;
+ case 'i':
+ ethdev = optarg;
+ break;
case 'h':
usage(progname);
return 0;
@@ -257,6 +262,16 @@ int main(int argc, char *argv[])
}
}

+ if (src == CLOCK_INVALID && ethdev) {
+ int phc_index = -1;
+ char phc_device[16];
+ if (sk_interface_phc(ethdev, &phc_index) || phc_index < 0) {
+ fprintf(stderr, "can't autodiscover PHC device\n");
+ return -1;
+ }
+ sprintf(phc_device, "/dev/ptp/%d", phc_index);
+ src = clock_open(phc_device);
+ }
if (!(device || src != CLOCK_INVALID) || dst == CLOCK_INVALID) {
usage(progname);
return -1;
Richard Cochran
2012-09-25 07:24:30 UTC
Permalink
Post by Jacob Keller
this patch adds support for -i to phc2sys in order to allow autolookup using
ethtool if it's supported, allowing users to use the ethernet device instead.
@@ -213,7 +215,7 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
double kp = KP, ki = KI;
- char *device = NULL, *progname;
+ char *device = NULL, *progname, *ethdev;
I think you need to set ethdev = NULL here.
Otherwise this looks okay to me.

Thanks,
Richard
Jacob Keller
2012-09-26 18:39:14 UTC
Permalink
Post by Richard Cochran
Post by Jacob Keller
this patch adds support for -i to phc2sys in order to allow autolookup using
ethtool if it's supported, allowing users to use the ethernet device instead.
@@ -213,7 +215,7 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
double kp = KP, ki = KI;
- char *device = NULL, *progname;
+ char *device = NULL, *progname, *ethdev;
I think you need to set ethdev = NULL here.
Otherwise this looks okay to me.
Thanks,
Richard
You're right. I will send a v2.

- Jake

Loading...