Skip to content

Support: trace native decode overlap - #1811

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
Crane-Liu:codex/deepseek-mtp-runtime-trace
Aug 17, 2026
Merged

ChaoWao merged 1 commit into
hw-native-sys:mainfrom
Crane-Liu:codex/deepseek-mtp-runtime-trace

Conversation

@Crane-Liu

@Crane-Liu Crane-Liu commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • emit correlated host-clock spans for graph build, frame staging, native prepare, launch acceptance, device execution, ordered release, and post-fence retirement
  • carry run_id / dispatch_id / slot_id / generation through the trace and add --assert-native-overlap for machine-verifiable ordering
  • make the existing A2/A3 concurrent-prepare stress test prove 39 adjacent overlap pairs without changing scheduling behavior

Testing

  • pre-commit run --files ...
  • pytest -q tests/ut/py/test_strace_timing.py (18 passed)
  • _task_interface build
  • test_orchestrator (54 passed)
  • test_scheduler (66 passed)
  • test_chip_run_lane (17 passed)
  • A2/A3 architecture precheck via task-submit
  • build_package_a2a3 with PTO-ISA pin 0cefc9a5a1c24c62655cc345d408559595a8af32
  • A2/A3 onboard test_concurrent_prepare_overlap via task-submit (1 passed, 40 runs / 39 adjacent pairs)
  • sim tests not run (not required for this A2/A3 trace PR)

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b04bee83-7aca-4735-a6a9-6534c291be4f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change adds host-clock tracing for native pipeline lifecycle phases. It records dispatch identities and validates adjacent-dispatch preparation overlap, launch ordering, and ordered release through strace_timing.py, with unit, stress, and documentation updates.

Changes

Native pipeline tracing and validation

Layer / File(s) Summary
Tracing contracts and metadata
src/common/hierarchical/pipeline_trace.h, src/common/log/include/common/strace.h, src/common/hierarchical/types.h, src/common/worker/native_run_context.h
Defines pipeline span emitters, conditional tracing macros, run timestamps, and native dispatch identity accessors.
Runtime pipeline span instrumentation
src/common/hierarchical/orchestrator.cpp, src/common/hierarchical/worker_manager.cpp, src/common/platform/onboard/host/c_api_shared.cpp
Emits graph-build, frame-staging, native preparation, device execution, launch-acceptance, ordered-release, and post-fence-retirement spans.
Overlap validation and verification coverage
simpler_setup/tools/strace_timing.py, tests/ut/py/test_strace_timing.py, tests/st/a2a3/host_build_graph/concurrent_prepare_stress/test_concurrent_prepare_stress.py, docs/dfx/host-trace.md
Parses and validates pipeline records, adds --assert-native-overlap, and covers valid overlap, invalid ordering, CLI failures, stress output, and trace usage.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Orchestrator
  participant WorkerThread_submit_dispatch
  participant NativeRunContext
  participant strace_timing
  Orchestrator->>Orchestrator: Emit graph_build and retirement spans
  WorkerThread_submit_dispatch->>WorkerThread_submit_dispatch: Emit frame_staging span
  NativeRunContext->>NativeRunContext: Record device trace start
  NativeRunContext->>strace_timing: Provide native pipeline spans
  strace_timing->>strace_timing: Validate adjacent dispatch overlap and release order
Loading

Possibly related PRs

Poem

Rabbit hops through spans of light,
Dispatch trails align just right.
Prep overlaps device flight,
Releases come in ordered sight.
Tests catch errors, crisp and bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: adding tracing support for native decode overlap.
Description check ✅ Passed The description accurately explains the tracing, validation, stress-test, and testing changes in the pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/dfx/host-trace.md`:
- Around line 122-125: Update the adjacent-dispatch overlap requirements in the
command documentation to state that native_prepare(N+1) must finish after
device_execution(N) starts and no later than device_execution(N) ends, while
preserving the existing start-before-end and ordered_release constraints.

In `@src/common/hierarchical/pipeline_trace.h`:
- Around line 49-53: Update the STRACE formatting call in the pipeline trace
emission to populate the tid field with the actual native thread ID, matching
the mechanism used by strace_tid(), while retaining getpid() for pid and leaving
the remaining fields unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 68aad3ec-83ea-4ed3-9b56-9b546304d1ca

📥 Commits

Reviewing files that changed from the base of the PR and between e4ab544 and 32ed069.

📒 Files selected for processing (11)
  • docs/dfx/host-trace.md
  • simpler_setup/tools/strace_timing.py
  • src/common/hierarchical/orchestrator.cpp
  • src/common/hierarchical/pipeline_trace.h
  • src/common/hierarchical/types.h
  • src/common/hierarchical/worker_manager.cpp
  • src/common/log/include/common/strace.h
  • src/common/platform/onboard/host/c_api_shared.cpp
  • src/common/worker/native_run_context.h
  • tests/st/a2a3/host_build_graph/concurrent_prepare_stress/test_concurrent_prepare_stress.py
  • tests/ut/py/test_strace_timing.py

Comment thread docs/dfx/host-trace.md Outdated
Comment thread src/common/hierarchical/pipeline_trace.h Outdated
The phased native lane claims run N+1's preparation runs concurrently with
run N's device execution. Nothing checked it, so make it machine-checkable
from a captured log:

    python -m simpler_setup.tools.strace_timing <log> --assert-native-overlap

Per adjacent run on one child process the command requires `bind(N+1)` to
overlap `runner_run(N)` — the intervals intersect — and `runner_run(N+1)`
not to start before `claim_release(N)`. The A2/A3 concurrent-prepare
stress test asserts it over all 39 adjacent pairs without changing
scheduling behavior.

Both windows already exist in the `simpler_run` tree, and the root span
already carries `run_id / dispatch_id / run_epoch / slot_id / generation`;
every sub-span of a run shares its `(pid, inv)`, so grouping by invocation
is what joins the windows to the identity. Reading `bind` rather than the
whole prepare is conservative: `bind` sits inside prepare, so an overlap it
reports is one the prepare certainly had.

`simpler_run.claim_release` is the one span this needed. It wraps
`release_native_run` inside finalize, the point a successor's launch becomes
admissible, and no other span marks that boundary. `l3.post_fence_retirement`
covers the L3 orchestrator's `release_run` tail for the same reason, and
`l3.dispatch` / `l3.frame_submit` gain the dispatch's pipeline lease so the
L3 side is lease-aware. Both new spans join a family that already exists, so
no view has to learn to filter them and neither can displace an invocation
root the way a second depth-0 span would.

`run_epoch` is the direct-chip lane's only identity — `_submit_chip_run_direct`
defaults `run_id` and `dispatch_id` to zero — so ordering falls back to it.
`NativeDispatchIdentity.sequence` makes that choice in the parser, where it is
visible, rather than letting one record field carry two meanings.

A K-deep pipeline is not K threads: the direct-chip lane drives prepare(N+1)
and finalize(N) from one OS thread, so a 40-run K=2 stress puts 40 overlapping
run lifetimes on one tid. Perfetto nests slices by timestamp containment within
a track, so `--swimlane` was rendering run N+1's spans inside run N's root —
false nesting that hid the overlap the view exists to show. A thread whose
depth-0 spans overlap is now split into one lane per pipeline slot, which reads
as a sequence because a run holds its slot exclusively; the overlap shows across
lanes instead. Each slice keeps `os_tid`, and a thread that ran sequentially —
the L3 scheduler, which carries a slot but never interleaves — keeps its tid.

`--require-hidden-prepare` adds the stronger claim that preparation also
finishes inside the predecessor's device window. That is a statement about
pipeline depth and is sensitive to how much host CPU a shared machine gives
the preparing thread, so it is opt-in and the scene test does not use it.

Co-authored-by: Chao Wang <26245345+ChaoWao@users.noreply.github.com>
@ChaoWao
ChaoWao merged commit 0d74814 into hw-native-sys:main Aug 17, 2026
18 of 19 checks passed
ChaoWao added a commit that referenced this pull request Aug 17, 2026
`test_sim_device_log` installs a pipe over stderr and reads it only after
every writer has finished. A pipe holds a bounded amount of unread data —
16 KiB on macOS, 64 KiB on Linux — and the two tests emit 19.3 KiB and
22.6 KiB. Wherever the total exceeds the capacity the writers block in
write(2) while the parent waits for them in join/waitpid, and nothing ever
drains: a deadlock, not a slow test.

That is what killed `ut (macos-latest, 3.10)` on #1811 — the job ran to its
20-minute limit with 98 of 99 tests reported and no failure named. The test
and the sim logger were unchanged from the head where the same job passed in
5m23s, so this is latent rather than a regression: it fires when the kernel
grants the 16 KiB pipe instead of a 64 KiB one.

Start the reader when the pipe is installed, so a writer never blocks however
much it emits. The reader holds the buffer through a shared_ptr, so returning
`Capture` by value cannot leave it writing into a moved-from string. Forking
alongside the thread is safe because the record path allocates nothing — it
formats into a stack buffer and calls write(2) — so a child cannot deadlock
on a malloc lock the reader happened to hold.

Add a regression test that shrinks the pipe to one page with F_SETPIPE_SZ and
emits an order of magnitude more than fits, which reproduces the condition on
Linux too; without the concurrent reader it deadlocks where the existing two
tests pass. Because a deadlock cannot fail a test on its own, also bound the
no-hardware ctest run with `--timeout 300`: a future regression then reports
`test_sim_device_log (Timeout)` in seconds instead of consuming the job.

The file's atomicity comment named Linux's PIPE_BUF. The portable floor is
_POSIX_PIPE_BUF (512), which is what macOS uses; these records are ~30 bytes
and inside either, so the claim holds — state the bound that actually applies.
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