Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932499Ab3IOJ05 (ORCPT ); Sun, 15 Sep 2013 05:26:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18809 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753787Ab3IOJ0z (ORCPT ); Sun, 15 Sep 2013 05:26:55 -0400 Date: Sun, 15 Sep 2013 17:25:12 +0800 From: Dong Zhu To: Richard Cochran Cc: Rob Landley , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v3] ptp: add the PTP_SYS_OFFSET ioctl to the testptp program Message-ID: <20130915092512.GE23682@zhudong.nay.redhat.com> References: <20130914080306.GC23682@zhudong.nay.redhat.com> <20130914143144.GA4206@netboy> <20130914153952.GD23682@zhudong.nay.redhat.com> <20130915084811.GA10163@netboy> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130915084811.GA10163@netboy> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3234 Lines: 115 Hi Richard, Thanks for your comments, I modified the patch and resubmit it again: >From 7636f69b74c34eca14c85fd2d518da6044b94f53 Mon Sep 17 00:00:00 2001 From: Dong Zhu Date: Sun, 15 Sep 2013 17:12:52 +0800 This patch add a method into testptp.c to measure the time offset between phc and system clock through the ioctl PTP_SYS_OFFSET. Signed-off-by: Dong Zhu --- Documentation/ptp/testptp.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/Documentation/ptp/testptp.c b/Documentation/ptp/testptp.c index f59ded0..b6f6f47 100644 --- a/Documentation/ptp/testptp.c +++ b/Documentation/ptp/testptp.c @@ -112,6 +112,8 @@ static void usage(char *progname) " -f val adjust the ptp clock frequency by 'val' ppb\n" " -g get the ptp clock time\n" " -h prints this message\n" + " -k val measure the time offset between phc and system clock\n" + " for 'val' times (Maximum 25)\n" " -p val enable output with a period of 'val' nanoseconds\n" " -P val enable or disable (val=1|0) the system clock PPS\n" " -s set the ptp clock time from the system time\n" @@ -133,8 +135,12 @@ int main(int argc, char *argv[]) struct itimerspec timeout; struct sigevent sigevent; + struct ptp_clock_time *pct; + struct ptp_sys_offset *sysoff; + + char *progname; - int c, cnt, fd; + int i, c, cnt, fd; char *device = DEVICE; clockid_t clkid; @@ -144,6 +150,8 @@ int main(int argc, char *argv[]) int extts = 0; int gettime = 0; int oneshot = 0; + int offset = 0; + int n_samples = 0; int periodic = 0; int perout = -1; int pps = -1; @@ -151,7 +159,7 @@ int main(int argc, char *argv[]) progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; - while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghp:P:sSt:v"))) { + while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghk:p:P:sSt:v"))) { switch (c) { case 'a': oneshot = atoi(optarg); @@ -174,6 +182,10 @@ int main(int argc, char *argv[]) case 'g': gettime = 1; break; + case 'k': + offset = 1; + n_samples = atoi(optarg); + break; case 'p': perout = atoi(optarg); break; @@ -376,6 +388,30 @@ int main(int argc, char *argv[]) } } + if (offset) { + sysoff = calloc(1, sizeof(*sysoff)); + if (!sysoff) { + perror("calloc"); + return -1; + } + sysoff->n_samples = n_samples; + + if (ioctl(fd, PTP_SYS_OFFSET, sysoff)) + perror("PTP_SYS_OFFSET"); + else + puts("phc and system clock time offset request okay"); + + pct = &sysoff->ts[0]; + for (i = 0; i < sysoff->n_samples; i++, pct++) { + printf("system time: %ld.%ld\n", pct->sec, pct->nsec); + pct++; + printf("phc time: %ld.%ld\n", pct->sec, pct->nsec); + } + printf("system time: %ld.%ld\n", pct->sec, pct->nsec); + + free(sysoff); + } + close(fd); return 0; } -- 1.7.11.7 -- Best Regards, Dong Zhu -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/