fix(ci): stabilize x86 Starry QEMU timing#1245
Conversation
- Removed the `handle_irq` function from `someboot::irq` as it is no longer needed. - Updated `somehal_macros` to eliminate the `irq_handler` macro, simplifying the IRQ handler declaration process. - Refactored IRQ handling in various platforms to utilize the new `begin_irq` and `ActiveIrq` structures for better encapsulation and management of IRQ states. - Adjusted platform-specific implementations to align with the new IRQ handling approach, ensuring compatibility across architectures. - Cleaned up unused code and comments related to the old IRQ handling mechanism.
There was a problem hiding this comment.
PR #1245 审查:fix(ci): stabilize x86 Starry QEMU timing
变更概述
本 PR 修复 x86_64 Starry QEMU CI 中因 TSC 频率来源不可靠导致的测试超时问题,同时将运行期 IRQ 分发统一为 RAII guard 模型,补齐 x86_64 串口输入中断路径,并修复 host HTTP fixture 大响应体写超时。
涉及 45 个文件,+659/-544 行,覆盖 axcpu、someboot、somehal-macros、somehal、axplat-dyn、axhal、axruntime、rdrive、axbuild 等核心组件。
实现逻辑分析
1. TSC 频率优先级重构(x86_64)
init_tsc_freq() 的频率来源改为按可信度排序:hypervisor CPUID > 有效 CPUID timing > PIT channel 2 校准 > processor base frequency > 1GHz fallback。valid_tsc_freq_hz() 通过 10MHz~10GHz 范围过滤拒绝无效值,逻辑正确。PIT 校准使用 50ms 模式 0 单次计时,启动时执行一次,不进入热路径。`
2. RAII IRQ 模型
somehal::irq::begin_irq(raw) -> Option<ActiveIrq>负责 claim/ack 后返回 RAII guardaxplat-dyn的IrqIfImpl::handle()在持有ActiveIrq的作用域内执行dispatch_irq()ActiveIrq::drop()在各架构实现 EOI/complete:GICv2/v3 的eoi1+dir,PLIC complete,LAPIClapic_eoi(),LoongArch complete- x86
begin_irq对APIC_TIMER_VECTOR直接返回ActiveIrq::new(systimer_irq),无需额外硬件 ack - 职责边界清晰:
ax-hal提供顶层 IRQ/preempt guard,somehal负责硬件事务,axplat-dyn负责 OS 分发
3. x86_64 COM1 串口中断
16550 寄存器定义正确(IER/IIR/LCR/MCR/LSR 偏移量),中断使能通过 MCR bit 3 + IER bit 0/2 设置。handle_irq() 同时检查 IIR 和 LSR 以覆盖中断类型和即时状态,返回 CONSOLE_IRQ_* 事件标志。
4. someboot 架构清理
旧的 _someboot_handle_irq / #[somehal::irq_handler] 回调路径已删除,替换为 panic 安全门。somehal-macros/src/trap.rs(152 行)完全移除。
5. HTTP fixture 写超时
HostHttpBody::write_timeout() 按响应体大小和最低 128KB/s 写速率计算超时(min 5s, max 300s),避免 20MiB curl fixture 在 QEMU usernet 下被截断。单元测试覆盖了小/大 body 的超时计算。
验证结果
cargo fmt --check✅ 通过cargo test -p rdrive acpi::tests --lib✅ 12 tests passed(含 ISA interrupt source override、GSI 路由、PCI IRQ routing 等)cargo test -p axbuild host_http --lib✅ 7 tests passed(含 write timeout scaling、generated body、port wait)
CI 状态
CI workflow run #27411610227 仍在执行中(status: in_progress),当前各 check run 均显示 skipped/queued 状态。PR 刚创建不久,CI 尚在排队。作者在 PR body 中提供了详尽的本地 QEMU 验证记录,涵盖 x86_64/riscv64/aarch64 架构的多个 Starry test case 和 ArceOS test case,结果均通过。不阻塞 CI 结果做本地再测试。
重复/重叠分析
搜索了相关 open PR:
- #1163(eBPF JIT smoke test suite):不涉及 IRQ/timing/16550 路径
- #1017(apk-cmake qemu case):不涉及 IRQ/timing 路径
无重复或冲突风险。
crates.io Patch 检查
未发现 [patch.crates-io] 覆盖。
无阻塞性问题
代码质量好,实现逻辑正确,RAII 模型职责边界清晰,TSC 校准策略合理,验证充分。APPROVE。
Powered by mimo-v2.5-pro
Manually resolved conflicts in: - os/arceos/modules/axtask/src/api.rs (timer IRQ split + wchan exports) - os/arceos/modules/axtask/src/future/time.rs (next_deadline + wchan w/ maybe_reprogram_timer) Upstream changes merged: - fix(ci): stabilize x86 Starry QEMU timing (rcore-os#1245) - fix(ci): limit self-hosted checkout depth (rcore-os#1251) - fix(starry): reprogram timer for short deadlines (rcore-os#1250) test-nix-prereqs: 1/1 case(s) passed (13/13 subtests)
* fix(x86): enable serial console interrupts * Refactor IRQ handling and remove deprecated macros - Removed the `handle_irq` function from `someboot::irq` as it is no longer needed. - Updated `somehal_macros` to eliminate the `irq_handler` macro, simplifying the IRQ handler declaration process. - Refactored IRQ handling in various platforms to utilize the new `begin_irq` and `ActiveIrq` structures for better encapsulation and management of IRQ states. - Adjusted platform-specific implementations to align with the new IRQ handling approach, ensuring compatibility across architectures. - Cleaned up unused code and comments related to the old IRQ handling mechanism. * fix(ci): stabilize x86 Starry QEMU timing
* fix(x86): enable serial console interrupts * Refactor IRQ handling and remove deprecated macros - Removed the `handle_irq` function from `someboot::irq` as it is no longer needed. - Updated `somehal_macros` to eliminate the `irq_handler` macro, simplifying the IRQ handler declaration process. - Refactored IRQ handling in various platforms to utilize the new `begin_irq` and `ActiveIrq` structures for better encapsulation and management of IRQ states. - Adjusted platform-specific implementations to align with the new IRQ handling approach, ensuring compatibility across architectures. - Cleaned up unused code and comments related to the old IRQ handling mechanism. * fix(ci): stabilize x86 Starry QEMU timing
问题
近期 Starry QEMU CI 中 x86_64 明显慢于其他架构,select/poll 等短超时用例会聚集到异常耗时,完整 system 组容易被拖到 20 分钟级别。排查过程中还发现 x86 Starry 的 console input IRQ 与其他架构不一致,以及旧的 someboot callback 式 IRQ 分发路径会让硬件 EOI/complete 与上层调度边界关系不够清晰。
修改
补齐 x86_64 串口输入中断路径:
irq_num、set_input_irq_enabled、handle_irqhook;axplat-dynconsole 将平台 console IRQ 事件转换给上层;将运行期 IRQ 分发统一为 RAII guard 模型:
somehal::irq::begin_irq(raw)在 claim/ack 后返回ActiveIrq;axplat-dyn在持有ActiveIrq的作用域内执行dispatch_irq();ActiveIrq::drop()负责架构相关的 GIC EOI/DIR、PLIC complete、LAPIC EOI 或 LoongArch complete;#[somehal::irq_handler]/someboot runtime callback glue,运行期 trap 统一由ax-cpu -> ax-hal -> axplat-dyn -> somehal串起来。修复 x86_64 TSC 频率来源不可信导致的 Starry QEMU 慢 CI:
修复 Starry host HTTP fixture 大响应体写超时:
更新文档和移植说明:
begin_irq(raw) -> ActiveIrq、dispatch 期间持有 guard、drop 时完成 EOI/complete 的契约;逻辑
x86 Starry 慢 CI 的主要根因不是 IRQ controller 锁热路径,而是 x86 QEMU 下 TSC 频率来源不可靠:旧逻辑可能接受无效 CPUID timing 信息或过早 fallback,导致内核时间尺度偏离真实时间,短超时测试整体变慢。PIT 校准只在启动阶段执行,不进入 IRQ 热路径。
RAII IRQ 模型把职责边界固定为:
ax-hal提供顶层 IRQ/preempt guard,somehal负责硬件事务生命周期,axplat-dyn负责 OS 分发。这样可以保证调度不会早于 GIC EOI/DIR、PLIC complete 或 LAPIC EOI。本地验证
cargo fmtcargo test -p rdrive acpi::tests --libcargo test -p axbuild host_http --libcargo xtask clippy --package axbuildcargo xtask clippy --package somebootcargo xtask clippy --package somehalcargo xtask clippy --package ax-cpucargo xtask clippy --package ax-halcargo xtask clippy --package ax-runtimecargo xtask clippy --package axplat-dyncargo xtask clippy --package rdrivecargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system/bugfix-bug-tty-sigintcargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system/syscall-test-select-poll-familycargo xtask starry test qemu --arch riscv64 -c qemu-smp1/system/syscall-test-select-poll-familycargo xtask starry test qemu --arch aarch64 -c qemu-smp1/system/syscall-test-select-poll-familycargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system/apk-curl-equivalencecargo xtask starry test qemu --arch x86_64 -c qemu-smp1/systemtest-select-poll-family约 6s,test-timer-family约 31s,未再出现 20 分钟级 timeout-heavy 行为。cargo xtask arceos test qemu --arch x86_64 -g rust -c task-sleep