From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796120893; b=wLxoz/AGS9Uxpt7TRfUgPbrFlsJ7+5nq/xNlG1oxjyuUIZSFJ9V/X1Sk6fB61fyDUDnH dIAH80TOp9kK6Ds/WEQR57anP7L0lJ6Cd3Ls3Mk8rhlGwjCUvQP7ADlnvF4Gc2B2WngrO PI4ci7fIeVNpiXEk4hc7avntmMNw5lJFPgDCtusfHFelkuGihegbXXx41A1tqUzvRWCok wXzw0scfZYvVUQjN+hXGLnwtJekqk/wxS77EtFT1CojI/3+xaqzV5JcxgGcV0s6dDO8L3 3mVe3/fGatqrF1eBq30Wo8SbDOBqRyFaA5ZMSGxqUf5uoc7hZEk/Qi4Cfmp/nejXASw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796120893; h=DMARC-Filter:Date:DKIM-Signature:DKIM-Signature:From:Sender:Reply-to: To:Subject:Cc:In-Reply-To:References:MIME-Version:Message-ID:Robot-ID: Robot-Unsubscribe:Precedence:Content-Type:Content-Transfer-Encoding; bh=sqLUCtFnKM6BDv8DeAa5WfyOpIUAtiBOig78nTnkodA=; b=0/W0/FeplZJrrPesbiekbmgKVFy8+ppJbHNhUkYhl5HtsJ8P4XJM0OEpKoRHNtqHHT0R rFq133Cs5z6OsaT6QBJg1CwOGeWFlfPm+Rc9/Z5Axgufqt2zBCXCJN89jvOiJi+56DPku nrEOg7QXt38k0JWGh/N4YNFMOlGUgTdMm9GJ8gXos+DNC+N6Mnimdaz+W74ZT1aRFtwmz zU94Dx88yiEWs+UZkAMI5LJvNMTjmlYPiNW6yOvI8Euao5uufXkSrk3AEkpSqwnbwAWsV jwRYZ7pigCFlScseSIQbFT7R6iqEMViS5smNsJyRWONJlNmfcowTHfodMNQSlp5inOQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b="mq6h/tQw"; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b="Hbo/ceTn"; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EA0D606A33B for ; Tue, 1 Dec 2026 10:28:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6EA0D606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=mq6h/tQw; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=Hbo/ceTn Date: Tue, 01 Dec 2026 10:28:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1796120891; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqLUCtFnKM6BDv8DeAa5WfyOpIUAtiBOig78nTnkodA=; b=mq6h/tQwUgCF2eFRITybHTJXRwY4QhLS8x685pLzK2Cc5YQ+r+iQ6fVJFYnkqn10hHU5vk 4pgY79RORQ9WhR0gDz016ifYWkmo0fx0DeXQ1f+w4Ps2MiQfsn/gN5j6M3MQJPbp2auC66 eCm/0wDTQZTNwVYzqPMToWpUEc9jxnuOEaE/OqGm3JVsB3EgGu/+aVCBiLI+SGPkWSwySH UB1l2VrMmvuTtgJp4yXARp7OOuAgsYTD5/CFr3Y+LnKkjudnH8FVeVhtcoJS7qWzNjIrqR g8v8hXt9KgQNsIIz6/UiJQ7gKK1OmbVUk1MLicqzdmyHvveqv9MlAp3SHxOhxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1796120891; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqLUCtFnKM6BDv8DeAa5WfyOpIUAtiBOig78nTnkodA=; b=Hbo/ceTncocC+qO+un605thqKKBJ6ThY5PI2Pt6hQbV8uv7wtKdgHQqtdyNj9yXnrY3/3+ WSC6BBr7BB/N6gAQ== From: "clocksource-bot for Enric Balletbo i Serra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-kernel@vger.kernel.org Subject: [clocksource: timers/drivers/next] clocksource/drivers/nxp-stm: Fix overshoot detection in set_next_event Cc: Enric Balletbo i Serra , Daniel Lezcano , Khristine Andreea Barbulescu In-Reply-To: <20261105-nxp-stm-fixes-v3-2-8129b912e74b@redhat.com> References: <20261105-nxp-stm-fixes-v3-2-8129b912e74b@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-ID: <179612088997.1190409.1331824630064367447.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the timers/drivers/next branch of c= locksource: Commit-ID: 73cf416dfa871feb9621564eae62315482e836ba Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/daniel.lezcano= /linux.git//73cf416dfa871feb9621564eae62315482e836ba Author: Enric Balletbo i Serra AuthorDate: Thu, 05 Nov 2026 09:18:33 +01:00 Committer: Daniel Lezcano CommitterDate: Tue, 01 Dec 2026 11:11:07 +01:00 clocksource/drivers/nxp-stm: Fix overshoot detection in set_next_event The existing overshoot check effectively compares two counter readings and only triggers on a counter wraparound between reads; the normal case where the counter advances past the programmed value during the read/write sequence is not detected. Replace it with the approach of hpet_clkevt_set_next_event(): read the counter after the comparator write and return -ETIME when less than STM_MIN_CYCLES remain until the match. Derive the minimum programming delta from that margin. See the cover letter for the measurement procedure and constant derivation. Fixes: cec32ac75827 ("clocksource/drivers/nxp-timer: Add the System Timer Mod= ule for the s32gx platforms") Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Enric Balletbo i Serra Signed-off-by: Daniel Lezcano Tested-by: Khristine Andreea Barbulescu Link: https://patch.msgid.link/20261105-nxp-stm-fixes-v3-2-8129b912e74b@redha= t.com --- drivers/clocksource/timer-nxp-stm.c | 53 ++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/drivers/clocksource/timer-nxp-stm.c b/drivers/clocksource/timer-= nxp-stm.c index 87ae0ae..36b0a11 100644 --- a/drivers/clocksource/timer-nxp-stm.c +++ b/drivers/clocksource/timer-nxp-stm.c @@ -20,7 +20,6 @@ #include #include #include -#include =20 #define STM_CR(__base) (__base) =20 @@ -52,6 +51,17 @@ =20 #define STM_ENABLE_MASK (STM_CR_FRZ | STM_CR_TEN) =20 +/* + * The comparator fires only on an exact match with the counter. + * STM_MIN_CYCLES is the post-write overshoot margin used by + * nxp_stm_clockevent_set_next_event(), following the same approach + * as hpet_clkevt_set_next_event(). STM_MIN_PROG_DELTA is the + * minimum programming delta derived from it. Both values are + * empirically sized from measurements on S32G. + */ +#define STM_MIN_CYCLES 512 +#define STM_MIN_PROG_DELTA (STM_MIN_CYCLES * 3) + struct stm_timer { void __iomem *base; unsigned long rate; @@ -244,6 +254,7 @@ static int nxp_stm_clockevent_set_next_event(unsigned lon= g delta, struct clock_e { struct stm_timer *stm_timer =3D ced_to_stm(ced); u32 val; + s32 res; =20 nxp_stm_clockevent_disable(stm_timer); =20 @@ -254,16 +265,26 @@ static int nxp_stm_clockevent_set_next_event(unsigned l= ong delta, struct clock_e writel(val, STM_CMP0(stm_timer->base)); =20 /* - * The counter is shared across the channels and can not be - * stopped while we are setting the next event. If the delta - * is very small it is possible the counter increases above - * the computed 'val'. The min_delta value specified when - * registering the clockevent will prevent that. The second - * case is if the counter wraps while we compute the 'val' and - * before writing the comparator register. We read the counter, - * check if we are back in time and abort the timer with -ETIME. + * The comparator generates an interrupt only on an exact match + * with the counter. If the counter reaches the programmed value + * before the write to the comparator takes effect, the match is + * missed and the next interrupt only fires after a full 32-bit + * counter wraparound (~32.2s at 133 MHz). + * + * The counter read below targets the same module as the + * comparator write, so it can only complete once the write has + * reached the device, and the signed difference between the + * programmed value and the counter reflects the hardware state at + * that point. If less than STM_MIN_CYCLES remain to the match, the + * write might not have made it into the comparator in time; + * return -ETIME so the clockevents core retries with a larger + * delta. + * + * This is the same approach as hpet_clkevt_set_next_event(). */ - if (val > nxp_stm_clockevent_read_counter(stm_timer) + delta) + res =3D (s32)(val - nxp_stm_clockevent_read_counter(stm_timer)); + + if (res < STM_MIN_CYCLES) return -ETIME; =20 nxp_stm_clockevent_enable(stm_timer); @@ -333,16 +354,12 @@ static int nxp_stm_clockevent_starting_cpu(unsigned int= cpu) return ret; =20 /* - * The timings measurement show reading the counter register - * and writing to the comparator register takes as a maximum - * value 1100 ns at 133MHz rate frequency. The timer must be - * set above this value and to be secure we set the minimum - * value equal to 2000ns, so 2us. - * - * minimum ticks =3D (rate / MICRO) * 2 + * The minimum programming delta absorbs the measured worst case + * read/write/read round trip and the overshoot margin, see the + * comment on STM_MIN_CYCLES. */ clockevents_config_and_register(&stm_timer->ced, stm_timer->rate, - (stm_timer->rate / MICRO) * 2, 0x7FFFFFFFU); + STM_MIN_PROG_DELTA, 0x7FFFFFFFU); =20 return 0; }