From patchwork Wed May 10 07:28:02 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: 91915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3429939vqo; Wed, 10 May 2023 00:31:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7v2yAJJDzTkrskYYBwrUe/x7TD4GVOtLcOlh9wEn9zvknMm0bvW0gM8oiFh//pG1nQct6L X-Received: by 2002:a05:6a00:885:b0:63d:3595:26db with SMTP id q5-20020a056a00088500b0063d359526dbmr21645986pfj.23.1683703892356; Wed, 10 May 2023 00:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683703892; cv=none; d=google.com; s=arc-20160816; b=tHILbegkMHU3ikA3N9i8bWRUdgtJfrw7Ap+0rDKdAhFWABalBK0GnwqF38lkFlPBqI a7oEBkBP/ZJYd51peaSv/D51ten9U7Ysq2GWIG/pPnt9qejIOcMcrpyFUDLozKnS45uk WIDuCi6tbB5N8gNT23P6HT7rPyhzCQjm0siGgZeH7XNdmxQeJQlqPaRlGPPhIqTJpd8i RoX/VToQHz1WfcGZmOzdyIcmPZKlS0Bw2IOLrjYKwgw0Z8mGa2NJ0bUxOvdqzD+dtOy+ iJLrb9tE5Mhur0TDPjTrVj+3VV2BOSa7Y5nwFS9tbPCmuwF0KN2Lp6mR15P64BpBxL2y 632w== 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=3nPoc4ex9ONP2BmQpTyzqK0BECnFowWD2Bg10S9sUhQ=; b=OiQkSvR7e94P033Wv2GckdrHpPhCnIHyiFAdYeYNW78vCJsgcHdimNcBeg2PFODRGN HmNrhUERCh+BgA42pSVjPrN+O06tcG4NNc1iwf5W6fALDO2XhML9hJKw/uALw0WEuGDF vcsIRhQoOdEdAtTBrua4LoqjIL3SXcSft4Ms4zOHNxPyYgZVgvTtCznYruu+fjktbFO7 aSYqKp8mk2sUoHoS9sjWFQDVaPRN8J8ikl2rdLs6fzwwtuNgkVt5HYdtsNoPnvWE6Yfk 94RqbxvkzZhAd99kU/8R95z6vftllpUzhrmJoe2SENRr003K0r/a4ZwFtSMIPqf5Twsn U6/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lwpH+7Mo; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a69-20020a621a48000000b0063d2eae52cdsi4355454pfa.224.2023.05.10.00.31.18; Wed, 10 May 2023 00:31:32 -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=@linutronix.de header.s=2020 header.b=lwpH+7Mo; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235893AbjEJH3e (ORCPT + 99 others); Wed, 10 May 2023 03:29:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236008AbjEJH3S (ORCPT ); Wed, 10 May 2023 03:29:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E87DC76A6 for ; Wed, 10 May 2023 00:28:52 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1683703719; 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=3nPoc4ex9ONP2BmQpTyzqK0BECnFowWD2Bg10S9sUhQ=; b=lwpH+7Mo0htGaU9or8EAzwRFe5sp59Qu2+vv4tgo/ceZXYYd+xWKKrTmDYs15FG3UeWi2n r2JQtjs5P0sbGkfv5pcR49ODrm1amWM2s7lW1/yfwHOOI5D0B9C4ZK1jyL7O1W7DNNocJA +lKP0qkjUxxoZVN7s6uEaUHxNw/uYQR3FCu8Zqt1QbKnmIC81i3vQvcv1Y8dZxibBTSiUo /ieJjYfY7ik86G2UHh/DTtldFX3XdIds7cO/AcKhOGYUUB6zSJv87r4vlNVC3uvoZsRnBU qRUxmudTfDKvaRPqp8NGUZvrnzEU0e2rfveNawg4gbMUNemjbMTiwKkMLDV8RA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1683703719; 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=3nPoc4ex9ONP2BmQpTyzqK0BECnFowWD2Bg10S9sUhQ=; b=8N+/a2xubOkF5Cwp8MuTwiUx8UZMgX05VDRVgyU92jJGqL+ALW6WCsncuIQecTAowMaZBA H7+vq2Cxw7ebEWAA== 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" , Anna-Maria Behnsen , Frederic Weisbecker Subject: [PATCH v6 06/21] timer: Rework idle logic Date: Wed, 10 May 2023 09:28:02 +0200 Message-Id: <20230510072817.116056-7-anna-maria@linutronix.de> In-Reply-To: <20230510072817.116056-1-anna-maria@linutronix.de> References: <20230510072817.116056-1-anna-maria@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765491492522874965?= X-GMAIL-MSGID: =?utf-8?q?1765491492522874965?= 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 1a61977f9efa..1522fb81887e 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1957,21 +1957,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); + + 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);