[lkml]   [2018]   [Nov]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectRe: [Patch v5 08/16] smt: Create cpu_smt_enabled static key for SMT specific code
On Fri, Nov 16, 2018 at 05:53:51PM -0800, Tim Chen wrote:
> In later code, STIBP will be turned on/off in the context switch code
> path when SMT is enabled. Checks for SMT is best
> avoided on such hot paths.
> Create cpu_smt_enabled static key to turn on such SMT specific code
> statically.

AFAICT this patch only follows the SMT control knob but not the actual
topology state.

And, as I previously wrote, we already have sched_smt_present, which is
supposed to do much the same.

All you need is the below to make it accurately track the topology.

Subject: sched/smt: Make sched_smt_present track topology

Currently the sched_smt_present static key is only enabled when we
encounter SMT topology. However there is demand to also disable the key
when the topology changes such that there is no SMT present anymore.

Implement this by making the key count the number of cores that have SMT

In particular, the SMT topology bits are set before we enable
interrrupts and similarly, are cleared after we disable interrupts for
the last time and die.

Signed-off-by: Peter Zijlstra (Intel) <>
kernel/sched/core.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f12225f26b70..77e552928c67 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5738,15 +5738,10 @@ int sched_cpu_activate(unsigned int cpu)

- * The sched_smt_present static key needs to be evaluated on every
- * hotplug event because at boot time SMT might be disabled when
- * the number of booted CPUs is limited.
- *
- * If then later a sibling gets hotplugged, then the key would stay
- * off and SMT scheduling would never be functional.
+ * When going up, increment the number of cores with SMT present.
- if (cpumask_weight(cpu_smt_mask(cpu)) > 1)
- static_branch_enable_cpuslocked(&sched_smt_present);
+ if (cpumask_weight(cpu_smt_mask(cpu)) == 2)
+ static_branch_inc_cpuslocked(&sched_smt_present);
set_cpu_active(cpu, true);

@@ -5790,6 +5785,14 @@ int sched_cpu_deactivate(unsigned int cpu)
synchronize_rcu_mult(call_rcu, call_rcu_sched);

+ /*
+ * When going down, decrement the number of cores with SMT present.
+ */
+ if (cpumask_weight(cpu_smt_mask(cpu)) == 2)
+ static_branch_dec_cpuslocked(&sched_smt_present);
if (!sched_smp_initialized)
return 0;

 \ /
  Last update: 2018-11-19 15:59    [W:0.242 / U:8.216 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site