Skip to content

feat(a5): add scheduler L2 phase telemetry - #1711

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
vegetabledoww:codex/issue-1582-b2-scheduler-phases
Aug 10, 2026
Merged

feat(a5): add scheduler L2 phase telemetry#1711
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
vegetabledoww:codex/issue-1582-b2-scheduler-phases

Conversation

@vegetabledoww

@vegetabledoww vegetabledoww commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR extends A5 scheduler observability so chip-swimlane profiling can attribute scheduler-side work to the same sub-phases already exposed by A2/A3.

What changed

  • Record Resolve around task completion and report the number of fanout consumers traversed.
  • Record Drain around successful sync-start drain staging and report the number of blocks staged by each scheduler thread.
  • Split sync-start staging into DrainPrepare and DrainPublish records with published-subtask counts.
  • Record deferred Release work on the no-progress flush path, matching the A2/A3 emission point.
  • Return the fanout traversal count from the non-profiling on_task_complete() path.
  • Keep deferred-release loops inline so the A5 scheduler remains structurally aligned with A2/A3.

Tests and documentation

  • Extend the existing A5 chip-swimlane scene to require positive Resolve and Release work.
  • Add a global sync-start drain scene that checks Drain, DrainPrepare, and DrainPublish all report consistent, non-zero workload counts.
  • Keep the fanout-count wiring test for both profiling and non-profiling signatures.
  • Document the drain phase taxonomy, scheduler-lane nesting, and tasks_processed semantics.

Verification

  • A5SIM chip-swimlane DFX suite: 4 passed.
  • A5SIM drain scene without profiling: 1 passed.
  • Repository pre-commit checks passed.
  • A local A5 onboard attempt was blocked before scene execution because the environment could not resolve the driver halResMap symbol; the PR CI hardware lane provides the authoritative onboard result.

Relation

Related to #1582.

@coderabbitai

coderabbitai Bot commented Aug 6, 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: f30096bb-a4a6-40d2-af1e-adadbb7838f8

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 scheduler now returns fanout traversal counts in non-profiling builds and records additional Resolve, Drain, DrainPrepare, DrainPublish, and Release phase timings under profiling configurations.

Changes

Scheduler profiling updates

Layer / File(s) Summary
Fanout count contract and validation
src/a5/runtime/.../scheduler/pto_scheduler.h, tests/ut/cpp/a5/test_wiring.cpp
Non-profiling on_task_complete returns the traversed consumer count. Profiling builds continue to return CompletionStats.
Completion and sync-start phase records
src/a5/runtime/.../scheduler/scheduler_completion.cpp
Completion records Resolve timing. Sync-start staging records DrainPrepare and DrainPublish timing and reuses the publication timestamp for dispatch timing.
Dispatch and release phase records
src/a5/runtime/.../scheduler/scheduler_dispatch.cpp
Drain handling, dummy completion, and deferred releases record phase timing with processed-item counts.
Estimated code review effort: 3 (Moderate) ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SchedulerCompletion
  participant SchedulerDispatch
  participant PTO2SchedulerState
  participant SchedulerPhaseProfiling
  SchedulerCompletion->>PTO2SchedulerState: complete task
  PTO2SchedulerState-->>SchedulerCompletion: fanout count or CompletionStats
  SchedulerCompletion->>SchedulerPhaseProfiling: record Resolve and drain phases
  SchedulerDispatch->>PTO2SchedulerState: complete dummy task
  PTO2SchedulerState-->>SchedulerDispatch: resolved fanout count
  SchedulerDispatch->>SchedulerPhaseProfiling: record Drain and Release phases
Loading

Possibly related PRs

Poem

A rabbit counts each thread,
Fanout paths are neatly read.
Resolve and Drain now leave a trace,
Release timings keep their place.
“Hop!” says the scheduler, light and fleet.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 and concisely describes the main change: adding A5 scheduler L2 phase telemetry.
Description check ✅ Passed The description directly explains the scheduler telemetry changes, fanout counts, tests, documentation, and verification results.

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: 3

🤖 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
`@src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_dispatch.cpp`:
- Around line 1192-1212: Instrument every deferred-release flush with the
`Release` phase timing and processed-count record, not only the loop near
`deferred_release_slot_states` in the shown scheduler path. Reuse a shared flush
helper if available, or apply equivalent timing around the capacity-triggered
flushes in `scheduler_completion.cpp`, this file’s earlier flush path, and the
final cleanup; preserve the existing release callback behavior and profiling
variants.
- Around line 1016-1028: Update handle_drain_mode and stage_sync_start_cores to
return the number of staged blocks, propagate that count through the drain path,
and pass it as the Drain phase record’s tasks_processed value in
chip_swimlane_aicpu_record_sched_phase. Keep drain_stage_wall exclusively as the
elapsed-time value.

In `@tests/ut/cpp/a5/test_wiring.cpp`:
- Around line 414-419: Update the profiling-enabled call to
PTO2SchedulerState::on_task_complete in the test around completion_stats to pass
the profiling thread index explicitly, using 0 as the test index; leave the
non-profiling call 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: b795e146-77a1-4fb5-b3d1-3ddc0bc070dc

📥 Commits

Reviewing files that changed from the base of the PR and between 64fe416 and 43146a0.

📒 Files selected for processing (4)
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/pto_scheduler.h
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_completion.cpp
  • src/a5/runtime/tensormap_and_ringbuffer/runtime/scheduler/scheduler_dispatch.cpp
  • tests/ut/cpp/a5/test_wiring.cpp

Comment thread tests/ut/cpp/a5/test_wiring.cpp

@ChaoZheng109 ChaoZheng109 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

整体是一个合格的 a5←a2a3 DFX 对齐 back-port,范围清晰、带回归测试。两点想请作者确认(已作为 inline 评论):Release 记录的发射位置与 a2a3 不一致,以及 flush_deferred_releases 只加在 a5 引入的两树结构分叉。

#if SIMPLER_DFX
if (release_t0 != 0) {
chip_swimlane_aicpu_record_sched_phase(
thread_idx, ChipSwimlaneSchedPhaseKind::Release, release_t0, get_sys_cnt_aicpu(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[需澄清] Release 发射位置与 a2a3 不一致,和"对齐 A2/A3"目标相悖。

Release 记录放进 flush_deferred_releases 内部后,4 个调用点会全部发射 Release

  • completion.cpp:204(completion 内 cap 触发的 flush)
  • scheduler_dispatch.cpp:1115(dummy cap 触发的 flush)
  • scheduler_dispatch.cpp:1213(no-progress 空转路径)
  • scheduler_dispatch.cpp:1289(最终 drain)

而 a2a3 只在 no-progress 空转路径这一处发射 Releasea2a3/.../scheduler_dispatch.cpp:1399);completion 的 cap-flush、dummy cap-flush、final-drain 三处刻意不记录(a2a3 scheduler_completion.cppRelease 出现次数为 0)。

后果:

  1. 与 PR 声明的"对齐 A2/A3"直接矛盾——a5 会在 a2a3 有意留白的位置多出 Release bar,下一个做对齐的人可能当回归。
  2. cap 触发的 flush 发生在有进展的半热路径上(一次放最多 256 个 slot),在此发 Release 会在 Complete/Dummy 外层 bar 内产生 a2a3 不会出现的嵌套/并列 span,可能干扰 swimlane 的时间包含关系。

建议二选一:

  • 收敛到 a2a3 语义:仅在 no-progress 路径发 Release(把记录逻辑留在该调用点,而非塞进 helper);或
  • 若这是有意增强(a5 额外覆盖 cap/final-drain 的释放),请在 PR 描述或此处注释里明确说明,以免被误判为偏离。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已按 a2a3 的既有语义收敛:Release 只在 no-progress flush 路径发射;completion 容量 flush、dummy 容量 flush和final cleanup 仍执行释放,但不额外生成嵌套 Release bar。flush_deferred_releases() 现在只负责释放逻辑。修复已包含在 commit id:ea40e300 中

inline constexpr int32_t PTO2_DEFERRED_RELEASE_CAP = 256;
}

void SchedulerContext::flush_deferred_releases(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Consider] flush_deferred_releases 只加在 a5,引入两树结构分叉。

就 DRY 而言,把原本 4 处重复的 deferred-release 循环收敛成一个 helper 是改进。但 a2a3 目前仍是 4 处内联循环,本 PR 只在 a5 抽取 helper,会让两棵树在结构上更不一致——这与本 PR 声明的"对齐"方向以及 CLAUDE.md rule 10(两树尽量收敛)略有张力。

非阻塞项:若目标是对齐,理想做法是同一 helper 也落到 a2a3(可作后续小 PR)。此处仅提示,便于后续跟踪。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已移除 A5-only 的 flush_deferred_releases helper,将四处 deferred-release 循环恢复为与 A2/A3 相同的内联结构,避免两棵 runtime 树新增结构分叉。后续若要统一抽象,会在 A2/A3 与 A5 中同步以独立重构处理。

@vegetabledoww
vegetabledoww force-pushed the codex/issue-1582-b2-scheduler-phases branch 6 times, most recently from 25139c0 to cd44b04 Compare August 10, 2026 06:25
Record Resolve, Drain, DrainPrepare, DrainPublish, and Release work so
A5 traces expose the same scheduler detail as A2/A3.

Return fanout traversal counts and report staged-block and
deferred-release counts through tasks_processed. Keep Release on the
no-progress deferred flush path to match A2/A3.

Add positive scene coverage for all five phases and document their
scheduler-lane roles and workload semantics.

Validation:
- A5SIM chip-swimlane DFX scenes (4 passed)
- A5SIM drain scene without profiling (1 passed)
- pre-commit checks
@vegetabledoww
vegetabledoww force-pushed the codex/issue-1582-b2-scheduler-phases branch from cd44b04 to 6594e5c Compare August 10, 2026 06:46
@ChaoZheng109
ChaoZheng109 merged commit 3e21993 into hw-native-sys:main Aug 10, 2026
18 checks passed
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