Skip to content

[Deepin-Kernel-SIG] [linux 6.18.y] [Backport] sched/fair: Revert 6d71a9c ("sched/fair: Fix EEVDF entity placement b… …ug causing scheduling lag")#1909

Open
opsiff wants to merge 3 commits into
deepin-community:linux-6.18.yfrom
opsiff:linux-6.18.y-2026-06-24-revert-sched
Open

[Deepin-Kernel-SIG] [linux 6.18.y] [Backport] sched/fair: Revert 6d71a9c ("sched/fair: Fix EEVDF entity placement b… …ug causing scheduling lag")#1909
opsiff wants to merge 3 commits into
deepin-community:linux-6.18.yfrom
opsiff:linux-6.18.y-2026-06-24-revert-sched

Conversation

@opsiff

@opsiff opsiff commented Jun 24, 2026

Copy link
Copy Markdown
Member

[ 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)
[jstultz: Resolved minor collision in the revert against 6.18-stable]
Signed-off-by: John Stultz jstultz@google.com

and revert and apply new bore for this version!

Summary by Sourcery

Revert a previous EEVDF entity placement fix in the fair scheduler and adjust vruntime, lag, deadline and protection handling around entity reweighting for the 6.18.y kernel backport.

Enhancements:

  • Introduce a helper to compute entity lag from a supplied average vruntime and reuse it across scheduling code.
  • Rework reweight_entity() to base vruntime, vlag, deadline and vprot adjustments on the cfs_rq average vruntime rather than the entity’s own vruntime.
  • Gate relative-deadline placement in place_entity() behind the PLACE_REL_DEADLINE scheduler feature and simplify delayed-entity requeueing logic under DELAY_ZERO, while keeping BORE-specific behavior intact.

opsiff and others added 3 commits June 24, 2026 14:04
This reverts commit 4ed4cc0.

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)
[jstultz: Resolved minor collision in the revert against 6.18-stable]
Signed-off-by: John Stultz <jstultz@google.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Backports an upstream revert of a previous EEVDF placement fix and reintroduces updated BORE handling by refactoring lag/deadline computation around avg_vruntime, adding a rescale helper for reweighting, and adjusting how vruntime, vlag, deadlines, and vprot are managed during reweight, placement, and delayed requeue.

Flow diagram for updated reweight_entity lag/deadline handling

flowchart TD
  A[reweight_entity] --> B{se.on_rq?}
  B -- no --> H[dequeue_load_avg]
  B -- yes --> C[update_curr]
  C --> D[avruntime = avg_vruntime]
  D --> E[se.vlag = entity_lag cfs_rq se avruntime]
  E --> F[se.deadline -= avruntime]
  F --> G{curr && protect_slice se?}
  G -- yes --> G1[se.vprot -= avruntime; rel_vprot = true]
  G -- no --> H
  G1 --> H[dequeue_load_avg]
  H --> I[rescale_entity se weight rel_vprot]
  I --> J[update_load_set se.load weight]
  J --> K[recompute se.avg.load_avg]
  K --> L[enqueue_load_avg]
  L --> M{se.on_rq?}
  M -- no --> Z[end]
  M -- yes --> N{rel_vprot?}
  N -- yes --> O[se.vprot += avruntime]
  N -- no --> P
  O --> P[se.deadline += avruntime]
  P --> Q[se.rel_deadline = 0]
  Q --> R[se.vruntime = avruntime - se.vlag]
  R --> S[update_load_add cfs_rq.load se.load.weight]
  S --> T{curr?}
  T -- no --> U[__enqueue_entity]
  T -- yes --> Z[end]
  U --> Z[end]
Loading

Flow diagram for DELAY_ZERO requeue_delayed_entity with BORE handling

flowchart TD
  A[requeue_delayed_entity] --> B{DELAY_ZERO feature?}
  B -- no --> Z[end]
  B -- yes --> C[update_entity_lag]
  C --> D{se.vlag > 0?}
  D -- no --> Z
  D -- yes --> E[cfs_rq.nr_queued--]
  E --> F{se != cfs_rq.curr?}
  F -- yes --> G[__dequeue_entity]
  F -- no --> H
  G --> H[se.vlag = 0]
  H --> I{CONFIG_SCHED_BORE && sched_bore_key && DELAY_ZERO?}
  I -- yes --> J[flags or= ENQUEUE_WAKEUP]
  I -- no --> K[flags = 0]
  J --> L[place_entity cfs_rq se flags]
  K --> L[place_entity cfs_rq se flags]
  L --> M{se != cfs_rq.curr?}
  M -- yes --> N[__enqueue_entity]
  M -- no --> O
  N --> O[cfs_rq.nr_queued++]
  O --> Z[end]
Loading

File-Level Changes

Change Details Files
Refactor entity lag calculation to allow using a pre-computed avg_vruntime snapshot and reuse it in multiple paths.
  • Introduce entity_lag() that computes and clamps vlag from a provided avruntime and entity vruntime.
  • Update update_entity_lag() to use entity_lag(avg_vruntime(cfs_rq)) and keep WARN_ON_ONCE(!se->on_rq).
kernel/sched/fair.c
Rework reweight_entity() logic to be based on a pre-snapshot of avg_vruntime, and to keep avg_vruntime invariant under reweight while maintaining vlag, vruntime, deadline, and vprot consistency.
  • Add rescale_entity() helper encapsulating math for adjusting vlag, deadline, and vprot on weight change, with extensive comments documenting invariants and proofs.
  • In reweight_entity(), capture avg_vruntime before reweight, convert deadline/vprot to relative form against avruntime, and use entity_lag() instead of update_entity_lag() for lag.
  • Replace inline vlag/deadline/vprot scaling with a call to rescale_entity(), then restore absolute deadline, vprot, and recompute vruntime from avruntime - vlag.
  • Simplify on-rq re-enqueue path: drop special BORE-specific curr handling and use direct vruntime reconstruction plus optional vprot adjustment, followed by enqueue when not current.
kernel/sched/fair.c
Gate relative-deadline placement on a feature flag and adjust DELAY_ZERO / delayed-entity behavior, including BORE interactions.
  • Make relative deadline handling in place_entity() conditional on sched_feat(PLACE_REL_DEADLINE).
  • Simplify DELAY_DEQUEUE path by removing BORE-specific update_entity_lag() invocation when delaying dequeue with DELAY_ZERO.
  • Change requeue_delayed_entity() so that update_entity_lag() is always called first under DELAY_ZERO, then, if vlag > 0, requeue via place_entity() while restoring BORE-specific ENQUEUE_WAKEUP flag wiring; ensure nr_queued and enqueue/dequeue are balanced.
kernel/sched/fair.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot deepin-ci-robot requested review from BLumia and shy129 June 24, 2026 06:20
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Backports an upstream revert in the CFS fair scheduler (EEVDF) to correct entity placement/lag behavior by making lag/deadline adjustments reference the cfs_rq average vruntime state, and by tightening when relative-deadline placement is applied.

Changes:

  • Add entity_lag() helper to compute lag from a supplied average vruntime and reuse it for lag updates.
  • Rework reweight_entity() to adjust vruntime/vlag/deadline/vprot relative to avg_vruntime(cfs_rq) instead of se->vruntime.
  • Gate relative-deadline placement in place_entity() behind PLACE_REL_DEADLINE and simplify DELAY_ZERO delayed requeueing logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kernel/sched/fair.c
Comment on lines 3997 to 4006
if (se->on_rq) {
/* commit outstanding execution time */
update_curr(cfs_rq);
update_entity_lag(cfs_rq, se);
#ifdef CONFIG_SCHED_BORE
vlag_unscaled = se->vlag;
#endif /* !CONFIG_SCHED_BORE */
se->deadline -= se->vruntime;
avruntime = avg_vruntime(cfs_rq);
se->vlag = entity_lag(cfs_rq, se, avruntime);
se->deadline -= avruntime;
se->rel_deadline = 1;
if (curr && protect_slice(se)) {
vprot = se->vprot - se->vruntime;
se->vprot -= avruntime;
rel_vprot = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants