Skip to content

fix(ax-task): avoid RR front insertion on wakeup#1532

Merged
ZR233 merged 1 commit into
rcore-os:devfrom
ZR233:codex/xkernel-unblock-task-rr
Jul 7, 2026
Merged

fix(ax-task): avoid RR front insertion on wakeup#1532
ZR233 merged 1 commit into
rcore-os:devfrom
ZR233:codex/xkernel-unblock-task-rr

Conversation

@ZR233

@ZR233 ZR233 commented Jul 7, 2026

Copy link
Copy Markdown
Member

问题

同步 openkylin/x-kernel 已合并的 RR wakeup 调度修复:当前 unblock_task(..., resched=true) 会把 resched 继续传给 put_task_with_state,RR scheduler 会把这次 wakeup 当成“被唤醒任务发生抢占且仍有时间片”,从而把它插到 ready queue 队首,压过已经排队的任务。

修改

  • AxRunQueueRef::unblock_taskCurrentRunQueueRef::unblock_task 将被唤醒任务入队时固定使用 preempt=false
  • 保留 resched 的原用途:只用于请求当前 CPU/远端 CPU 尽快进入调度,而不改变被唤醒任务在 RR 队列里的公平顺序。
  • 增加 RR host-test:已有 ready 任务在队列中时,unblock_task(blocked, true) 不能把被唤醒任务插到队首。

验证

  • cargo test -p ax-task --features "sched-rr host-test" unblock_resched_does_not_front_insert_rr_task
  • cargo xtask clippy --package ax-task

参考:openkylin/x-kernel!334

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查结果:批准 (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 std job 覆盖
  • 该修复来自 openkylin/x-kernel 已合并的相同修复,增加了一层跨项目验证

无阻塞问题

  • [patch.crates-io] 引入
  • 无 unsafe 代码变更
  • 无公共 API 变更
  • 无并发安全或资源泄漏风险

Powered by deepseek-v4-pro

@ZR233
ZR233 merged commit dca837d into rcore-os:dev Jul 7, 2026
56 checks passed
@ZR233
ZR233 deleted the codex/xkernel-unblock-task-rr branch July 7, 2026 12:25
This was referenced Jul 7, 2026
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.

1 participant