From: Ivan Vecera <ivecera@redhat.com>
To: Vadim Fedorenko <vadim.fedorenko@linux.dev>, netdev@vger.kernel.org
Cc: Petr Oros <poros@redhat.com>,
Chris du Quesnay <Chris.duQuesnay@microchip.com>,
Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>,
Jakub Kicinski <kuba@kernel.org>, Jiri Pirko <jiri@resnulli.us>,
Min Li <min.li@microchip.com>, Paolo Abeni <pabeni@redhat.com>,
Richard Cochran <richardcochran@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v7 2/3] dpll: zl3073x: add channel ToD, phase step and TIE operations
Date: Fri, 14 Aug 2026 10:07:08 +0200 [thread overview]
Message-ID: <49dd691c-088f-41f9-8334-a6319096caed@redhat.com> (raw)
In-Reply-To: <dfbb7647-8c39-4620-9eb6-74d84b066f19@linux.dev>
On 8/13/26 11:21 PM, Vadim Fedorenko wrote:
> On 11/08/2026 14:46, Ivan Vecera wrote:
>
> [...]
>
>> + * zl3073x_chan_tod_adjust - atomic ToD read-modify-write with
>> rollover guard
>> + * @zldev: pointer to zl3073x device
>> + * @ch: DPLL channel index
>> + * @delta: time adjustment to apply
>> + *
>> + * Reads the next-Hz ToD and current ToD, then checks whether enough
>> time
>> + * remains before the next 1 Hz rollover to safely complete the write.
>> + * Re-reads if the 1 Hz tick crossed between the two reads or if less
>> + * than 20 ms remains before the next rollover. Applies @delta and
>> writes
>> + * the result back.
>
> you keep 20ms threshold based on the avg read/write transaction time (I
> assume), but it may happen, that this call will be preempted in between
> reads and write, and 20ms will not be enough before 1Hz rollover. Have
> you though about such option?
Yes, this is a possibility. The 20 ms threshold provides margin for
the write sequence (ready-wait + three register writes + command)
which normally completes in single-digit milliseconds, but a
scheduling delay could consume the remaining margin.
If that happens, the hardware applies the written value at the
following 1 Hz edge instead of the intended one, resulting in a
1 second ToD offset. The PTP servo detects and corrects this in the
next cycle. There is no atomic ToD update command in the hardware,
so this trade-off is inherent to the device's register interface.
I tried to run 1000x times loop with comparing jiffies after ToD read
and after ToD write. The testptp that adjusted ToD has been pinned to
single CPU and parallel stress CPU program on the same CPU during
testing. The average time for write-tod operation was 9ms with maximum
of 10ms.
>
>> + *
>> + * Context: Caller must serialize all zl3073x_chan_tod_* calls
>> externally.
>> + * Return: 0 on success, <0 on error
>> + */
>> +int zl3073x_chan_tod_adjust(struct zl3073x_dev *zldev, u8 ch,
>> + struct timespec64 delta)
>> +{
>> +#define ZL_TOD_MAX_RETRIES 20
>> + static const long threshold_ns = 20 * NSEC_PER_MSEC;
>> + struct timespec64 ts_next, ts_cur, diff;
>> + int rc, i;
>> +
>> + for (i = 0; i < ZL_TOD_MAX_RETRIES; i++) {
>> + rc = zl3073x_chan_tod_read(zldev, ch, true, &ts_next, NULL);
>> + if (rc)
>> + return rc;
>> +
>> + rc = zl3073x_chan_tod_read(zldev, ch, false, &ts_cur, NULL);
>> + if (rc)
>> + return rc;
>> +
>> + /* Ensure the 1 Hz tick did not cross between the two reads
>> + * and that enough margin remains to complete the write.
>> + */
>> + diff = timespec64_sub(ts_next, ts_cur);
>> + if (diff.tv_sec > 0 ||
>> + (!diff.tv_sec && diff.tv_nsec >= threshold_ns))
>> + break;
>> + }
>> + if (i == ZL_TOD_MAX_RETRIES) {
>> + dev_warn(zldev->dev,
>> + "DPLL%u ToD adjust failed to get stable margin\n",
>> + ch);
>> + return -EBUSY;
>> + }
>> +
>> + /* Apply delta to the next-Hz ToD */
>> + ts_next = timespec64_add(ts_next, delta);
>> + if (!timespec64_valid(&ts_next))
>
> maybe timespec64_valid_settod() will be better as the code is about
> modifying ToD?
Good point. Will switch to timespec64_valid_settod() in v8.
Ivan
next prev parent reply other threads:[~2026-08-14 8:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 13:46 [PATCH net-next v7 0/3] dpll: zl3073x: add PTP clock support Ivan Vecera
2026-08-11 13:46 ` [PATCH net-next v7 1/3] dpll: zl3073x: scale poll interval proportionally to timeout Ivan Vecera
2026-08-12 10:05 ` Vadim Fedorenko
2026-08-11 13:46 ` [PATCH net-next v7 2/3] dpll: zl3073x: add channel ToD, phase step and TIE operations Ivan Vecera
2026-08-12 6:57 ` Ivan Vecera
2026-08-12 10:04 ` Vadim Fedorenko
2026-08-12 11:00 ` Ivan Vecera
2026-08-13 20:38 ` Vadim Fedorenko
2026-08-13 20:51 ` Ivan Vecera
2026-08-13 20:57 ` Vadim Fedorenko
2026-08-13 21:21 ` Vadim Fedorenko
2026-08-14 8:07 ` Ivan Vecera [this message]
2026-08-11 13:47 ` [PATCH net-next v7 3/3] dpll: zl3073x: add PTP clock support Ivan Vecera
2026-08-12 6:58 ` Ivan Vecera
2026-08-13 21:31 ` Vadim Fedorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49dd691c-088f-41f9-8334-a6319096caed@redhat.com \
--to=ivecera@redhat.com \
--cc=Chris.duQuesnay@microchip.com \
--cc=arkadiusz.kubalewski@intel.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=min.li@microchip.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=poros@redhat.com \
--cc=richardcochran@gmail.com \
--cc=vadim.fedorenko@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox