๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7552

Re: [PATCH net v5 3/5] ptp: vclock: propagate physical clock sampling errors

#7552
From: netdev-bot+sashiko
Date: Mon, 26 Oct 2026 15:53
114 lines
12022 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The exponential retry backoff added to ptp_vclock_refresh() in
  drivers/ptp/ptp_vclock.c only looks at the previous retry delay.

--

ptp: vclock: propagate physical clock sampling errors

This patch caches a successful parent PHC sample before timecounter
operations. Read failures are now returned to callers instead of being
consumed as a zero sample. It also adds a refresh retry that starts at
10 ms and doubles on consecutive failures, up to the normal two second
interval, and makes ptp_vclock_register() return error pointers.

> diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c
> index 84cb527f59ccc..c10eba6443f9a 100644
> --- a/drivers/ptp/ptp_vclock.c
> +++ b/drivers/ptp/ptp_vclock.c

[ ... ]

> @@ -13,6 +14,7 @@
>  #define PTP_VCLOCK_FADJ_SHIFT		9
>  #define PTP_VCLOCK_FADJ_DENOMINATOR	15625ULL
>  #define PTP_VCLOCK_REFRESH_INTERVAL	(HZ * 2)
> +#define PTP_VCLOCK_RETRY_INTERVAL		msecs_to_jiffies(10)

[ ... ]

> @@ -151,8 +175,18 @@ static long ptp_vclock_refresh(struct ptp_clock_info *ptp)
>  	struct ptp_vclock *vclock = info_to_vclock(ptp);
>  	struct timespec64 ts;
>  
> -	ptp_vclock_gettime(&vclock->info, &ts);
> +	/* Retry transient failures promptly, but back off during long outages. */
> +	if (ptp_vclock_gettime(&vclock->info, &ts)) {
> +		if (!vclock->retry_delay)
> +			vclock->retry_delay = PTP_VCLOCK_RETRY_INTERVAL;
> +		else
> +			vclock->retry_delay = min_t(unsigned long,
> +						    vclock->retry_delay * 2,
> +						    PTP_VCLOCK_REFRESH_INTERVAL);
> +		return vclock->retry_delay;
> +	}

[Severity: Medium]
Can this backoff skip past the 32-bit counter wrap and lose a full wrap
of virtual time?

The doubling only looks at the previous retry_delay. It does not look at
how long ago the last successful parent sample was taken. The
cyclecounter uses CYCLECOUNTER_MASK(32), so it wraps every 2^32 ns,
about 4.295 s.

Suppose the last good refresh was at t0 and getcycles64() starts failing
at the regular t0+2 s refresh. The retries then run at about:

  t0+2.010, 2.030, 2.070, 2.150, 2.310, 2.630, 3.270 s

After that the delay becomes 1280 ms, so the next attempt is at about
t0+4.550 s. At HZ=250, msecs_to_jiffies(10) rounds up to 12 ms, and the
last two attempts are at 3.524 s and 5.060 s.

If the outage ends anywhere between about 3.27 s and 4.295 s, the first
successful sample still comes more than 2^32 ns after cycle_last.
timecounter_read_delta() then masks the delta:

kernel/time/timecounter.c:timecounter_read_delta() {
    ...
	cycle_delta = (cycle_now - tc->cycle_last) & tc->cc->mask;
    ...
}

As a result, tc->nsec moves forward about 0.255 s instead of about
4.55 s. The virtual clock silently steps back by about 4.295 s, and no
error is returned.

A fixed 2 s refresh would have retried at t0+4.0 s and kept the wrap.
The commit message says:

    An isolated read failure
    should not deliberately defer the next attempt until that sample is four
    seconds old.

Here the backoff delays the next attempt until the sample is about
4.55 s old, after an outage of only about 1.3 to 2.3 s.

The later patches in this series do not change ptp_vclock_refresh(), so
this looks like it is still present at the end of the series.

Could the code record jiffies at the last successful sample and clamp
the returned delay? The next attempt would then land before
last_success + 2^32 ns, and preferably before the half-wrap point.

>  
> +	vclock->retry_delay = 0;
>  	return PTP_VCLOCK_REFRESH_INTERVAL;
>  }

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261022-ptp-vclock-sampling-v5-0-06ceace17bac%40gmail.com
Technical Details
Message-ID: <179303002839.3134.5595255852218546734@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351981-linux-kernel-netdev=dewy.ru
References: <20261022-ptp-vclock-sampling-v5-3-06ceace17bac@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351981-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v5 3/5] ptp: vclock: propagate physical clock sampling errors
Date: Mon, 26 Oct 2026 15:53:48 +0000
Organization: Usenet Network
Message-ID: <179303002839.3134.5595255852218546734@kernel.org>
References: <20261022-ptp-vclock-sampling-v5-3-06ceace17bac@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1342821"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/8aJIFNOnglXKB8P7uopFBQ2wJA= sha256:33NC2PXnTyaRDs5Q93D7jbS8A84+rkbhkGmS9iaKU04=
	sha1:zjhr5g3aq0QmVZeiaIQ93D3SBGw= sha256:cyaAaupsO2YV+cxLtDX/H8ThYipq5JiBwELNKE7Y/D8=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 051E4125BAF; Mon, 26 Oct 2026 18:59:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.738
X-Spam-Status: No, score=-3.738 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id JCVP3YlHNBnY;
	Mon, 26 Oct 2026 18:59:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351981-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 7B7DD125BAD; Mon, 26 Oct 2026 18:59:29 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 46197241AF; Mon, 26 Oct 2026 15:53:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793030036;
	b=cpwuK+bdZoHo6ZFAUKwli1T6dCiLDMymuSctgNsYzvHakyBJSL3vHgIMfqtMgdVlpmbS
	 N/TEnfaYGcive9p8EhC/DXFmpXGJ6mqPIekMV109kIq+uQy5gv8CONJSN6cy4nbwqCq8m
	 jYTj/jK/mOItlxC6sREfa69m26iGlmBXTusSfaRwiLDhCzg9XDEYLLEDSjX/tHATuzNjf
	 9lq0UakQq4pYBMDD+VUYZjI4UQb0L6gLs+VoWza9bFm4NYW36Baf4dMWXNTo3g2Zr56Ae
	 LtP2mXJ1P5ao/Zom49bOP2+j/87TT3TY0X0/oeJJjlWu4I79y01IJ+bVftOVFD8zN9A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793030036;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=2svq3CU+h/wjTBe/BPU6GyHCrFin2y9txfqrV1ibhEY=;
	b=V3OEmPqMTEk5njDPRCYstgVRp/bEF/SGXGj6dwhlX40NdJpPN7qo6HKeKr4u1HI/MsRT
	 FibATadxaJrT8CzAQ/7Z3mGGzrOljbszmfGF4OoHYhGVfR3QnnVR/QhZ5LgBDLJAv9R09
	 OsLj+nTvQZr/6oxDM/UK+lbSmRHGv5ROhAmDU3VqBqs+HY0u6r8ST9eI3X8SbWoEmirxb
	 oyS02w4GzjXDSiWYghZ0o6i/m8hpor4oxQh3NWCWMF94bwaJF8hnYQu7rt2rS0tVA1EkK
	 +xikU67sVH46SOJh8Ij5DIxduoibAZlPjzEmQkxLHLk+csLgS7RrRiQqZwpBdtGRErA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lkbbGEzY;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C4A8606A322;
	Mon, 26 Oct 2026 15:53:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lkbbGEzY
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793030030;
	b=lJzRq2kM2HpdLW77CbYk/5mvobviyDdA+lBCHUfN5j/YUxnOwbfPcvegi2PngKEqerdq
	 Rk1+uHXmis5fbwJVGk0tMFXjfpbEHroQTDDxDVzIMLvr7q0mPQ2tcReZ00kcWynMlG8OL
	 xAHKRSY1HZdJ22gP45nt718HhXXX4kUQ6XcfI33c5oXSh3BhJRknCBwYtH2JcFweTdlav
	 Soxwy1EVqHKPcMDvqvhJhT5XUb76TmX7pYG671/llsaEawTgzeV/ZD/00+WeqaBt/C3o4
	 JQrlR2bExXAFqXyvhQnw3xbaoo7SSYOa3ag0daLgzyy8+VI8749Qsbu1nrd5K/bwWNA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793030030;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=2svq3CU+h/wjTBe/BPU6GyHCrFin2y9txfqrV1ibhEY=;
	b=gl/sMuTGINun0WDSVm79KONwrAuvo/4Q6LoBq0GswffbblM743IuPAPrOnWvWQ5mMGYM
	 gnxQZ8DBmdwBPL9eH/CWVaalY48acpBR1KRl1ENfavtvmrG8GRg5SOLUDhg1H0KyIMBLf
	 SnYT5WRgAcfBkXvzutsi1PfpERqV35/MMRFxmDAFf0gXpiwS4m2TmzdBmbMey/rbbuTNo
	 TiYRyBBs7pg7deorkSK4+fpLhjbpisb8fWC4jH1DC6SEmyE5Bo+KJJstTku3/HLC+Xmt4
	 Hgnquu+5gDOl87CKJ2tYT261tt3d0CXlOdLzLrV47gYA7CpZ57ZyfOmHw4Z2mQ0+uLA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lkbbGEzY;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFA0E606A31A;
	Mon, 26 Oct 2026 15:53:49 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E834C1F031E2;
	Mon, 26 Oct 2026 15:53:48 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793030029;
	bh=2svq3CU+h/wjTBe/BPU6GyHCrFin2y9txfqrV1ibhEY=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=lkbbGEzY0sWtN+8n+j35aa/SbQxM2MqaScZT0XIFmKcUpanNPgCNaCoyJf3JFzarg
	 SOf8KKn31Bmt5vL35tcI8t7u5UN3TRTSauZrpPUSJhHliBcVmQPOPLeDDIqtuZ3gIx
	 YEvf/7oab6POZGn/53cw7tRGXCkc9GY8Muh5ZK37CUkgSRHCphWVGJdhG4TR+6xX9j
	 mQnrprEWUq++Qg4RW2Gj+ASPDzCefOtGgNqz2wNf3y7dRJITIcJJoq3ZN0gaM1o0YH
	 wI4KxxYvY4pMXsaeL/x9De2dj0kziLBpMxQ1DpFxKexV7Eyi9dIKGicU/WgnKHZ5WM
	 /ALj7KXDIH9cw==
X-Cc: netdev@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org,
 richardcochran@gmail.com, andrew+netdev@lunn.ch, yangbo.lu@nxp.com,
 mlichvar@redhat.com, edumazet@kernel.org, davem@davemloft.net,
 linux-kernel@vger.kernel.org, vadim.fedorenko@linux.dev
X-In-Reply-To: <20261022-ptp-vclock-sampling-v5-3-06ceace17bac@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list