From: Mahesh Bandewar <maheshb@google.com>
To: Netdev <netdev@vger.kernel.org>,
Linux <linux-kernel@vger.kernel.org>,
David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>, Don Hatchett <hatch@google.com>,
Yuliang Li <yuliangli@google.com>,
Mahesh Bandewar <mahesh@bandewar.net>,
Mahesh Bandewar <maheshb@google.com>,
Shuah Khan <shuah@kernel.org>,
Richard Cochran <richardcochran@gmail.com>,
Rahul Rameshbabu <rrameshbabu@nvidia.com>,
linux-kselftest@vger.kernel.org
Subject: [PATCH 4/4] selftes/ptp: extend test to include ptp_gettimex64any()
Date: Thu, 28 Sep 2023 19:37:46 -0700 [thread overview]
Message-ID: <20230929023746.1611832-1-maheshb@google.com> (raw)
add -y/-Y options to support PTP_SYS_OFFSET_ANY2 op. where -y represents
samples to collect while -Y is to choose the timebase from available
options of cycles, real, mono, or raw.
Signed-off-by: Mahesh Bandewar <maheshb@google.com>
CC: Shuah Khan <shuah@kernel.org>
CC: Richard Cochran <richardcochran@gmail.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: Rahul Rameshbabu <rrameshbabu@nvidia.com>
CC: Jakub Kicinski <kuba@kernel.org>
CC: linux-kselftest@vger.kernel.org
CC: netdev@vger.kernel.org
---
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/ptp/testptp.c | 79 ++++++++++++++++++++++++++-
2 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 42806add0114..c5e59cfc9830 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -66,6 +66,7 @@ TARGETS += powerpc
TARGETS += prctl
TARGETS += proc
TARGETS += pstore
+TARGETS += ptp
TARGETS += ptrace
TARGETS += openat2
TARGETS += resctrl
diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
index c9f6cca4feb4..7000caa39ede 100644
--- a/tools/testing/selftests/ptp/testptp.c
+++ b/tools/testing/selftests/ptp/testptp.c
@@ -37,6 +37,13 @@
#define NSEC_PER_SEC 1000000000LL
+static char *time_base_arr[PTP_TS_MAX] = {
+ "cycles",
+ "system time",
+ "monotonic time",
+ "raw-monotonic time",
+};
+
/* clock_adjtime is not available in GLIBC < 2.14 */
#if !__GLIBC_PREREQ(2, 14)
#include <sys/syscall.h>
@@ -145,8 +152,10 @@ static void usage(char *progname)
" -T val set the ptp clock time to 'val' seconds\n"
" -x val get an extended ptp clock time with the desired number of samples (up to %d)\n"
" -X get a ptp clock cross timestamp\n"
+ " -y val get an extended-any ptp clock time with the desired number of samples (up to %d) with given time-base for sandwich (with -Y opt)\n"
+ " -Y val sandwich timebase to use {cycles|real|mono|raw}\n"
" -z test combinations of rising/falling external time stamp flags\n",
- progname, PTP_MAX_SAMPLES);
+ progname, PTP_MAX_SAMPLES, PTP_MAX_SAMPLES);
}
int main(int argc, char *argv[])
@@ -162,6 +171,7 @@ int main(int argc, char *argv[])
struct ptp_sys_offset *sysoff;
struct ptp_sys_offset_extended *soe;
struct ptp_sys_offset_precise *xts;
+ struct ptp_sys_offset_any *ats;
char *progname;
unsigned int i;
@@ -182,6 +192,8 @@ int main(int argc, char *argv[])
int pct_offset = 0;
int getextended = 0;
int getcross = 0;
+ int get_ext_any = 0;
+ int ext_any_type = -1;
int n_samples = 0;
int pin_index = -1, pin_func;
int pps = -1;
@@ -196,7 +208,7 @@ int main(int argc, char *argv[])
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
- while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) {
+ while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xy:Y:z"))) {
switch (c) {
case 'c':
capabilities = 1;
@@ -273,6 +285,31 @@ int main(int argc, char *argv[])
case 'X':
getcross = 1;
break;
+ case 'y':
+ get_ext_any = atoi(optarg);
+ if (get_ext_any < 1 || get_ext_any > PTP_MAX_SAMPLES) {
+ fprintf(stderr,
+ "number of extended-any timestamp samples must be between 1 and %d; was asked for %d\n",
+ PTP_MAX_SAMPLES, get_ext_any);
+ return -1;
+ }
+ break;
+ case 'Y':
+ if (!strcasecmp(optarg, "cycles"))
+ ext_any_type = PTP_TS_CYCLES;
+ else if (!strcasecmp(optarg, "real"))
+ ext_any_type = PTP_TS_REAL;
+ else if (!strcasecmp(optarg, "mono"))
+ ext_any_type = PTP_TS_MONO;
+ else if (!strcasecmp(optarg, "raw"))
+ ext_any_type = PTP_TS_RAW;
+ else {
+ fprintf(stderr,
+ "type needs to be one of cycles,real,mono,raw only; was given %s\n",
+ optarg);
+ return -1;
+ }
+ break;
case 'z':
flagtest = 1;
break;
@@ -286,6 +323,14 @@ int main(int argc, char *argv[])
}
}
+ /* For ptp_sys_offset_any both options 'y' and 'Y' must be given */
+ if (get_ext_any > 0 && ext_any_type == -1) {
+ fprintf(stderr,
+ "For extended-any TS both options -y, and -Y are required.\n");
+ usage(progname);
+ return -1;
+ }
+
fd = open(device, O_RDWR);
if (fd < 0) {
fprintf(stderr, "opening %s: %s\n", device, strerror(errno));
@@ -604,6 +649,36 @@ int main(int argc, char *argv[])
free(xts);
}
+ if (get_ext_any) {
+ ats = calloc(1, sizeof(*ats));
+ if (!ats) {
+ perror("calloc");
+ return -1;
+ }
+
+ ats->n_samples = get_ext_any;
+ ats->ts_type = ext_any_type;
+
+ if (ioctl(fd, PTP_SYS_OFFSET_ANY2, ats)) {
+ perror("PTP_SYS_OFFSET_ANY2");
+ } else {
+ printf("extended-any timestamp request returned %d samples\n",
+ get_ext_any);
+
+ for (i = 0; i < get_ext_any; i++) {
+ printf("sample #%2d: %s before: %lld.%09u\n",
+ i, time_base_arr[ext_any_type],
+ ats->ts[i][0].sec, ats->ts[i][0].nsec);
+ printf(" phc time: %lld.%09u\n",
+ ats->ts[i][1].sec, ats->ts[i][1].nsec);
+ printf(" %s after: %lld.%09u\n",
+ time_base_arr[ext_any_type],
+ ats->ts[i][2].sec, ats->ts[i][2].nsec);
+ }
+ }
+
+ free(ats);
+ }
close(fd);
return 0;
}
--
2.42.0.582.g8ccd20d70d-goog
reply other threads:[~2023-09-29 2:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230929023746.1611832-1-maheshb@google.com \
--to=maheshb@google.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hatch@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mahesh@bandewar.net \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=rrameshbabu@nvidia.com \
--cc=shuah@kernel.org \
--cc=yuliangli@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).