diff mbox series

[3/3] package: linuxptp: workaround for system crash if PHY is not initialized

Message ID 1517155221-19399-3-git-send-email-brain@jikos.cz
State Changes Requested
Headers show
Series [1/3] package: linuxptp: bump to the latest GIT version | expand

Commit Message

Petr Kulhavy Jan. 28, 2018, 4 p.m. UTC
On some systems (tested on i.MX6 with Freescale kernel 4.1) the system freezes
if phc2sys starts before the PHY is initialized (phc2sys opens /dev/ptp0).

Unfortunately systemd network.target does not guarantee the PHY to be initialized.
This workaround pulls in the network-online.target dependency, which postpones
the phc2sys start after the link is up.

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
---
 package/linuxptp/linuxptp-system-clock.service | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Thomas Petazzoni Jan. 30, 2018, 10:01 p.m. UTC | #1
Hello,

On Sun, 28 Jan 2018 17:00:21 +0100, Petr Kulhavy wrote:
> On some systems (tested on i.MX6 with Freescale kernel 4.1) the system freezes
> if phc2sys starts before the PHY is initialized (phc2sys opens /dev/ptp0).
> 
> Unfortunately systemd network.target does not guarantee the PHY to be initialized.
> This workaround pulls in the network-online.target dependency, which postpones
> the phc2sys start after the link is up.
> 
> Signed-off-by: Petr Kulhavy <brain@jikos.cz>

Do we really want to workaround this, which appears to be a kernel
problem?

> +# workaround for crashing Freescale PHY if initialized after /dev/ptp0 is open
> +After=network-online.target
> +Wants=network-online.target

Does it make sense to have After and Wants set to the same value ? Are
both really needed ?

(Again: I don't know much about systemd, so don't hesitate to teach me
even the basics!)

Thomas
Petr Kulhavy Jan. 30, 2018, 10:14 p.m. UTC | #2
Hi Thomas,

most likely I will post another patch for this as I have modified the 
service file even further.
In the newer version both come after network-online.target because I 
noticed ptp4l fails to execute some ioctl if started too early. This 
causes that it doesn't start syncing.

I'm not very happy with the network-online.target either, because it 
literally waits for the network to come up. Which makes some sense - PTP 
needs a peer - however systemd documentation indicates this is not the 
most reliable way to solve missing network and recommends to write 
robust programs which can wait for network.
And in the end neither ptp4l or phc2sys need the network to be up. They 
both just need the kernel to finish the initialization (which is not the 
same as network up). Unfortunately systemd doesn't provide such target :(

I'm also not an expert in systemd. These changes are base on my 
self-education. So a real systemd expert would be appreciated.

Petr

On 30/01/18 23:01, Thomas Petazzoni wrote:
> Hello,
>
> On Sun, 28 Jan 2018 17:00:21 +0100, Petr Kulhavy wrote:
>> On some systems (tested on i.MX6 with Freescale kernel 4.1) the system freezes
>> if phc2sys starts before the PHY is initialized (phc2sys opens /dev/ptp0).
>>
>> Unfortunately systemd network.target does not guarantee the PHY to be initialized.
>> This workaround pulls in the network-online.target dependency, which postpones
>> the phc2sys start after the link is up.
>>
>> Signed-off-by: Petr Kulhavy <brain@jikos.cz>
> Do we really want to workaround this, which appears to be a kernel
> problem?
>
>> +# workaround for crashing Freescale PHY if initialized after /dev/ptp0 is open
>> +After=network-online.target
>> +Wants=network-online.target
> Does it make sense to have After and Wants set to the same value ? Are
> both really needed ?
>
> (Again: I don't know much about systemd, so don't hesitate to teach me
> even the basics!)
>
> Thomas
Arnout Vandecappelle Oct. 21, 2018, 10:12 p.m. UTC | #3
On 30/01/2018 22:14, Petr Kulhavy wrote:
> Hi Thomas,
>
> most likely I will post another patch for this as I have modified the service
> file even further.
> In the newer version both come after network-online.target because I noticed
> ptp4l fails to execute some ioctl if started too early. This causes that it
> doesn't start syncing.

 This looks to me like something that should be fixed in ptp4l itself. Like, if
you are running ptp4l on a removable device, you have to wait for the device to
be available. Or alternatively, trigger the service on the availability of the
device (i.e. start it from udev). Though honestly I have no idea of how to do
that properly from systemd.

 Anyway, since you said that you have an improved patch lined up, I've marked
this one as Changes Requested in patchwork.


 Regards,
 Arnout


>
> I'm not very happy with the network-online.target either, because it literally
> waits for the network to come up. Which makes some sense - PTP needs a peer -
> however systemd documentation indicates this is not the most reliable way to
> solve missing network and recommends to write robust programs which can wait
> for network.
> And in the end neither ptp4l or phc2sys need the network to be up. They both
> just need the kernel to finish the initialization (which is not the same as
> network up). Unfortunately systemd doesn't provide such target :(
>
> I'm also not an expert in systemd. These changes are base on my
> self-education. So a real systemd expert would be appreciated.
>
> Petr
>
> On 30/01/18 23:01, Thomas Petazzoni wrote:
>> Hello,
>>
>> On Sun, 28 Jan 2018 17:00:21 +0100, Petr Kulhavy wrote:
>>> On some systems (tested on i.MX6 with Freescale kernel 4.1) the system freezes
>>> if phc2sys starts before the PHY is initialized (phc2sys opens /dev/ptp0).
>>>
>>> Unfortunately systemd network.target does not guarantee the PHY to be
>>> initialized.
>>> This workaround pulls in the network-online.target dependency, which postpones
>>> the phc2sys start after the link is up.
>>>
>>> Signed-off-by: Petr Kulhavy <brain@jikos.cz>
>> Do we really want to workaround this, which appears to be a kernel
>> problem?
>>
>>> +# workaround for crashing Freescale PHY if initialized after /dev/ptp0 is open
>>> +After=network-online.target
>>> +Wants=network-online.target
>> Does it make sense to have After and Wants set to the same value ? Are
>> both really needed ?
>>
>> (Again: I don't know much about systemd, so don't hesitate to teach me
>> even the basics!)
>>
>> Thomas
>
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
>
diff mbox series

Patch

diff --git a/package/linuxptp/linuxptp-system-clock.service b/package/linuxptp/linuxptp-system-clock.service
index a4436a3..0c73983 100644
--- a/package/linuxptp/linuxptp-system-clock.service
+++ b/package/linuxptp/linuxptp-system-clock.service
@@ -2,6 +2,10 @@ 
 Description=Precision Time Protocol system clock synchronization
 After=linuxptp.service
 
+# workaround for crashing Freescale PHY if initialized after /dev/ptp0 is open
+After=network-online.target
+Wants=network-online.target
+
 [Service]
 ExecStart=/usr/sbin/phc2sys -s /dev/ptp0 -c CLOCK_REALTIME -w -S 1.0
 Restart=always