From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CD3AE9271B for ; Thu, 5 Oct 2023 15:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234419AbjJEP5i (ORCPT ); Thu, 5 Oct 2023 11:57:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbjJEP4k (ORCPT ); Thu, 5 Oct 2023 11:56:40 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AB7C158F7 for ; Thu, 5 Oct 2023 06:57:54 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD8A4C16ABD; Thu, 5 Oct 2023 10:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696501080; bh=c11wMeSi6YGSdSS3k/QlnBSkcnWEMqoCHdS2WvriOXQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qS9fl7P505rUWJRl8/BhHaZ2S6v4rykk6cClVWFcLS7li/yjxrdWfDzCmsPdebCpv NmDUN2VwhqDWbCpv7Ks/SFaG0QXcCopnYiWKkKfnUkFng0xIOd9PKp91ytk1Jlr8Bo o76zVc1dpUyVCo76Gk5gmQiKJFsYgVfABCtO2jqHL7+duDF+K/SY97s750x5Rld2/Y ih+fTy/c939nYq55596zcXwi1KS1srfKfyVr+Tb6Q7klJd94tv1DYGlGcVKyqbPhUk svhx1XYebhWieOHxpwFRAsXs6MhwhRhp8pkzu2f4QrK8n0VHFsS+fCv5fiTB/cPGHs YTdoV8ndtmw0A== Date: Thu, 5 Oct 2023 12:17:57 +0200 From: Frederic Weisbecker To: Anna-Maria Behnsen Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Rik van Riel , Steven Rostedt , Sebastian Siewior , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak Subject: Re: [PATCH v8 05/25] timers: Clarify check in forward_timer_base() Message-ID: References: <20231004123454.15691-1-anna-maria@linutronix.de> <20231004123454.15691-6-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231004123454.15691-6-anna-maria@linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 04, 2023 at 02:34:34PM +0200, Anna-Maria Behnsen wrote: > The current check whether a forward of the timer base is required can be > simplified by using an already existing comparison function which is easier > to read. The related comment is outdated and was not updated when the check > changed in commit 36cd28a4cdd0 ("timers: Lower base clock forwarding > threshold"). > > Use time_before_eq() for the check and replace the comment by copying the > comment from the same check inside get_next_timer_interrupt(). > > No functional change. > > Signed-off-by: Anna-Maria Behnsen > --- > kernel/time/timer.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index 5e17244a9465..31aed8353db1 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -944,11 +944,10 @@ static inline void forward_timer_base(struct timer_base *base) > unsigned long jnow = READ_ONCE(jiffies); > > /* > - * No need to forward if we are close enough below jiffies. > - * Also while executing timers, base->clk is 1 offset ahead > - * of jiffies to avoid endless requeuing to current jiffies. > + * Check whether we can forward the base. We can only do that when > + * @basej is past base->clk otherwise we might rewind base->clk. Reviewed-by: Frederic Weisbecker Also can we keep the precious information in the comment and move it to the right place? Such as: diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 63a8ce7177dd..3e70ac818034 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -2015,6 +2015,10 @@ static inline void __run_timers(struct timer_base *base) */ WARN_ON_ONCE(!levels && !base->next_expiry_recalc && base->timers_pending); + /* + * While executing timers, base->clk is set 1 offset ahead of + * jiffies to avoid endless requeuing to current jiffies. + */ base->clk++; base->next_expiry = __next_timer_interrupt(base); Thanks! > */ > - if ((long)(jnow - base->clk) < 1) > + if (time_before_eq(jnow, base->clk)) > return; > > /* > -- > 2.39.2 >