* [PATCH net-next] testptp: add option to shift clock by nanoseconds
@ 2022-02-21 20:06 Maciek Machnikowski
2022-02-22 0:09 ` Richard Cochran
2022-02-23 1:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Maciek Machnikowski @ 2022-02-21 20:06 UTC (permalink / raw)
To: netdev; +Cc: richardcochran
Add option to shift the clock by a specified number of nanoseconds.
The new argument -n will specify the number of nanoseconds to add to the
ptp clock. Since the API doesn't support negative shifts those needs to
be calculated by subtracting full seconds and adding a nanosecond offset.
Signed-off-by: Maciek Machnikowski <maciek@machnikowski.net>
---
tools/testing/selftests/ptp/testptp.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
index c0f6a062364d..198ad5f32187 100644
--- a/tools/testing/selftests/ptp/testptp.c
+++ b/tools/testing/selftests/ptp/testptp.c
@@ -133,6 +133,7 @@ static void usage(char *progname)
" 0 - none\n"
" 1 - external time stamp\n"
" 2 - periodic output\n"
+ " -n val shift the ptp clock time by 'val' nanoseconds\n"
" -p val enable output with a period of 'val' nanoseconds\n"
" -H val set output phase to 'val' nanoseconds (requires -p)\n"
" -w val set output pulse width to 'val' nanoseconds (requires -p)\n"
@@ -165,6 +166,7 @@ int main(int argc, char *argv[])
clockid_t clkid;
int adjfreq = 0x7fffffff;
int adjtime = 0;
+ int adjns = 0;
int capabilities = 0;
int extts = 0;
int flagtest = 0;
@@ -186,7 +188,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: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:z"))) {
switch (c) {
case 'c':
capabilities = 1;
@@ -223,6 +225,9 @@ int main(int argc, char *argv[])
return -1;
}
break;
+ case 'n':
+ adjns = atoi(optarg);
+ break;
case 'p':
perout = atoll(optarg);
break;
@@ -305,11 +310,16 @@ int main(int argc, char *argv[])
}
}
- if (adjtime) {
+ if (adjtime || adjns) {
memset(&tx, 0, sizeof(tx));
- tx.modes = ADJ_SETOFFSET;
+ tx.modes = ADJ_SETOFFSET | ADJ_NANO;
tx.time.tv_sec = adjtime;
- tx.time.tv_usec = 0;
+ tx.time.tv_usec = adjns;
+ while (tx.time.tv_usec < 0) {
+ tx.time.tv_sec -= 1;
+ tx.time.tv_usec += 1000000000;
+ }
+
if (clock_adjtime(clkid, &tx) < 0) {
perror("clock_adjtime");
} else {
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] testptp: add option to shift clock by nanoseconds
2022-02-21 20:06 [PATCH net-next] testptp: add option to shift clock by nanoseconds Maciek Machnikowski
@ 2022-02-22 0:09 ` Richard Cochran
2022-02-23 1:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Richard Cochran @ 2022-02-22 0:09 UTC (permalink / raw)
To: Maciek Machnikowski; +Cc: netdev
On Mon, Feb 21, 2022 at 09:06:37PM +0100, Maciek Machnikowski wrote:
> Add option to shift the clock by a specified number of nanoseconds.
>
> The new argument -n will specify the number of nanoseconds to add to the
> ptp clock. Since the API doesn't support negative shifts those needs to
> be calculated by subtracting full seconds and adding a nanosecond offset.
>
> Signed-off-by: Maciek Machnikowski <maciek@machnikowski.net>
Acked-by: Richard Cochran <richardcochran@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] testptp: add option to shift clock by nanoseconds
2022-02-21 20:06 [PATCH net-next] testptp: add option to shift clock by nanoseconds Maciek Machnikowski
2022-02-22 0:09 ` Richard Cochran
@ 2022-02-23 1:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-23 1:10 UTC (permalink / raw)
To: Maciek Machnikowski; +Cc: netdev, richardcochran
Hello:
This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 21 Feb 2022 21:06:37 +0100 you wrote:
> Add option to shift the clock by a specified number of nanoseconds.
>
> The new argument -n will specify the number of nanoseconds to add to the
> ptp clock. Since the API doesn't support negative shifts those needs to
> be calculated by subtracting full seconds and adding a nanosecond offset.
>
> Signed-off-by: Maciek Machnikowski <maciek@machnikowski.net>
>
> [...]
Here is the summary with links:
- [net-next] testptp: add option to shift clock by nanoseconds
https://git.kernel.org/netdev/net-next/c/f64ae40de5ef
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-23 1:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-21 20:06 [PATCH net-next] testptp: add option to shift clock by nanoseconds Maciek Machnikowski
2022-02-22 0:09 ` Richard Cochran
2022-02-23 1:10 ` patchwork-bot+netdevbpf
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).