From patchwork Fri Dec 1 09:26:34 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: 172348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp991726vqy; Fri, 1 Dec 2023 01:27:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5qFET8aGFrzdyIVibjCJci+Ft6FCKqZOdkZWwH5mDKR9TKTNHNsLGawbNvbkRci6rVkOX X-Received: by 2002:aca:1b1a:0:b0:3b2:e6a4:e177 with SMTP id b26-20020aca1b1a000000b003b2e6a4e177mr2073265oib.51.1701422878068; Fri, 01 Dec 2023 01:27:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701422878; cv=none; d=google.com; s=arc-20160816; b=J6Csz8PRhF59mZG1Q81udY9b8EHfzdr+ik/zhu643B6fWL/8SPIXikmrtTcOHvQulN FbijCWcvU0PDgDfHdgCnlY++2RJtwzrmMoWVmp2RriMx3E0rpDlseDI2jgB4dQUjL9yR /5wLudxOgUn4GB96YfYuSjrLHRl/QAbN4iGmmCY856ARnH+TrlA0Senn3VJ9gfruivux VrddHkrYXRx6CxAJ8u9HTvamDuzUBjHUZNKTztKMmcd8fHLzYH//QkUPUV7oBT4oL28d u4ic2ON/MWJklUu7Vi7aKEiV1MWKAN6cI2/E58Ief00hX0550sd5BwZc+cxY+b4dhqko b5Gg== 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=nZi/SXfoi2GICSzM+IYBAVSlO8Hm1DXEFr76jQHYOZ0=; fh=PG6uS4TiiUSDyl8D/joYkWbwCgDm4ug0ir2h7tHBJXQ=; b=HD1x18lJAYoG/c4S+FLkOjtAx0Cdp/pTcQX3Ro7VlzjkZkLaMgH7tJkfcD6SiBWbwA eqZ7BZc0gGBC3Ub3AgEgKhu+zJeOtfhktvsg2/BJbEA6t2pNCYCF9B3kOlMNe3sexEc9 Wv3rKHxMA2/dss5UUagIaHsjIn6Fl/WC0JjBrVRmIIhgVf3ZLiZDr59QXj9eyAliJELG HdpauBjgD8lzNb9R9QKEKF/cXvyVyT2nSnAFtPgwLKcdtWLOXkOPfdmk7fUl89zXy/kL JSRxRKNeecOv2x78GRnxGZUjSzI0CZo58EuXIxULKiOTLirz2LHGtVWfQS5nyIkkKZYb gdKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="lPUu/u37"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DGxDnst2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id bx41-20020a056a02052900b005c5e2ac7c3csi3279148pgb.732.2023.12.01.01.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:27:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="lPUu/u37"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DGxDnst2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 24B31833AB02; Fri, 1 Dec 2023 01:27:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378043AbjLAJ1m (ORCPT + 99 others); Fri, 1 Dec 2023 04:27:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378055AbjLAJ1W (ORCPT ); Fri, 1 Dec 2023 04:27:22 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3A521725 for ; Fri, 1 Dec 2023 01:27:15 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701422834; 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=nZi/SXfoi2GICSzM+IYBAVSlO8Hm1DXEFr76jQHYOZ0=; b=lPUu/u3782O76F4tssDfbbwJSu1UYJWRXA1YF1HFvK1m8kbs0zLQsUh/Qrq0SympHt1Xn4 fWs6pLLsziRXsDGGtVSkmgIluUmEPyOt49N0oJuW1GpqQsDrQiTwLCGHDYPxL2sHNl8pO8 uZrfXgDRa3Soql/IDz++WAZHigpe67VrkWm7MrhlkMdDJb1cuTVJRBpNVrj0k0qs67dVi3 SnfBc962XKiwdxw27XZSz4hJUgXOfPYnpxuSOBDbSvDj36Sfa0N/0H08AMFC8K3OePFC/t LsAllTQBY9b+fu99vTafsfRYXEb2PxTXLZsynXnrqJJ34TflfOYmg29flJ7ItA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701422834; 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=nZi/SXfoi2GICSzM+IYBAVSlO8Hm1DXEFr76jQHYOZ0=; b=DGxDnst2vjquka22zFxBnL29sukEirkFvC4s2bWFecYQdCP9TQh2tKsQYBTAwCLj3xIhX6 heDteX2CRHR+6lAg== 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 v9 12/32] timers: Fix nextevt calculation when no timers are pending Date: Fri, 1 Dec 2023 10:26:34 +0100 Message-Id: <20231201092654.34614-13-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 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:27:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784071195826791695 X-GMAIL-MSGID: 1784071195826791695 When no timer is queued into an empty timer base, the next_expiry will not be updated. It was originally calculated as base->clk + NEXT_TIMER_MAX_DELTA When the timer base stays empty long enough (> NEXT_TIMER_MAX_DELTA), the next_expiry value of the empty base suggests that there is a timer pending soon. This might be more a kind of a theoretical problem, but the fix doesn't hurt. Use only base->next_expiry value as nextevt when timers are pending. Otherwise nextevt will be jiffies + NEXT_TIMER_MAX_DELTA. As all information is in place, update base->next_expiry value of the empty timer base as well. Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker --- v9: New patch --- kernel/time/timer.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 0826018d9873..4dffe966424c 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1922,8 +1922,8 @@ static u64 cmp_next_hrtimer_event(u64 basem, u64 expires) u64 get_next_timer_interrupt(unsigned long basej, u64 basem) { struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); + unsigned long nextevt = basej + NEXT_TIMER_MAX_DELTA; u64 expires = KTIME_MAX; - unsigned long nextevt; /* * Pretend that there is no timer pending if the cpu is offline. @@ -1935,7 +1935,6 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) raw_spin_lock(&base->lock); if (base->next_expiry_recalc) next_expiry_recalc(base); - nextevt = base->next_expiry; /* * We have a fresh next event. Check whether we can forward the @@ -1944,10 +1943,20 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem) __forward_timer_base(base, basej); if (base->timers_pending) { + nextevt = base->next_expiry; + /* If we missed a tick already, force 0 delta */ if (time_before(nextevt, basej)) nextevt = basej; expires = basem + (u64)(nextevt - basej) * TICK_NSEC; + } else { + /* + * Move next_expiry for the empty base into the future to + * prevent a unnecessary raise of the timer softirq when the + * next_expiry value will be reached even if there is no timer + * pending. + */ + base->next_expiry = nextevt; } /*