Skip to content

Commit 35ce649

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/idle: Select idle routine only once
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> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/87edcu6vaq.ffs@tglx
1 parent 5f75916 commit 35ce649

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

arch/x86/include/asm/processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static inline void load_sp0(unsigned long sp0)
558558

559559
unsigned long __get_wchan(struct task_struct *p);
560560

561-
extern void select_idle_routine(const struct cpuinfo_x86 *c);
561+
extern void select_idle_routine(void);
562562
extern void amd_e400_c1e_apic_setup(void);
563563

564564
extern unsigned long boot_option_idle_override;

arch/x86/kernel/cpu/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,6 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19381938
/* Init Machine Check Exception if available. */
19391939
mcheck_cpu_init(c);
19401940

1941-
select_idle_routine(c);
1942-
19431941
#ifdef CONFIG_NUMA
19441942
numa_add_cpu(smp_processor_id());
19451943
#endif
@@ -2344,6 +2342,8 @@ void __init arch_cpu_finalize_init(void)
23442342
{
23452343
identify_boot_cpu();
23462344

2345+
select_idle_routine();
2346+
23472347
/*
23482348
* identify_boot_cpu() initialized SMT support information, let the
23492349
* core code know.

arch/x86/kernel/process.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,9 @@ void __noreturn stop_this_cpu(void *dummy)
853853
* Do not prefer MWAIT if MONITOR instruction has a bug or idle=nomwait
854854
* is passed to kernel commandline parameter.
855855
*/
856-
static bool prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c)
856+
static __init bool prefer_mwait_c1_over_halt(void)
857857
{
858+
const struct cpuinfo_x86 *c = &boot_cpu_data;
858859
u32 eax, ebx, ecx, edx;
859860

860861
/* If override is enforced on the command line, fall back to HALT. */
@@ -908,18 +909,19 @@ static __cpuidle void mwait_idle(void)
908909
__current_clr_polling();
909910
}
910911

911-
void select_idle_routine(const struct cpuinfo_x86 *c)
912+
void __init select_idle_routine(void)
912913
{
913914
if (boot_option_idle_override == IDLE_POLL) {
914915
if (IS_ENABLED(CONFIG_SMP) && smp_num_siblings > 1)
915916
pr_warn_once("WARNING: polling idle and HT enabled, performance may degrade\n");
916917
return;
917918
}
918919

920+
/* Required to guard against xen_set_default_idle() */
919921
if (x86_idle_set())
920922
return;
921923

922-
if (prefer_mwait_c1_over_halt(c)) {
924+
if (prefer_mwait_c1_over_halt()) {
923925
pr_info("using mwait in idle threads\n");
924926
static_call_update(x86_idle, mwait_idle);
925927
} else if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) {

0 commit comments

Comments
 (0)