Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp223886rdb; Tue, 5 Dec 2023 03:53:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXYEyaXI8IYW1/hSS8dPRrrUGIXQa4oP3h8xQySbGlZa19CLnCkqOu+XmiuU6w0ZZa5UY/ X-Received: by 2002:a17:90b:4f4c:b0:285:9ec0:892a with SMTP id pj12-20020a17090b4f4c00b002859ec0892amr838065pjb.33.1701777204004; Tue, 05 Dec 2023 03:53:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701777203; cv=none; d=google.com; s=arc-20160816; b=TVrPwtCCd/KF7VqhzKsQwraQDgjML1+Yzy+S71TL4NslKlANXiELBtpdTeAZI+t12R 1lx+Qvnw5Uhw5IFcW+m4veeLqP5ISqySGdDF9u9+u4WE53pH38QIm2tednjPeSWJtT4P /rv4YBL3ZGqYI3x7lhgm3xs2UtzAVphcntU0ZbinL6PFGh7DFSv5mSoUn6rgt+j9GI6G uzvA6dDdEjogia7Wa0kxH4xZwVgdOnTcaXuQIRTE9e6AwO30rwUnpRIkZ1sgWc+8lHN0 W9DQs10UKDgfmpnkVpSTYp5TEI+e2oj1lmM7OLHZZTzdzDYptdmn8TLEcQhrhOAJnSOj 2DHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=rpwcUJUhNeWtCBatU+tgVe3nUzZLjauuSSOu3dLjEkA=; fh=zngDPpHc9IOT4XyfACYkaIQBkMO1o2QUewR15pJChdQ=; b=l4lpoIAS3BfwsINymyybdkAej7LHJJMqQJmMpBmc+WuabZofra36FGDG/vpRIyU6s0 xtYCnQGNkPs6mzATUrZkBoKfasa+8xFRpiL4jndhqw2ODNOCzcF7HNzUv5ZPaCLIgCWd 0J/kih/zIJa9hxtK2fOtCLBmKtNKukM9+OfSY+KvY4Bp7Lz0O+4+De1vhYQ6i17vAswo 07CKmf0YJIfBXxP9OuLGdZN3gBFyW7eBMZLAidjcQPJxsVz31eFHhNzJczBwaiE+dmrH 9NvSVmHaRdRf7E7DeeiQdlOyTQOTHO8ImFRo23NjWahQfsYoCUMTeJeU+EVJw429S2t2 ev6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Clk6PjAB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9eczm+iq; 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 Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id az5-20020a170902a58500b001cfbd3f391bsi9104712plb.226.2023.12.05.03.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:53:23 -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=Clk6PjAB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=9eczm+iq; 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 2E54F8132A7E; Tue, 5 Dec 2023 03:53:21 -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 S1347027AbjLELxF (ORCPT + 99 others); Tue, 5 Dec 2023 06:53:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345333AbjLELxE (ORCPT ); Tue, 5 Dec 2023 06:53:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D52A019F for ; Tue, 5 Dec 2023 03:53:06 -0800 (PST) From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701777184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rpwcUJUhNeWtCBatU+tgVe3nUzZLjauuSSOu3dLjEkA=; b=Clk6PjABvXj315VoDPdWp+X8kS8Vgi/wb/l2AXTJ/biubHBku41B5ymIs1P63xnqfBW89i 0b3nty/Q/+NgNYtb31V1VswMf0Qc2o+beXuExtVn+N0bAuzyarwlxQNtpHcVTWsemK1OAv QUEiwQ5RnRvZiVJpU5IbM1kt7gMNjM+5iTFM07Cs+GhEmAfXeAd+lH5tUdElhNruZZUGNL dm9XXOLPRaePTtR/rRwYbJ3/immp+a2eVgHLdnQHw8AVrqexiPA4xLo6TFaoAYy7jsSJVE RozZr0xhVE305O0s8Wcwh9RNHwMnODYcxstHuawQCray7JPc9HSXaR3laj/PFg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701777184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rpwcUJUhNeWtCBatU+tgVe3nUzZLjauuSSOu3dLjEkA=; b=9eczm+iq/+AkqOdt7s9W4AhgqeLrK11YpF1SQRZYE6Wxo8qmHydhLRjKYBEboT/D3y5hNu Bz/UME4rngd483AQ== To: Sebastian Siewior Cc: linux-kernel@vger.kernel.org, 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 , Giovanni Gherdovich , Lukasz Luba , "Gautham R . Shenoy" , Srinivas Pandruvada , K Prateek Nayak Subject: Re: [PATCH v9 12/32] timers: Fix nextevt calculation when no timers are pending In-Reply-To: <20231204160350.OTCnqCJf@linutronix.de> References: <20231201092654.34614-1-anna-maria@linutronix.de> <20231201092654.34614-13-anna-maria@linutronix.de> <20231204160350.OTCnqCJf@linutronix.de> Date: Tue, 05 Dec 2023 12:53:03 +0100 Message-ID: <87zfyodfxc.fsf@somnus> MIME-Version: 1.0 Content-Type: text/plain 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 05 Dec 2023 03:53:21 -0800 (PST) Sebastian Siewior writes: > On 2023-12-01 10:26:34 [+0100], Anna-Maria Behnsen wrote: >> 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. > > So __run_timers() sets base::next_expiry to base->clk + > NEXT_TIMER_MAX_DELTA and then we have no more timers enqueued. > > But wouldn't base->timers_pending remain false? Therefore it would use > "expires = KTIME_MAX" as return value (well cmp_next_hrtimer_event())? Jupp. > Based on the code as of #11, it would only set timer_base::is_idle > wrongly false if it wraps around. Other than that, I don't see an issue. > What do I miss? And it will raise an unnecessary softirq when it wraps around as you also mentioned on the next paragraph. > If you update it regardless here then it would make a difference to > run_local_timers() assuming we have still hrtimer which expire and this > next_expiry check might raise a softirq since it does not consider the > timers_pending value. The only difference with this change would be that the softirq will not be raised when it wraps around. >> 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. > > or consider timers_pending in run_local_timers()? An additional read vs > write? This would also be a possibility to add the check in run_local_timers() with timers_pending. And we also have to make the is_idle marking in get_next_timer_interrupt() dependant on base::timers_pending bit. But this also means, we cannot rely on next_expiry when no timer is pending. Frederic, what do you think? Thanks, Anna-Maria