From patchwork Wed May 24 07:06:14 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: 98348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2654725vqo; Wed, 24 May 2023 00:19:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Fkqm8qVeF/YWXW6albtNI9iRDewcq4C5d9rMD4kySZtk2UMr3neQaBPhzdqSzGWymxi4k X-Received: by 2002:a17:902:6bc2:b0:1ae:6003:2de0 with SMTP id m2-20020a1709026bc200b001ae60032de0mr14368475plt.68.1684912755399; Wed, 24 May 2023 00:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684912755; cv=none; d=google.com; s=arc-20160816; b=gjl9KX9nKIZwEmIfKwpSYlI6IBa3E2qvtW8QmE6gH5Lcbr1YIDHt9YxtXzwxCy9bel g//zwitq0qp4J5x//EnTYQVGm3sYfBoRbpaUDNmpoPaynUGVaN45uCcohNPonw702Pir E4YIxJzKNasP37Ow+ecjkG/xaym4q2kv4ToH9d2PvHANJPNZ2697NegDQWqR9Ojb9xhr XHO2J9Mu+8emYKpVY3ymsCo3lcIS329x8Y69Rv4rEkC8vF07nUOBqHQAtBZQ0IiHD2vY jx+PF7icbEjd9MyeT+lhgt7j5nlDjJn3zwtHlAc1TSkH2lYj8c7Vv5MgIWyM+1YONr2x s3yg== 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=ilOjG5OMxqCvAqDj+GfncPT0EiVgUxGa1ODohIiq6Qgd1UG15RgKog1p1pZGHJd1BS uFB5QWNOUUFlV+TKwucUxq0ygiW6b1uXiSO6nrKN1FZJb8GCM2LZrj8CITIfnqZt1JKz Gt00SMXserAqf0ldnZRRmOPuxo+yk17FKIGitAWEa0nk4etm2NV6hm0HlIfqJ4mYfuIt IwSWYJRv5qtiMZscoGs3nqE0VHnURwTNZrmtgV56x69MXUNRRk1QgX7NAwSWWbbQFC8V Qxv2xDQwhZ+Hh2jmVvoDpl7FhnbHb9udoIMRDSSDdn2jCBfrqb588XsIWc6oUrcCMAH0 +oyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ygmvl73R; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=nyt4KIqC; 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 je11-20020a170903264b00b001ae5b59462asi7620855plb.309.2023.05.24.00.19.03; Wed, 24 May 2023 00:19:15 -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=ygmvl73R; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=nyt4KIqC; 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 S239878AbjEXHHX (ORCPT + 99 others); Wed, 24 May 2023 03:07:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239793AbjEXHHC (ORCPT ); Wed, 24 May 2023 03:07:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC47E6 for ; Wed, 24 May 2023 00:07:00 -0700 (PDT) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684912018; 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=ygmvl73RIKtg2CvGUhk/vWDDvl4mJ296sHFwke/NlcFYGUeimMzJVFINJlSkfCGe9tiExJ djEqcpnCw8xR0lTyXMg3hlI9V4Mo3Idol2TFcDFpgwnSjVHcMoB/LrG5IQPL+jbbrzbRyT IAiOZuEWqLH26XKLgRDNcYc7rSPGK/QJobgGL/co7LsFVcqY3M46RTYIC85fp8My1OB+4y 3PN4dydZktD7gqvWs2ubcK5VK4tMRC16SLC07VXXjzLxfHSMBlsagGS2T5IEFQjTFBtaVp cJeqU6NRotBD0Z9Ry/UTaVYStzAwHHgyG+lqelGd3wFZooDCP0hZjnuedx6guQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684912018; 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=nyt4KIqCFq0Er9OWDgdt9jN0tYGg+h+0Ojga3OXErmHJ3T8wH27jM7FPc9tt//rkAMhiMx Yd9vKAN+xKRWpVBg== 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 v7 06/21] timer: Rework idle logic Date: Wed, 24 May 2023 09:06:14 +0200 Message-Id: <20230524070629.6377-7-anna-maria@linutronix.de> In-Reply-To: <20230524070629.6377-1-anna-maria@linutronix.de> References: <20230524070629.6377-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 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?1766759077553284197?= X-GMAIL-MSGID: =?utf-8?q?1766759077553284197?= 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);