Skip to content

feat(oscomp): 支持评测自动运行并修复大内存启动#261

Merged
a6d9a6m merged 3 commits into
mainfrom
feat/oscomp-auto-run-shutdown
Jun 3, 2026
Merged

feat(oscomp): 支持评测自动运行并修复大内存启动#261
a6d9a6m merged 3 commits into
mainfrom
feat/oscomp-auto-run-shutdown

Conversation

@a6d9a6m

@a6d9a6m a6d9a6m commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

背景

OSCOMP 评测环境会同时挂载测试镜像和我们的 rootfs,并要求系统启动后自动运行测试、测试结束后自动关机。

当前分支同时处理两个问题:

  • 评测模式下需要稳定识别 rootfs / 测试镜像,并自动执行 *_testcode.sh
  • 评测机可能使用较大的内存配置,原先依赖固定 MEMORY_END 会导致 DTB 或可用内存范围处理不完整

改动

  • 新增 oscomp feature,make all 构建评测内核时默认启用该 feature
  • OSCOMP 模式下自动探测双盘:
    • 通过 /bin/sh/bin/ash 识别 rootfs
    • 通过 *_testcode.sh 识别测试镜像,并挂载到 /tests
  • 更新 RISC-V / LoongArch rootfs 的 rcS
    • 自动扫描 /tests 下的测试脚本
    • 为 glibc 测试程序补齐 loader / libc 软链
    • 非交互执行测试脚本
    • 测试结束后主动 poweroff
  • 新增本地复现目标:
    • make run-oscomp-rv
    • make run-oscomp-la
  • 内存初始化改为优先使用设备树中的真实 DRAM 范围
    • RISC-V 覆盖完整 DRAM,避免 DTB 位于高地址时缺页
    • LoongArch 对可用物理内存和直映射范围限制到 1GiB,避免大范围 4K 页映射过慢

兼容性

oscomp feature 下仍保持原有单盘启动和交互式 shell 行为,本地开发流程不受影响。

a6d9a6m added 2 commits June 3, 2026 15:48
帧分配器与内核直映射此前硬编码到编译期 MEMORY_END(riscv 128MB /
loongarch 128MB)。评测机给 1–2GB(本地复现 -m 4G)时,QEMU 把 DTB 放在
RAM 顶端(-m 4G 时约 0xbfe0_0000),落在 128MB 直映射窗口之外,切换页表后
platform::init() 解引用 DTB 即缺页 panic;且帧分配器也无法管理评测所需的
大内存。

改为优先采用 device_tree::dram_info() 报告的真实 DRAM 末端:
- mm::init():帧分配器 end 取 DRAM 末端;
- map_kernel_space():物理内存直映射 end 取同一 DRAM 末端,二者保持一致,
  保证每个可分配帧都在直映射内。
- LoongArch:经 DMW 硬件直映射访问物理内存(不走页表),且 DTB 报告超大 RAM
  窗口,4K 页映射多 GB 既慢又无意义,故两处均 cap 在 1GiB。
- RISC-V:不设上限覆盖全部 DRAM,并对 DTB 增加兜底映射(map_mmio_region),
  以防其落在直映射窗口外。

已用 qemu-system-riscv64 -m 2G 验证:正确识别 DRAM 0x80000000-0x100000000,
解析顶端 DTB 不再 panic,ext4 挂载与 rootfs 选择正常。
让 `make all` 产出的内核在评测机上自动跑测试并主动关机:

- os/Cargo.toml:新增 `oscomp` feature。
- fs/mod.rs:init_oscomp_filesystems()——按内容探测双盘,rootfs(认
  /bin/sh|/bin/ash)挂 /,测试镜像(认 *_testcode.sh)挂 /tests;
  total_blocks 由设备实际大小推导。
- kernel/boot.rs:oscomp 模式下 init() 调 init_oscomp_filesystems(),
  否则保持原有单盘 init_ext4_from_block_device()。
- data/*/etc/init.d/rcS(两架构一致):扫 /tests 下 *_testcode.sh(含下一层),
  glibc loader 软链到 /lib,逐个执行,跑完 /sbin/poweroff -f;无 /tests 回落
  交互 shell。
- Makefile:kernel-rv/la 默认带 --features oscomp;新增 run-oscomp-rv/la、
  prepare-testimg-rv/la 及相关变量。

两架构 --features oscomp 编译通过,冒烟测试确认 init_oscomp_filesystems()
正确识别 rootfs。注意:内核态首次写 ext4(mkdir /tests 等)会触发一个既有的
ext4 写路径崩溃(write_offset 收到 self=pa_to_va(0)),端到端尚未跑通,该写
路径 bug 另行处理。

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces the OSCOMP evaluation mode, enabling automatic test execution and shutdown on QEMU for both RISC-V and LoongArch architectures. Key changes include new Makefile targets, automated test runner scripts (rcS), dynamic physical memory mapping based on device tree DRAM info, and dual-disk probing/mounting. The reviewer feedback highlights several critical issues: failed filesystem mount attempts for rootfs and testfs must be unmounted to prevent resource leaks; the directory scanner must skip "." and ".." to avoid recursive scanning of the parent directory; the DTB mapping size should be restricted if it lies before the kernel to prevent overlapping with the kernel's .text segment; and the rcS scripts should use "ln -sf" to safely handle broken symlinks.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread os/src/fs/mod.rs
Comment thread os/src/fs/mod.rs
Comment thread os/src/fs/mod.rs
Comment thread os/src/mm/memory_space/space/kernel_space.rs
Comment thread data/risc-v_musl/etc/init.d/rcS
Comment thread data/loongarch_musl/etc/init.d/rcS
@a6d9a6m a6d9a6m merged commit c99bcc0 into main Jun 3, 2026
1 check passed
@a6d9a6m a6d9a6m deleted the feat/oscomp-auto-run-shutdown branch June 3, 2026 12:16
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