问题
ax-sync 的 multitask 单测默认并行运行时会共享 test_runtime.rs 中进程级的 PREEMPT_DEPTH。部分 fixture 在 clear() 中直接把该计数清零,而其他测试线程可能仍持有 NoPreempt / PreemptGuardToken;随后 guard drop 在 fetch_sub 处下溢并触发断言。
稳定复现
cargo test -p ax-sync --features multitask --lib
本次观察到 27 项中 10 项失败,统一落在:
os/arceos/modules/axsync/src/test_runtime.rs:108
assertion failed: PREEMPT_DEPTH.fetch_sub(1, Ordering::AcqRel) > 0
而串行运行稳定通过 27/27:
cargo test -p ax-sync --features multitask --lib -- --test-threads=1
根因边界
PREEMPT_DEPTH、runtime handle 和 clear() 是进程级全局状态;
IRQ_GUARD_ENTRIES 已使用 thread-local,preemption depth 没有;
RUNTIME_TEST_LOCK 只覆盖显式安装 fixture 的测试,无法保护不调用 install() 的普通 mutex fast-path 测试;
- 因此这属于测试 runtime 隔离问题,不是 PI mutex 或 scheduler 的功能失败。
建议后续
将纯线程上下文的 preemption depth 改成 thread-local,或让所有依赖全局 runtime 状态的测试统一持有同一 fixture lease;同时增加并行压力回归,禁止 clear() 重置其他线程仍拥有的 guard 状态。不要以 CI 全局 --test-threads=1 掩盖隔离缺陷。
发现版本
在 PR #1775 分支检查点 cfe4fd247 后的 ax-task clockevent 接口适配过程中发现;该问题位于 ax-sync 测试基础设施,独立于本轮 ax-task/ax-runtime 调度重构。
问题
ax-sync的 multitask 单测默认并行运行时会共享test_runtime.rs中进程级的PREEMPT_DEPTH。部分 fixture 在clear()中直接把该计数清零,而其他测试线程可能仍持有NoPreempt/PreemptGuardToken;随后 guard drop 在fetch_sub处下溢并触发断言。稳定复现
本次观察到 27 项中 10 项失败,统一落在:
而串行运行稳定通过 27/27:
根因边界
PREEMPT_DEPTH、runtime handle 和clear()是进程级全局状态;IRQ_GUARD_ENTRIES已使用 thread-local,preemption depth 没有;RUNTIME_TEST_LOCK只覆盖显式安装 fixture 的测试,无法保护不调用install()的普通 mutex fast-path 测试;建议后续
将纯线程上下文的 preemption depth 改成 thread-local,或让所有依赖全局 runtime 状态的测试统一持有同一 fixture lease;同时增加并行压力回归,禁止
clear()重置其他线程仍拥有的 guard 状态。不要以 CI 全局--test-threads=1掩盖隔离缺陷。发现版本
在 PR #1775 分支检查点
cfe4fd247后的 ax-task clockevent 接口适配过程中发现;该问题位于 ax-sync 测试基础设施,独立于本轮 ax-task/ax-runtime 调度重构。