From patchwork Wed Oct 4 12:34:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna-Maria Behnsen X-Patchwork-Id: 148266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp98694vqb; Wed, 4 Oct 2023 05:36:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEI2kJ3MHJ684C6RimPhk+kmUvG/6jmakpdnfD5IIQuhzxh+q7OOHjimwcwxjmVCWbSN0q2 X-Received: by 2002:a05:6a20:431c:b0:136:ea0e:d23 with SMTP id h28-20020a056a20431c00b00136ea0e0d23mr2514176pzk.11.1696423005756; Wed, 04 Oct 2023 05:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696423005; cv=none; d=google.com; s=arc-20160816; b=ZWVe/8uh7KnskpVpbJZH+12gZIk3oS4r/YZY1s/XMgKOAhW1c7P79E7OJy5VNpzQKq M/Q8SvIbJjZz1DPxLeX1CewEIQOYJx/Dynovhd7+GelylVVrjc1NmHZWcIHfQHpT7t/5 +DMyZhWrIj4HQ8T69MVKosVAmyA89l7K2kvB3MjJa3CCmDk/xCy/ehvD6t3urIRrMXL8 zngGl2oGbZf9qvWK8NCfWmdPvgFwb1IKQ3rHCZfEhifvuSdkSCA2YD+03QSm2NgsjQOR fLwcu6rU1YXyp940O8t4/KSRvnnv4c6K7oS7dw54lMnm8vnyIcacqU/3U9qJ3H8VgXmS LGXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=dxpi78IDwxZZgGLEvaVUb//vKcdGLGnLWfwEyUx5Nmw=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=nbcXty1q5z5wn/oIMAXmpzei5OofrDlMlHtrBNJ49wkT6W+0EwykCDgTo7Bf0DMKhd Tw26kw/oRyBTuD/kEbZaVJ+wW3DoxdkCIG/ZAt1iEy9Q5PhBTRoiPuOCs/lUFAXcEDQ4 P4TMTzeYxkin3iB1HGUMj0bIP/7ZcLqwpn+Meij04xp8ZoyHrKMt0Oa2YfTjmkws5R9n KaNdoEv4Hkb7bToHDvXwhFBoN6INKITXnVj0d4qzlWnQtvZObdT8IEQks4avwg4AbnIo ObB84p9x2vohFRGZDtyQMW6I4govLS4jUFy9/7iDp4O59PP7FG/HByALNYaYx2yE3jw/ i34g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BDLOxBrp; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id t12-20020a056a0021cc00b0068fbd15c036si3838860pfj.286.2023.10.04.05.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 05:36:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BDLOxBrp; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3DCA580BD51F; Wed, 4 Oct 2023 05:36:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242412AbjJDMfy (ORCPT + 18 others); Wed, 4 Oct 2023 08:35:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242371AbjJDMfe (ORCPT ); Wed, 4 Oct 2023 08:35:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3BC4C1 for ; Wed, 4 Oct 2023 05:35:31 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696422930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dxpi78IDwxZZgGLEvaVUb//vKcdGLGnLWfwEyUx5Nmw=; b=BDLOxBrpk3OptCr9bdEYLu1NT+9K7T/RiwoEvkZ/7gmRSnp35L1Ky0L5I76iA0nT6WpyF/ /UAflRMfwUegkPMshVRxDOX46Ng8CXg+0RjKSp/JD2ZfmUJWF9HQP4JG0d0gHiPQO3XDKU CRAtp0MTRbGrsi04whb4Q2ET2AKv4V/35kS1QR0LIvvXkwump5FR6wUEgQV7bpRHOjPkhe W3ZaAJsdUFWBJ4WjU4cNDcyE5jk21IpJU1lECmoFHmKS0Shy1EWc5eGhkr6LeAyqL1kAh2 7qHcP0n+Y6206fWDV9dDpDFhzqn/y8ODkl0V/hSIapte4S78tQBHOzW+/jS05g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696422930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dxpi78IDwxZZgGLEvaVUb//vKcdGLGnLWfwEyUx5Nmw=; b=ZjvV/Gf61Hjp7Rgy1OmNsLZBFCK3wKahqbT70dfSzdcmtdWYmwpBuE+3dGglFB3SyiNNCP Nks9H9Zliz8MaGCA== To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , John Stultz , Thomas Gleixner , Eric Dumazet , "Rafael J . Wysocki" , Arjan van de Ven , "Paul E . McKenney" , Frederic Weisbecker , Rik van Riel , Steven Rostedt , Sebastian Siewior , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak , Anna-Maria Behnsen Subject: [PATCH v8 08/25] timer: Rework idle logic Date: Wed, 4 Oct 2023 14:34:37 +0200 Message-Id: <20231004123454.15691-9-anna-maria@linutronix.de> In-Reply-To: <20231004123454.15691-1-anna-maria@linutronix.de> References: <20231004123454.15691-1-anna-maria@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 04 Oct 2023 05:36:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778828449887880360 X-GMAIL-MSGID: 1778828449887880360 From: Thomas Gleixner To improve readability of the code, split base->idle calculation and expires calculation into separate parts. Thereby the following subtle change happens if the next event is just one jiffy ahead and the tick was already stopped: Originally base->is_idle remains true in this situation. Now base->is_idle turns to false. This may spare an IPI if a timer is enqueued remotely to an idle CPU that is going to tick on the next jiffy. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker --- v4: Change condition to force 0 delta and update commit message (Frederic) --- 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 dc58c479d35a..18f8aac9b19a 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1943,21 +1943,20 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) */ __forward_timer_base(base, basej); - 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); + + if (base->timers_pending) { + /* If we missed a tick already, force 0 delta */ + if (time_before(nextevt, basej)) + nextevt = basej; + expires = basem + (u64)(nextevt - basej) * TICK_NSEC; } raw_spin_unlock(&base->lock);