Repository navigation
fix(executor): give times fork-face baselines in subshell/comsub/pipeline (Refs #3387) - #3481
Merged
Merged
Conversation
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项):
F 点:无。(fmt 红为机械卫生项,非机制问题) 续作记录:无。 未跑/VOID 的腿:无。 |
…line (Refs #3387) Root cause: `times` prints getrusage(RUSAGE_SELF) + getrusage(RUSAGE_CHILDREN) of the host process, but the three fork faces run in-process on the shared rusage — a `( )` subshell, a `$( )`/`${ }`/`<()` body, and a pipeline element all printed the host's accumulated clocks instead of the near-zero clocks a true fork would show (GNU builtins/times.def:65-84 reads both rusages in the forked child; execute_cmd.c:1576 execute_in_subshell, subst.c:7143 command_substitute, subst.c:6362 process_substitute, execute_cmd.c:2620 execute_pipeline). Fix: a thread-local baseline stack in read_helpers.rs (same thread_local idiom as profiler.rs). Each fork face snapshots the four raw counters at entry — CloneBoundary via ShellState::clone_for_child_save (covers the flat `( )` regions, the in-place comsub fast paths, and the fresh-shell child script), PipelineStage via an RAII guard at the top of execute_pipeline_stage, ComsubBody via guards around the `$( )`, `${ }` and `<()` body executions — and process_times() reports the current counters minus the innermost baseline (saturating). Pops are conditional on (kind, depth) so a restore belonging to another boundary can never eat an outer face's baseline. The `time` keyword is untouched (it reads rusage_counters() differentially). The lastpipe last element never comes through execute_pipeline_stage, so its `times` keeps the accumulated reading (execute_cmd.c:2758, negative control in the nail). Regression nail: tests/issue3387_times_fork_faces_regressions.rs — one shared 50k-iteration parent burn; subshell/comsub/pipeline/procsub SELF user must be <= 20ms and below the parent, lastpipe last stage must stay accumulated (> 20ms). UNVERIFIED-BY-CAPTAIN: no local build or test run was possible in this round (local builds prohibited by the EDQUOT write wall; Simular box disk 100% full; old-server ssh banner-dead; X299 direct lane not yet open). Verification legs (new nail stem, full lib vs base, RUSTFLAGS="-D warnings" cargo check) are owed to the captain review round on X299.
caomengxuan666
force-pushed
the
fix/3387-times-subshell-rusage
branch
from
November 15, 2026 02:26
0a678f1 to
cc21c52
Compare
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
根因
times印的是宿主进程的 getrusage(RUSAGE_SELF) + getrusage(RUSAGE_CHILDREN),而三 fork 面在 rubash 里都是进程内模拟、共用进程 rusage:( )子 shell、$()/${ }/<( )体、管道段全都印宿主累计值,而非真 fork 的近零时钟。GNU 锚点:builtins/times.def:65-84(子进程内读两组 rusage);execute_cmd.c:1576 execute_in_subshell、subst.c:7143 command_substitute、subst.c:6362 process_substitute、execute_cmd.c:2620 execute_pipeline 均为真 fork。
修法
read_helpers.rs 增线程本地基线栈(仿 profiler.rs 的 thread_local 惯例):每个 fork 面在进入时快照四组原始计数,process_times() 返回当前值减栈顶基线(saturating_sub)。
( )、in-place comsub 快捷路径、fresh-shell 子脚本;restore_flat_subshell() 与 external_finish.rs 直接赋值恢复处按 (kind, depth) 条件弹栈。$()、${ }、<( )体执行点各置 guard。time关键字不动(走 rusage_counters() 差分读数)。type -t快捷路径不跑用户代码,未加基线;外部命令替换是真子进程,无需基线。回归钉
tests/issue3387_times_fork_faces_regressions.rs:50k 迭代父面 burn 共享;subshell/comsub/pipeline/procsub 四面 SELF user ≤ 20ms 且 < 父;lastpipe 末段保持累计(> 20ms)。
本 PR 删除了什么
无删除。纯加法:新增基线栈与 guard(read_helpers.rs),其余 6 个文件各加数行压栈/弹栈调用,新增 1 个回归钉文件。
UNVERIFIED-BY-CAPTAIN
本轮未做本地构建与测试运行(本地写墙 EDQUOT 禁构建;Simular box 盘满;老服务器 ssh 未恢复;X299 直连未通)。以下腿留队长复核轮在 X299 上跑:新钉 stem、lib 全量与 base 逐数对齐、RUSTFLAGS="-D warnings" cargo check、逐文件 rustfmt --check。
Refs #3387