From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Ivan Vecera <ivecera@redhat.com>, 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: Thu, 13 Aug 2026 22:21:56 +0100 [thread overview]
Message-ID: <dfbb7647-8c39-4620-9eb6-74d84b066f19@linux.dev> (raw)
In-Reply-To: <20260811134700.1211010-3-ivecera@redhat.com>
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?
> + *
> + * 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?
> + return -EINVAL;
> +
> + return zl3073x_chan_tod_write(zldev, ch, ts_next);
> +#undef ZL_TOD_MAX_RETRIES
> +}
next prev parent reply other threads:[~2026-08-13 21:22 UTC|newest]
Thread overview: 14+ 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 [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=dfbb7647-8c39-4620-9eb6-74d84b066f19@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=Chris.duQuesnay@microchip.com \
--cc=arkadiusz.kubalewski@intel.com \
--cc=ivecera@redhat.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 \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.