diff mbox series

[08/31] sched: Expose css_tg() and __setscheduler_prio() in kernel/sched/sched.h

Message ID 20221130082313.3241517-9-tj@kernel.org (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series [01/31] rhashtable: Allow rhashtable to be used from irq-safe contexts | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR fail merge-conflict

Commit Message

Tejun Heo Nov. 30, 2022, 8:22 a.m. UTC
These will be used by a new sched_class.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: David Vernet <dvernet@meta.com>
Acked-by: Josh Don <joshdon@google.com>
Acked-by: Hao Luo <haoluo@google.com>
Acked-by: Barret Rhoden <brho@google.com>
---
 kernel/sched/core.c  | 7 +------
 kernel/sched/sched.h | 7 +++++++
 2 files changed, 8 insertions(+), 6 deletions(-)

Comments

Peter Zijlstra Dec. 12, 2022, 11:49 a.m. UTC | #1
On Tue, Nov 29, 2022 at 10:22:50PM -1000, Tejun Heo wrote:
> These will be used by a new sched_class.

Uhhh.. wtf does a policy need __setscheduler_prio() for?
Tejun Heo Dec. 12, 2022, 5:47 p.m. UTC | #2
On Mon, Dec 12, 2022 at 12:49:59PM +0100, Peter Zijlstra wrote:
> On Tue, Nov 29, 2022 at 10:22:50PM -1000, Tejun Heo wrote:
> > These will be used by a new sched_class.
> 
> Uhhh.. wtf does a policy need __setscheduler_prio() for?

Whether a task is on sched_ext or not is determined by a few factors - the
chosen sched class of the task, whether the BPF scheduler is loaded and
whether it's using scx_bpf_switch_all(). That selection logic is implemented
in __setscheduler_prio(). When the BPF scheduler gets initialized and
exited, the selection changes and sched_ext needs to walk the tasks
reapplying the selection logic, so the export.

This ties together with the sched_enq_and_set_task() that you replied to in
another thread. Imma continue there.
diff mbox series

Patch

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index cc5d1867bb4c..ec3af657e8f4 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6845,7 +6845,7 @@  int default_wake_function(wait_queue_entry_t *curr, unsigned mode, int wake_flag
 }
 EXPORT_SYMBOL(default_wake_function);
 
-static void __setscheduler_prio(struct task_struct *p, int prio)
+void __setscheduler_prio(struct task_struct *p, int prio)
 {
 	if (dl_prio(prio))
 		p->sched_class = &dl_sched_class;
@@ -10245,11 +10245,6 @@  void sched_move_task(struct task_struct *tsk)
 	task_rq_unlock(rq, tsk, &rf);
 }
 
-static inline struct task_group *css_tg(struct cgroup_subsys_state *css)
-{
-	return css ? container_of(css, struct task_group, css) : NULL;
-}
-
 static struct cgroup_subsys_state *
 cpu_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
 {
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 31f008f1e0cc..5d12c386aac6 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -469,6 +469,11 @@  static inline int walk_tg_tree(tg_visitor down, tg_visitor up, void *data)
 	return walk_tg_tree_from(&root_task_group, down, up, data);
 }
 
+static inline struct task_group *css_tg(struct cgroup_subsys_state *css)
+{
+	return css ? container_of(css, struct task_group, css) : NULL;
+}
+
 extern int tg_nop(struct task_group *tg, void *data);
 
 extern void free_fair_sched_group(struct task_group *tg);
@@ -493,6 +498,8 @@  extern long sched_group_rt_runtime(struct task_group *tg);
 extern long sched_group_rt_period(struct task_group *tg);
 extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk);
 
+extern void __setscheduler_prio(struct task_struct *p, int prio);
+
 extern struct task_group *sched_create_group(struct task_group *parent);
 extern void sched_online_group(struct task_group *tg,
 			       struct task_group *parent);