From nobody Sun Feb 8 14:07:42 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 6B8D51FC11A; Tue, 4 Mar 2025 08:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741076873; cv=none; b=rOiQnuLn4alb1yJh0gT3u9ukvkEtd1l9BtbgLhU9QyhnVWc9inLOttlHEWuSnqsSYVj9p4NEk5fOfpI4zWHg6trFmTn+d7vYzoFjXVIsCQqowXubHc06D3v4FihmAvBUMECONVy+DXTtHRHQ2Ly52YsmCB5k32ELxp+qztY0ChY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741076873; c=relaxed/simple; bh=XTn45d3uSUhgVfLaEwcB92ck3kk80yHADl5WV4hXr3Q=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=JPl4KSyFsfxWoNK86uRbROjnijukUun4IVgW+9NZ1cOcDEcnk1IjNjlbKgMAl/QYq9i1bHo0TKd1+Kmp5s62NUMnmxUniIqKvwQYuXgoDyXV17V0WregTWyGlVCWq45S6cRGUnkyxiemYTdD2jPw7vs7xSOwLdBQdCscllHAU+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GJc63spF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=AHdLPLra; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GJc63spF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AHdLPLra" Date: Tue, 04 Mar 2025 08:27:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741076869; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zywy28gsiHdbWMOkuCimRsPefCrwML+KXFIPNT7zi1A=; b=GJc63spFywEguxGKB65Tc84w1BcnPZsdh+sgJzg1ffqPktP1uvWcP+yelK74oJwE/cZ29e k2KTikCy1b/uU1HGrGlhBbU2YUCg3FmCiDjyR8E6wFm4UO1qLJUU7pWk0q1Dr15TOk+I6s 1uc7JGWaOTs2f5jMNPcf5UsLmjbfbK+fwLJIxgABvVJNRj2w0VGG8hYu0iCQv3JNxtVCH3 ZTPWtzhwJ28nLAFvZltt8RaXS1W+K5211u0VqBpguznvEYMrjhvCgVmvAwSuh895CHyLlo 38wXCKKvI2QQPa7FLycSbt2CW83C+sQH03gpK85SqfZ7j4qr6IaGhiI2rwvdAA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741076869; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zywy28gsiHdbWMOkuCimRsPefCrwML+KXFIPNT7zi1A=; b=AHdLPLralU7fiJqf3+9BKgKwEFGy3O8ubPpARZQ7ULENRG9oehBF7XQAxQwI1RoKr7yx3c bDZAc9dfiGoIqWAA== From: "tip-bot2 for Brian Gerst" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86/preempt: Move preempt count to percpu hot section Cc: Brian Gerst , Ingo Molnar , Uros Bizjak , Linus Torvalds , Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250303165246.2175811-4-brgerst@gmail.com> References: <20250303165246.2175811-4-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <174107686913.14745.13117533696613764531.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/core branch of tip: Commit-ID: 4f2b419dd00eddd34952966a38c78892cd7c5715 Gitweb: https://git.kernel.org/tip/4f2b419dd00eddd34952966a38c78892c= d7c5715 Author: Brian Gerst AuthorDate: Mon, 03 Mar 2025 11:52:38 -05:00 Committer: Ingo Molnar CommitterDate: Mon, 03 Mar 2025 21:37:41 +01:00 x86/preempt: Move preempt count to percpu hot section No functional change. Signed-off-by: Brian Gerst Signed-off-by: Ingo Molnar Acked-by: Uros Bizjak Cc: Linus Torvalds Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20250303165246.2175811-4-brgerst@gmail.com --- arch/x86/include/asm/current.h | 1 - arch/x86/include/asm/preempt.h | 25 +++++++++++++------------ arch/x86/kernel/cpu/common.c | 4 +++- include/linux/preempt.h | 1 + 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/current.h b/arch/x86/include/asm/current.h index 60bc66e..46a736d 100644 --- a/arch/x86/include/asm/current.h +++ b/arch/x86/include/asm/current.h @@ -14,7 +14,6 @@ struct task_struct; =20 struct pcpu_hot { struct task_struct *current_task; - int preempt_count; int cpu_number; #ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING u64 call_depth; diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h index 7e83482..a1748b4 100644 --- a/arch/x86/include/asm/preempt.h +++ b/arch/x86/include/asm/preempt.h @@ -4,10 +4,11 @@ =20 #include #include -#include =20 #include =20 +DECLARE_PER_CPU_CACHE_HOT(int, __preempt_count); + /* We use the MSB mostly because its available */ #define PREEMPT_NEED_RESCHED 0x80000000 =20 @@ -23,18 +24,18 @@ */ static __always_inline int preempt_count(void) { - return raw_cpu_read_4(pcpu_hot.preempt_count) & ~PREEMPT_NEED_RESCHED; + return raw_cpu_read_4(__preempt_count) & ~PREEMPT_NEED_RESCHED; } =20 static __always_inline void preempt_count_set(int pc) { int old, new; =20 - old =3D raw_cpu_read_4(pcpu_hot.preempt_count); + old =3D raw_cpu_read_4(__preempt_count); do { new =3D (old & PREEMPT_NEED_RESCHED) | (pc & ~PREEMPT_NEED_RESCHED); - } while (!raw_cpu_try_cmpxchg_4(pcpu_hot.preempt_count, &old, new)); + } while (!raw_cpu_try_cmpxchg_4(__preempt_count, &old, new)); } =20 /* @@ -43,7 +44,7 @@ static __always_inline void preempt_count_set(int pc) #define init_task_preempt_count(p) do { } while (0) =20 #define init_idle_preempt_count(p, cpu) do { \ - per_cpu(pcpu_hot.preempt_count, (cpu)) =3D PREEMPT_DISABLED; \ + per_cpu(__preempt_count, (cpu)) =3D PREEMPT_DISABLED; \ } while (0) =20 /* @@ -57,17 +58,17 @@ static __always_inline void preempt_count_set(int pc) =20 static __always_inline void set_preempt_need_resched(void) { - raw_cpu_and_4(pcpu_hot.preempt_count, ~PREEMPT_NEED_RESCHED); + raw_cpu_and_4(__preempt_count, ~PREEMPT_NEED_RESCHED); } =20 static __always_inline void clear_preempt_need_resched(void) { - raw_cpu_or_4(pcpu_hot.preempt_count, PREEMPT_NEED_RESCHED); + raw_cpu_or_4(__preempt_count, PREEMPT_NEED_RESCHED); } =20 static __always_inline bool test_preempt_need_resched(void) { - return !(raw_cpu_read_4(pcpu_hot.preempt_count) & PREEMPT_NEED_RESCHED); + return !(raw_cpu_read_4(__preempt_count) & PREEMPT_NEED_RESCHED); } =20 /* @@ -76,12 +77,12 @@ static __always_inline bool test_preempt_need_resched(v= oid) =20 static __always_inline void __preempt_count_add(int val) { - raw_cpu_add_4(pcpu_hot.preempt_count, val); + raw_cpu_add_4(__preempt_count, val); } =20 static __always_inline void __preempt_count_sub(int val) { - raw_cpu_add_4(pcpu_hot.preempt_count, -val); + raw_cpu_add_4(__preempt_count, -val); } =20 /* @@ -91,7 +92,7 @@ static __always_inline void __preempt_count_sub(int val) */ static __always_inline bool __preempt_count_dec_and_test(void) { - return GEN_UNARY_RMWcc("decl", __my_cpu_var(pcpu_hot.preempt_count), e, + return GEN_UNARY_RMWcc("decl", __my_cpu_var(__preempt_count), e, __percpu_arg([var])); } =20 @@ -100,7 +101,7 @@ static __always_inline bool __preempt_count_dec_and_tes= t(void) */ static __always_inline bool should_resched(int preempt_offset) { - return unlikely(raw_cpu_read_4(pcpu_hot.preempt_count) =3D=3D preempt_off= set); + return unlikely(raw_cpu_read_4(__preempt_count) =3D=3D preempt_offset); } =20 #ifdef CONFIG_PREEMPTION diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 24aa8d4..c479d3c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2049,12 +2049,14 @@ __setup("setcpuid=3D", setup_setcpuid); =20 DEFINE_PER_CPU_CACHE_HOT(struct pcpu_hot, pcpu_hot) =3D { .current_task =3D &init_task, - .preempt_count =3D INIT_PREEMPT_COUNT, .top_of_stack =3D TOP_OF_INIT_STACK, }; EXPORT_PER_CPU_SYMBOL(pcpu_hot); EXPORT_PER_CPU_SYMBOL(const_pcpu_hot); =20 +DEFINE_PER_CPU_CACHE_HOT(int, __preempt_count) =3D INIT_PREEMPT_COUNT; +EXPORT_PER_CPU_SYMBOL(__preempt_count); + #ifdef CONFIG_X86_64 static void wrmsrl_cstar(unsigned long val) { diff --git a/include/linux/preempt.h b/include/linux/preempt.h index ca86235..4c1af9b 100644 --- a/include/linux/preempt.h +++ b/include/linux/preempt.h @@ -319,6 +319,7 @@ do { \ #ifdef CONFIG_PREEMPT_NOTIFIERS =20 struct preempt_notifier; +struct task_struct; =20 /** * preempt_ops - notifiers called when a task is preempted and rescheduled