Skip to content

[Deepin-Kernel-SIG] [linux 6.12.y] [Backport] sched/fair: Revert 6d71a9c ("sched/fair: Fix EEVDF entity placement b…#1907

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

[Deepin-Kernel-SIG] [linux 6.12.y] [Backport] sched/fair: Revert 6d71a9c ("sched/fair: Fix EEVDF entity placement b…#1907
opsiff wants to merge 2 commits into
deepin-community:linux-6.12.yfrom
opsiff:linux-6.12.y-2026-06-24-revert-sched

Conversation

@opsiff

@opsiff opsiff commented Jun 24, 2026

Copy link
Copy Markdown
Member

…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:

  • Ensure entity lag computation uses a provided average vruntime snapshot so placement logic sees pre-placement state.
  • Fix CFS entity reweighting so vruntime, lag, and virtual deadlines are adjusted consistently when on-rq entities change weight, including maintaining invariant avg_vruntime under reweight.
  • Prevent unintended relative-deadline adjustments unless explicitly enabled via the PLACE_REL_DEADLINE scheduler feature flag.

@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Backports 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 logic

flowchart 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
Loading

File-Level Changes

Change Details Files
Refactor lag computation into a reusable helper and use it consistently for entity lag updates and reweight logic.
  • Introduce entity_lag(avruntime, se) to compute and clamp vlag based on a supplied avg_vruntime snapshot.
  • Change update_entity_lag() to call entity_lag(avg_vruntime(cfs_rq), se) instead of computing vlag inline.
kernel/sched/fair.c
Rework reweighting of EEVDF entities so that vruntime and deadlines are adjusted relative to a stable pre-placement avg_vruntime, instead of ad‑hoc scaling of vlag and deadlines.
  • Add reweight_eevdf(se, avruntime, weight) to adjust se->vruntime and se->deadline under weight changes, using mathematical derivations to preserve lag and average vruntime invariants.
  • Update reweight_entity() to snapshot avg_vruntime() when se is on_rq, call reweight_eevdf() for on_rq entities, and only scale se->vlag directly when se is off_rq.
  • Remove the old logic that scaled se->vlag and se->deadline (via rel_deadline) directly and re-placed the entity via place_entity(), and instead update rq-wide min_vruntime at the end of reweight for on_rq entities.
kernel/sched/fair.c
Adjust relative-deadline placement so that it is controlled by a scheduler feature flag instead of being unconditional.
  • Guard the rel_deadline handling in place_entity() with sched_feat(PLACE_REL_DEADLINE), so relative deadlines are only converted when the feature is enabled.
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

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.

opsiff and others added 2 commits June 24, 2026 13:58
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>
@opsiff opsiff force-pushed the linux-6.12.y-2026-06-24-revert-sched branch from f34889f to 52f12c7 Compare June 24, 2026 05:59
@Avenger-285714 Avenger-285714 self-requested a review June 24, 2026 06:00
@dongert dongert requested a review from Copilot June 24, 2026 12:14

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

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.

Comment thread kernel/sched/fair.c
Comment on lines +3871 to +3875
if (avruntime != se->vruntime) {
vlag = entity_lag(avruntime, se);
vlag = div_s64(vlag * old_weight, weight);
se->vruntime = avruntime - vlag;
}
Comment thread kernel/sched/fair.c
Comment on lines +3889 to +3891
vslice = (s64)(se->deadline - avruntime);
vslice = div_s64(vslice * old_weight, weight);
se->deadline = avruntime + vslice;
Comment thread kernel/sched/fair.c
Comment on lines +3912 to +3918
} 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);
}
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.

3 participants