Skip to content

fix(starry): FIOCLEX ioctl + /proc status ctxt_switches + quiet non-tty ioctl probes (TUI)#1168

Merged
ZR233 merged 1 commit into
rcore-os:devfrom
Lfan-ke:fix-tui-procfs-ioctl
Jun 10, 2026
Merged

fix(starry): FIOCLEX ioctl + /proc status ctxt_switches + quiet non-tty ioctl probes (TUI)#1168
ZR233 merged 1 commit into
rcore-os:devfrom
Lfan-ke:fix-tui-procfs-ioctl

Conversation

@Lfan-ke

@Lfan-ke Lfan-ke commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

让全屏 TUI(glances / htop / textual / casca)在 StarryOS 串口控制台上显示正确、操作响应正确、持续不崩的三处 Linux 兼容修。用 pyte(参考 VT102 模拟器)离线渲染 starry 串口流定位与验证。

1. FIOCLEX / FIONCLEX ioctl(syscall/fs/ctl.rs)

ioctl(fd, FIOCLEX)(0x5451)/FIONCLEX(0x5450)是 fcntl(fd, F_SETFD, FD_CLOEXEC) 的 ioctl 拼写,libc/musl 与 CPython 对新开 fd 设 close-on-exec 时使用。Linux 对任意 fd 通用实现;starry 之前下发到 per-file ioctl(只认 tty/device),对普通 fd 报 Unsupported ioctl command: 21585。修:在 sys_ioctl 内联(同 FIONBIO),路由到 fd 表 cloexec

2. /proc//status 补 ctxt_switches(pseudofs/proc.rs)

psutil Process.num_ctx_switches()/proc/<pid>/statusvoluntary_ctxt_switches: / nonvoluntary_ctxt_switches: 时抛未捕获NotImplementedError("the kernel is probably older than 2.6.23")(不是 psutil 会吞的 NoSuchProcess/AccessDenied),导致 glances 的扩展进程视图崩溃,异常 traceback 打在 curses 屏上(表现为"第一帧后涂抹")。经 pyte 渲染串口流定位。我们暂未逐任务统计上下文切换次数,故 stub 0(字段存在即满足 psutil,与最小 procfs 实现一致;日后可接调度器真实计数)。

3. ioctl NotATty 探测降噪(syscall/fs/ctl.rs)

NotATty 是 isatty/termios/console 探测(TCGETS/KDGKBTYPE/TIOCGPGRP…)在非 tty fd 上的合法负答,不是未实现命令。libc/ncurses/CPython 对每个 fd 都会探;原 warn! 每次打到串口,会污染在同一串口绘制的全屏 TUI(htop/glances)。降为 debug!

验证

含本修的内核四架构 starry(qemu-10 单核)上:

  • glances:pyte 渲染出完整 CPU/MEM/LOAD/SWAP/进程表面板,连续刷新无 traceback、无涂抹。
  • htop:CPU meter 条/Mem/Tasks/进程表/F 键栏正确;F2 Setup、F5 Tree、F6 SortBy 操作响应正确,操作后无异常。
  • textual / casca:App.run_test() Pilot / handle_input 驱动的 widget+CSS+reactive/状态+控制 各 9/9 四架构通过。

关联 #764 的 glances / textual / casca / htop(TUI 类)。

@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 包含三处针对 StarryOS TUI 兼容性的 Linux 语义修复,变更范围小且聚焦(2 文件,+28/-12):

1. FIOCLEX/FIONCLEX ioctl 支持

sys_ioctl 中内联处理 FIOCLEX(0x5451)/FIONCLEX(0x5450),路由到 FD_TABLE 的 cloexec 字段,与现有 fcntl(F_SETFD) 路径一致。实现正确:常量值匹配 Linux 内核定义,写锁获取/释放时机合理(get_file_like 返回 Arc 后已释放读锁)。这是 libc/musl、CPython 对每个新 fd 的标准操作,Linux 对任意 fd 通用实现——PR 补齐了这个缺失的通用 ioctl 路径。

2. /proc/pid/status 补 ctxt_switches

render_task_status_fields 中添加 voluntary_ctxt_switches: 0nonvoluntary_ctxt_switches: 0,避免 psutil num_ctx_switches() 抛出未捕获的 NotImplementedError 导致 glances 崩溃。Stub 值与最小 procfs 实现一致,字段存在即可满足 psutil 解析要求。后续可接调度器真实计数。

3. NotATty 探测降噪

将非 tty fd 上的 ioctl 探测从 warn! 降为 debug!NotATty 是 isatty/termios/console 探测的合法负答,不是未实现命令。原 warn! 会污染串口控制台输出,破坏全屏 TUI 绘制。移除了旧的硬编码 ioctl 命令列表(TIOCGWINSZ | TCGETS | BLKGETSIZE64 | ...),改为对所有 NotATty 统一降噪——更合理,因为所有 NotATty 都是合法负答而非错误。

CI 状态

所有 CI 检查通过:

  • Check formatting: ✅
  • Run sync-lint: ✅
  • Test starry (x86_64/aarch64/loongarch64/riscv64) QEMU: ✅
  • Test arceos (x86_64/aarch64/loongarch64/riscv64) QEMU: ✅
  • Test with std: ✅
  • Run clippy: ✅(run_container 变体被跳过是互斥矩阵的预期行为)
  • 板级测试(orangepi-5-plus、roc-rk3568-pc、phytiumpi): ✅

本地验证

  • cargo fmt --check -p starry-kernel: ✅ 通过
  • cargo clippy -p starry-kernel -- -D warnings: ✅ 无警告

重复/重叠分析

  • 搜索 base 分支上的相关代码:FIOCLEX 未在 base 上实现,/proc status 缺 ctxt_switches 字段——PR 补齐。
  • PR #1167(feat(starry-kernel): improve GDB usability)也修改了 proc.rs,但关注的是 GDB ptrace 相关的 /proc 增强,与本 PR 的 ctxt_switches stub 无冲突,互补。
  • 无其他重复或冲突的 open PR。

结论

三处修复均正确、简洁、有明确的 Linux 兼容性理由,变更与现有代码模式一致。无阻塞问题,建议合并。

Powered by mimo-v2.5-pro

@Lfan-ke

Lfan-ke commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

@codex review.

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

我完整看了这次变更和相关现有测试,FIOCLEX/FIONCLEX 的实现方向、/proc status 补字段以及 ENOTTY 探测降噪本身都比较聚焦,也和 Linux 兼容目标一致。当前 head 上远端 formatting、clippy、sync-lint 和 Starry 四个架构 QEMU 都是通过状态;我本地也跑了 cargo fmt --check,通过。

阻塞点是这次 PR 明确修复两个可复现的兼容性 bug,但没有新增会在旧行为上失败的回归测试。按项目 review 要求,bugfix 需要补对应回归用例,除非有具体不可测原因;这里两个场景都可以放进现有 Starry 普通 QEMU 测试里,所以先 request changes。

Comment thread os/StarryOS/kernel/src/syscall/fs/ctl.rs
Comment thread os/StarryOS/kernel/src/pseudofs/proc.rs
…iet non-tty ioctl probes

让全屏 TUI(glances / htop / textual)在 starry 上显示正确、持续不崩,三处 Linux 兼容修:

1. syscall/fs/ctl.rs: 实现 FIOCLEX(0x5451)/FIONCLEX(0x5450) —— ioctl 拼写的 fcntl F_SETFD FD_CLOEXEC. 内联路由到 fd 表 cloexec, 任意 fd 可用(与 Linux 一致). libc/musl/CPython 对新开 fd 设 close-on-exec 用之, 缺则报 "Unsupported ioctl command: 21585".

2. pseudofs/proc.rs: /proc/<pid>/status 补 voluntary_ctxt_switches/nonvoluntary_ctxt_switches(stub 0). psutil Process.num_ctx_switches() 缺这两行时抛 uncaught NotImplementedError("kernel older than 2.6.23"), 使 glances 扩展进程视图崩溃, 异常 traceback 打在 curses 屏上(经 pyte 离线渲染串口流定位). 我们暂未逐任务统计上下文切换, 故 stub 0(字段存在即满足 psutil).

3. syscall/fs/ctl.rs: ioctl 对 NotATty 的 warn! 降为 debug!. isatty/termios/console 探测(TCGETS/KDGKBTYPE/TIOCGPGRP…)在非 tty fd 返 NotATty 是合法负答, 每次 warn 打串口会污染同屏全屏 TUI.

应 reviewer 要求新增 checked-in 回归测例(test-suit/starryos/qemu-smp1/system/):

- syscall-test-ioctl-cloexec: 在非 tty fd(pipe)上 ioctl(FIOCLEX) set / ioctl(FIONCLEX) clear, 经 fcntl(F_GETFD) 验证 FD_CLOEXEC 切换, 并与 fcntl(F_SETFD) 互证两条路径一致; 无效 fd(-1)与已关闭 fd 返回 EBADF. 修复前 FIOCLEX 在普通 fd 上失败 / FD_CLOEXEC 不变 → 该测例 FAIL, 修复后 PASS.

- syscall-test-procfs-ctxt-switches: 断言 /proc/self/status 与 /proc/<pid>/status 均含 voluntary_ctxt_switches 与 nonvoluntary_ctxt_switches 行且可解析为整数. 修复前字段缺失 → FAIL, 修复后 PASS.

验证: glances/htop/textual 在含本修内核四架构 starry 上 curses 显示正确、操作响应正确(pyte 渲染确认). 两个新回归测例在 x86_64 / aarch64 / riscv64 / loongarch64 单核 qemu10 全 PASS(test-ioctl-cloexec 15/15, test-procfs-ctxt-switches 4/4). 关联 rcore-os#764 glances/textual/casca/htop(TUI).

> 把困困投入生产后更名 `智慧集群`

Signed-off-by: 困困集群 <kunkun.cluster@users.noreply.github.com>
Signed-off-by: 林晨 (Leo Cheng) <chengkelfan@qq.com>
@Lfan-ke
Lfan-ke force-pushed the fix-tui-procfs-ioctl branch from c6fcb94 to ba0cf61 Compare June 10, 2026 08:22
@Lfan-ke

Lfan-ke commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

感谢 review,已按要求补 checked-in 回归测例,并 rebase 到当前 dev。

新增两个普通 QEMU 回归测例(test-suit/starryos/qemu-smp1/system/,随聚合 runner /usr/bin/starry-test-suit/* 自动执行):

  1. syscall-test-ioctl-cloexec(对应 syscall/fs/ctl.rs 的 FIOCLEX/FIONCLEX):在非 tty fd(pipe)上 ioctl(fd, FIOCLEX) set、ioctl(fd, FIONCLEX) clear,经 fcntl(fd, F_GETFD) 断言 FD_CLOEXEC 被正确置位/清除,并与 fcntl(fd, F_SETFD, FD_CLOEXEC) 互证两条路径一致;无效 fd(-1)与已关闭 fd 断言返回 EBADF。修复前 FIOCLEX 在普通 fd 上失败 / FD_CLOEXEC 不变 → 该测例 FAIL,修复后 PASS。

  2. syscall-test-procfs-ctxt-switches(对应 pseudofs/proc.rs 的 ctxt_switches):断言 /proc/self/status/proc/<pid>/status 均含 voluntary_ctxt_switches / nonvoluntary_ctxt_switches 行且能解析为整数。修复前字段缺失 → FAIL,修复后 PASS。

已 rebase 到最新 dev(解决 /proc/<pid>/status 格式串重构带来的 proc.rs 冲突)。两个测例在 x86_64 / aarch64 / riscv64 / loongarch64 单核 qemu10 实测全 PASS(test-ioctl-cloexec 15/15,test-procfs-ctxt-switches 4/4)。

@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 针对 StarryOS 全屏 TUI (glances/htop/textual/casca) 在串口控制台上的兼容性,进行了三处 Linux 语义修复,变更范围聚焦(2 个内核文件 +28/-12, 6 个新增测试文件)。当前 head (ba0cf61) 已包含 reviewer 要求的回归测试。

1. FIOCLEX/FIONCLEX ioctl 支持(ctl.rs)

sys_ioctl 入口内联处理 FIOCLEX(0x5451)/FIONCLEX(0x5450),直接修改 FD_TABLEcloexec 位,与现有 fcntl(F_SETFD) 路径一致。常量值与 Linux 内核定义完全匹配。这一实现正确补齐了 libc/musl/CPython 对每个新 fd 使用的标准 ioctl 路径,Linux 对任意 fd 通用实现。

2. /proc/pid/status 补 ctxt_switches 字段(proc.rs)

render_task_status_fields 末尾追加 voluntary_ctxt_switches: 0nonvoluntary_ctxt_switches: 0。格式与 man 5 proc 规定一致(name:\tnumber)。由于暂未逐任务统计上下文切换,stub 值为 0——字段存在即满足 psutil 解析要求,避免 NotImplementedError 崩溃 glances。后续可接入调度器真实计数。

3. NotATty 探测降噪(ctl.rs)

将非 tty fd 上的 ioctl 探测从 warn! 降为 debug!。移除了原先硬编码的 ioctl 命令白名单(TIOCGWINSZ | TCGETS | BLKGETSIZE64 | BLKRAGET | BLKSSZGET),改为对所有 NotATty 统一降噪。这一修改更合理:所有 NotATty 都是 isatty/termios/console 探测的合法负答,不是未实现命令。log 消息也更加清晰:"ioctl {cmd} on non-tty fd {fd} -> ENOTTY (probe)"

新增回归测试

  • syscall-test-ioctl-cloexec (15 断言):在非 tty fd(pipe)上验证 ioctl(FIOCLEX) set / ioctl(FIONCLEX) clear,经 fcntl(F_GETFD) 验证 FD_CLOEXEC 切换,并与 fcntl(F_SETFD) 互证两条路径一致;覆盖无效 fd(-1) 和已关闭 fd 的 EBADF。
  • syscall-test-procfs-ctxt-switches (4 断言):验证 /proc/self/status 和 /proc//status 均含 voluntary_ctxt_switches 与 nonvoluntary_ctxt_switches 字段且可解析为整数。

测试通过 CMakeLists.txt 的 GLOB 自动发现集成,无需手动注册。

本地验证

  • cargo fmt --check -p starry-kernel:通过 ✅
  • diff 确认两个 test_framework.h 副本一致

CI 状态

CI workflow (run #5901) 处于 queued 状态,尚未执行。这是 fork PR 的预期行为——需要 maintainer approve workflow run。所有 run_container 变体在 fork PR 上 skip 是互斥矩阵的正常行为。待 CI 运行后确认四架构 Starry QEMU 全部通过。

重复/重叠分析

  • 已合并的 PR #1167 (GDB ptrace) 也修改了 proc.rs,但关注的是 ptrace stop/wait 和 /proc/task 路径,与本 PR 的 ctxt_switches stub 互不冲突。
  • 当前 base 分支不含 FIOCLEX/FIONCLEX 实现,也不含 ctxt_switches 字段——PR 补齐了这些缺失。
  • 检查其他 open PR(#1208, #1209 等),均不涉及相同文件或相同语义面,无冲突。

审查线程

ZR233 在此前 head (c6fcb94) 上提出的两项 CHANGES_REQUESTED(要求补充 FIOCLEX/FIONCLEX 回归测试和 ctxt_switches 回归测试)已在本 head 中通过新增测试解决,对应的 review thread 已 resolved。

结论

三处修复均正确、简洁,符合 Linux 兼容性语义,新增回归测试覆盖充分。无阻塞问题,建议合并(待 CI 通过)。

Powered by deepseek-v4-pro

@Lfan-ke

Lfan-ke commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@ZR233 上一轮的阻塞(缺会在旧行为上失败的回归测例)已在最新 head ba0cf6102 解决:新增两个普通 QEMU 回归测例 syscall-test-ioctl-cloexec(非 tty fd 的 FIOCLEX/FIONCLEX → fcntl(F_GETFD) 看到 FD_CLOEXEC set/clear + 无效 fd EBADF)与 syscall-test-procfs-ctxt-switches(/proc/self/status 与 /proc//status 的 voluntary/nonvoluntary_ctxt_switches 存在且可解析)。四架构单核 qemu10 实测各 15/15、4/4 全 PASS,mai-team-app 已 APPROVE 当前 head。烦请 re-review,谢谢!

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

已复查当前提交。此前要求补充的两个回归测试已经覆盖:FIOCLEX/FIONCLEX 在非 tty fd 上设置/清除 FD_CLOEXEC,并验证无效/关闭 fd 返回 EBADF;/proc/self/status 和 /proc//status 也都验证了 voluntary_ctxt_switches 与 nonvoluntary_ctxt_switches 字段存在且可解析。最新 CI 通过,本地也验证了这两个新增 Starry qemu 子用例。

@ZR233
ZR233 merged commit ccca529 into rcore-os:dev Jun 10, 2026
50 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 10, 2026
@Lfan-ke
Lfan-ke deleted the fix-tui-procfs-ioctl branch June 10, 2026 15:14
luodeb pushed a commit that referenced this pull request Jun 30, 2026
…iet non-tty ioctl probes (#1168)

让全屏 TUI(glances / htop / textual)在 starry 上显示正确、持续不崩,三处 Linux 兼容修:

1. syscall/fs/ctl.rs: 实现 FIOCLEX(0x5451)/FIONCLEX(0x5450) —— ioctl 拼写的 fcntl F_SETFD FD_CLOEXEC. 内联路由到 fd 表 cloexec, 任意 fd 可用(与 Linux 一致). libc/musl/CPython 对新开 fd 设 close-on-exec 用之, 缺则报 "Unsupported ioctl command: 21585".

2. pseudofs/proc.rs: /proc/<pid>/status 补 voluntary_ctxt_switches/nonvoluntary_ctxt_switches(stub 0). psutil Process.num_ctx_switches() 缺这两行时抛 uncaught NotImplementedError("kernel older than 2.6.23"), 使 glances 扩展进程视图崩溃, 异常 traceback 打在 curses 屏上(经 pyte 离线渲染串口流定位). 我们暂未逐任务统计上下文切换, 故 stub 0(字段存在即满足 psutil).

3. syscall/fs/ctl.rs: ioctl 对 NotATty 的 warn! 降为 debug!. isatty/termios/console 探测(TCGETS/KDGKBTYPE/TIOCGPGRP…)在非 tty fd 返 NotATty 是合法负答, 每次 warn 打串口会污染同屏全屏 TUI.

应 reviewer 要求新增 checked-in 回归测例(test-suit/starryos/qemu-smp1/system/):

- syscall-test-ioctl-cloexec: 在非 tty fd(pipe)上 ioctl(FIOCLEX) set / ioctl(FIONCLEX) clear, 经 fcntl(F_GETFD) 验证 FD_CLOEXEC 切换, 并与 fcntl(F_SETFD) 互证两条路径一致; 无效 fd(-1)与已关闭 fd 返回 EBADF. 修复前 FIOCLEX 在普通 fd 上失败 / FD_CLOEXEC 不变 → 该测例 FAIL, 修复后 PASS.

- syscall-test-procfs-ctxt-switches: 断言 /proc/self/status 与 /proc/<pid>/status 均含 voluntary_ctxt_switches 与 nonvoluntary_ctxt_switches 行且可解析为整数. 修复前字段缺失 → FAIL, 修复后 PASS.

验证: glances/htop/textual 在含本修内核四架构 starry 上 curses 显示正确、操作响应正确(pyte 渲染确认). 两个新回归测例在 x86_64 / aarch64 / riscv64 / loongarch64 单核 qemu10 全 PASS(test-ioctl-cloexec 15/15, test-procfs-ctxt-switches 4/4). 关联 #764 glances/textual/casca/htop(TUI).

> 把困困投入生产后更名 `智慧集群`

Signed-off-by: 困困集群 <kunkun.cluster@users.noreply.github.com>
Signed-off-by: 林晨 (Leo Cheng) <chengkelfan@qq.com>
Co-authored-by: 困困集群 <kunkun.cluster@users.noreply.github.com>
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.

2 participants