Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from sched-ext/task_on_scx
Browse files Browse the repository at this point in the history
SCX: s/task_on_scx()/task_should_scx()/ and add new task_on_scx() whi…
  • Loading branch information
Byte-Lab authored Jun 22, 2023
2 parents 711b42e + dec3eaa commit 3ef5047
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
19 changes: 8 additions & 11 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,8 @@ static inline int __task_prio(const struct task_struct *p)
if (p->sched_class == &idle_sched_class)
return MAX_RT_PRIO + NICE_WIDTH; /* 140 */

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

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

static inline bool ttwu_queue_cond(struct task_struct *p, int cpu)
{
#ifdef CONFIG_SCHED_CLASS_EXT
/*
* The BPF scheduler may depend on select_task_rq() being invoked during
* wakeups and @p may end up executing on a different CPU regardless of
* what happens in the wakeup path making the ttwu_queue optimization
* ineffective. Skip if on SCX.
* wakeups. In addition, @p may end up executing on a different CPU
* regardless of what happens in the wakeup path making the ttwu_queue
* optimization less meaningful. Skip if on SCX.
*/
if (p->sched_class == &ext_sched_class)
if (task_on_scx(p))
return false;
#endif

/*
* Do not complicate things with the async wake_list while the CPU is
* in hotplug state.
Expand Down Expand Up @@ -4799,7 +4796,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
} else if (rt_prio(p->prio)) {
p->sched_class = &rt_sched_class;
#ifdef CONFIG_SCHED_CLASS_EXT
} else if (task_on_scx(p)) {
} else if (task_should_scx(p)) {
p->sched_class = &ext_sched_class;
#endif
} else {
Expand Down Expand Up @@ -7096,7 +7093,7 @@ void __setscheduler_prio(struct task_struct *p, int prio)
else if (rt_prio(prio))
p->sched_class = &rt_sched_class;
#ifdef CONFIG_SCHED_CLASS_EXT
else if (task_on_scx(p))
else if (task_should_scx(p))
p->sched_class = &ext_sched_class;
#endif
else
Expand Down
2 changes: 1 addition & 1 deletion kernel/sched/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,
P(dl.deadline);
}
#ifdef CONFIG_SCHED_CLASS_EXT
__PS("ext.enabled", p->sched_class == &ext_sched_class);
__PS("ext.enabled", task_on_scx(p));
#endif
#undef PN_SCHEDSTAT
#undef P_SCHEDSTAT
Expand Down
2 changes: 1 addition & 1 deletion kernel/sched/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2867,7 +2867,7 @@ static void scx_cgroup_config_knobs(void) {}
* Used by sched_fork() and __setscheduler_prio() to pick the matching
* sched_class. dl/rt are already handled.
*/
bool task_on_scx(struct task_struct *p)
bool task_should_scx(struct task_struct *p)
{
if (!scx_enabled() || scx_ops_disabling())
return false;
Expand Down
8 changes: 7 additions & 1 deletion kernel/sched/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ DECLARE_STATIC_KEY_FALSE(__scx_switched_all);

DECLARE_STATIC_KEY_FALSE(scx_ops_cpu_preempt);

bool task_on_scx(struct task_struct *p);
static inline bool task_on_scx(struct task_struct *p)
{
return scx_enabled() && p->sched_class == &ext_sched_class;
}

bool task_should_scx(struct task_struct *p);
void scx_pre_fork(struct task_struct *p);
int scx_fork(struct task_struct *p);
void scx_post_fork(struct task_struct *p);
Expand Down Expand Up @@ -198,6 +203,7 @@ bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
#define scx_enabled() false
#define scx_switched_all() false

static inline bool task_on_scx(struct task_struct *p) { return false; }
static inline void scx_pre_fork(struct task_struct *p) {}
static inline int scx_fork(struct task_struct *p) { return 0; }
static inline void scx_post_fork(struct task_struct *p) {}
Expand Down

0 comments on commit 3ef5047

Please sign in to comment.