sched_ext: Merge branch 'for-6.17-fixes' into for-6.18

Pull sched_ext/for-6.17-fixes to receive:

 55ed11b181 ("sched_ext: idle: Handle migration-disabled tasks in BPF code")

which conflicts with the following commit in for-6.18:

 2407bae23d ("sched_ext: Add the @sch parameter to ext_idle helpers")

The conflict is a simple context conflict which can be resolved by taking
the updated parts from both commits.

Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
Tejun Heo 2025-09-23 09:10:20 -10:00
commit ebfd5226ec
4 changed files with 33 additions and 8 deletions

View File

@ -9549,7 +9549,7 @@ static unsigned long tg_weight(struct task_group *tg)
#ifdef CONFIG_FAIR_GROUP_SCHED
return scale_load_down(tg->shares);
#else
return sched_weight_from_cgroup(tg->scx_weight);
return sched_weight_from_cgroup(tg->scx.weight);
#endif
}

View File

@ -4662,6 +4662,9 @@ static int scx_enable(struct sched_ext_ops *ops, struct bpf_link *link)
__setscheduler_class(p->policy, p->prio);
struct sched_enq_and_set_ctx ctx;
if (!tryget_task_struct(p))
continue;
if (old_class != new_class && p->se.sched_delayed)
dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
@ -4674,6 +4677,7 @@ static int scx_enable(struct sched_ext_ops *ops, struct bpf_link *link)
sched_enq_and_set_task(&ctx);
check_class_changed(task_rq(p), p, old_class, p->prio);
put_task_struct(p);
}
scx_task_iter_stop(&sti);
percpu_up_write(&scx_fork_rwsem);
@ -5740,12 +5744,8 @@ __bpf_kfunc u32 scx_bpf_reenqueue_local(void)
* CPUs disagree, they use %ENQUEUE_RESTORE which is bypassed to
* the current local DSQ for running tasks and thus are not
* visible to the BPF scheduler.
*
* Also skip re-enqueueing tasks that can only run on this
* CPU, as they would just be re-added to the same local
* DSQ without any benefit.
*/
if (p->migration_pending || is_migration_disabled(p) || p->nr_cpus_allowed == 1)
if (p->migration_pending)
continue;
dispatch_dequeue(rq, p);

View File

@ -856,6 +856,32 @@ static bool check_builtin_idle_enabled(struct scx_sched *sch)
return false;
}
/*
* Determine whether @p is a migration-disabled task in the context of BPF
* code.
*
* We can't simply check whether @p->migration_disabled is set in a
* sched_ext callback, because migration is always disabled for the current
* task while running BPF code.
*
* The prolog (__bpf_prog_enter) and epilog (__bpf_prog_exit) respectively
* disable and re-enable migration. For this reason, the current task
* inside a sched_ext callback is always a migration-disabled task.
*
* Therefore, when @p->migration_disabled == 1, check whether @p is the
* current task or not: if it is, then migration was not disabled before
* entering the callback, otherwise migration was disabled.
*
* Returns true if @p is migration-disabled, false otherwise.
*/
static bool is_bpf_migration_disabled(const struct task_struct *p)
{
if (p->migration_disabled == 1)
return p != current;
else
return p->migration_disabled;
}
static s32 select_cpu_from_kfunc(struct scx_sched *sch, struct task_struct *p,
s32 prev_cpu, u64 wake_flags,
const struct cpumask *allowed, u64 flags)
@ -899,7 +925,7 @@ static s32 select_cpu_from_kfunc(struct scx_sched *sch, struct task_struct *p,
* selection optimizations and simply check whether the previously
* used CPU is idle and within the allowed cpumask.
*/
if (p->nr_cpus_allowed == 1 || is_migration_disabled(p)) {
if (p->nr_cpus_allowed == 1 || is_bpf_migration_disabled(p)) {
if (cpumask_test_cpu(prev_cpu, allowed ?: p->cpus_ptr) &&
scx_idle_test_and_clear_cpu(prev_cpu))
cpu = prev_cpu;

View File

@ -6,7 +6,6 @@
#include <bpf/bpf.h>
#include <sched.h>
#include <scx/common.h>
#include <sched.h>
#include <sys/wait.h>
#include <unistd.h>