selftests/ptp: Add support for new timestamp IOCTLs
Subsystems (3)
v2 cover selftests/ptp: Add support for new timestamp IOCTLs
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.
Changes in v2:
- Fixed rebase issues (v1 somehow ended up with patch 1 being from the first manual split of my changes and patch 2 being from rebase 2 out of 3)
- Rebased on top of net-next
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 | 73 ++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED
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.
--- tools/testing/selftests/ptp/testptp.c | 44 +++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-)
tools/testing/selftests/ptp/testptp.c +42 -2
@@ -143,8 +143,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[])
@@ -158,6 +159,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;
@@ -176,6 +178,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 ;
@@ -190,7 +193,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:z" ))) { +while (EOF != (c =getopt (argc, argv,"cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:z" ))) {switch (c) {case 'c' : capabilities =1 ;
@@ -255,6 +258,15 @@ 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 ;
@@ -535,6 +547,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 ; }
Signature · 1 line
2.25.1
PATCH v2 2/2 selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE
In reply to Alex MafteiThe -X option was chosen because X looks like a cross, and the underlying callback is 'get cross timestamp'.
--- tools/testing/selftests/ptp/testptp.c | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
tools/testing/selftests/ptp/testptp.c +30 -1
@@ -144,6 +144,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); }
@@ -160,6 +161,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;
@@ -179,6 +181,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 ;
@@ -193,7 +196,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:z" ))) { +while (EOF != (c =getopt (argc, argv,"cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz" ))) {switch (c) {case 'c' : capabilities =1 ;
@@ -267,6 +270,9 @@ int main(int argc, char *argv[])return -1 ; }break ; +case 'X' : + getcross =1 ; +break ;case 'z' : flagtest =1 ;break ;
@@ -575,6 +581,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 ; }
Signature · 1 line
2.25.1
Quoted 14 lines · Alex Maftei
PTP_SYS_OFFSET_EXTENDEDwas added in November 2018 in361800876f80(" ptp: addPTP_SYS_OFFSET_EXTENDEDioctl")
andPTP_SYS_OFFSET_PRECISEwas added in February 2016 in719f1aa4a671("ptp: AddPTP_SYS_OFFSET_PRECISEfor driver crosstimestamping")The PTP selftest code is lacking support for these two IOCTLS. This short series of patches adds support for them.
Changes in v2:
- Fixed rebase issues (v1 somehow ended up with patch 1 being from the first manual split of my changes and patch 2 being from rebase 2 out of 3)
- Rebased on top of net-next
Quoted 6 lines
Alex Maftei (2):
selftests/ptp: Add -x option for testingPTP_SYS_OFFSET_EXTENDEDselftests/ptp: Add -X option for testingPTP_SYS_OFFSET_PRECISEtools/testing/selftests/ptp/testptp.c | 73 ++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-)
For the series:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 9 lines · On Tue, 25 Jul 2023 22:53:32 +0100 you wrote:
PTP_SYS_OFFSET_EXTENDEDwas added in November 2018 in361800876f80(" ptp: addPTP_SYS_OFFSET_EXTENDEDioctl")
andPTP_SYS_OFFSET_PRECISEwas added in February 2016 in719f1aa4a671("ptp: AddPTP_SYS_OFFSET_PRECISEfor driver crosstimestamping")The PTP selftest code is lacking support for these two IOCTLS. This short series of patches adds support for them.
[...]
Here is the summary with links:
- [net-next,v2,1/2] selftests/ptp: Add -x option for testing PTP_SYS_OFFSET_EXTENDED
https://git.kernel.org/netdev/net-next/c/c8ba75c4eb84 - [net-next,v2,2/2] selftests/ptp: Add -X option for testing PTP_SYS_OFFSET_PRECISE https://git.kernel.org/netdev/net-next/c/3cf119ad5dc2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html