Skip to content

Commit f8b6d1c

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Use jump_labels for sched_feat
Now that we initialize jump_labels before sched_init() we can use them for the debug features without having to worry about a window where they have the wrong setting. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/n/tip-vpreo4hal9e0kzqmg5y0io2k@git.kernel.org Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent be726ff commit f8b6d1c

3 files changed

Lines changed: 81 additions & 22 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int sched_feat_show(struct seq_file *m, void *v)
149149
{
150150
int i;
151151

152-
for (i = 0; sched_feat_names[i]; i++) {
152+
for (i = 0; i < __SCHED_FEAT_NR; i++) {
153153
if (!(sysctl_sched_features & (1UL << i)))
154154
seq_puts(m, "NO_");
155155
seq_printf(m, "%s ", sched_feat_names[i]);
@@ -159,6 +159,36 @@ static int sched_feat_show(struct seq_file *m, void *v)
159159
return 0;
160160
}
161161

162+
#ifdef HAVE_JUMP_LABEL
163+
164+
#define jump_label_key__true jump_label_key_enabled
165+
#define jump_label_key__false jump_label_key_disabled
166+
167+
#define SCHED_FEAT(name, enabled) \
168+
jump_label_key__##enabled ,
169+
170+
struct jump_label_key sched_feat_keys[__SCHED_FEAT_NR] = {
171+
#include "features.h"
172+
};
173+
174+
#undef SCHED_FEAT
175+
176+
static void sched_feat_disable(int i)
177+
{
178+
if (jump_label_enabled(&sched_feat_keys[i]))
179+
jump_label_dec(&sched_feat_keys[i]);
180+
}
181+
182+
static void sched_feat_enable(int i)
183+
{
184+
if (!jump_label_enabled(&sched_feat_keys[i]))
185+
jump_label_inc(&sched_feat_keys[i]);
186+
}
187+
#else
188+
static void sched_feat_disable(int i) { };
189+
static void sched_feat_enable(int i) { };
190+
#endif /* HAVE_JUMP_LABEL */
191+
162192
static ssize_t
163193
sched_feat_write(struct file *filp, const char __user *ubuf,
164194
size_t cnt, loff_t *ppos)
@@ -182,17 +212,20 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
182212
cmp += 3;
183213
}
184214

185-
for (i = 0; sched_feat_names[i]; i++) {
215+
for (i = 0; i < __SCHED_FEAT_NR; i++) {
186216
if (strcmp(cmp, sched_feat_names[i]) == 0) {
187-
if (neg)
217+
if (neg) {
188218
sysctl_sched_features &= ~(1UL << i);
189-
else
219+
sched_feat_disable(i);
220+
} else {
190221
sysctl_sched_features |= (1UL << i);
222+
sched_feat_enable(i);
223+
}
191224
break;
192225
}
193226
}
194227

195-
if (!sched_feat_names[i])
228+
if (i == __SCHED_FEAT_NR)
196229
return -EINVAL;
197230

198231
*ppos += cnt;
@@ -221,8 +254,7 @@ static __init int sched_init_debug(void)
221254
return 0;
222255
}
223256
late_initcall(sched_init_debug);
224-
225-
#endif
257+
#endif /* CONFIG_SCHED_DEBUG */
226258

227259
/*
228260
* Number of tasks to iterate in a single balance run.

‎kernel/sched/features.h‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,68 @@
33
* them to run sooner, but does not allow tons of sleepers to
44
* rip the spread apart.
55
*/
6-
SCHED_FEAT(GENTLE_FAIR_SLEEPERS, 1)
6+
SCHED_FEAT(GENTLE_FAIR_SLEEPERS, true)
77

88
/*
99
* Place new tasks ahead so that they do not starve already running
1010
* tasks
1111
*/
12-
SCHED_FEAT(START_DEBIT, 1)
12+
SCHED_FEAT(START_DEBIT, true)
1313

1414
/*
1515
* Based on load and program behaviour, see if it makes sense to place
1616
* a newly woken task on the same cpu as the task that woke it --
1717
* improve cache locality. Typically used with SYNC wakeups as
1818
* generated by pipes and the like, see also SYNC_WAKEUPS.
1919
*/
20-
SCHED_FEAT(AFFINE_WAKEUPS, 1)
20+
SCHED_FEAT(AFFINE_WAKEUPS, true)
2121

2222
/*
2323
* Prefer to schedule the task we woke last (assuming it failed
2424
* wakeup-preemption), since its likely going to consume data we
2525
* touched, increases cache locality.
2626
*/
27-
SCHED_FEAT(NEXT_BUDDY, 0)
27+
SCHED_FEAT(NEXT_BUDDY, false)
2828

2929
/*
3030
* Prefer to schedule the task that ran last (when we did
3131
* wake-preempt) as that likely will touch the same data, increases
3232
* cache locality.
3333
*/
34-
SCHED_FEAT(LAST_BUDDY, 1)
34+
SCHED_FEAT(LAST_BUDDY, true)
3535

3636
/*
3737
* Consider buddies to be cache hot, decreases the likelyness of a
3838
* cache buddy being migrated away, increases cache locality.
3939
*/
40-
SCHED_FEAT(CACHE_HOT_BUDDY, 1)
40+
SCHED_FEAT(CACHE_HOT_BUDDY, true)
4141

4242
/*
4343
* Use arch dependent cpu power functions
4444
*/
45-
SCHED_FEAT(ARCH_POWER, 0)
45+
SCHED_FEAT(ARCH_POWER, false)
4646

47-
SCHED_FEAT(HRTICK, 0)
48-
SCHED_FEAT(DOUBLE_TICK, 0)
49-
SCHED_FEAT(LB_BIAS, 1)
47+
SCHED_FEAT(HRTICK, false)
48+
SCHED_FEAT(DOUBLE_TICK, false)
49+
SCHED_FEAT(LB_BIAS, true)
5050

5151
/*
5252
* Spin-wait on mutex acquisition when the mutex owner is running on
5353
* another cpu -- assumes that when the owner is running, it will soon
5454
* release the lock. Decreases scheduling overhead.
5555
*/
56-
SCHED_FEAT(OWNER_SPIN, 1)
56+
SCHED_FEAT(OWNER_SPIN, true)
5757

5858
/*
5959
* Decrement CPU power based on time not spent running tasks
6060
*/
61-
SCHED_FEAT(NONTASK_POWER, 1)
61+
SCHED_FEAT(NONTASK_POWER, true)
6262

6363
/*
6464
* Queue remote wakeups on the target CPU and process them
6565
* using the scheduler IPI. Reduces rq->lock contention/bounces.
6666
*/
67-
SCHED_FEAT(TTWU_QUEUE, 1)
67+
SCHED_FEAT(TTWU_QUEUE, true)
6868

69-
SCHED_FEAT(FORCE_SD_OVERLAP, 0)
70-
SCHED_FEAT(RT_RUNTIME_SHARE, 1)
69+
SCHED_FEAT(FORCE_SD_OVERLAP, false)
70+
SCHED_FEAT(RT_RUNTIME_SHARE, true)

‎kernel/sched/sched.h‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
581581
* Tunables that become constants when CONFIG_SCHED_DEBUG is off:
582582
*/
583583
#ifdef CONFIG_SCHED_DEBUG
584+
# include <linux/jump_label.h>
584585
# define const_debug __read_mostly
585586
#else
586587
# define const_debug const
@@ -593,11 +594,37 @@ extern const_debug unsigned int sysctl_sched_features;
593594

594595
enum {
595596
#include "features.h"
597+
__SCHED_FEAT_NR,
596598
};
597599

598600
#undef SCHED_FEAT
599601

602+
#if defined(CONFIG_SCHED_DEBUG) && defined(HAVE_JUMP_LABEL)
603+
static __always_inline bool static_branch__true(struct jump_label_key *key)
604+
{
605+
return likely(static_branch(key)); /* Not out of line branch. */
606+
}
607+
608+
static __always_inline bool static_branch__false(struct jump_label_key *key)
609+
{
610+
return unlikely(static_branch(key)); /* Out of line branch. */
611+
}
612+
613+
#define SCHED_FEAT(name, enabled) \
614+
static __always_inline bool static_branch_##name(struct jump_label_key *key) \
615+
{ \
616+
return static_branch__##enabled(key); \
617+
}
618+
619+
#include "features.h"
620+
621+
#undef SCHED_FEAT
622+
623+
extern struct jump_label_key sched_feat_keys[__SCHED_FEAT_NR];
624+
#define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))
625+
#else /* !(SCHED_DEBUG && HAVE_JUMP_LABEL) */
600626
#define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
627+
#endif /* SCHED_DEBUG && HAVE_JUMP_LABEL */
601628

602629
static inline u64 global_rt_period(void)
603630
{

0 commit comments

Comments
 (0)