Skip to content

Docs: state that the device log threshold is fixed at device init - #2117

Open
ChaoWao wants to merge 1 commit into
hw-native-sys:mainfrom
ChaoWao:device-threshold-is-init-only
Open

Docs: state that the device log threshold is fixed at device init#2117
ChaoWao wants to merge 1 commit into
hw-native-sys:mainfrom
ChaoWao:device-threshold-is-init-only

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #2109 by recording the contract rather than building a mechanism for it.

I filed #2109 as a defect. It is not one — the device threshold being fixed at device init is a design decision, and the actual defect was that nothing said so. This documents it.

Two lifetimes, and only one was described

reader when a set_level takes effect
Every host module in the process, including a dlopened one immediately — each reads state()->threshold per record
Sim AICPU immediately — it runs in the host process as one of them
Onboard AICPU never; it keeps what device init gave it

simpler_aicpu_init latches InitArgs.log_level into a device-side flag, and that entry runs once per Worker.

What the docs said before:

  • docs/logging.md"all bound host modules observe a native state update immediately instead of requiring threshold fan-out to every DSO." Correct as written, and easy to read as "live everywhere".
  • the configuration-flow table's onboard AICPU row described only CANN policy, not our own one-shot flag.
  • set_level carried no note about its reach at all.

Why it stays one-shot

Raising verbosity mid-run to chase a device-side problem is not a workflow this runtime supports; recreate the Worker with the level you want.

  • A Worker is cheap to recreate, so the workaround costs nothing a debugging session would notice.
  • Device log volume is exactly where an accidental DEBUG is most expensive. codestyle.md rule 7 forbids AICPU hot-path logging because device_log writes serialize on the single AICPU op and can trip the op-execute timeout — a threshold outside code can raise into that is a liability, not a feature.

The doc also records what delivering it would cost, so the next person does not have to re-derive it: making it immediately live needs either a device launch per set_level — the opposite direction from #2092, which exists to make simpler_aicpu_init launch exactly once — or a new host-writable device-resident location polled outside any launch.

I did start down the "make it work" path before this was settled, and found the threshold could ride an existing per-run payload (KernelArgs is host-built per run and read by simpler_aicpu_exec, and onboard set_log_level is a single bool store, so a per-run refresh would be nearly free and give next-run granularity). That is recorded in the doc as the cheap option that still is not worth taking, since there is no use case asking for it. Better to write it down than to leave it as a discovery someone repeats.

What changed

  • docs/logging.md — a new "The threshold is live on the host and fixed on the device" section with the table above and the rationale; the configuration-flow table's AICPU row now names the latch.
  • src/common/log/include/host_log.hset_level scopes its own liveness claim and points at the doc.
  • src/common/platform/onboard/host/device_runner_base.cpp — the InitArgs.log_level fill says it is the only time it happens.
  • src/a2a3/…/aicpu/kernel.cpp and src/a5/…/aicpu/kernel.cpp — the set_log_level call says it is one-shot. Both trees, since they are near-duplicates and a contract note that lands in one is stale in the other.

No behaviour change: comments and docs only.

Testing

cpput 132/132
pyut 2102 passed, 18 skipped
st a2a3sim / a5sim 33 / 29
st a2a3 onboard 67
linters clang-format, clang-tidy, ruff, pyright, markdownlint, retired-names, headers, english-only — clean

The onboard sweep is the one that matters here: the two annotated lines are on the AICPU init path, and although the edit is comment-only, all four platforms were rebuilt and the sweep run rather than assuming a comment cannot break a build.

@coderabbitai

coderabbitai Bot commented Sep 3, 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: Team

Run ID: d59515c4-05f1-4d46-acc3-6f7bce489ded

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

Run ID: 86010a61-3347-4db9-afde-6f071f1007d2

📥 Commits

Reviewing files that changed from the base of the PR and between 0edd65c and bd53230.

📒 Files selected for processing (5)
  • docs/logging.md
  • src/a2a3/platform/onboard/aicpu/kernel.cpp
  • src/a5/platform/onboard/aicpu/kernel.cpp
  • src/common/log/include/host_log.h
  • src/common/platform/onboard/host/device_runner_base.cpp

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


📝 Walkthrough

Walkthrough

The PR documents that host and simulated-AICPU log thresholds update immediately, while onboard AICPU latches InitArgs.log_level during one-time Worker initialization. Comments identify the initialization boundary and state that Worker recreation is required to change the onboard threshold.

Changes

Onboard AICPU logging lifetime

Layer / File(s) Summary
Logging lifetime contract and initialization annotations
src/common/log/include/host_log.h, docs/logging.md, src/common/platform/onboard/host/device_runner_base.cpp, src/a2a3/platform/onboard/aicpu/kernel.cpp, src/a5/platform/onboard/aicpu/kernel.cpp
The documentation and code comments distinguish live host and simulated-AICPU thresholds from the onboard AICPU threshold latched once during Worker initialization. They state that changing the onboard threshold requires recreating the Worker.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to bd532

This change documents the existing distinction between live host logging thresholds and the Worker-lifetime onboard AICPU threshold, including Worker recreation as the supported way to change device verbosity. No behavior changes are introduced, and the change is ready to merge.

Poem

A rabbit reads the logging lore
One level stays fixed at the door
Host thresholds hop and change
Device logs keep their range
New Workers bring a setting more

🚥 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 3 functions across 4 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: documenting that the device log threshold is fixed during device initialization.
Description check ✅ Passed The description directly explains the host-versus-onboard logging lifetimes, the documentation changes, the supported Worker recreation workaround, and the absence of behavior changes.
Linked Issues check ✅ Passed The changes satisfy issue [#2109] by documenting that host and Sim AICPU thresholds update live while onboard AICPU latches the threshold during simpler_aicpu_init for the Worker's lifetime. The cha…
Out of Scope Changes check ✅ Passed All changes are documentation comments or documentation updates that support issue [#2109]. No unrelated functional, API, or behavioral changes are present.
Full details: Linked Issues check

Explanation

The changes satisfy issue [#2109] by documenting that host and Sim AICPU thresholds update live while onboard AICPU latches the threshold during simpler_aicpu_init for the Worker's lifetime. The changes also scope set_level and identify Worker recreation as the supported method for changing device verbosity.

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 3 functions across 4 files. (1 skipped: 1 unsupported.)


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.

@ChaoWao

ChaoWao commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

st-sim-a2a3 (ubuntu) went red here on native_run_lifecycle (assert 4 == 5). Not this PR — this one is comments and docs only — but I triaged it rather than re-running, and it turned out to be real.

Since #2029 a [STRACE] record reaches captured stderr through the writer thread, so the test's bare capfd.readouterr() races it. The captured tail in the failure shows the fifth invocation's spans still arriving after the read. #2029 fixed that shape in runtime_fatal_codes and host_build_graph_validation and missed three more files that read spans the same way.

Fixed in #2118, which covers all three. Once that lands I will rebase this one; re-running the job here would probably go green on its own, but the flake would stay.

Two lifetimes exist and the docs described only one. Every host module reads the
bound state's threshold per record, so a `set_level` reaches all of them
immediately — sim AICPU included, since it runs in the host process as one of
them. Onboard AICPU is different: `simpler_aicpu_init` latches
`InitArgs.log_level` into a device-side flag, that entry runs once per Worker, and
no later `set_level` reaches it.

Nothing said so. `docs/logging.md` claimed "all bound host modules observe a
native state update immediately instead of requiring threshold fan-out to every
DSO" — correct as written and easy to read as "live everywhere" — while the
configuration-flow table described the onboard AICPU row only in terms of CANN
policy. `set_level` itself carried no note about its reach.

This is the intended contract rather than a missing refresh, and it is now
recorded as one: raising verbosity mid-run to chase a device-side problem is not
a supported workflow, and recreating the Worker is what to do instead. A `Worker`
is cheap to recreate, and device log volume is where an accidental `DEBUG` costs
most — `codestyle.md` rule 7 forbids AICPU hot-path logging because `device_log`
writes serialize on the single AICPU op and can trip the op-execute timeout, so a
threshold that outside code can raise into that is a liability rather than a
feature.

Both ends of the one-shot path now say so at the line that creates it, in both
architecture trees, and `set_level`'s declaration scopes its own liveness claim.

Closes hw-native-sys#2109.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ChaoWao
ChaoWao force-pushed the device-threshold-is-init-only branch from bd53230 to 4cb3cc4 Compare September 3, 2026 11:31
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.

[Code Health] Onboard AICPU's log threshold is a one-shot snapshot taken at device init

1 participant