Skip to content

Commit ba2591a

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
sched/smt: Update sched_smt_present at runtime
The static key sched_smt_present is only updated at boot time when SMT siblings have been detected. Booting with maxcpus=1 and bringing the siblings online after boot rebuilds the scheduling domains correctly but does not update the static key, so the SMT code is not enabled. Let the key be updated in the scheduler CPU hotplug code to fix this. Signed-off-by: Peter Zijlstra <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]> Acked-by: Ingo Molnar <[email protected]>
1 parent 56563f5 commit ba2591a

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

kernel/sched/core.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,6 +5777,18 @@ int sched_cpu_activate(unsigned int cpu)
57775777
struct rq *rq = cpu_rq(cpu);
57785778
struct rq_flags rf;
57795779

5780+
#ifdef CONFIG_SCHED_SMT
5781+
/*
5782+
* The sched_smt_present static key needs to be evaluated on every
5783+
* hotplug event because at boot time SMT might be disabled when
5784+
* the number of booted CPUs is limited.
5785+
*
5786+
* If then later a sibling gets hotplugged, then the key would stay
5787+
* off and SMT scheduling would never be functional.
5788+
*/
5789+
if (cpumask_weight(cpu_smt_mask(cpu)) > 1)
5790+
static_branch_enable_cpuslocked(&sched_smt_present);
5791+
#endif
57805792
set_cpu_active(cpu, true);
57815793

57825794
if (sched_smp_initialized) {
@@ -5874,22 +5886,6 @@ int sched_cpu_dying(unsigned int cpu)
58745886
}
58755887
#endif
58765888

5877-
#ifdef CONFIG_SCHED_SMT
5878-
DEFINE_STATIC_KEY_FALSE(sched_smt_present);
5879-
5880-
static void sched_init_smt(void)
5881-
{
5882-
/*
5883-
* We've enumerated all CPUs and will assume that if any CPU
5884-
* has SMT siblings, CPU0 will too.
5885-
*/
5886-
if (cpumask_weight(cpu_smt_mask(0)) > 1)
5887-
static_branch_enable(&sched_smt_present);
5888-
}
5889-
#else
5890-
static inline void sched_init_smt(void) { }
5891-
#endif
5892-
58935889
void __init sched_init_smp(void)
58945890
{
58955891
sched_init_numa();
@@ -5911,8 +5907,6 @@ void __init sched_init_smp(void)
59115907
init_sched_rt_class();
59125908
init_sched_dl_class();
59135909

5914-
sched_init_smt();
5915-
59165910
sched_smp_initialized = true;
59175911
}
59185912

kernel/sched/fair.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6238,6 +6238,7 @@ static inline int find_idlest_cpu(struct sched_domain *sd, struct task_struct *p
62386238
}
62396239

62406240
#ifdef CONFIG_SCHED_SMT
6241+
DEFINE_STATIC_KEY_FALSE(sched_smt_present);
62416242

62426243
static inline void set_idle_cores(int cpu, int val)
62436244
{

0 commit comments

Comments
 (0)