Skip to content

Commit e196c90

Browse files
committed
sched, sched_ext: Move some declarations from kernel/sched/ext.h to sched.h
While sched_ext was out of tree, everything sched_ext specific which can be put in kernel/sched/ext.h was put there to ease forward porting. However, kernel/sched/sched.h is the better location for some of them. Relocate. - struct sched_enq_and_set_ctx, sched_deq_and_put_task() and sched_enq_and_set_task(). - scx_enabled() and scx_switched_all(). - for_active_class_range() and for_each_active_class(). sched_class declarations are moved above the class iterators for this. No functional changes intended. Signed-off-by: Tejun Heo <tj@kernel.org> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: David Vernet <void@manifault.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de>
1 parent 744d836 commit e196c90

File tree

2 files changed

+59
-45
lines changed

2 files changed

+59
-45
lines changed

kernel/sched/ext.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@
88
*/
99
#ifdef CONFIG_SCHED_CLASS_EXT
1010

11-
struct sched_enq_and_set_ctx {
12-
struct task_struct *p;
13-
int queue_flags;
14-
bool queued;
15-
bool running;
16-
};
17-
18-
void sched_deq_and_put_task(struct task_struct *p, int queue_flags,
19-
struct sched_enq_and_set_ctx *ctx);
20-
void sched_enq_and_set_task(struct sched_enq_and_set_ctx *ctx);
21-
22-
extern const struct sched_class ext_sched_class;
23-
24-
DECLARE_STATIC_KEY_FALSE(__scx_ops_enabled);
25-
DECLARE_STATIC_KEY_FALSE(__scx_switched_all);
26-
#define scx_enabled() static_branch_unlikely(&__scx_ops_enabled)
27-
#define scx_switched_all() static_branch_unlikely(&__scx_switched_all)
28-
2911
void scx_tick(struct rq *rq);
3012
void init_scx_entity(struct sched_ext_entity *scx);
3113
void scx_pre_fork(struct task_struct *p);
@@ -52,32 +34,13 @@ static inline bool task_on_scx(const struct task_struct *p)
5234
return scx_enabled() && p->sched_class == &ext_sched_class;
5335
}
5436

55-
static inline const struct sched_class *next_active_class(const struct sched_class *class)
56-
{
57-
class++;
58-
if (scx_switched_all() && class == &fair_sched_class)
59-
class++;
60-
if (!scx_enabled() && class == &ext_sched_class)
61-
class++;
62-
return class;
63-
}
64-
65-
#define for_active_class_range(class, _from, _to) \
66-
for (class = (_from); class != (_to); class = next_active_class(class))
67-
68-
#define for_each_active_class(class) \
69-
for_active_class_range(class, __sched_class_highest, __sched_class_lowest)
70-
7137
#ifdef CONFIG_SCHED_CORE
7238
bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
7339
bool in_fi);
7440
#endif
7541

7642
#else /* CONFIG_SCHED_CLASS_EXT */
7743

78-
#define scx_enabled() false
79-
#define scx_switched_all() false
80-
8144
static inline void scx_tick(struct rq *rq) {}
8245
static inline void scx_pre_fork(struct task_struct *p) {}
8346
static inline int scx_fork(struct task_struct *p) { return 0; }
@@ -91,8 +54,6 @@ static inline int scx_check_setscheduler(struct task_struct *p, int policy) { re
9154
static inline bool task_on_scx(const struct task_struct *p) { return false; }
9255
static inline void init_sched_ext_class(void) {}
9356

94-
#define for_each_active_class for_each_class
95-
9657
#endif /* CONFIG_SCHED_CLASS_EXT */
9758

9859
#if defined(CONFIG_SCHED_CLASS_EXT) && defined(CONFIG_SMP)

kernel/sched/sched.h

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,19 +2438,54 @@ const struct sched_class name##_sched_class \
24382438
extern struct sched_class __sched_class_highest[];
24392439
extern struct sched_class __sched_class_lowest[];
24402440

2441+
extern const struct sched_class stop_sched_class;
2442+
extern const struct sched_class dl_sched_class;
2443+
extern const struct sched_class rt_sched_class;
2444+
extern const struct sched_class fair_sched_class;
2445+
extern const struct sched_class idle_sched_class;
2446+
2447+
#ifdef CONFIG_SCHED_CLASS_EXT
2448+
extern const struct sched_class ext_sched_class;
2449+
2450+
DECLARE_STATIC_KEY_FALSE(__scx_ops_enabled); /* SCX BPF scheduler loaded */
2451+
DECLARE_STATIC_KEY_FALSE(__scx_switched_all); /* all fair class tasks on SCX */
2452+
2453+
#define scx_enabled() static_branch_unlikely(&__scx_ops_enabled)
2454+
#define scx_switched_all() static_branch_unlikely(&__scx_switched_all)
2455+
#else /* !CONFIG_SCHED_CLASS_EXT */
2456+
#define scx_enabled() false
2457+
#define scx_switched_all() false
2458+
#endif /* !CONFIG_SCHED_CLASS_EXT */
2459+
2460+
/*
2461+
* Iterate only active classes. SCX can take over all fair tasks or be
2462+
* completely disabled. If the former, skip fair. If the latter, skip SCX.
2463+
*/
2464+
static inline const struct sched_class *next_active_class(const struct sched_class *class)
2465+
{
2466+
class++;
2467+
#ifdef CONFIG_SCHED_CLASS_EXT
2468+
if (scx_switched_all() && class == &fair_sched_class)
2469+
class++;
2470+
if (!scx_enabled() && class == &ext_sched_class)
2471+
class++;
2472+
#endif
2473+
return class;
2474+
}
2475+
24412476
#define for_class_range(class, _from, _to) \
24422477
for (class = (_from); class < (_to); class++)
24432478

24442479
#define for_each_class(class) \
24452480
for_class_range(class, __sched_class_highest, __sched_class_lowest)
24462481

2447-
#define sched_class_above(_a, _b) ((_a) < (_b))
2482+
#define for_active_class_range(class, _from, _to) \
2483+
for (class = (_from); class != (_to); class = next_active_class(class))
24482484

2449-
extern const struct sched_class stop_sched_class;
2450-
extern const struct sched_class dl_sched_class;
2451-
extern const struct sched_class rt_sched_class;
2452-
extern const struct sched_class fair_sched_class;
2453-
extern const struct sched_class idle_sched_class;
2485+
#define for_each_active_class(class) \
2486+
for_active_class_range(class, __sched_class_highest, __sched_class_lowest)
2487+
2488+
#define sched_class_above(_a, _b) ((_a) < (_b))
24542489

24552490
static inline bool sched_stop_runnable(struct rq *rq)
24562491
{
@@ -3698,6 +3733,24 @@ static inline void balance_callbacks(struct rq *rq, struct balance_callback *hea
36983733

36993734
#endif
37003735

3736+
#ifdef CONFIG_SCHED_CLASS_EXT
3737+
/*
3738+
* Used by SCX in the enable/disable paths to move tasks between sched_classes
3739+
* and establish invariants.
3740+
*/
3741+
struct sched_enq_and_set_ctx {
3742+
struct task_struct *p;
3743+
int queue_flags;
3744+
bool queued;
3745+
bool running;
3746+
};
3747+
3748+
void sched_deq_and_put_task(struct task_struct *p, int queue_flags,
3749+
struct sched_enq_and_set_ctx *ctx);
3750+
void sched_enq_and_set_task(struct sched_enq_and_set_ctx *ctx);
3751+
3752+
#endif /* CONFIG_SCHED_CLASS_EXT */
3753+
37013754
#include "ext.h"
37023755

37033756
#endif /* _KERNEL_SCHED_SCHED_H */

0 commit comments

Comments
 (0)