From patchwork Wed Mar 1 14:17:31 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: 62915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3658478wrd; Wed, 1 Mar 2023 06:22:47 -0800 (PST) X-Google-Smtp-Source: AK7set/FrdxyrnqBoqpRPodDuKCME8iZqOrsPNs9o4kVUgb2WXv9VabvKURHnd0cbg4CwXAyKGs+ X-Received: by 2002:aa7:dd4b:0:b0:4b1:b71d:cbfe with SMTP id o11-20020aa7dd4b000000b004b1b71dcbfemr7379403edw.2.1677680566847; Wed, 01 Mar 2023 06:22:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677680566; cv=none; d=google.com; s=arc-20160816; b=D+GwjvfCSUktHRN5tPJyLejQ/fP+KU2SWX7/m+PLSJHdLVbOwGX87N7y9Jn38hNPZr k1YhsmFXBx/Uw2bSJGVdvUFREp+7BDgBM7Y6zPTTxqQEFjvyN3DoH3z3NpB1KXObgqA2 ulRdn1OAjU1Lr3i/8v2PQPQh5ZD4urLJmqm4hCkmnlQ6IGTZzwMsCmuvyFfAAduLatlf oGYq+kE1AcTV5vQD+btrYDzbIfj0v7Hjtf9VT8oX84N3HZsBsKKBnGgsvXo30b6QlvFq 2DXK8NODHd/nVIn23N6zIy9LZ+ZJqcWxi5Ytlv6+A7Bcl+jjrEqvVFm8N9GKrk9J6TKf xTRg== 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=mxBQLfqFMmn/4LKpc4xr9a8h2eIYUaZukb+bTAZlfes=; b=lSe2Gh8DYVKOl1K3Rv92ECRhAoxk6IT8IVJLEra43SHRMTxI5brykzRwTJ7GeHrIhM 8YCUnJkk53ES5XZKSIGHkJbTQAn4iX4/JRfeU0Bei72jyP1gzu4vFKLJUNgmrHsbJBBM QDD1pipRWxOS03B2IST7hDV9X6Zw9ea3RfKmcqsicL0HIItus09bUrzvyCiXUXH4hzJC qkye/WKGWwm9+Ljkf9JLIWZ+ufKC4OpbqNHaRdBqfTGFP4QvWfA7z1RWGSWR7NpsqoeE h9d6I2s5Jn+R8BbdYkFonzhOa4L0JTAgf32AaaqznpK8tvAK+yDm4wYQThNUPZBHdvQy S0JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4se4AVrv; dkim=neutral (no key) header.i=@linutronix.de header.b=BTBv5acI; 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 c20-20020a056402121400b004afadaef702si13961890edw.606.2023.03.01.06.22.23; Wed, 01 Mar 2023 06:22:46 -0800 (PST) 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=4se4AVrv; dkim=neutral (no key) header.i=@linutronix.de header.b=BTBv5acI; 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 S230110AbjCAOSZ (ORCPT + 99 others); Wed, 1 Mar 2023 09:18:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbjCAOSJ (ORCPT ); Wed, 1 Mar 2023 09:18:09 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAE1623DA4 for ; Wed, 1 Mar 2023 06:18:07 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1677680284; 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=mxBQLfqFMmn/4LKpc4xr9a8h2eIYUaZukb+bTAZlfes=; b=4se4AVrvLdzBcWQjXgIXW9CmrWvBZGxWhLunDIKEAhH1PUHbrFnelH0e5fnHB5qQvT7l/J uxO4fQAqLOXIgahydxDpwa/A+fvwbPnYb6AAN/+b4HOBDK5odzWSHu6Tf1tLp3hmMNzLM5 aGondTb2qrb1CLSytKZF0GOJ3rR1z/D25PuZmHw+VLrOCI9MmnrgpErECf9tCQEfQWP3x2 +W7zmO6z0HiV9R2ks9sSCfTPA/BSCBhDNLRyOZXVDFqFXqI9oBNjbwfgkWwTkuEg/sERJ/ QNfO4eJSJX+9tFjroGFam4wERVfB1nXbbNj2HxCXAaOVcRAU7WAFGb/FaKzu9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1677680284; 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=mxBQLfqFMmn/4LKpc4xr9a8h2eIYUaZukb+bTAZlfes=; b=BTBv5acIz2sWHYAB6pSVgBKf4KjRx45jcrlu+rqaSbUZwZ81H3AAla2zQhp/eOt0Rkz2ar NNMCk5FbcTjXVqBw== 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 , Anna-Maria Behnsen , Frederic Weisbecker Subject: [PATCH v5 05/18] timer: Rework idle logic Date: Wed, 1 Mar 2023 15:17:31 +0100 Message-Id: <20230301141744.16063-6-anna-maria@linutronix.de> In-Reply-To: <20230301141744.16063-1-anna-maria@linutronix.de> References: <20230301141744.16063-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 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?1759175578159019315?= X-GMAIL-MSGID: =?utf-8?q?1759175578159019315?= 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 --- 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 9e6c2058889b..d74d538e06a2 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1962,21 +1962,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);