Skip to content

Commit 3ef5047

Browse files
authored
Merge pull request raspberrypi#24 from sched-ext/task_on_scx
SCX: s/task_on_scx()/task_should_scx()/ and add new task_on_scx() whi…
2 parents 711b42e + dec3eaa commit 3ef5047

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

kernel/sched/core.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,8 @@ static inline int __task_prio(const struct task_struct *p)
167167
if (p->sched_class == &idle_sched_class)
168168
return MAX_RT_PRIO + NICE_WIDTH; /* 140 */
169169

170-
#ifdef CONFIG_SCHED_CLASS_EXT
171-
if (p->sched_class == &ext_sched_class)
170+
if (task_on_scx(p))
172171
return MAX_RT_PRIO + MAX_NICE + 1; /* 120, squash ext */
173-
#endif
174172

175173
return MAX_RT_PRIO + MAX_NICE; /* 119, squash fair */
176174
}
@@ -3954,16 +3952,15 @@ bool cpus_share_cache(int this_cpu, int that_cpu)
39543952

39553953
static inline bool ttwu_queue_cond(struct task_struct *p, int cpu)
39563954
{
3957-
#ifdef CONFIG_SCHED_CLASS_EXT
39583955
/*
39593956
* The BPF scheduler may depend on select_task_rq() being invoked during
3960-
* wakeups and @p may end up executing on a different CPU regardless of
3961-
* what happens in the wakeup path making the ttwu_queue optimization
3962-
* ineffective. Skip if on SCX.
3957+
* wakeups. In addition, @p may end up executing on a different CPU
3958+
* regardless of what happens in the wakeup path making the ttwu_queue
3959+
* optimization less meaningful. Skip if on SCX.
39633960
*/
3964-
if (p->sched_class == &ext_sched_class)
3961+
if (task_on_scx(p))
39653962
return false;
3966-
#endif
3963+
39673964
/*
39683965
* Do not complicate things with the async wake_list while the CPU is
39693966
* in hotplug state.
@@ -4799,7 +4796,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
47994796
} else if (rt_prio(p->prio)) {
48004797
p->sched_class = &rt_sched_class;
48014798
#ifdef CONFIG_SCHED_CLASS_EXT
4802-
} else if (task_on_scx(p)) {
4799+
} else if (task_should_scx(p)) {
48034800
p->sched_class = &ext_sched_class;
48044801
#endif
48054802
} else {
@@ -7096,7 +7093,7 @@ void __setscheduler_prio(struct task_struct *p, int prio)
70967093
else if (rt_prio(prio))
70977094
p->sched_class = &rt_sched_class;
70987095
#ifdef CONFIG_SCHED_CLASS_EXT
7099-
else if (task_on_scx(p))
7096+
else if (task_should_scx(p))
71007097
p->sched_class = &ext_sched_class;
71017098
#endif
71027099
else

kernel/sched/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,
10971097
P(dl.deadline);
10981098
}
10991099
#ifdef CONFIG_SCHED_CLASS_EXT
1100-
__PS("ext.enabled", p->sched_class == &ext_sched_class);
1100+
__PS("ext.enabled", task_on_scx(p));
11011101
#endif
11021102
#undef PN_SCHEDSTAT
11031103
#undef P_SCHEDSTAT

kernel/sched/ext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,7 @@ static void scx_cgroup_config_knobs(void) {}
28672867
* Used by sched_fork() and __setscheduler_prio() to pick the matching
28682868
* sched_class. dl/rt are already handled.
28692869
*/
2870-
bool task_on_scx(struct task_struct *p)
2870+
bool task_should_scx(struct task_struct *p)
28712871
{
28722872
if (!scx_enabled() || scx_ops_disabling())
28732873
return false;

kernel/sched/ext.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ DECLARE_STATIC_KEY_FALSE(__scx_switched_all);
110110

111111
DECLARE_STATIC_KEY_FALSE(scx_ops_cpu_preempt);
112112

113-
bool task_on_scx(struct task_struct *p);
113+
static inline bool task_on_scx(struct task_struct *p)
114+
{
115+
return scx_enabled() && p->sched_class == &ext_sched_class;
116+
}
117+
118+
bool task_should_scx(struct task_struct *p);
114119
void scx_pre_fork(struct task_struct *p);
115120
int scx_fork(struct task_struct *p);
116121
void scx_post_fork(struct task_struct *p);
@@ -198,6 +203,7 @@ bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
198203
#define scx_enabled() false
199204
#define scx_switched_all() false
200205

206+
static inline bool task_on_scx(struct task_struct *p) { return false; }
201207
static inline void scx_pre_fork(struct task_struct *p) {}
202208
static inline int scx_fork(struct task_struct *p) { return 0; }
203209
static inline void scx_post_fork(struct task_struct *p) {}

0 commit comments

Comments
 (0)