Skip to content

fix(ci): stabilize x86 Starry QEMU timing#1245

Merged
ZR233 merged 3 commits into
rcore-os:devfrom
ZR233:fix/x86-serial-irq
Jun 12, 2026
Merged

fix(ci): stabilize x86 Starry QEMU timing#1245
ZR233 merged 3 commits into
rcore-os:devfrom
ZR233:fix/x86-serial-irq

Conversation

@ZR233

@ZR233 ZR233 commented Jun 12, 2026

Copy link
Copy Markdown
Member

问题

近期 Starry QEMU CI 中 x86_64 明显慢于其他架构,select/poll 等短超时用例会聚集到异常耗时,完整 system 组容易被拖到 20 分钟级别。排查过程中还发现 x86 Starry 的 console input IRQ 与其他架构不一致,以及旧的 someboot callback 式 IRQ 分发路径会让硬件 EOI/complete 与上层调度边界关系不够清晰。

修改

  1. 补齐 x86_64 串口输入中断路径:

    • 在 someboot console trait 中增加可选 irq_numset_input_irq_enabledhandle_irq hook;
    • x86_64 COM1 返回 IRQ4 对应 vector,并打开 16550 接收相关中断;
    • axplat-dyn console 将平台 console IRQ 事件转换给上层;
    • ACPI/IOAPIC routing 支持 ISA IRQ 默认 edge/active-high,并处理 MADT interrupt source override。
  2. 将运行期 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 串起来。
  3. 修复 x86_64 TSC 频率来源不可信导致的 Starry QEMU 慢 CI:

    • 优先使用可信 hypervisor TSC 频率;
    • 其次使用有效范围内的 CPUID timing 信息;
    • 在 QEMU/虚拟 CPU 组合暴露无效 timing leaf 时,通过 PIT channel 2 做短校准;
    • 最后才回退到 processor base frequency 或 1GHz fallback。
  4. 修复 Starry host HTTP fixture 大响应体写超时:

    • 保留短 read timeout;
    • write timeout 按响应体大小伸缩,避免 20MiB curl fixture 在 QEMU usernet 下被 host 端 1s 写超时截断。
  5. 更新文档和移植说明:

    • 记录 begin_irq(raw) -> ActiveIrq、dispatch 期间持有 guard、drop 时完成 EOI/complete 的契约;
    • 记录 x86 QEMU timing leaf 需要可信度校验和 PIT 校准兜底。

逻辑

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 fmt
  • cargo test -p rdrive acpi::tests --lib
  • cargo test -p axbuild host_http --lib
  • cargo xtask clippy --package axbuild
  • cargo xtask clippy --package someboot
  • cargo xtask clippy --package somehal
  • cargo xtask clippy --package ax-cpu
  • cargo xtask clippy --package ax-hal
  • cargo xtask clippy --package ax-runtime
  • cargo xtask clippy --package axplat-dyn
  • cargo xtask clippy --package rdrive
  • cargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system/bugfix-bug-tty-sigint
  • cargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system/syscall-test-select-poll-family
  • cargo xtask starry test qemu --arch riscv64 -c qemu-smp1/system/syscall-test-select-poll-family
  • cargo xtask starry test qemu --arch aarch64 -c qemu-smp1/system/syscall-test-select-poll-family
  • cargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system/apk-curl-equivalence
  • cargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system
    • 结果:通过,total 约 688s;test-select-poll-family 约 6s,test-timer-family 约 31s,未再出现 20 分钟级 timeout-heavy 行为。
  • cargo xtask arceos test qemu --arch x86_64 -g rust -c task-sleep

ZR233 added 2 commits June 12, 2026 15:27
- 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.
@ZR233 ZR233 changed the title fix(x86): enable serial console interrupts fix(ci): stabilize x86 Starry QEMU timing Jun 12, 2026

@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.

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 行,覆盖 axcpusomebootsomehal-macrossomehalaxplat-dynaxhalaxruntimerdriveaxbuild 等核心组件。

实现逻辑分析

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 guard
  • axplat-dynIrqIfImpl::handle() 在持有 ActiveIrq 的作用域内执行 dispatch_irq()
  • ActiveIrq::drop() 在各架构实现 EOI/complete:GICv2/v3 的 eoi1+dir,PLIC complete,LAPIC lapic_eoi(),LoongArch complete
  • x86 begin_irqAPIC_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

@mai-team-app
mai-team-app Bot requested review from ZCShou and yfblock June 12, 2026 11:34
@ZR233
ZR233 merged commit 52bb25a into rcore-os:dev Jun 12, 2026
50 checks passed
@ZR233
ZR233 deleted the fix/x86-serial-irq branch June 12, 2026 11:57
@github-actions github-actions Bot mentioned this pull request Jun 12, 2026
silicalet added a commit to silicalet/tgoskits that referenced this pull request Jun 12, 2026
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)
@github-actions github-actions Bot mentioned this pull request Jun 15, 2026
fzg-23 pushed a commit to fzg-23/tgoskits that referenced this pull request Jun 16, 2026
* 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
luodeb pushed a commit that referenced this pull request Jun 30, 2026
* 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
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