* [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix
@ 2022-02-02 9:33 Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 1/4] ptp: unregister virtual clocks when unregistering physical clock Miroslav Lichvar
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Miroslav Lichvar @ 2022-02-02 9:33 UTC (permalink / raw)
To: netdev; +Cc: Miroslav Lichvar
v2:
- dropped patch changing initial time of virtual clocks
The first patch fixes an oops when unloading a driver with PTP clock and
enabled virtual clocks.
The other patches add missing features to make synchronization with
virtual clocks work as well as with the physical clock.
Miroslav Lichvar (4):
ptp: unregister virtual clocks when unregistering physical clock.
ptp: increase maximum adjustment of virtual clocks.
ptp: add gettimex64() to virtual clocks.
ptp: add getcrosststamp() to virtual clocks.
drivers/ptp/ptp_clock.c | 11 ++++++--
drivers/ptp/ptp_vclock.c | 56 +++++++++++++++++++++++++++++++++++++---
2 files changed, 62 insertions(+), 5 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCHv2 net-next 1/4] ptp: unregister virtual clocks when unregistering physical clock.
2022-02-02 9:33 [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix Miroslav Lichvar
@ 2022-02-02 9:33 ` Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 2/4] ptp: increase maximum adjustment of virtual clocks Miroslav Lichvar
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Miroslav Lichvar @ 2022-02-02 9:33 UTC (permalink / raw)
To: netdev; +Cc: Miroslav Lichvar, Richard Cochran, Yangbo Lu, Yang Yingliang
When unregistering a physical clock which has some virtual clocks,
unregister the virtual clocks with it.
This fixes the following oops, which can be triggered by unloading
a driver providing a PTP clock when it has enabled virtual clocks:
BUG: unable to handle page fault for address: ffffffffc04fc4d8
Oops: 0000 [#1] PREEMPT SMP NOPTI
RIP: 0010:ptp_vclock_read+0x31/0xb0
Call Trace:
timecounter_read+0xf/0x50
ptp_vclock_refresh+0x2c/0x50
? ptp_clock_release+0x40/0x40
ptp_aux_kworker+0x17/0x30
kthread_worker_fn+0x9b/0x240
? kthread_should_park+0x30/0x30
kthread+0xe2/0x110
? kthread_complete_and_exit+0x20/0x20
ret_from_fork+0x22/0x30
Fixes: 73f37068d540 ("ptp: support ptp physical/virtual clocks conversion")
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Cc: Yangbo Lu <yangbo.lu@nxp.com>
Cc: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/ptp/ptp_clock.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 0e4bc8b9329d..b6f2cfd15dd2 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -317,11 +317,18 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
}
EXPORT_SYMBOL(ptp_clock_register);
+static int unregister_vclock(struct device *dev, void *data)
+{
+ struct ptp_clock *ptp = dev_get_drvdata(dev);
+
+ ptp_vclock_unregister(info_to_vclock(ptp->info));
+ return 0;
+}
+
int ptp_clock_unregister(struct ptp_clock *ptp)
{
if (ptp_vclock_in_use(ptp)) {
- pr_err("ptp: virtual clock in use\n");
- return -EBUSY;
+ device_for_each_child(&ptp->dev, NULL, unregister_vclock);
}
ptp->defunct = 1;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCHv2 net-next 2/4] ptp: increase maximum adjustment of virtual clocks.
2022-02-02 9:33 [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 1/4] ptp: unregister virtual clocks when unregistering physical clock Miroslav Lichvar
@ 2022-02-02 9:33 ` Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 3/4] ptp: add gettimex64() to " Miroslav Lichvar
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Miroslav Lichvar @ 2022-02-02 9:33 UTC (permalink / raw)
To: netdev; +Cc: Miroslav Lichvar, Richard Cochran, Yangbo Lu
Increase the maximum frequency offset of virtual clocks to 50% to enable
faster slewing corrections.
This value cannot be represented as scaled ppm when long has 32 bits,
but that is already the case for other drivers, even those that provide
the adjfine() function, i.e. 32-bit applications are expected to check
for the limit.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Cc: Yangbo Lu <yangbo.lu@nxp.com>
---
drivers/ptp/ptp_vclock.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c
index ab1d233173e1..5aa2b32d9dc7 100644
--- a/drivers/ptp/ptp_vclock.c
+++ b/drivers/ptp/ptp_vclock.c
@@ -84,8 +84,7 @@ static long ptp_vclock_refresh(struct ptp_clock_info *ptp)
static const struct ptp_clock_info ptp_vclock_info = {
.owner = THIS_MODULE,
.name = "ptp virtual clock",
- /* The maximum ppb value that long scaled_ppm can support */
- .max_adj = 32767999,
+ .max_adj = 500000000,
.adjfine = ptp_vclock_adjfine,
.adjtime = ptp_vclock_adjtime,
.gettime64 = ptp_vclock_gettime,
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCHv2 net-next 3/4] ptp: add gettimex64() to virtual clocks.
2022-02-02 9:33 [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 1/4] ptp: unregister virtual clocks when unregistering physical clock Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 2/4] ptp: increase maximum adjustment of virtual clocks Miroslav Lichvar
@ 2022-02-02 9:33 ` Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 4/4] ptp: add getcrosststamp() " Miroslav Lichvar
2022-02-03 14:10 ` [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: Miroslav Lichvar @ 2022-02-02 9:33 UTC (permalink / raw)
To: netdev; +Cc: Miroslav Lichvar, Richard Cochran, Yangbo Lu
If the physical clock has the gettimex64() function, provide a
gettimex64() wrapper in the virtual clock to enable more accurate
and stable synchronization.
This adds support for the PTP_SYS_OFFSET_EXTENDED ioctl.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Cc: Yangbo Lu <yangbo.lu@nxp.com>
---
drivers/ptp/ptp_vclock.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c
index 5aa2b32d9dc7..2f0b46386176 100644
--- a/drivers/ptp/ptp_vclock.c
+++ b/drivers/ptp/ptp_vclock.c
@@ -57,6 +57,30 @@ static int ptp_vclock_gettime(struct ptp_clock_info *ptp,
return 0;
}
+static int ptp_vclock_gettimex(struct ptp_clock_info *ptp,
+ struct timespec64 *ts,
+ struct ptp_system_timestamp *sts)
+{
+ struct ptp_vclock *vclock = info_to_vclock(ptp);
+ struct ptp_clock *pptp = vclock->pclock;
+ struct timespec64 pts;
+ unsigned long flags;
+ int err;
+ u64 ns;
+
+ err = pptp->info->gettimex64(pptp->info, &pts, sts);
+ if (err)
+ return err;
+
+ spin_lock_irqsave(&vclock->lock, flags);
+ ns = timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts));
+ spin_unlock_irqrestore(&vclock->lock, flags);
+
+ *ts = ns_to_timespec64(ns);
+
+ return 0;
+}
+
static int ptp_vclock_settime(struct ptp_clock_info *ptp,
const struct timespec64 *ts)
{
@@ -87,7 +111,6 @@ static const struct ptp_clock_info ptp_vclock_info = {
.max_adj = 500000000,
.adjfine = ptp_vclock_adjfine,
.adjtime = ptp_vclock_adjtime,
- .gettime64 = ptp_vclock_gettime,
.settime64 = ptp_vclock_settime,
.do_aux_work = ptp_vclock_refresh,
};
@@ -123,6 +146,10 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock)
vclock->pclock = pclock;
vclock->info = ptp_vclock_info;
+ if (pclock->info->gettimex64)
+ vclock->info.gettimex64 = ptp_vclock_gettimex;
+ else
+ vclock->info.gettime64 = ptp_vclock_gettime;
vclock->cc = ptp_vclock_cc;
snprintf(vclock->info.name, PTP_CLOCK_NAME_LEN, "ptp%d_virt",
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCHv2 net-next 4/4] ptp: add getcrosststamp() to virtual clocks.
2022-02-02 9:33 [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix Miroslav Lichvar
` (2 preceding siblings ...)
2022-02-02 9:33 ` [PATCHv2 net-next 3/4] ptp: add gettimex64() to " Miroslav Lichvar
@ 2022-02-02 9:33 ` Miroslav Lichvar
2022-02-03 14:10 ` [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: Miroslav Lichvar @ 2022-02-02 9:33 UTC (permalink / raw)
To: netdev; +Cc: Miroslav Lichvar, Richard Cochran, Yangbo Lu
If the physical clock supports cross timestamping (it has the
getcrosststamp() function), provide a wrapper in the virtual clock to
enable cross timestamping.
This adds support for the PTP_SYS_OFFSET_PRECISE ioctl.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Cc: Yangbo Lu <yangbo.lu@nxp.com>
---
drivers/ptp/ptp_vclock.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c
index 2f0b46386176..cb179a3ea508 100644
--- a/drivers/ptp/ptp_vclock.c
+++ b/drivers/ptp/ptp_vclock.c
@@ -95,6 +95,28 @@ static int ptp_vclock_settime(struct ptp_clock_info *ptp,
return 0;
}
+static int ptp_vclock_getcrosststamp(struct ptp_clock_info *ptp,
+ struct system_device_crosststamp *xtstamp)
+{
+ struct ptp_vclock *vclock = info_to_vclock(ptp);
+ struct ptp_clock *pptp = vclock->pclock;
+ unsigned long flags;
+ int err;
+ u64 ns;
+
+ err = pptp->info->getcrosststamp(pptp->info, xtstamp);
+ if (err)
+ return err;
+
+ spin_lock_irqsave(&vclock->lock, flags);
+ ns = timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device));
+ spin_unlock_irqrestore(&vclock->lock, flags);
+
+ xtstamp->device = ns_to_ktime(ns);
+
+ return 0;
+}
+
static long ptp_vclock_refresh(struct ptp_clock_info *ptp)
{
struct ptp_vclock *vclock = info_to_vclock(ptp);
@@ -150,6 +172,8 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock)
vclock->info.gettimex64 = ptp_vclock_gettimex;
else
vclock->info.gettime64 = ptp_vclock_gettime;
+ if (pclock->info->getcrosststamp)
+ vclock->info.getcrosststamp = ptp_vclock_getcrosststamp;
vclock->cc = ptp_vclock_cc;
snprintf(vclock->info.name, PTP_CLOCK_NAME_LEN, "ptp%d_virt",
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix
2022-02-02 9:33 [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix Miroslav Lichvar
` (3 preceding siblings ...)
2022-02-02 9:33 ` [PATCHv2 net-next 4/4] ptp: add getcrosststamp() " Miroslav Lichvar
@ 2022-02-03 14:10 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-03 14:10 UTC (permalink / raw)
To: Miroslav Lichvar; +Cc: netdev
Hello:
This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:
On Wed, 2 Feb 2022 10:33:54 +0100 you wrote:
> v2:
> - dropped patch changing initial time of virtual clocks
>
> The first patch fixes an oops when unloading a driver with PTP clock and
> enabled virtual clocks.
>
> The other patches add missing features to make synchronization with
> virtual clocks work as well as with the physical clock.
>
> [...]
Here is the summary with links:
- [PATCHv2,net-next,1/4] ptp: unregister virtual clocks when unregistering physical clock.
https://git.kernel.org/netdev/net-next/c/bfcbb76b0f59
- [PATCHv2,net-next,2/4] ptp: increase maximum adjustment of virtual clocks.
https://git.kernel.org/netdev/net-next/c/f77222d693cc
- [PATCHv2,net-next,3/4] ptp: add gettimex64() to virtual clocks.
https://git.kernel.org/netdev/net-next/c/f0067ebfc42b
- [PATCHv2,net-next,4/4] ptp: add getcrosststamp() to virtual clocks.
https://git.kernel.org/netdev/net-next/c/21fad63084c2
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] 6+ messages in thread
end of thread, other threads:[~2022-02-03 14:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-02 9:33 [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 1/4] ptp: unregister virtual clocks when unregistering physical clock Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 2/4] ptp: increase maximum adjustment of virtual clocks Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 3/4] ptp: add gettimex64() to " Miroslav Lichvar
2022-02-02 9:33 ` [PATCHv2 net-next 4/4] ptp: add getcrosststamp() " Miroslav Lichvar
2022-02-03 14:10 ` [PATCHv2 net-next 0/4] Virtual PTP clock improvements and fix 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).