All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs
@ 2023-06-16 22:48 Alex Maftei
  2023-06-16 22:48 ` [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED Alex Maftei
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Alex Maftei @ 2023-06-16 22:48 UTC (permalink / raw)
  To: richardcochran, shuah; +Cc: Alex Maftei, linux-kselftest, linux-kernel, netdev

PTP_SYS_OFFSET_EXTENDED was added in November 2018 in
361800876f80 (" ptp: add PTP_SYS_OFFSET_EXTENDED ioctl")
and PTP_SYS_OFFSET_PRECISE was added in February 2016 in
719f1aa4a671 ("ptp: Add PTP_SYS_OFFSET_PRECISE for driver crosstimestamping")

The PTP selftest code is lacking support for these two IOCTLS.
This short series of patches adds support for them.

Alex Maftei (2):
  selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED
  selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE

 tools/testing/selftests/ptp/testptp.c | 71 ++++++++++++++++++++++++++-
 1 file changed, 69 insertions(+), 2 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED
  2023-06-16 22:48 [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs Alex Maftei
@ 2023-06-16 22:48 ` Alex Maftei
  2023-06-19  9:39   ` Horatiu Vultur
  2023-06-19  9:46   ` Maftei, Alex
  2023-06-16 22:48 ` [PATCH net 2/2] selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE Alex Maftei
  2023-06-17  0:58 ` [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs Richard Cochran
  2 siblings, 2 replies; 8+ messages in thread
From: Alex Maftei @ 2023-06-16 22:48 UTC (permalink / raw)
  To: richardcochran, shuah; +Cc: Alex Maftei, linux-kselftest, linux-kernel, netdev

The -x option (where 'x' stands for eXtended) takes an argument which
represents the number of samples to request from the PTP device.
The help message will display the maximum number of samples allowed.
Providing an invalid argument will also display the maximum number of
samples allowed.

Signed-off-by: Alex Maftei <alex.maftei@amd.com>
---
 tools/testing/selftests/ptp/testptp.c | 42 +++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
index cfa9562f3cd8..2a99973ffc1b 100644
--- a/tools/testing/selftests/ptp/testptp.c
+++ b/tools/testing/selftests/ptp/testptp.c
@@ -142,8 +142,9 @@ static void usage(char *progname)
 		" -S         set the system time from the ptp clock time\n"
 		" -t val     shift the ptp clock time by 'val' seconds\n"
 		" -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"
 		" -z         test combinations of rising/falling external time stamp flags\n",
-		progname);
+		progname, PTP_MAX_SAMPLES);
 }
 
 int main(int argc, char *argv[])
@@ -157,6 +158,7 @@ int main(int argc, char *argv[])
 	struct timex tx;
 	struct ptp_clock_time *pct;
 	struct ptp_sys_offset *sysoff;
+	struct ptp_sys_offset_extended *soe;
 
 	char *progname;
 	unsigned int i;
@@ -174,6 +176,7 @@ int main(int argc, char *argv[])
 	int index = 0;
 	int list_pins = 0;
 	int pct_offset = 0;
+	int getextended = 0;
 	int n_samples = 0;
 	int pin_index = -1, pin_func;
 	int pps = -1;
@@ -188,7 +191,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:p:P:sSt:T:w:z"))) {
+	while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:p:P:sSt:T:w:x:Xz"))) {
 		switch (c) {
 		case 'c':
 			capabilities = 1;
@@ -250,6 +253,13 @@ int main(int argc, char *argv[])
 		case 'w':
 			pulsewidth = atoi(optarg);
 			break;
+		case 'x':
+			getextended = atoi(optarg);
+			if (getextended < 1 || getextended > PTP_MAX_SAMPLES) {
+				fprintf(stderr, "number of extended timestamp samples must be between 1 and %d; was asked for %d\n", PTP_MAX_SAMPLES, getextended);
+				return -1;
+			}
+			break;
 		case 'z':
 			flagtest = 1;
 			break;
@@ -516,6 +526,34 @@ int main(int argc, char *argv[])
 		free(sysoff);
 	}
 
+	if (getextended) {
+		soe = calloc(1, sizeof(*soe));
+		if (!soe) {
+			perror("calloc");
+			return -1;
+		}
+
+		soe->n_samples = getextended;
+
+		if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, soe))
+			perror("PTP_SYS_OFFSET_EXTENDED");
+		else {
+			printf("extended timestamp request returned %d samples\n",
+				getextended);
+
+			for (i = 0; i < getextended; i++) {
+				printf("sample #%2d: system time before: %lld.%09u\n",
+				i, soe->ts[i][0].sec, soe->ts[i][0].nsec);
+				printf("            phc time: %lld.%09u\n",
+				soe->ts[i][1].sec, soe->ts[i][1].nsec);
+				printf("            system time after: %lld.%09u\n",
+				soe->ts[i][2].sec, soe->ts[i][2].nsec);
+			}
+		}
+
+		free(soe);
+	}
+
 	close(fd);
 	return 0;
 }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net 2/2] selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE
  2023-06-16 22:48 [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs Alex Maftei
  2023-06-16 22:48 ` [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED Alex Maftei
@ 2023-06-16 22:48 ` Alex Maftei
  2023-06-17  0:58 ` [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs Richard Cochran
  2 siblings, 0 replies; 8+ messages in thread
From: Alex Maftei @ 2023-06-16 22:48 UTC (permalink / raw)
  To: richardcochran, shuah; +Cc: Alex Maftei, linux-kselftest, linux-kernel, netdev

The -X option was chosen because X looks like a cross, and the underlying
callback is 'get cross timestamp'.

Signed-off-by: Alex Maftei <alex.maftei@amd.com>
---
 tools/testing/selftests/ptp/testptp.c | 29 +++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
index 2a99973ffc1b..6ab5836b53ff 100644
--- a/tools/testing/selftests/ptp/testptp.c
+++ b/tools/testing/selftests/ptp/testptp.c
@@ -143,6 +143,7 @@ static void usage(char *progname)
 		" -t val     shift the ptp clock time by 'val' seconds\n"
 		" -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"
 		" -z         test combinations of rising/falling external time stamp flags\n",
 		progname, PTP_MAX_SAMPLES);
 }
@@ -159,6 +160,7 @@ int main(int argc, char *argv[])
 	struct ptp_clock_time *pct;
 	struct ptp_sys_offset *sysoff;
 	struct ptp_sys_offset_extended *soe;
+	struct ptp_sys_offset_precise *xts;
 
 	char *progname;
 	unsigned int i;
@@ -177,6 +179,7 @@ int main(int argc, char *argv[])
 	int list_pins = 0;
 	int pct_offset = 0;
 	int getextended = 0;
+	int getcross = 0;
 	int n_samples = 0;
 	int pin_index = -1, pin_func;
 	int pps = -1;
@@ -260,6 +263,9 @@ int main(int argc, char *argv[])
 				return -1;
 			}
 			break;
+		case 'X':
+			getcross = 1;
+			break;
 		case 'z':
 			flagtest = 1;
 			break;
@@ -554,6 +560,29 @@ int main(int argc, char *argv[])
 		free(soe);
 	}
 
+	if (getcross) {
+		xts = calloc(1, sizeof(*xts));
+		if (!xts) {
+			perror("calloc");
+			return -1;
+		}
+
+		if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, xts))
+			perror("PTP_SYS_OFFSET_PRECISE");
+		else {
+			puts("system and phc crosstimestamping request okay");
+
+			printf("device time: %lld.%09u\n",
+			       xts->device.sec, xts->device.nsec);
+			printf("system time: %lld.%09u\n",
+			       xts->sys_realtime.sec, xts->sys_realtime.nsec);
+			printf("monoraw time: %lld.%09u\n",
+			       xts->sys_monoraw.sec, xts->sys_monoraw.nsec);
+		}
+
+		free(xts);
+	}
+
 	close(fd);
 	return 0;
 }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs
  2023-06-16 22:48 [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs Alex Maftei
  2023-06-16 22:48 ` [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED Alex Maftei
  2023-06-16 22:48 ` [PATCH net 2/2] selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE Alex Maftei
@ 2023-06-17  0:58 ` Richard Cochran
  2 siblings, 0 replies; 8+ messages in thread
From: Richard Cochran @ 2023-06-17  0:58 UTC (permalink / raw)
  To: Alex Maftei; +Cc: shuah, linux-kselftest, linux-kernel, netdev

On Fri, Jun 16, 2023 at 11:48:43PM +0100, Alex Maftei wrote:
> PTP_SYS_OFFSET_EXTENDED was added in November 2018 in
> 361800876f80 (" ptp: add PTP_SYS_OFFSET_EXTENDED ioctl")
> and PTP_SYS_OFFSET_PRECISE was added in February 2016 in
> 719f1aa4a671 ("ptp: Add PTP_SYS_OFFSET_PRECISE for driver crosstimestamping")
> 
> The PTP selftest code is lacking support for these two IOCTLS.
> This short series of patches adds support for them.

This is new functionality, so the target branch should be net-next.

Thanks,
Richard



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED
  2023-06-16 22:48 ` [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED Alex Maftei
@ 2023-06-19  9:39   ` Horatiu Vultur
  2023-06-19  9:48     ` Maftei, Alex
  2023-06-19  9:46   ` Maftei, Alex
  1 sibling, 1 reply; 8+ messages in thread
From: Horatiu Vultur @ 2023-06-19  9:39 UTC (permalink / raw)
  To: Alex Maftei; +Cc: richardcochran, shuah, linux-kselftest, linux-kernel, netdev

The 06/16/2023 23:48, Alex Maftei wrote:

Hi Alex,

As I can see you will need to send another patch, I have just a small
comment bellow.


> The -x option (where 'x' stands for eXtended) takes an argument which
> represents the number of samples to request from the PTP device.
> The help message will display the maximum number of samples allowed.
> Providing an invalid argument will also display the maximum number of
> samples allowed.
> 
> Signed-off-by: Alex Maftei <alex.maftei@amd.com>
> ---
>  tools/testing/selftests/ptp/testptp.c | 42 +++++++++++++++++++++++++--
>  1 file changed, 40 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
> index cfa9562f3cd8..2a99973ffc1b 100644
> --- a/tools/testing/selftests/ptp/testptp.c
> +++ b/tools/testing/selftests/ptp/testptp.c
> @@ -142,8 +142,9 @@ static void usage(char *progname)
>                 " -S         set the system time from the ptp clock time\n"
>                 " -t val     shift the ptp clock time by 'val' seconds\n"
>                 " -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"
>                 " -z         test combinations of rising/falling external time stamp flags\n",
> -               progname);
> +               progname, PTP_MAX_SAMPLES);
>  }
> 
>  int main(int argc, char *argv[])
> @@ -157,6 +158,7 @@ int main(int argc, char *argv[])
>         struct timex tx;
>         struct ptp_clock_time *pct;
>         struct ptp_sys_offset *sysoff;
> +       struct ptp_sys_offset_extended *soe;
> 
>         char *progname;
>         unsigned int i;
> @@ -174,6 +176,7 @@ int main(int argc, char *argv[])
>         int index = 0;
>         int list_pins = 0;
>         int pct_offset = 0;
> +       int getextended = 0;
>         int n_samples = 0;
>         int pin_index = -1, pin_func;
>         int pps = -1;
> @@ -188,7 +191,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:p:P:sSt:T:w:z"))) {
> +       while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:p:P:sSt:T:w:x:Xz"))) {

The 'X' needs to be part of the next patch, as you introduce here only 'x'.

>                 switch (c) {
>                 case 'c':
>                         capabilities = 1;
> @@ -250,6 +253,13 @@ int main(int argc, char *argv[])
>                 case 'w':
>                         pulsewidth = atoi(optarg);
>                         break;
> +               case 'x':
> +                       getextended = atoi(optarg);
> +                       if (getextended < 1 || getextended > PTP_MAX_SAMPLES) {
> +                               fprintf(stderr, "number of extended timestamp samples must be between 1 and %d; was asked for %d\n", PTP_MAX_SAMPLES, getextended);
> +                               return -1;
> +                       }
> +                       break;
>                 case 'z':
>                         flagtest = 1;
>                         break;
> @@ -516,6 +526,34 @@ int main(int argc, char *argv[])
>                 free(sysoff);
>         }
> 
> +       if (getextended) {
> +               soe = calloc(1, sizeof(*soe));
> +               if (!soe) {
> +                       perror("calloc");
> +                       return -1;
> +               }
> +
> +               soe->n_samples = getextended;
> +
> +               if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, soe))
> +                       perror("PTP_SYS_OFFSET_EXTENDED");
> +               else {
> +                       printf("extended timestamp request returned %d samples\n",
> +                               getextended);
> +
> +                       for (i = 0; i < getextended; i++) {
> +                               printf("sample #%2d: system time before: %lld.%09u\n",
> +                               i, soe->ts[i][0].sec, soe->ts[i][0].nsec);
> +                               printf("            phc time: %lld.%09u\n",
> +                               soe->ts[i][1].sec, soe->ts[i][1].nsec);
> +                               printf("            system time after: %lld.%09u\n",
> +                               soe->ts[i][2].sec, soe->ts[i][2].nsec);
> +                       }
> +               }
> +
> +               free(soe);
> +       }
> +
>         close(fd);
>         return 0;
>  }
> --
> 2.28.0
> 
> 

-- 
/Horatiu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED
  2023-06-16 22:48 ` [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED Alex Maftei
  2023-06-19  9:39   ` Horatiu Vultur
@ 2023-06-19  9:46   ` Maftei, Alex
  2023-06-20 16:42     ` Jakub Kicinski
  1 sibling, 1 reply; 8+ messages in thread
From: Maftei, Alex @ 2023-06-19  9:46 UTC (permalink / raw)
  To: richardcochran, shuah; +Cc: linux-kselftest, linux-kernel, netdev

I see I've accidentally sent an older revision of the patch series, before I've rebased properly and before I used checkpatch.
I will send the fixed one (and to the correct tree this time) in a v2 series.
Replying to the first patch because the cover letter did not land in my inbox, somehow.
I hope this is the right thing to add:
--
pw-bot: cr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED
  2023-06-19  9:39   ` Horatiu Vultur
@ 2023-06-19  9:48     ` Maftei, Alex
  0 siblings, 0 replies; 8+ messages in thread
From: Maftei, Alex @ 2023-06-19  9:48 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: richardcochran, shuah, linux-kselftest, linux-kernel, netdev

Hi Horatiu,

v2 of the series will have that fixed.
I've accidentally sent an older revision of this patch series, before I've rebased the changes properly.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED
  2023-06-19  9:46   ` Maftei, Alex
@ 2023-06-20 16:42     ` Jakub Kicinski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2023-06-20 16:42 UTC (permalink / raw)
  To: Maftei, Alex; +Cc: richardcochran, shuah, linux-kselftest, linux-kernel, netdev

On Mon, 19 Jun 2023 09:46:33 +0000 Maftei, Alex wrote:
> I see I've accidentally sent an older revision of the patch series, before I've rebased properly and before I used checkpatch.
> I will send the fixed one (and to the correct tree this time) in a v2 series.
> Replying to the first patch because the cover letter did not land in my inbox, somehow.
> I hope this is the right thing to add:
> --
> pw-bot: cr

Eh, didn't work, the bot does a simple == comparison:

https://github.com/kuba-moo/nipa/blob/master/mailbot.py#L294

so "Maftei, Alex" <alex.maftei@amd.com>
vs Alex Maftei <alex.maftei@amd.com>

won't match.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-06-20 16:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 22:48 [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs Alex Maftei
2023-06-16 22:48 ` [PATCH net 1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED Alex Maftei
2023-06-19  9:39   ` Horatiu Vultur
2023-06-19  9:48     ` Maftei, Alex
2023-06-19  9:46   ` Maftei, Alex
2023-06-20 16:42     ` Jakub Kicinski
2023-06-16 22:48 ` [PATCH net 2/2] selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE Alex Maftei
2023-06-17  0:58 ` [PATCH net 0/2] selftests/ptp: Add support for new timestamp IOCTLs Richard Cochran

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.