Skip to content

Fix: normalize onboard CANN worker scheduling policy - #2166

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
Crane-Liu:codex/aicpu-normal-scheduling
Sep 9, 2026
Merged

Fix: normalize onboard CANN worker scheduling policy#2166
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
Crane-Liu:codex/aicpu-normal-scheduling

Conversation

@Crane-Liu

@Crane-Liu Crane-Liu commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Continuous FIFO polling can exhaust the real-time CPU budget and produce periodic stalls. Hardware runs showed roughly 40 ms pauses near 1 Hz, with a configured RT budget of 950000 us per 1000000 us. The observations are consistent with real-time bandwidth throttling; a kernel throttle event was not captured directly.

After the affinity gate, A2/A3 onboard simpler_aicpu_exec calls a helper that checks each active CANN worker's policy on every invocation and sets SCHED_OTHER, priority 0, when needed. This covers TMR orchestration/scheduler workers and HBG scheduling workers.

Syscall failures produce one warning per loaded runtime SO, guarded atomically, while workers continue barrier participation. The policy persists across calls; contention under normal scheduling may add latency.

Adds four Linux syscall-wrapper tests and indexed troubleshooting documentation.

Hardware Evidence

A3, CANN 9.0, GCC 10; Qwen3-14B, batch 16, 127 decode steps, two slots split 64/63, and 122 steady-state samples per qualification run:

Runtime Baseline runs Final candidate runs Max effective latency, baseline to candidate Max completion interval, baseline to candidate
TMR 4 2 86.589 to 39.087 ms 86.852 to 39.763 ms
HBG 1 1 85.721 to 42.342 ms 86.130 to 43.566 ms

All final candidate runs passed golden checks. Effective latency measures TMR scheduler duration and HBG device wall time; compare each runtime against its own baseline. No candidate run had an effective sample above 50 ms.

One earlier TMR candidate run had a token mismatch at step 112. Across all candidate runs, TMR passed 4/5 golden checks and HBG 4/4. The mismatch did not recur in follow-up runs; its cause was not established.

Hardware evidence used base 39ce891, before rebasing onto 7bcdc95. Intervening main changes include DFX configuration, HBG early-dispatch prerequisites, A2/A3 worker retirement, and A5 HBG profiling. The scheduling implementation is unchanged; the only manual conflict resolution preserved both troubleshooting index entries. Hardware tests were not rerun on the rebased integration. These are qualification measurements, not the formal multi-run performance campaign.

Validation

  • 136 no-hardware CTest targets, 24 Qwen Python tests, pre-commit, and the full A2/A3 simulation sweep passed.
  • Onboard L2: HBG 40 passed / 1 skipped; TMR 58 passed.
  • Four communication-resource tests raised BufferError: cannot close exported pointers exist, reproduced individually on both baseline and candidate: test_worker_chip_message_queue, test_worker_chip_orch_comm_stream, test_l3_single_hop_two_lifecycles, and test_l4_two_hop_two_lifecycles.
  • Separate SDMA and cross-host suites were not run.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview 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: Advanced

Run ID: 111ad231-46c5-4fb3-bb9b-764dd695e32f

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 1a46db09-15fa-4515-8633-896394f6e280

📥 Commits

Reviewing files that changed from the base of the PR and between 7bcdc95 and 41cc95f.

📒 Files selected for processing (7)
  • docs/troubleshooting/README.md
  • docs/troubleshooting/a2a3-scheduling-tails.md
  • mkdocs.yml
  • src/a2a3/platform/include/aicpu/thread_scheduling.h
  • src/a2a3/platform/onboard/aicpu/kernel.cpp
  • tests/ut/cpp/CMakeLists.txt
  • tests/ut/cpp/a2a3/test_thread_scheduling.cpp

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds a scheduling helper that selects SCHED_OTHER for A2/A3 AICPU execution, integrates failure handling, adds Linux unit tests, and documents the observed scheduling behavior.

Changes

A2/A3 scheduling control

Layer / File(s) Summary
Scheduling helper and runtime integration
src/a2a3/platform/include/aicpu/thread_scheduling.h, src/a2a3/platform/onboard/aicpu/kernel.cpp
The runtime checks the calling thread policy after the affinity gate and attempts to select SCHED_OTHER. Failures produce one warning and do not stop execution.
Scheduling behavior tests
tests/ut/cpp/CMakeLists.txt, tests/ut/cpp/a2a3/test_thread_scheduling.cpp
Linux-only tests validate policy conversion, worker reuse, and scheduler error propagation with wrapped system calls.
Troubleshooting documentation
docs/troubleshooting/README.md, docs/troubleshooting/a2a3-scheduling-tails.md, mkdocs.yml
The documentation describes A2/A3 scheduling tails, policy lifetime, failure handling, measurements, and troubleshooting checks. The guide is added to navigation.

Priority: ➖ Normal — Schedule the A2/A3 worker scheduling change because it addresses periodic FIFO-polling stalls and real-time CPU throttling, with qualification showing lower worst-case latency.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 41cc9

A2/A3 onboard AICPU workers are normalized to normal Linux scheduling after affinity selection, reducing real-time scheduling stalls while safely retaining the existing policy if adjustment fails. No concrete merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant AICPUWorker
  participant simpler_aicpu_exec
  participant SchedulingHelper
  participant LinuxScheduler
  AICPUWorker->>simpler_aicpu_exec: invoke kernel
  simpler_aicpu_exec->>SchedulingHelper: use_normal_aicpu_scheduling()
  SchedulingHelper->>LinuxScheduler: query current policy
  LinuxScheduler-->>SchedulingHelper: return policy
  SchedulingHelper->>LinuxScheduler: set SCHED_OTHER when needed
  SchedulingHelper-->>simpler_aicpu_exec: return status
  simpler_aicpu_exec-->>AICPUWorker: continue kernel execution
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (4 skipped: 4… 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 and concisely identifies the main change: normalizing onboard CANN worker scheduling policy.
Description check ✅ Passed The description directly explains the scheduling-policy change, its motivation, tests, hardware evidence, documentation, and known validation limitations.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (4 skipped: 4 unsupported.)

✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch codex/aicpu-normal-scheduling

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

A rabbit checks the worker thread,
And sets its pace to SCHED_OTHER instead.
Tails grow short across the run,
Tests catch errors one by one.
Docs guide paws through every thread.

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

@Crane-Liu
Crane-Liu force-pushed the codex/aicpu-normal-scheduling branch from 41cc95f to d3cec5f Compare September 8, 2026 21:21
Set active A2/A3 CANN workers to SCHED_OTHER with priority 0 after
the affinity gate in simpler_aicpu_exec. Check each invocation and
skip the setter when the worker already has the requested policy.

Continuous FIFO polling can exhaust the real-time CPU budget and
produce periodic stalls during dual-slot decode.

Cover TMR orchestration and scheduler workers and HBG scheduling
workers. Warn once per loaded runtime SO on syscall failure and
continue barrier participation.

Add four Linux syscall-wrapper tests and indexed troubleshooting
documentation for periodic worker stalls and scheduling tradeoffs.
@Crane-Liu
Crane-Liu force-pushed the codex/aicpu-normal-scheduling branch from d3cec5f to 9c1e1f6 Compare September 8, 2026 23:05
@ChaoZheng109
ChaoZheng109 merged commit e750ccf into hw-native-sys:main Sep 9, 2026
20 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