Message ID | 20231201092654.34614-17-anna-maria@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp991827vqy; Fri, 1 Dec 2023 01:28:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKlaoZwBLX5ezGHmdjSHhbWnKWyB5a1wlcS+UlWaeq7N+w/2zhHUOXSv/KKgivq3Fd7uPJ X-Received: by 2002:a17:90b:1d83:b0:285:adca:e8e7 with SMTP id pf3-20020a17090b1d8300b00285adcae8e7mr19146090pjb.5.1701422893134; Fri, 01 Dec 2023 01:28:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701422893; cv=none; d=google.com; s=arc-20160816; b=Eo5NKMkVEHpyJ9OyPSA6QJVH3I/nEfSekBTSkEOuP7iWmoXrL/CxPt1g/nh0nvwl9l aZQCWqXWvkpWq4VZkw3VmF4yS2493N2GxmBfx2Teh2dM+7VACuhJ2XbTSgvqo738qz/O 3FLaVR/OondJ7iALkLnckweBOv9CnJ6Zh12TX2JLVbQaMfU2j+eBFTlHMgTXE4twYLgE mo5NzGFGnjzqO/1FGkYOJ4JbvR5VhrHFBQeBmzDkx0BislBXYrGFy8Ktpo75sb/rI4lJ E3WEcZceNbIqsXyycyXejm3D4C5p0KzkuaMCjdKNgBzhIaedYuVx4gddGgNIB1MDQ4Ln Rpaw== 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=nS3of1gsjpadmlTzOeKtxhnS0y1kmX6N3aik41bHBiA=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=i8PWzu8NNUDXsOocGUO3T/ugxKr7iTg8p7eB6G++xAekHByKKFxOUMIQhj5hXjfZfs t5aBBo94lB8wfqskVfU/cF152C3WbMaX7C8rJudx9nFeN32lmWo79U9YR6aFbdFmM/3V 2KDn/9OhW+MMdr5wV0Bg3Kc38WwI3r7bHL/bsxalqmRWSEJaEdEjkyUBSoMM/4wM3LHX 8SfAhk//L09iITize68k53Ay+9XeRoqJsnMkvCLbYLidXKZFLDL7KRiEe96mkluYt8LK VhYUNdEZ+tT2jwhp0Qi6rfFfd4W/09tsX8OBUknj/RSSrl26STXL8YkxNUzOPPOh6zXP pCyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jd8JdSo6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id w8-20020a170902904800b001cfd4c10e47si2852892plz.8.2023.12.01.01.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:28:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jd8JdSo6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id D0B1A83D9B66; Fri, 1 Dec 2023 01:28:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378069AbjLAJ1y (ORCPT <rfc822;ruipengqi7@gmail.com> + 99 others); Fri, 1 Dec 2023 04:27:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378071AbjLAJ12 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 1 Dec 2023 04:27:28 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE00B173B for <linux-kernel@vger.kernel.org>; Fri, 1 Dec 2023 01:27:18 -0800 (PST) From: Anna-Maria Behnsen <anna-maria@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701422837; 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=nS3of1gsjpadmlTzOeKtxhnS0y1kmX6N3aik41bHBiA=; b=jd8JdSo6RSMAzUQGD0eFZtqqXum4T5DNbkhKfHsGgfKrpZeYgvPMRbitqOvajGAVnOXjI6 CUwVNu95rNCy/L5GzK63NOh365EDVDrf9ayAK4msa7dXSpEa80xXUWomRi6duxWLFm+VbM qCr1hrcESNQGxbIdSVpGa6B5nMD7U+enDcqohqFlaqh/MYvEqE3lCzl2P2uDwny8GJ0pZb e+Y7Q5UkpxPIXt7kcmWi+U4AE9QBHs0PlQvwXPRBOBrT+RaB+0SEBxJG882s2281fx76As 0B3s31n61vB24z+VP0fxZkI3ZAtKnfsQ0JzpWsdc4wBnNvNXxSgu/bYlY0W5kw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701422837; 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=nS3of1gsjpadmlTzOeKtxhnS0y1kmX6N3aik41bHBiA=; b=XvAVoft42FnLB6t8nWzHoq+keWMNp0u+ZuAOQmacO5++zBupzj5qe3N+KJ0loGqLT7o1ZZ rrBvtWXBA6WYHMAg== To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra <peterz@infradead.org>, John Stultz <jstultz@google.com>, Thomas Gleixner <tglx@linutronix.de>, Eric Dumazet <edumazet@google.com>, "Rafael J . Wysocki" <rafael.j.wysocki@intel.com>, Arjan van de Ven <arjan@infradead.org>, "Paul E . McKenney" <paulmck@kernel.org>, Frederic Weisbecker <frederic@kernel.org>, Rik van Riel <riel@surriel.com>, Steven Rostedt <rostedt@goodmis.org>, Sebastian Siewior <bigeasy@linutronix.de>, Giovanni Gherdovich <ggherdovich@suse.cz>, Lukasz Luba <lukasz.luba@arm.com>, "Gautham R . Shenoy" <gautham.shenoy@amd.com>, Srinivas Pandruvada <srinivas.pandruvada@intel.com>, K Prateek Nayak <kprateek.nayak@amd.com>, Anna-Maria Behnsen <anna-maria@linutronix.de> Subject: [PATCH v9 16/32] timers: Optimization for timer_base_try_to_set_idle() Date: Fri, 1 Dec 2023 10:26:38 +0100 Message-Id: <20231201092654.34614-17-anna-maria@linutronix.de> In-Reply-To: <20231201092654.34614-1-anna-maria@linutronix.de> References: <20231201092654.34614-1-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:28:07 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784071211965782339 X-GMAIL-MSGID: 1784071211965782339 |
Series |
timers: Move from a push remote at enqueue to a pull at expiry model
|
|
Commit Message
Anna-Maria Behnsen
Dec. 1, 2023, 9:26 a.m. UTC
When tick is stopped also the timer base is_idle flag is set. When
reentering the timer_base_try_to_set_idle() with the tick stopped, there is
no need to check whether the timer base needs to be set idle again. When a
timer was enqueued in the meantime, this is already handled by the
nohz_get_next_event() call which was executed before tick_nohz_stop_tick().
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
---
v9: New, as this optimization was splitted from the patch before.
---
kernel/time/tick-sched.c | 2 +-
kernel/time/timer.c | 11 ++++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
Comments
On 2023-12-01 10:26:38 [+0100], Anna-Maria Behnsen wrote: > When tick is stopped also the timer base is_idle flag is set. When > reentering the timer_base_try_to_set_idle() with the tick stopped, there is > no need to check whether the timer base needs to be set idle again. When a > timer was enqueued in the meantime, this is already handled by the > nohz_get_next_event() call which was executed before tick_nohz_stop_tick(). as of #15 tick_stopped is set later in tick_nohz_stop_tick() and both (tick_sched::tick_stopped and timer_base::is_idle) are cleared in tick_nohz_restart_sched_tick(). Then we have tick_nohz_idle_retain_tick() with only one caller and is only clearing timer_base::is_idle. Now, wouldn't it make sense to preload timer_idle based on timer_base::is_idle? I don't know if it there is a different outcome if timer_base::is_idle gets cleared in the idle path vs tick_sched::tick_stopped. I can't find nohz_get_next_event(). > Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de> Sebastian
Sebastian Siewior <bigeasy@linutronix.de> writes: > On 2023-12-01 10:26:38 [+0100], Anna-Maria Behnsen wrote: >> When tick is stopped also the timer base is_idle flag is set. When >> reentering the timer_base_try_to_set_idle() with the tick stopped, there is >> no need to check whether the timer base needs to be set idle again. When a >> timer was enqueued in the meantime, this is already handled by the >> nohz_get_next_event() call which was executed before tick_nohz_stop_tick(). > > as of #15 tick_stopped is set later in tick_nohz_stop_tick() and both > (tick_sched::tick_stopped and timer_base::is_idle) are cleared in > tick_nohz_restart_sched_tick(). > > Then we have tick_nohz_idle_retain_tick() with only one caller and is > only clearing timer_base::is_idle. Now, wouldn't it make sense to > preload timer_idle based on timer_base::is_idle? When revisting the code, this timer_clear_idle() is no longer required in tick_nohz_idle_retain_tick(). This is only called when the tick is not stopped - so timer base is not idle as well and this call is superfluous. As we keep both states in sync (tick_sched::tick_stopped and timer_base::is_idle) it doesn't matter which one is used. In tick_nohz_stop_tick() I don't have access to timer base. I could add it to timer_base_try_to_set_idle() but it will not make a difference. > I don't know if it there is a different outcome if timer_base::is_idle > gets cleared in the idle path vs tick_sched::tick_stopped. > I can't find nohz_get_next_event(). s/nohz_get_next_event/tick_nohz_next_event/ ... >> Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de> > > Sebastian Thanks, Anna-Maria
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 3e1cdb7c6966..c6b415052c56 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -886,7 +886,7 @@ static void tick_nohz_stop_tick(struct tick_sched *ts, int cpu) struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); unsigned long basejiff = ts->last_jiffies; u64 basemono = ts->timer_expires_base; - bool timer_idle; + bool timer_idle = ts->tick_stopped; u64 expires; /* Make sure we won't be trying to stop it twice in a row. */ diff --git a/kernel/time/timer.c b/kernel/time/timer.c index df6558f62e6f..177bcde8a2c0 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1996,13 +1996,18 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) * timer_base_try_to_set_idle() - Try to set the idle state of the timer bases * @basej: base time jiffies * @basem: base time clock monotonic - * @idle: pointer to store the value of timer_base->is_idle + * @idle: pointer to store the value of timer_base->is_idle on return; + * *idle contains the information whether tick was already stopped * - * Returns the tick aligned clock monotonic time of the next pending - * timer or KTIME_MAX if no timer is pending. + * Returns the tick aligned clock monotonic time of the next pending timer or + * KTIME_MAX if no timer is pending. When tick was already stopped KTIME_MAX is + * returned as well. */ u64 timer_base_try_to_set_idle(unsigned long basej, u64 basem, bool *idle) { + if (*idle) + return KTIME_MAX; + return __get_next_timer_interrupt(basej, basem, idle); }