[Deepin-Kernel-SIG] [linux 6.12.y] [Backport] sched/fair: Revert 6d71a9c ("sched/fair: Fix EEVDF entity placement b…#1907
Conversation
Reviewer's GuideBackports an upstream fix that reworks how EEVDF entities are reweighted and placed by separating lag computation, introducing a dedicated reweight_eevdf() path that adjusts vruntime/deadline based on a pre-placement avg_vruntime snapshot, and gating relative-deadline placement on a sched feature, effectively reverting a prior buggy lag fix while resolving merge conflicts with local fair.c changes. Flow diagram for updated reweight_entity and reweight_eevdf logicflowchart TD
A[reweight_entity] --> B{se->on_rq?}
B -->|yes| C[update_curr]
C --> D[avg_vruntime]
D --> E[maybe __dequeue_entity]
E --> F[update_load_sub]
F --> G[dequeue_load_avg]
G --> H[update_load_set]
H --> I[enqueue_load_avg]
I --> J{se->on_rq?}
J -->|yes| K[reweight_eevdf]
K --> L[update_load_add]
L --> M[maybe __enqueue_entity]
M --> N[update_min_vruntime]
B -->|no| G
J -->|no| O[scale se->vlag]
O --> P[update_load_add]
P --> Q[end]
subgraph reweight_eevdf
K1[entity_lag] --> K2[adjust se->vruntime]
K2 --> K3[adjust se->deadline]
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[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 |
This reverts commit c8cc11b. Conflicts: kernel/sched/fair.c Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
…ug causing scheduling lag") [ Upstream commit 101f3498b4bdfef97152a444847948de1543f692 ] Zicheng Qu reported that, because avg_vruntime() always includes cfs_rq->curr, when ->on_rq, place_entity() doesn't work right. Specifically, the lag scaling in place_entity() relies on avg_vruntime() being the state *before* placement of the new entity. However in this case avg_vruntime() will actually already include the entity, which breaks things. Also, Zicheng Qu argues that avg_vruntime should be invariant under reweight. IOW commit 6d71a9c ("sched/fair: Fix EEVDF entity placement bug causing scheduling lag") was wrong! The issue reported in 6d71a9c could possibly be explained by rounding artifacts -- notably the extreme weight '2' is outside of the range of avg_vruntime/sum_w_vruntime, since that uses scale_load_down(). By scaling vruntime by the real weight, but accounting it in vruntime with a factor 1024 more, the average moves significantly. However, that is now cured. Tested by reverting 66951e4 ("sched/fair: Fix update_cfs_group() vs DELAY_DEQUEUE") and tracing vruntime and vlag figures again. Reported-by: Zicheng Qu <quzicheng@huawei.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Tested-by: K Prateek Nayak <kprateek.nayak@amd.com> Tested-by: Shubhang Kaushik <shubhang@os.amperecomputing.com> Link: https://patch.msgid.link/20260219080625.066102672%40infradead.org (cherry picked from commit 101f3498b4bdfef97152a444847948de1543f692) This reverts commit 8ead5fd. Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
f34889f to
52f12c7
Compare
There was a problem hiding this comment.
Pull request overview
This PR backports an upstream CFS/EEVDF change set to correct entity placement and reweighting semantics by reverting the earlier “Fix EEVDF entity placement bug causing scheduling lag” approach and aligning vruntime/lag/deadline handling with the updated upstream design.
Changes:
- Refactors lag computation into
entity_lag(avruntime, se)and uses an avg_vruntime snapshot when updating lag. - Reworks reweighting for on-rq entities via
reweight_eevdf()to adjust vruntime/deadline consistently during weight changes. - Gates relative-deadline placement behavior behind
sched_feat(PLACE_REL_DEADLINE).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (avruntime != se->vruntime) { | ||
| vlag = entity_lag(avruntime, se); | ||
| vlag = div_s64(vlag * old_weight, weight); | ||
| se->vruntime = avruntime - vlag; | ||
| } |
| vslice = (s64)(se->deadline - avruntime); | ||
| vslice = div_s64(vslice * old_weight, weight); | ||
| se->deadline = avruntime + vslice; |
| } else { | ||
| /* | ||
| * Because we keep se->vlag = V - v_i, while: lag_i = w_i*(V - v_i), | ||
| * we need to scale se->vlag when w_i changes. | ||
| */ | ||
| se->vlag = div_s64(se->vlag * se->load.weight, weight); | ||
| } |
…ug causing scheduling lag")
[ Upstream commit 101f3498b4bdfef97152a444847948de1543f692 ]
Zicheng Qu reported that, because avg_vruntime() always includes cfs_rq->curr, when ->on_rq, place_entity() doesn't work right.
Specifically, the lag scaling in place_entity() relies on avg_vruntime() being the state before placement of the new entity. However in this case avg_vruntime() will actually already include the entity, which breaks things.
Also, Zicheng Qu argues that avg_vruntime should be invariant under reweight. IOW commit 6d71a9c ("sched/fair: Fix EEVDF entity placement bug causing scheduling lag") was wrong!
The issue reported in 6d71a9c could possibly be explained by rounding artifacts -- notably the extreme weight '2' is outside of the range of avg_vruntime/sum_w_vruntime, since that uses scale_load_down(). By scaling vruntime by the real weight, but accounting it in vruntime with a factor 1024 more, the average moves significantly. However, that is now cured.
Tested by reverting 66951e4 ("sched/fair: Fix update_cfs_group() vs DELAY_DEQUEUE") and tracing vruntime and vlag figures again.
Reported-by: Zicheng Qu quzicheng@huawei.com
Reviewed-by: Vincent Guittot vincent.guittot@linaro.org
Tested-by: K Prateek Nayak kprateek.nayak@amd.com
Tested-by: Shubhang Kaushik shubhang@os.amperecomputing.com
Link: https://patch.msgid.link/20260219080625.066102672%40infradead.org (cherry picked from commit 101f3498b4bdfef97152a444847948de1543f692)
This reverts commit c8cc11b.
Conflicts:
kernel/sched/fair.c
Summary by Sourcery
Backport upstream scheduler changes to correct EEVDF entity placement and reweighting behavior in CFS, reverting a previous fix and aligning vruntime/lag handling with the updated design.
Bug Fixes: