Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp733813rwi; Wed, 26 Oct 2022 06:39:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4js5Xd/DkyAZ+arN2imSQRL8RLfkP5HySzqIFqz5RF40FLbpMaDieIhEOkO27QtJA/HBjI X-Received: by 2002:a65:5ac8:0:b0:463:9c77:285a with SMTP id d8-20020a655ac8000000b004639c77285amr37412485pgt.517.1666791593470; Wed, 26 Oct 2022 06:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666791593; cv=none; d=google.com; s=arc-20160816; b=IWP6zdFUv0oyYutXtcwwhNWlI5rT0bYkUk3ZGXvXWfkwXdXqhtEfo3bttDZC2e7YIf GDiIYN9apCxff7Tns8Xt3T4/Aj8C/iANeP774rLAcAWmCT7eE+q0kvnnHrNpUVtxguAy 3a0HB4bZd+h4EPVoHxSIf+6IeYNRHh/FHeADOb9CaEKaAyPPqoDPJAfrBuAP3UKm0ORy ix0NQ8kunOW2KOmTjRuI+fm65S3QWxy9iOLNZRzsv2yrwrvzdScVDokaSCKRhpH77j7b /VvyY7V1oosDGY0kPqdBV8atzy72DgQgOagXnJf5o3KD+c249uU15TBlvXi28sqCdV+J dj/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iNK7y9CpvTQ2GUJqcQsZm/ZhJBgrlm5Z0cK3Md05lTE=; b=z4PSjYM6DkMAn6A6a01EOnKPefvvYS7F+d4LrsfdR66vBBUjMrFyZITr70euQUFWfK JjDgwbJuHf7kAFwazA49aOn5tMlnOovfFtHT8Dkmw7R/Hfswe94+D6KAB4dC1sUJtG4F l1mp89UWnDOLiml5zGpTdFLxx9YwLlU0mYXcazPyKNoY+W4/DdFO1WPquuGDgqY01D/e HTR+gnIv0keYFcFZNZ7TcJxSSf/zWcbdO+u8szr6wV7q9gOFZgxtbIzvnfhN8QeEDtqv 5flKQVHGRg+xTpzShIMJdIWorv51dzByuWjmXFBU9kI6fAUp/bg5Qr9gmQJshXRmvvLC J2bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r2dack70; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i190-20020a6387c7000000b0046ed15af9d1si6459467pge.213.2022.10.26.06.39.41; Wed, 26 Oct 2022 06:39:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r2dack70; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233812AbiJZN1e (ORCPT + 99 others); Wed, 26 Oct 2022 09:27:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233367AbiJZN1a (ORCPT ); Wed, 26 Oct 2022 09:27:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67012B7F57; Wed, 26 Oct 2022 06:27:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 219AEB8224F; Wed, 26 Oct 2022 13:27:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77918C433D6; Wed, 26 Oct 2022 13:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666790844; bh=Bdy+O4IcsdfGRjS9WX5k++Rmhb023ZdYe5PoD5BO7Gw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r2dack708B9WhO8PTbYpiWM1MlANxYay+zjYz/4flu/RfQzfFfyKSV+OpgkuGwVw+ JekG0KIugCyj7fz1hTMXYKPN9xpmHnd1BHC13C9JbePy2j9HoK1Cox9oTwsoH+YdZu 0xcnZtvnEJ/2FzjSg+Bzz63AnuDS9hc8mF4lHoyou344+zfwbECFQz1EiuHLFlkgfl KU+598W3DHcS9r1Y6E2caGQ0+W6mQXoR7InXdEq7bz9Z8qAdArlMngQqnvwQcXIWCd cwP8Un1loFTeq1McB7rgkmr+XHYG+izvYfSKEdTuqBYrLe9ScsvHTgF09uwYSq/BKK lVLRdX2tBpW2w== Date: Wed, 26 Oct 2022 15:27:22 +0200 From: Frederic Weisbecker To: Anna-Maria Behnsen Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , John Stultz , Eric Dumazet , Thomas Gleixner , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, Arjan van de Ven , "Paul E. McKenney" , Frederic Weisbecker , Rik van Riel Subject: Re: [PATCH v3 05/17] timer: Rework idle logic Message-ID: <20221026132722.GC1327339@lothringen> References: <20221025135850.51044-1-anna-maria@linutronix.de> <20221025135850.51044-6-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221025135850.51044-6-anna-maria@linutronix.de> X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 25, 2022 at 03:58:38PM +0200, Anna-Maria Behnsen wrote: > From: Thomas Gleixner > > To improve readability of the code, split base->idle calculation and > expires calculation into separate parts. > > Signed-off-by: Thomas Gleixner > Signed-off-by: Anna-Maria Behnsen > --- > kernel/time/timer.c | 29 ++++++++++++++--------------- > 1 file changed, 14 insertions(+), 15 deletions(-) > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index f34bc75ff848..cb4194ecca60 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -1727,21 +1727,20 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) > base->clk = nextevt; > } > > - if (time_before_eq(nextevt, basej)) { > - expires = basem; > - base->is_idle = false; > - } else { > - if (base->timers_pending) > - expires = basem + (u64)(nextevt - basej) * TICK_NSEC; > - /* > - * If we expect to sleep more than a tick, mark the base idle. > - * Also the tick is stopped so any added timer must forward > - * the base clk itself to keep granularity small. This idle > - * logic is only maintained for the BASE_STD base, deferrable > - * timers may still see large granularity skew (by design). > - */ > - if ((expires - basem) > TICK_NSEC) > - base->is_idle = true; > + /* > + * Base is idle if the next event is more than a tick away. Also > + * the tick is stopped so any added timer must forward the base clk > + * itself to keep granularity small. This idle logic is only > + * maintained for the BASE_STD base, deferrable timers may still > + * see large granularity skew (by design). > + */ > + base->is_idle = time_after(nextevt, basej + 1); A subtle change, yet welcome, is introduced here. If the next event is just one jiffy ahead, base->is_idle used to be left untouched. So the behaviour was: 1) If the tick was already stopped (so we must be after an idle IRQ), base->is_idle remains true 2) If the tick was not yet stopped, base->is_idle remains false After this patch, 1) becomes: 1) If the tick was already stopped, turn base->is_idle to false As a result, we may spare an IPI if we remotely enqueue a timer to an idle CPU that is going to tick on the next jiffy. Whether it's worth mentioning in the changelog, I leave it to you. > + > + if (base->timers_pending) { > + /* If we missed a tick already, force 0 delta */ > + if (time_before_eq(nextevt, basej)) > + nextevt = basej; Can be time_before() then, right? Reviewed-by: Frederic Weisbecker > + expires = basem + (u64)(nextevt - basej) * TICK_NSEC; > } > raw_spin_unlock(&base->lock); > > -- > 2.30.2 >