fix(ax-task): avoid RR front insertion on wakeup#1532
Merged
Conversation
Contributor
There was a problem hiding this comment.
审查结果:批准 (APPROVE)
变更概要
PR 修复了 RR 调度器在 unblock_task 时将 resched 参数传递给 put_task_with_state 导致被唤醒任务被插入队首而非队尾的 bug。该行为会破坏 RR 调度公平性:已有 ready 任务在队列中时,后续的 wakeup 可能抢到更靠前的位置。
修改内容:
AxRunQueueRef::unblock_task:入队时固定使用preempt=false,不再将resched传入put_task_with_state(第 593 行)CurrentRunQueueRef::unblock_task:同上(第 627 行)- 新增
rr_tests模块,包含unblock_resched_does_not_front_insert_rr_task回归测试
resched 标志的原有语义(请求当前 CPU / 远端 CPU 尽快进入调度)在修改后保持不变,仅不再影响被唤醒任务在 RR 队列中的位置。
实现分析
RR 调度器的 put_prev_task 中,当 preempt=true 且任务仍有时间片时,会调用 push_front 将任务插入队首。而 wakeup 场景下被唤醒的任务(从 Blocked 到 Ready)不应被视为"被抢占",应和其他新入队的任务一样放到队尾。修改后 always preempt=false,确保 RR 公平性。
验证结果
| 检查项 | 结果 |
|---|---|
cargo fmt --check |
✅ 通过 |
cargo test -p ax-task --features "sched-rr host-test" unblock_resched_does_not_front_insert_rr_task |
✅ 通过 |
cargo clippy -p ax-task --features "sched-rr host-test" -- -D warnings |
✅ 通过(无新增警告) |
| CI (rcore-os/tgoskits) | ✅ 全部通过(fmt、sync-lint、spin-lint、所有架构测试) |
重复/重叠分析
- base 分支 (
origin/dev) 上unblock_task仍使用旧的resched透传行为,无等效修复 - 相关 open PR #1451(同一作者的 IRQ runtime 重构)不与此 PR 冲突,两者修改不同代码路径
- 无其他重叠或冲突的 open PR
测试覆盖
- 回归测试
unblock_resched_does_not_front_insert_rr_task正确验证了修复行为:已有 ready 任务在队列中时,unblock_task(blocked, true)不应把被唤醒任务插到队首 - 测试在
host-test环境下可执行,CI 中已有对应的Test with stdjob 覆盖 - 该修复来自 openkylin/x-kernel 已合并的相同修复,增加了一层跨项目验证
无阻塞问题
- 无
[patch.crates-io]引入 - 无 unsafe 代码变更
- 无公共 API 变更
- 无并发安全或资源泄漏风险
Powered by deepseek-v4-pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
同步 openkylin/x-kernel 已合并的 RR wakeup 调度修复:当前
unblock_task(..., resched=true)会把resched继续传给put_task_with_state,RR scheduler 会把这次 wakeup 当成“被唤醒任务发生抢占且仍有时间片”,从而把它插到 ready queue 队首,压过已经排队的任务。修改
AxRunQueueRef::unblock_task和CurrentRunQueueRef::unblock_task将被唤醒任务入队时固定使用preempt=false。resched的原用途:只用于请求当前 CPU/远端 CPU 尽快进入调度,而不改变被唤醒任务在 RR 队列里的公平顺序。unblock_task(blocked, true)不能把被唤醒任务插到队首。验证
cargo test -p ax-task --features "sched-rr host-test" unblock_resched_does_not_front_insert_rr_taskcargo xtask clippy --package ax-task参考:openkylin/x-kernel!334