Repository navigation
[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] sched update for sched_ext - #2219
Conversation
mainline inclusion from mainline-v6.7-rc1 category: feature This patch makes some preparations for using css_task_iter_*() in BPF Program. 1. Flags CSS_TASK_ITER_* are #define-s and it's not easy for bpf prog to use them. Convert them to enum so bpf prog can take them from vmlinux.h. 2. In the next patch we will add css_task_iter_*() in common kfuncs which is not safe. Since css_task_iter_*() does spin_unlock_irq() which might screw up irq flags depending on the context where bpf prog is running. So we should use irqsave/irqrestore here and the switching is harmless. Suggested-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20231018061746.111364-2-zhouchuyi@bytedance.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> (cherry picked from commit 6da8830) Signed-off-by: LFRon <ronforever@outlook.com> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.12-rc1 category: feature Currently, sched_init() checks that the sched_class'es are in the expected order by testing each adjacency which is a bit brittle and makes it cumbersome to add optional sched_class'es. Instead, let's verify whether they're in the expected order using sched_class_above() which is what matters. Signed-off-by: Tejun Heo <tj@kernel.org> Suggested-by: Peter Zijlstra <peterz@infradead.org> Reviewed-by: David Vernet <dvernet@meta.com> (cherry picked from commit df26838) Signed-off-by: LFRon <ronforever@outlook.com> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
…ork() mainline inclusion from mainline-v6.12-rc1 category: feature A new BPF extensible sched_class will need more control over the forking process. It wants to be able to fail from sched_cgroup_fork() after the new task's sched_task_group is initialized so that the loaded BPF program can prepare the task with its cgroup association is established and reject fork if e.g. allocation fails. Allow sched_cgroup_fork() to fail by making it return int instead of void and adding sched_cancel_fork() to undo sched_fork() in the error path. sched_cgroup_fork() doesn't fail yet and this patch shouldn't cause any behavior changes. v2: Patch description updated to detail the expected use. 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> (cherry picked from commit 304b3f2) Signed-off-by: LFRon <ronforever@outlook.com> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.12-rc1 category: feature Currently, during a task weight change, sched core directly calls reweight_task() defined in fair.c if @p is on CFS. Let's make it a proper sched_class operation instead. CFS's reweight_task() is renamed to reweight_task_fair() and now called through sched_class. While it turns a direct call into an indirect one, set_load_weight() isn't called from a hot path and this change shouldn't cause any noticeable difference. This will be used to implement reweight_task for a new BPF extensible sched_class so that it can keep its cached task weight up-to-date. 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> Conflicts: kernel/sched/core.c kernel/sched/fair.c kernel/sched/sched.h (cherry picked from commit e83edbf) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
…g/changed() mainline inclusion from mainline-v6.12-rc1 category: feature When a task switches to a new sched_class, the prev and new classes are notified through ->switched_from() and ->switched_to(), respectively, after the switching is done. A new BPF extensible sched_class will have callbacks that allow the BPF scheduler to keep track of relevant task states (like priority and cpumask). Those callbacks aren't called while a task is on a different sched_class. When a task comes back, we wanna tell the BPF progs the up-to-date state before the task gets enqueued, so we need a hook which is called before the switching is committed. This patch adds ->switching_to() which is called during sched_class switch through check_class_changing() before the task is restored. Also, this patch exposes check_class_changing/changed() in kernel/sched/sched.h. They will be used by the new BPF extensible sched_class to implement implicit sched_class switching which is used e.g. when falling back to CFS when the BPF scheduler fails or unloads. This is a prep patch and doesn't cause any behavior changes. The new operation and exposed functions aren't used yet. v3: Refreshed on top of tip:sched/core. v2: Improve patch description w/ details on planned use. 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> Conflicts: kernel/sched/core.c (cherry picked from commit d8c7bc2) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion from mainline-v6.12-rc1 category: feature Factor out sched_weight_from/to_cgroup() which convert between scheduler shares and cgroup weight. No functional change. The factored out functions will be used by a new BPF extensible sched_class so that the weights can be exposed to the BPF programs in a way which is consistent cgroup weights and easier to interpret. The weight conversions will be used regardless of cgroup usage. It's just borrowing the cgroup weight range as it's more intuitive. CGROUP_WEIGHT_MIN/DFL/MAX constants are moved outside CONFIG_CGROUPS so that the conversion helpers can always be defined. v2: The helpers are now defined regardless of COFNIG_CGROUPS. 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> (cherry picked from commit 4f9c7ca) Signed-off-by: LFRon <ronforever@outlook.com> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
…rs() mainline inclusion from mainline-v6.12-rc1 category: feature RT, DL, thermal and irq load and utilization metrics need to be decayed and updated periodically and before consumption to keep the numbers reasonable. This is currently done from __update_blocked_others() as a part of the fair class load balance path. Let's factor it out to update_other_load_avgs(). Pure refactor. No functional changes. This will be used by the new BPF extensible scheduling class to ensure that the above metrics are properly maintained. v2: Refreshed on top of tip:sched/core. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: David Vernet <dvernet@meta.com> Conflicts: kernel/sched/fair.c (cherry picked from commit 96fd6c6) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
A new BPF extensible sched_class will need to dynamically change how a task picks its sched_class. For example, if the loaded BPF scheduler progs fail, the tasks will be forced back on CFS even if the task's policy is set to the new sched_class. To support such mapping, add normal_policy() which wraps testing for %SCHED_NORMAL. This doesn't cause any behavior changes. v2: Update the description with more details on the expected use. 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> (cherry picked from commit 2c8d046) Conflicts: kernel/sched/fair.c Signed-off-by: LFRon <ronforever@outlook.com> Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideUpdates the 6.6 scheduler and cgroup interfaces for sched_ext by adding scheduling-class lifecycle hooks, making fork setup cancellable, hardening cgroup iteration locking, and refactoring load-average and cgroup-weight handling into shared scheduler helpers. Sequence diagram for cancellable scheduler fork setupsequenceDiagram
participant Fork as copy_process
participant Scheduler as sched_cgroup_fork
participant Cgroup as cgroup_cancel_fork
participant Cancel as sched_cancel_fork
Fork->>Scheduler: sched_cgroup_fork(p, args)
alt scheduler fork setup fails
Scheduler-->>Fork: return error
Fork->>Cgroup: cgroup_cancel_fork(p, args)
else later fork failure
Scheduler-->>Fork: return 0
Fork->>Cgroup: cgroup_cancel_fork(p, args)
end
Fork->>Cancel: sched_cancel_fork(p)
Flow diagram for scheduler class transition handlingflowchart TD
A[Scheduler changes task class] --> B[check_class_changing]
B --> C{Previous class differs?}
C -- No --> D[Continue scheduling update]
C -- Yes --> E{New class has switching_to?}
E -- No --> D
E -- Yes --> F[Call switching_to]
F --> D
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
🟡 Changes recommended
The new scheduler-class callbacks bypass existing reserved slots and break the preserved binary layout on KABI-enabled builds.
1 open issue
What changed in this PR
This PR prepares the scheduler and cgroup interfaces for sched_ext integration, adding lifecycle hooks and shared scheduler helpers.
Changes:
- Add scheduler-class reweighting and transition callbacks, plus fork cancellation and error-handling paths.
- Centralize non-fair load-average updates and cgroup weight conversions.
- Preserve interrupt state during cgroup task iteration.
| File | Description |
|---|---|
| kernel/sched/syscalls.c | Add shared load-average updates and invoke the class-transition hook. |
| kernel/sched/sched.h | Define scheduler callbacks, policy helpers, and weight conversions. |
| kernel/sched/fair.c | Register fair-class reweighting and use shared helpers. |
| kernel/sched/core.c | Wire scheduler hooks, fork interfaces, and weight helpers. |
| kernel/fork.c | Handle scheduler fork errors and cancellation cleanup. |
| kernel/cgroup/cgroup.c | Preserve interrupt state around iterator locks. |
| include/linux/sched/task.h | Declare updated scheduler fork interfaces. |
| include/linux/cgroup.h | Expose weight constants unconditionally and convert iterator flags to an enum. |
Review effort: Balanced
| void (*reweight_task)(struct rq *this_rq, struct task_struct *task, | ||
| const struct load_weight *lw); |

Aligned with: https://gitee.com/anolis/cloud-kernel/pulls/4865/commits
Summary by Sourcery
Update scheduler and cgroup interfaces to support sched_ext scheduling classes and safer task lifecycle handling.
Bug Fixes:
Enhancements: