From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 117343D9029 for ; Thu, 13 Aug 2026 21:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786656124; cv=none; b=Kbcgqgb+5FG4cdz4EGaXYLKAYSSU3R8Dx1uQqumfjuGk4QXE3SypyZCRMIFB8LDfjSG+wHplz0VKYdx2sCvuUfhmL7D8Oi36J825pcuch3Q3BESs5S0qaJ4GNUdBTCLGJeqAFggQlRchgjsB1wtBPeNCKF+5v6BkMnZ+mxGICOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786656124; c=relaxed/simple; bh=ItWFzxV4XvwvnuvE0xfB+o8XfGydReax69cRxpasOvU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OlblbUHusyDvD/TttoWxjcQWwvOZOKByBBrd2Vn4dlQfXKdPwxzUA2gVm/yIHUGCH/Arv2SkoM+gtFn5HRdzGBIxL7TZ0h0jrSD4+SQo/Gir+r4O1PbpsaRy2cgr3qoan5ev0SeARDXlbrjUFszuEzQCFwyY8GYWnQgDoq46KgY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Toq/J8fB; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Toq/J8fB" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ItWFzxV4XvwvnuvE0xfB+o8XfGydReax69cRxpasOvU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786656117; v=1; x=1787260917; b=Toq/J8fBL4CgtqOE8Y74/bSM+teg3t6JQBi/AfiJqEM7xg/lAehYbHX+Do1ufCp7rYryvFWC xFMnwaJEpF0xTc1u7X5n5QKGufAh853y2lHnV5ziqVnuCa4MvajtTp1VFUbTeUgWiY2QovMh1v3 nkS67OApQzsmj/FJBVSHpSTk= X-Envelope-To: linux-kernel@vger.kernel.org Received: from [192.168.1.24] (64.43.42.247) by smtp.migadu.com with ESMTPS id cf8d6393399d12c1; Thu, 13 Aug 2026 21:21:57 +0000 X-Migadu-Flow: FLOW_OUT Message-ID: Date: Thu, 13 Aug 2026 22:21:56 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v7 2/3] dpll: zl3073x: add channel ToD, phase step and TIE operations To: Ivan Vecera , netdev@vger.kernel.org Cc: Petr Oros , Chris du Quesnay , Arkadiusz Kubalewski , Jakub Kicinski , Jiri Pirko , Min Li , Paolo Abeni , Richard Cochran , linux-kernel@vger.kernel.org References: <20260811134700.1211010-1-ivecera@redhat.com> <20260811134700.1211010-3-ivecera@redhat.com> Content-Language: en-US From: Vadim Fedorenko In-Reply-To: <20260811134700.1211010-3-ivecera@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 > +}