public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Gerst <brgerst@gmail.com>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Ingo Molnar <mingo@kernel.org>, "H . Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>, Ard Biesheuvel <ardb@kernel.org>,
	Uros Bizjak <ubizjak@gmail.com>,
	Linus Torvalds <torvalds@linuxfoundation.org>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Brian Gerst <brgerst@gmail.com>
Subject: [PATCH v3 03/11] x86/preempt: Move preempt count to percpu hot section
Date: Mon,  3 Mar 2025 11:52:38 -0500	[thread overview]
Message-ID: <20250303165246.2175811-4-brgerst@gmail.com> (raw)
In-Reply-To: <20250303165246.2175811-1-brgerst@gmail.com>

No functional change.

Signed-off-by: Brian Gerst <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 60bc66edca83..46a736d6f2ec 100644
--- a/arch/x86/include/asm/current.h
+++ b/arch/x86/include/asm/current.h
@@ -14,7 +14,6 @@ struct task_struct;
 
 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 7e834820e030..a1748b4e5598 100644
--- a/arch/x86/include/asm/preempt.h
+++ b/arch/x86/include/asm/preempt.h
@@ -4,10 +4,11 @@
 
 #include <asm/rmwcc.h>
 #include <asm/percpu.h>
-#include <asm/current.h>
 
 #include <linux/static_call_types.h>
 
+DECLARE_PER_CPU_CACHE_HOT(int, __preempt_count);
+
 /* We use the MSB mostly because its available */
 #define PREEMPT_NEED_RESCHED	0x80000000
 
@@ -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;
 }
 
 static __always_inline void preempt_count_set(int pc)
 {
 	int old, new;
 
-	old = raw_cpu_read_4(pcpu_hot.preempt_count);
+	old = raw_cpu_read_4(__preempt_count);
 	do {
 		new = (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));
 }
 
 /*
@@ -43,7 +44,7 @@ static __always_inline void preempt_count_set(int pc)
 #define init_task_preempt_count(p) do { } while (0)
 
 #define init_idle_preempt_count(p, cpu) do { \
-	per_cpu(pcpu_hot.preempt_count, (cpu)) = PREEMPT_DISABLED; \
+	per_cpu(__preempt_count, (cpu)) = PREEMPT_DISABLED; \
 } while (0)
 
 /*
@@ -57,17 +58,17 @@ static __always_inline void preempt_count_set(int pc)
 
 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);
 }
 
 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);
 }
 
 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);
 }
 
 /*
@@ -76,12 +77,12 @@ static __always_inline bool test_preempt_need_resched(void)
 
 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);
 }
 
 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);
 }
 
 /*
@@ -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]));
 }
 
@@ -100,7 +101,7 @@ static __always_inline bool __preempt_count_dec_and_test(void)
  */
 static __always_inline bool should_resched(int preempt_offset)
 {
-	return unlikely(raw_cpu_read_4(pcpu_hot.preempt_count) == preempt_offset);
+	return unlikely(raw_cpu_read_4(__preempt_count) == preempt_offset);
 }
 
 #ifdef CONFIG_PREEMPTION
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index c33eaca1e9f9..8db36699dc78 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -2051,12 +2051,14 @@ __setup("setcpuid=", setup_setcpuid);
 
 DEFINE_PER_CPU_CACHE_HOT(struct pcpu_hot, pcpu_hot) = {
 	.current_task	= &init_task,
-	.preempt_count	= INIT_PREEMPT_COUNT,
 	.top_of_stack	= TOP_OF_INIT_STACK,
 };
 EXPORT_PER_CPU_SYMBOL(pcpu_hot);
 EXPORT_PER_CPU_SYMBOL(const_pcpu_hot);
 
+DEFINE_PER_CPU_CACHE_HOT(int, __preempt_count) = 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 ca86235ac15c..4c1af9b7e28b 100644
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -319,6 +319,7 @@ do { \
 #ifdef CONFIG_PREEMPT_NOTIFIERS
 
 struct preempt_notifier;
+struct task_struct;
 
 /**
  * preempt_ops - notifiers called when a task is preempted and rescheduled
-- 
2.48.1


  parent reply	other threads:[~2025-03-03 16:53 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 16:52 [PATCH v3 00/11] Add a percpu subsection for cache hot data Brian Gerst
2025-03-03 16:52 ` [PATCH v3 01/11] percpu: Introduce percpu hot section Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:34   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 02/11] x86/percpu: Move pcpu_hot to " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:34   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` Brian Gerst [this message]
2025-03-04  8:27   ` [tip: x86/core] x86/preempt: Move preempt count " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:34   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 04/11] x86/smp: Move cpu number " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:34   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 05/11] x86/retbleed: Move call depth " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:34   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 06/11] x86/softirq: Move softirq_pending " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:34   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 07/11] x86/irq: Move irq stacks " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:34   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 08/11] x86/percpu: Move top_of_stack " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:33   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 09/11] x86/percpu: Move current_task " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:33   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 10/11] x86/stackprotector: Move __stack_chk_guard " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:33   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 16:52 ` [PATCH v3 11/11] x86/smp: Move this_cpu_off " Brian Gerst
2025-03-04  8:27   ` [tip: x86/core] " tip-bot2 for Brian Gerst
2025-03-04 10:36   ` tip-bot2 for Brian Gerst
2025-03-04 19:33   ` tip-bot2 for Brian Gerst
2025-03-04 19:43   ` tip-bot2 for Brian Gerst
2025-03-03 19:53 ` [PATCH v3 00/11] Add a percpu subsection for cache hot data Uros Bizjak
2025-03-03 20:38 ` Ingo Molnar
2025-03-03 20:55   ` Brian Gerst
2025-03-04  8:47     ` Ingo Molnar
2025-03-04  9:26       ` Brian Gerst
2025-03-04  9:47         ` Ingo Molnar
2025-03-04  9:52           ` Uros Bizjak
2025-03-04  9:55             ` Ingo Molnar
2025-03-04 15:00               ` Brian Gerst
2025-03-04 16:01                 ` Uros Bizjak
2025-03-04 16:42                   ` Brian Gerst
2025-03-04 16:48                     ` Uros Bizjak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250303165246.2175811-4-brgerst@gmail.com \
    --to=brgerst@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linuxfoundation.org \
    --cc=ubizjak@gmail.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox