Skip to content

Commit 744d836

Browse files
committed
sched, sched_ext: Open code for_balance_class_range()
For flexibility, sched_ext allows the BPF scheduler to select the CPU to execute a task on at dispatch time so that e.g. a queue can be shared across multiple CPUs. To enable this, the dispatch path is executed from balance() so that a dispatched task can be hot-migrated to its target CPU. This means that sched_ext needs its balance() method invoked before every pick_next_task() even when the CPU is waking up from SCHED_IDLE. for_balance_class_range() defined in kernel/sched/ext.h implements this selective iteration promotion. However, the indirection obfuscates more than helps. Open code the iteration promotion in put_prev_task_balance() and remove for_balance_class_range(). No functional changes intended. Signed-off-by: Tejun Heo <tj@kernel.org> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: 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 6ab228e commit 744d836

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

kernel/sched/core.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5825,7 +5825,19 @@ static void put_prev_task_balance(struct rq *rq, struct task_struct *prev,
58255825
struct rq_flags *rf)
58265826
{
58275827
#ifdef CONFIG_SMP
5828+
const struct sched_class *start_class = prev->sched_class;
58285829
const struct sched_class *class;
5830+
5831+
#ifdef CONFIG_SCHED_CLASS_EXT
5832+
/*
5833+
* SCX requires a balance() call before every pick_next_task() including
5834+
* when waking up from SCHED_IDLE. If @start_class is below SCX, start
5835+
* from SCX instead.
5836+
*/
5837+
if (sched_class_above(&ext_sched_class, start_class))
5838+
start_class = &ext_sched_class;
5839+
#endif
5840+
58295841
/*
58305842
* We must do the balancing pass before put_prev_task(), such
58315843
* that when we release the rq->lock the task is in the same
@@ -5834,7 +5846,7 @@ static void put_prev_task_balance(struct rq *rq, struct task_struct *prev,
58345846
* We can terminate the balance pass as soon as we know there is
58355847
* a runnable task of @class priority or higher.
58365848
*/
5837-
for_balance_class_range(class, prev->sched_class, &idle_sched_class) {
5849+
for_active_class_range(class, start_class, &idle_sched_class) {
58385850
if (class->balance(rq, prev, rf))
58395851
break;
58405852
}

kernel/sched/ext.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ static inline const struct sched_class *next_active_class(const struct sched_cla
6868
#define for_each_active_class(class) \
6969
for_active_class_range(class, __sched_class_highest, __sched_class_lowest)
7070

71-
/*
72-
* SCX requires a balance() call before every pick_next_task() call including
73-
* when waking up from idle.
74-
*/
75-
#define for_balance_class_range(class, prev_class, end_class) \
76-
for_active_class_range(class, (prev_class) > &ext_sched_class ? \
77-
&ext_sched_class : (prev_class), (end_class))
78-
7971
#ifdef CONFIG_SCHED_CORE
8072
bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
8173
bool in_fi);
@@ -100,7 +92,6 @@ static inline bool task_on_scx(const struct task_struct *p) { return false; }
10092
static inline void init_sched_ext_class(void) {}
10193

10294
#define for_each_active_class for_each_class
103-
#define for_balance_class_range for_class_range
10495

10596
#endif /* CONFIG_SCHED_CLASS_EXT */
10697

0 commit comments

Comments
 (0)