From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 282B83A7F5F for ; Tue, 24 Feb 2026 16:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771951057; cv=none; b=MZ63opwkBUg4IcIib4tZ46r9Pt0/+JFtK3+C1+wGCc5iefYuOXFXbJE8r5odJ3WJUf6fsz1PugKYzknHCdJTksC3CUf5YOqjoJ107UXDSzRpIwRaJExhijTo09HNa4pHgPeS63cjdVc2QU9e0Z/0pebXo5+wx7C+CDbpHUd47K0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771951057; c=relaxed/simple; bh=7eZmj/zvoLv6mIE24CqHWS9+DAQfZ47PSvPeMFsmLa4=; h=Date:Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=M6pTl8ds5xcDwMb9pMmCYnHwBVO1eKm0BLtxb9fTUlgQq3NobDrUYSPl1yZtmxDAo6x7jy8jteZrwWvHG9qZTVEeUE4ndbp/G3Oreqf5dHh5SqtQxg9KZhUmy5RjYGPOqRbNT2K0CNauEwLcpxL8zx2ymU/axbGGPUDbzXQFMFQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RufTrlhG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RufTrlhG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38728C116D0; Tue, 24 Feb 2026 16:37:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771951056; bh=7eZmj/zvoLv6mIE24CqHWS9+DAQfZ47PSvPeMFsmLa4=; h=Date:From:To:Cc:Subject:References:From; b=RufTrlhGtO+qlvsnyrNOf8RRac0uvW+T+4FhTfIhT9T2oebRkAcsaGb24FIuGv9gL dkMaMXVsb1DbPxs/Tg04EHTYb4zi3FwunbDEA8TYYnuEzjBgwPdKmwOcDEjlJlMYh7 mo9y8ATu+K4xsKYU4l2HOVDDMffxnWwj6dFABprDDMjXg+hkPtmw8ChAHIDAbLKgx2 NIR+phpycpqTHhgSLxpCOtviSoZtKYBaH3JdiosYAcjKOWixKuJV+OmIl5GAGD4GjV VdlFom9U2aQMZKe6bdJy//n0SESN0e4QRNblhe0qgwxKvFt+/DsWtcK1x3zo0i08J2 VIaSXYrhIgIaQ== Date: Tue, 24 Feb 2026 17:37:33 +0100 Message-ID: <20260224163430.673473029@kernel.org> User-Agent: quilt/0.68 From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , John Stultz , Stephen Boyd , Daniel Lezcano , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , x86@kernel.org, Peter Zijlstra , Frederic Weisbecker , Eric Dumazet Subject: [patch 29/48] hrtimer: Use NOHZ information for locality References: <20260224163022.795809588@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 The decision to keep a timer which is associated to the local CPU on that CPU does not take NOHZ information into account. As a result there are a lot of hrtimer base switch invocations which end up not switching the base and stay on the local CPU. That's just work for nothing and can be further improved. If the local CPU is part of the NOISE housekeeping mask, then check: 1) Whether the local CPU has the tick running, which means it is either not idle or already expecting a timer soon. 2) Whether the tick is stopped and need_resched() is set, which means the CPU is about to exit idle. This reduces the amount of hrtimer base switch attempts, which end up on the local CPU anyway, significantly and prepares for further optimizations. Signed-off-by: Thomas Gleixner --- kernel/time/hrtimer.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1231,7 +1231,18 @@ static __always_inline bool hrtimer_pref */ if (!is_local) return false; - return is_first || is_pinned; + if (is_first || is_pinned) + return true; + + /* Honour the NOHZ full restrictions */ + if (!housekeeping_cpu(smp_processor_id(), HK_TYPE_KERNEL_NOISE)) + return false; + + /* + * If the tick is not stopped or need_resched() is set, then + * there is no point in moving the timer somewhere else. + */ + return !tick_nohz_tick_stopped() || need_resched(); } return is_local; }