public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: x86@kernel.org, Steven Rostedt <rostedt@goodmis.org>,
	"Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: [patch 6/6] x86/idle: Select idle routine only once
Date: Fri, 01 Mar 2024 12:33:33 +0100	[thread overview]
Message-ID: <87edcu6vaq.ffs@tglx> (raw)
In-Reply-To: <87h6hq74j0.ffs@tglx>

On Fri, Mar 01 2024 at 09:14, Thomas Gleixner wrote:
> On Thu, Feb 29 2024 at 15:23, Thomas Gleixner wrote:
>>  
>> -	if (x86_idle_set())
>> -		return;
>> -
>
> Bah. With XEN=n this results in a defined but not used warning.
> Updated version below.

I'm a moron. xen_set_default_idle() is invoked very early on, so
select_idle_routine() has to keep the check. Sigh.

Fixed it and added an comment to that effect.

---
Subject: x86/idle: Select idle routine only once
From: Thomas Gleixner <tglx@linutronix.de>
Date: Wed, 28 Feb 2024 23:20:32 +0100

The idle routine selection is done on every CPU bringup operation and has a
guard in place which is effective after the first invocation, which is a
pointless exercise.

Invoke it once on the boot CPU and mark the related functions __init.
The guard check has to stay as xen_set_default_idle() runs early.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V1b: Keep the x86_idle_set() check so XEN keeps working
V1a: Move x86_idle_set() into the only usage site (0day)
---
 arch/x86/include/asm/processor.h |    2 +-
 arch/x86/kernel/cpu/common.c     |    4 ++--
 arch/x86/kernel/process.c        |    8 +++++---
 3 files changed, 8 insertions(+), 6 deletions(-)

--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -555,7 +555,7 @@ static inline void load_sp0(unsigned lon
 
 unsigned long __get_wchan(struct task_struct *p);
 
-extern void select_idle_routine(const struct cpuinfo_x86 *c);
+extern void select_idle_routine(void);
 extern void amd_e400_c1e_apic_setup(void);
 
 extern unsigned long		boot_option_idle_override;
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1938,8 +1938,6 @@ static void identify_cpu(struct cpuinfo_
 	/* Init Machine Check Exception if available. */
 	mcheck_cpu_init(c);
 
-	select_idle_routine(c);
-
 #ifdef CONFIG_NUMA
 	numa_add_cpu(smp_processor_id());
 #endif
@@ -2343,6 +2341,8 @@ void __init arch_cpu_finalize_init(void)
 {
 	identify_boot_cpu();
 
+	select_idle_routine();
+
 	/*
 	 * identify_boot_cpu() initialized SMT support information, let the
 	 * core code know.
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -853,8 +853,9 @@ void __noreturn stop_this_cpu(void *dumm
  * Do not prefer MWAIT if MONITOR instruction has a bug or idle=nomwait
  * is passed to kernel commandline parameter.
  */
-static bool prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c)
+static __init bool prefer_mwait_c1_over_halt(void)
 {
+	const struct cpuinfo_x86 *c = &boot_cpu_data;
 	u32 eax, ebx, ecx, edx;
 
 	/* If override is enforced on the command line, fall back to HALT. */
@@ -908,7 +909,7 @@ static __cpuidle void mwait_idle(void)
 	__current_clr_polling();
 }
 
-void select_idle_routine(const struct cpuinfo_x86 *c)
+void __init select_idle_routine(void)
 {
 	if (boot_option_idle_override == IDLE_POLL) {
 		if (IS_ENABLED(CONFIG_SMP) && smp_num_siblings > 1)
@@ -916,10 +917,11 @@ void select_idle_routine(const struct cp
 		return;
 	}
 
+	/* Required to guard against xen_set_default_idle() */
 	if (x86_idle_set())
 		return;
 
-	if (prefer_mwait_c1_over_halt(c)) {
+	if (prefer_mwait_c1_over_halt()) {
 		pr_info("using mwait in idle threads\n");
 		static_call_update(x86_idle, mwait_idle);
 	} else if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) {

  reply	other threads:[~2024-03-01 11:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 14:23 [patch 0/6] x86/idle: Cure RCU violations and cleanups Thomas Gleixner
2024-02-29 14:23 ` [patch 1/6] sched/idle: Conditionally handle tick broadcast in default_idle_call() Thomas Gleixner
2024-03-01 20:48   ` [tip: x86/core] " tip-bot2 for Thomas Gleixner
2024-02-29 14:23 ` [patch 2/6] x86/idle: Sanitize X86_BUG_AMD_E400 handling Thomas Gleixner
2024-03-01 12:33   ` Thomas Gleixner
2024-03-01 20:48     ` [tip: x86/core] " tip-bot2 for Thomas Gleixner
2024-03-04 16:51     ` tip-bot2 for Thomas Gleixner
2024-02-29 14:23 ` [patch 3/6] x86/idle: Clean up idle selection Thomas Gleixner
2024-03-01 20:48   ` [tip: x86/core] " tip-bot2 for Thomas Gleixner
2024-03-04 16:51   ` tip-bot2 for Thomas Gleixner
2024-02-29 14:23 ` [patch 4/6] x86/idle: Cleanup idle_setup() Thomas Gleixner
2024-03-01 20:48   ` [tip: x86/core] " tip-bot2 for Thomas Gleixner
2024-03-04 16:51   ` tip-bot2 for Thomas Gleixner
2024-02-29 14:23 ` [patch 5/6] x86/idle: Let prefer_mwait_c1_over_halt() return bool Thomas Gleixner
2024-03-01 20:48   ` [tip: x86/core] " tip-bot2 for Thomas Gleixner
2024-03-04 16:51   ` tip-bot2 for Thomas Gleixner
2024-02-29 14:23 ` [patch 6/6] x86/idle: Select idle routine only once Thomas Gleixner
2024-03-01  8:14   ` Thomas Gleixner
2024-03-01 11:33     ` Thomas Gleixner [this message]
2024-03-01 20:48       ` [tip: x86/core] " tip-bot2 for Thomas Gleixner
2024-03-04 16:51       ` tip-bot2 for Thomas Gleixner
2024-03-01 18:41 ` [patch 0/6] x86/idle: Cure RCU violations and cleanups Borislav Petkov

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=87edcu6vaq.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rostedt@goodmis.org \
    --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