History

sched: Simplify ifdeffery around cpu_smt_mask

Now, that cpu_smt_mask is defined as cpumask_of(cpu) for CONFIG_SCHED_SMT=n, it is possible to get rid of the ifdeffery. Effectively, - This makes sched_smt_present is defined always - cpumask_weight(cpumask_of(cpu)) == 1. So sched_smt_present_inc/dec will never enable the sched_smt_present. Which is expected. - Paths that were compile-time eliminated become runtime guarded using static keys. - Defines set_idle_cores, test_idle_cores, etc which could likely benefit the CONFIG_SCHED_SMT=n systems to use the same optimizations within the LLC at wakeups. - This will expose sched_smt_present symbol for CONFIG_SCHED_SMT=n. Likely not a concern. - There is a bloat of code CONFIG_SCHED_SMT=n. (NR_CPUS=2048) add/remove: 24/18 grow/shrink: 26/28 up/down: 6396/-3188 (3208) Total: Before=30629880, After=30633088, chg +0.01% - No code bloat for CONFIG_SCHED_SMT=y, which is expected. - Add comments around stop_core_cpuslocked on why ifdefs are not removed. - This leaves the remaining uses of CONFIG_SCHED_SMT mainly for topology building bits which has a policy based decision.

Shrikanth Hegde committed 6 months ago

Commit 5bc6ab21 parent 815c5cb8 files · +5 −63Browse files

Unified · Split

8 files
  1. include/linux/sched/smt.h +0 −4
  2. kernel/sched/core.c +0 −6
  3. kernel/sched/ext_idle.c +0 −6
  4. kernel/sched/fair.c +0 −35
  5. kernel/sched/sched.h +0 −6
  6. kernel/sched/topology.c +0 −2
  7. kernel/stop_machine.c +5 −0
  8. kernel/workqueue.c +0 −4
include/linux/sched/smt.h+0−4
@@ -4,16 +4,12 @@ · 3 unmodified lines
44
55 #include <linux/static_key.h>
66
7−#ifdef CONFIG_SCHED_SMT
87 extern struct static_key_false sched_smt_present;
98
109 static __always_inline bool sched_smt_active(void)
1110 {
1211 return static_branch_likely(&sched_smt_present);
1312 }
14−#else
15−static __always_inline bool sched_smt_active(void) { return false; }
16−#endif
1713
1814 void arch_smt_update(void);
1915
kernel/sched/core.c+0−6
@@ -8612,18 +8612,14 @@ static void cpuset_cpu_inactive(unsigned int cpu) · 8611 unmodified lines
86128612
86138613 static inline void sched_smt_present_inc(int cpu)
86148614 {
8615−#ifdef CONFIG_SCHED_SMT
86168615 if (cpumask_weight(cpu_smt_mask(cpu)) == 2)
86178616 static_branch_inc_cpuslocked(&sched_smt_present);
8618−#endif
86198617 }
86208618
86218619 static inline void sched_smt_present_dec(int cpu)
86228620 {
8623−#ifdef CONFIG_SCHED_SMT
86248621 if (cpumask_weight(cpu_smt_mask(cpu)) == 2)
86258622 static_branch_dec_cpuslocked(&sched_smt_present);
8626−#endif
86278623 }
86288624
86298625 int sched_cpu_activate(unsigned int cpu)
@@ -8711,9 +8707,7 @@ int sched_cpu_deactivate(unsigned int cpu) · 81 unmodified lines
87118707 */
87128708 sched_smt_present_dec(cpu);
87138709
8714−#ifdef CONFIG_SCHED_SMT
87158710 sched_core_cpu_deactivate(cpu);
8716−#endif
87178711
87188712 if (!sched_smp_initialized)
87198713 return 0;
kernel/sched/ext_idle.c+0−6
@@ -79,7 +79,6 @@ static bool scx_idle_test_and_clear_cpu(int cpu) · 78 unmodified lines
7979 int node = scx_cpu_node_if_enabled(cpu);
8080 struct cpumask *idle_cpus = idle_cpumask(node)->cpu;
8181
82−#ifdef CONFIG_SCHED_SMT
8382 /*
8483 * SMT mask should be cleared whether we can claim @cpu or not. The SMT
8584 * cluster is not wholly idle either way. This also prevents
@@ -104,7 +103,6 @@ static bool scx_idle_test_and_clear_cpu(int cpu) · 18 unmodified lines
104103 else if (cpumask_test_cpu(cpu, idle_smts))
105104 __cpumask_clear_cpu(cpu, idle_smts);
106105 }
107−#endif
108106
109107 return cpumask_test_and_clear_cpu(cpu, idle_cpus);
110108 }
@@ -622,7 +620,6 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, · 511 unmodified lines
622620 goto out_unlock;
623621 }
624622
625−#ifdef CONFIG_SCHED_SMT
626623 /*
627624 * Use @prev_cpu's sibling if it's idle.
628625 */
@@ -634,7 +631,6 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, · 5 unmodified lines
634631 goto out_unlock;
635632 }
636633 }
637−#endif
638634
639635 /*
640636 * Search for any idle CPU in the same LLC domain.
@@ -714,7 +710,6 @@ static void update_builtin_idle(int cpu, bool idle) · 73 unmodified lines
714710
715711 assign_cpu(cpu, idle_cpus, idle);
716712
717−#ifdef CONFIG_SCHED_SMT
718713 if (sched_smt_active()) {
719714 const struct cpumask *smt = cpu_smt_mask(cpu);
720715 struct cpumask *idle_smts = idle_cpumask(node)->smt;
@@ -731,7 +726,6 @@ static void update_builtin_idle(int cpu, bool idle) · 10 unmodified lines
731726 cpumask_andnot(idle_smts, idle_smts, smt);
732727 }
733728 }
734−#endif
735729 }
736730
737731 /*
kernel/sched/fair.c+0−35
@@ -1555,7 +1555,6 @@ update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se) · 1554 unmodified lines
15551555
15561556 static inline bool is_core_idle(int cpu)
15571557 {
1558−#ifdef CONFIG_SCHED_SMT
15591558 int sibling;
15601559
15611560 for_each_cpu(sibling, cpu_smt_mask(cpu)) {
@@ -1565,7 +1564,6 @@ static inline bool is_core_idle(int cpu) · 3 unmodified lines
15651564 if (!idle_cpu(sibling))
15661565 return false;
15671566 }
1568−#endif
15691567
15701568 return true;
15711569 }
@@ -2248,7 +2246,6 @@ numa_type numa_classify(unsigned int imbalance_pct, · 676 unmodified lines
22482246 return node_fully_busy;
22492247 }
22502248
2251−#ifdef CONFIG_SCHED_SMT
22522249 /* Forward declarations of select_idle_sibling helpers */
22532250 static inline bool test_idle_cores(int cpu);
22542251 static inline int numa_idle_core(int idle_core, int cpu)
@@ -2266,12 +2263,6 @@ static inline int numa_idle_core(int idle_core, int cpu) · 11 unmodified lines
22662263
22672264 return idle_core;
22682265 }
2269−#else /* !CONFIG_SCHED_SMT: */
2270−static inline int numa_idle_core(int idle_core, int cpu)
2271−{
2272− return idle_core;
2273−}
2274−#endif /* !CONFIG_SCHED_SMT */
22752266
22762267 /*
22772268 * Gather all necessary information to make NUMA balancing placement
@@ -7778,7 +7769,6 @@ static inline int __select_idle_cpu(int cpu, struct task_struct *p) · 5500 unmodified lines
77787769 return -1;
77797770 }
77807771
7781−#ifdef CONFIG_SCHED_SMT
77827772 DEFINE_STATIC_KEY_FALSE(sched_smt_present);
77837773 EXPORT_SYMBOL_GPL(sched_smt_present);
77847774
@@ -7888,29 +7878,6 @@ static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int t · 103 unmodified lines
78887878 return -1;
78897879 }
78907880
7891−#else /* !CONFIG_SCHED_SMT: */
7892−
7893−static inline void set_idle_cores(int cpu, int val)
7894−{
7895−}
7896−
7897−static inline bool test_idle_cores(int cpu)
7898−{
7899− return false;
7900−}
7901−
7902−static inline int select_idle_core(struct task_struct *p, int core, struct cpumask *cpus, int *idle_cpu)
7903−{
7904− return __select_idle_cpu(core, p);
7905−}
7906−
7907−static inline int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target)
7908−{
7909− return -1;
7910−}
7911−
7912−#endif /* !CONFIG_SCHED_SMT */
7913−
79147881 /*
79157882 * Scan the LLC domain for idle CPUs; this is dynamically regulated by
79167883 * comparing the average scan cost (tracked in sd->avg_scan_cost) against the
@@ -12002,9 +11969,7 @@ static int should_we_balance(struct lb_env *env) · 4085 unmodified lines
1200211969 * idle has been found, then its not needed to check other
1200311970 * SMT siblings for idleness:
1200411971 */
12005−#ifdef CONFIG_SCHED_SMT
1200611972 cpumask_andnot(swb_cpus, swb_cpus, cpu_smt_mask(cpu));
12007−#endif
1200811973 continue;
1200911974 }
1201011975
kernel/sched/sched.h+0−6
@@ -1667,7 +1667,6 @@ do { \ · 1666 unmodified lines
16671667 flags = _raw_spin_rq_lock_irqsave(rq); \
16681668 } while (0)
16691669
1670−#ifdef CONFIG_SCHED_SMT
16711670 extern void __update_idle_core(struct rq *rq);
16721671
16731672 static inline void update_idle_core(struct rq *rq)
@@ -1676,12 +1675,7 @@ static inline void update_idle_core(struct rq *rq) · 2 unmodified lines
16761675 __update_idle_core(rq);
16771676 }
16781677
1679−#else /* !CONFIG_SCHED_SMT: */
1680−static inline void update_idle_core(struct rq *rq) { }
1681−#endif /* !CONFIG_SCHED_SMT */
1682−
16831678 #ifdef CONFIG_FAIR_GROUP_SCHED
1684−
16851679 static inline struct task_struct *task_of(struct sched_entity *se)
16861680 {
16871681 WARN_ON_ONCE(!entity_is_task(se));
kernel/sched/topology.c+0−2
@@ -1310,9 +1310,7 @@ static void init_sched_groups_capacity(int cpu, struct sched_domain *sd) · 1309 unmodified lines
13101310 cpumask_copy(mask, sched_group_span(sg));
13111311 for_each_cpu(cpu, mask) {
13121312 cores++;
1313−#ifdef CONFIG_SCHED_SMT
13141313 cpumask_andnot(mask, mask, cpu_smt_mask(cpu));
1315−#endif
13161314 }
13171315 sg->cores = cores;
13181316
kernel/stop_machine.c+5−0
@@ -633,6 +633,11 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus) · 632 unmodified lines
633633 EXPORT_SYMBOL_GPL(stop_machine);
634634
635635 #ifdef CONFIG_SCHED_SMT
636+/*
637+ * INTEL_IFS is the only user of this API. That selftest can
638+ * only be compiled if SMP=y. On x86 it selects SCHED_SMT.
639+ * Keep the ifdefs for now.
640+ */
636641 int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
637642 {
638643 const struct cpumask *smt_mask = cpu_smt_mask(cpu);
kernel/workqueue.c+0−4
@@ -8187,11 +8187,7 @@ static bool __init cpus_dont_share(int cpu0, int cpu1) · 8186 unmodified lines
81878187
81888188 static bool __init cpus_share_smt(int cpu0, int cpu1)
81898189 {
8190−#ifdef CONFIG_SCHED_SMT
81918190 return cpumask_test_cpu(cpu0, cpu_smt_mask(cpu1));
8192−#else
8193− return false;
8194−#endif
81958191 }
81968192
81978193 static bool __init cpus_share_numa(int cpu0, int cpu1)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t