Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2806912rdb; Mon, 4 Dec 2023 08:04:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBVHeSx0fLqvEohmEVMTGzTGRvZCQez6KNx/TvuFA4rEBYPY9ys2dTzTaDQw9/bColPuNy X-Received: by 2002:a05:6830:1450:b0:6d9:a12c:4db0 with SMTP id w16-20020a056830145000b006d9a12c4db0mr1696269otp.31.1701705847373; Mon, 04 Dec 2023 08:04:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701705846; cv=none; d=google.com; s=arc-20160816; b=bJ05LwpJnIendt+AEB8fn93Fdfm/PYZXXdrMsQrpSxQ9BH0vB0MA+lp69eprLAr8z0 SwWUTO9fMqaqA8nxt+4/mbI1DvC+KnJwPNozZ/Yo1P/pCyV3SZ/+YV+fWeu5C+Mul8Od 2cUxIYR/HQvUdH+xqNR7gVt4cLNKw8mFat9IZLRdcW12vh1lV6ROCZVXV9a1cJN1YCYQ cCrKPCaamBl/Wk5ae0Y1hxws2TjpEWz/tOZCuIJB2ESHadKt6gXyMWOXrAuqMk5ZM+Q+ vRcKBHINJ31wzBb9mdfkUV1FcmHI7PV0/a6bF1wxf5U6e+QuPGS+Qj2qXu2se2kiuyBi A2pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=oOGKvQa+fD1H+3fJFY5r6c8uqdzNpto7YjAjUn5AcY0=; fh=5cMh8CKYPGN1F0fzuaj1xrlN5+dBfa6bPK4XIprQ5s0=; b=sKuviLPqeYWaiYrcvwDmVoSp1s4vGdk8Q1AG403MArFGFePTgMYcXgvmXXXw2Xfn7J U6uYQMarWaul/0ESPZmMJL0PhpE9LWcja8iyRsfs9bV5M0/HU+byA6zgVH3U4qHQPLn9 F1STjh6Ul+AH4t5wfaD26IiI2F+SAzWQziuqkEqOe4TlxkSa+jx6Gj49OFKDJN7dWl0x 132/4cJ1MqzfIWas7fqOS2/m9Sx9/aaWJAxcJ+ThFMKtoRmbHHqiundVPprdBTct4ksR paM5S2PL3hhtZOtlNZ6Mo04J9QqegSSnDXKkQTtXqV2UxhUm3ozncSfwVVptgepjfBkO tgig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dpoiyQpk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id o4-20020a9d7644000000b006d81cfc70d6si3067462otl.265.2023.12.04.08.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:04:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dpoiyQpk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 6196B8062DD1; Mon, 4 Dec 2023 08:04:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343904AbjLDQDs (ORCPT + 99 others); Mon, 4 Dec 2023 11:03:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234633AbjLDQDr (ORCPT ); Mon, 4 Dec 2023 11:03:47 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1008EA4 for ; Mon, 4 Dec 2023 08:03:54 -0800 (PST) Date: Mon, 4 Dec 2023 17:03:50 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701705832; 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=oOGKvQa+fD1H+3fJFY5r6c8uqdzNpto7YjAjUn5AcY0=; b=dpoiyQpkZqd+2evWeKtSi1P8xf0rf9vXzPmGHc6oWblsnmNoTMz9RQR434dvHSTf0Lg4mI 2q4I0UgltZ9u3gUlmNoUCHYha4EtxHONuqS99YbVIX1Ore/77+UhP8Bp+wbaJC0Kvfd+iP wXZAab0aukZBo7RVG3hD2XZdOqvz3pfjIJh8nco4CEhjwOL+QdNleCZA8GJH1B6EHZ+yvQ Mf5jShs46Vt06LLgmEqti+/Iuy0RPTsC/BXcj+wL9HQLfqRh9aXAMIFIBxhsd+AqpnunX7 QLlMHDgtB57WL004UxHaLTqWIN7jn0qQGVqYDmuftkCqYpIb1Hh1YiaY2ftC8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701705832; 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=oOGKvQa+fD1H+3fJFY5r6c8uqdzNpto7YjAjUn5AcY0=; b=b9GXWlF6yHaVfbz5YlE9faTuI1oRyyQGPVLDbIe7882o09LJh/Z3Q/uHEGi40++uhPo/zq NFaP6QvjXe4XQ4Dg== From: Sebastian Siewior To: Anna-Maria Behnsen 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 Message-ID: <20231204160350.OTCnqCJf@linutronix.de> References: <20231201092654.34614-1-anna-maria@linutronix.de> <20231201092654.34614-13-anna-maria@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231201092654.34614-13-anna-maria@linutronix.de> 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 04 Dec 2023 08:04:03 -0800 (PST) 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())? 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? 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. > 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? > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -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 an > + * next_expiry value will be reached even if there is no timer > + * pending. > + */ > + base->next_expiry = nextevt; > } > > /* Sebastian