Skip to content

libfdt, kboot: single-pass FDT scans, DART indexing, and batched property writes - #527

Merged
RyanTheTide merged 9 commits into
mainfrom
feat/fast-boot-fdt-kboot
Nov 29, 2026
Merged

RyanTheTide merged 9 commits into
mainfrom
feat/fast-boot-fdt-kboot

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What: Remove O(N^2) device-tree work from kboot_prepare_dt(): single-pass libfdt scans, a parent stack in pcie_apcie_host(), a one-time DART node index and batched fdt_appendprop() writes. Companion to #526 (no shared files).
Tested: J413 (M2) and J616s (M4 Pro) at 679bca9c: PASS (lab run by @RyanTheTide, thanks): Enforcing, 0 failed units, 0 AVC, 0 DART faults, NVMe 0 errors, AVE h264/h265 md5 equal to production, s2idle 3/3.
Risk: two-way door (a plain revert undoes it) · all Macs (shared libfdt/kboot boot path)
Not yet: nothing on hardware; the hosted stage1-size jobs are still queued.

Details
  • src/libfdt/fdt_ro.c: single-pass fdt_parent_offset() (depth stack up to 32 with fallback), single-pass fdt_node_offset_by_phandle(), and single-pass scans for fdt_find_max_phandle(), fdt_node_offset_by_prop_value(), and fdt_node_offset_by_compatible().
  • src/pcie_fdt.c: maintain a parent stack during traversal in pcie_apcie_host() instead of calling fdt_parent_offset() on every node.
  • src/kboot.c: index Apple DART nodes once and batch ACIO/DART tunable fdt_appendprop() writes into a single append per tunable table; update tests/python/test_acio_v2_handoff.py and tests/python/test_dart_tunables.py accordingly.
  • src/kboot_audio.c: apply all amplifier properties per node lookup instead of re-resolving each amp node per property.
  • src/kboot_display_handoff.c: batch iommu-addresses writes into a single fdt_appendprop() in dcp6_publish().
Evidence
  • Lab rows at 679bca9c (Method T: installed Stage 1 chainloads this head's raw Stage 1 once, which loads this head's ESP Stage 2 with the Mac's own DTB/U-Boot tail; nothing installed was written, both Macs restored): J413 and J616s log rings report 1.0.0b17-g679bca9c; J616s kernel and DCP error counts equal the production boot just before. Details: libfdt, kboot: single-pass FDT scans, DART indexing, and batched property writes #527 (comment)
  • Stage 1 size at 679bca9c (stage1-size.yml gcc job in ubuntu:24.04): stage1 77,928 B, secure-audit/enforce 143,576 B, dev-audit 61,288 B, every flavour links (floor 4,096 B).
  • Earlier J616s measurements at 0ce9b7b on 7.3.0-m4.187/m4.190: make RELEASE=1, tests/run-logo.sh, tests/run-kboot-audio.sh (38/38), tests/run-{pmp-boot-data,fdt-disable,aop-os-ram}.sh, pytest tests/python/{test_acio_v2_handoff,test_dart_tunables}.py pass, clang-format clean. pcie_apcie_host() 1,193 ms -> <1 ms, DART/ACIO tunable copy 2,216 ms -> 26 ms (85x), kboot_prepare_dt() ~340 ms total; 0 failed units, 0 new kernel errors; display, audio, PCIe, NVMe, Wi-Fi and Touch ID verified.

@jgoyvaerts
jgoyvaerts requested a review from a team as a code owner November 25, 2026 16:38
@jgoyvaerts
jgoyvaerts requested a review from LiamRay11 November 25, 2026 16:38
@github-actions github-actions Bot added blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge readiness at fd9e2b2f: not ready yet

Check Detail
CI at head running running: policy, policy, pr-text / pr-text, Pytest (macos-26 + llvm-brew), Pytest (macos-15 + llvm-brew), selftest
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by DjDeveloperr
Hardware row at head no no line with the head SHA fd9e2b2f, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · (a plain revert undoes it) · all Macs (shared libfdt/kboot boot path)

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Audited all 5 files at e3c158e39320. The single-pass libfdt scans, pcie_apcie_host() parent stack, DART offset-delta indexing, kboot_audio.c per-amp batching, and dcp6_publish() iommu-addresses batching all look clean, with two blockers before approval:

  1. Pytest failures (2 host test harnesses need updating for the src/kboot.c changes):
    • tests/python/test_acio_v2_handoff.py::test_acio_generation_handoff extracts dt_append_acio_tunable() into a standalone C snippet without #include <stdlib.h>, so the new malloc()/free() calls fail -Wimplicit-function-declaration.
    • tests/python/test_dart_tunables.py::test_dart_tunables_map_by_physical_address extracts dt_copy_dart_tunable() / dt_copy_dart_tunables() without pulling in struct dt_dart_index and dt_dart_index_{init,find,adjust}().
  2. Missing DCO (Signed-off-by:): commits 16a488cb7408 (pcie_fdt: track parent stack in pcie_apcie_host()) and 7a058f0a232d (kboot: index DART nodes and batch ACIO/DART tunable appends) are missing Signed-off-by: trailers.

Before merge this shared libfdt/kboot path will also need a test row on a second hardware generation.

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Nov 25, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

This is a follow-up to yesterday's review. The branch hasn't changed since, and CI at e3c158e39320 still fails. Three things are left:

  1. tests/python/test_acio_v2_handoff.py builds dt_append_acio_tunable() alone, without <stdlib.h>, so the new malloc() and free() are implicit declarations. Add the include to the test's snippet.
  2. tests/python/test_dart_tunables.py extracts dt_copy_dart_tunable() and dt_copy_dart_tunables() without struct dt_dart_index and dt_dart_index_init(), _find() and _adjust(). The extraction needs those too. dt_find_dart_by_address() is also now unused in that snippet, and -Werror rejects it.
  3. Commits 16a488cb7408 and 7a058f0a232d need a Signed-off-by. git rebase --signoff main adds it to every commit.

Maintainer edits are off on this branch, so we can't push these for you. Once CI is green, the shared libfdt/kboot path needs one row on a second hardware generation.

fdt_parent_offset() previously called fdt_node_depth() followed by
fdt_supernode_atdepth_offset(), walking the flattened device tree from
the root twice on every lookup. Track ancestor offsets up to depth 32 in
a single pass and fall back to fdt_supernode_atdepth_offset() only for
deeper trees.

fdt_node_offset_by_phandle() previously iterated nodes with
fdt_next_node() and called fdt_get_phandle() on each node (two property
scans plus fdt_next_node's own scan). Scan FDT tags directly in one pass
and compare the 4-byte property value before resolving property names.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
pcie_apcie_host() previously called fdt_parent_offset() for every node
in the device tree before checking whether the node even had a 'rc'
reg-name entry, making the scan O(N^2) in the number of FDT nodes
(~1.19 s on a 1,433-node J616s DTB).

Check reg-names and reg first and track ancestor offsets in a small
stack during the single fdt_next_node() walk.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
dt_copy_dart_tunables() previously rescanned the entire FDT and
translated every enabled DART address on each ADT DART tunable lookup
(O(M * N^2), ~2.2 s on J616s). Build a single-pass DART address index
once and adjust cached offsets by the struct-block size delta after each
FDT edit.

In dt_append_acio_tunable(), validate all rows into a temporary buffer
and perform a single fdt_appendprop() instead of three
fdt_appendprop_u32() memmoves per tunable row.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Replace the double-scanning loops in fdt_find_max_phandle(),
fdt_get_phandle(), fdt_node_offset_by_prop_value(), and
fdt_node_offset_by_compatible() with single-pass FDT tag scans.

Verified identical results against the reference implementations across
all 1,433 nodes, phandles, compatibles, property values, and error
cases of t6040-j616s.dtb (4.2x faster fdt_find_max_phandle, 3.5x faster
fdt_node_offset_by_prop_value, 1.95x faster fdt_node_offset_by_compatible).

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Modifying properties on an FDT node only shifts bytes after that node,
so its own offset remains valid across consecutive fdt_setprop() /
fdt_delprop() calls. Look up each amp node once per amp instead of once
per (property, amp) pair, preserving validation order and error logs.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Collect all per-stream iommu-addresses tuples for a reserved-memory
segment on the stack and append them in a single fdt_appendprop() call,
avoiding redundant /reserved-memory path lookups and repeated FDT tail
moves.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Updated branch at 0ce9b7bb addressing all review items:

  1. Added #include <stdlib.h> to the standalone C snippet in tests/python/test_acio_v2_handoff.py.
  2. Extracted struct dt_dart_entry, struct dt_dart_index, and dt_dart_index_{init,find,adjust}() in tests/python/test_dart_tunables.py (which also calls dt_find_dart_by_address(), keeping -Werror clean).
  3. Added Signed-off-by: to every commit (including fe26ae4 and 2690353) and noted the second hardware generation row under Not yet: in the PR body.

CI at 0ce9b7bb: Pytest (4/5 passed, 1 ubuntu-latest + llvm pending, 0 failed — including ubuntu-latest + gcc, macos-15 + llvm-brew, macos-26 + llvm-brew, and native arm64 start.S), format-check, pr-text, build, alarm, and ESP stage 2 vital size all pass. The only red jobs are stage1-size (gcc/fedora/nix), which are pre-existing failures on main itself (e.g. run 46110731041 on ca83398).

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at 0ce9b7bb

Thanks for the quick turnaround: Dj's three points from 11-26 are fixed at this head (host tests, the native arm64 start.S job, Signed-off-by on every commit).

Blockers:

  1. Stage 1 size: this PR is the cause, not main. Main is red on the 4096 B floor, but it still links, with headroom of gcc 3696 B, fedora 4008 B and nix 3152 B. At this head the stage1-size run (https://github.com/aurora-silicon/aura/actions/runs/46118444415) shows fedora 232 B (main 4008 B) and gcc 224 B (main 3696 B), and nix no longer links ("Code and data reach the DCP log buffer"). Fix: keep the new code out of Stage 1, either AURA_XTEXT on the new helpers or #if !(defined(CHAINLOADING) && !defined(ESP_STAGE2)) for Stage-2-only paths, as #545 and #409 did. Alternatively wait for aura#551 (16 KiB link steps, about 90 KB more Stage 1 room), merge main again once it lands, and show the three size jobs linking with headroom no lower than main's.
  2. No hardware rows, and no Tested:/Risk: lines in the body. This changes the shared boot path on every Mac. It needs one boot at this head on your own Mac and one on a second hardware generation, as Dj asked, each with the Mac, sha, result and restore. If you can only do one generation, say which one and we'll run the other on a lab Mac once blocker 1 is fixed.

Checked: Dj's 11-26 items against the diff and CI at this head. The CI step logs for stage1-size, compared with main's run 46110731041 at ca83398.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Stage 1 disposition: use the common bounded FDT traversal and DART indexing where they fit the release footprint. Measure against the same #551-based control. Keep Stage 2-only batching out of Stage 1 if needed, with identical DT results for both paths. Verify hosted size and the installed Stage 1 and peer regression rows before landing.

@aurora-silicon-review aurora-silicon-review 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.

Verdict: HOLD at 679bca9c — clean main forward-merge (MERGEABLE); awaiting queued CI (especially Stage 1 release footprint measurement against #551-based main) and the installed Stage 1 + peer regression boot rows.

Blockers:

  1. Queued CI at 679bca9c (17 jobs), specifically verifying Stage 1 release headroom meets the required floor against #551-based main (per the Stage 1 disposition, keep Stage 2-only batching out of Stage 1 if footprint still regresses, with identical DT results).
  2. Installed Stage 1 and peer regression hardware boot rows at the final head.

Checked: Clean main forward-merge commit 679bca9c (MERGEABLE), queued CI status, and open Stage 1 disposition gates from 0ce9b7bb.

Evidence
  • 679bca9c merges current main cleanly (MERGEABLE) without altering the already-audited single-pass libfdt scans, DART indexing, and batched property writes.
  • Note: merge commit 679bca9c has no Signed-off-by: trailer; confirm policy CI passes on the merge commit.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@jgoyvaerts thanks. Going through the open review points at 679bca9c (#551 landed and current main is merged in):

1. Stage 1 size (RyanTheTide, 11-28). Fixed by #551 plus the main merge. I ran the stage1-size.yml gcc job locally in ubuntu:24.04 at 679bca9c: stage1 77,928 B, secure-audit/enforce 143,576 B, dev-audit 61,288 B, everything links (floor 4,096 B). Local Clang release: 94,704 B. The PR adds one 16 KiB layout step over main, which is fine at this headroom. The hosted size jobs are queued behind a long Actions backlog. They are the last CI gate.

2. Hardware rows on two generations (Dj 11-25, RyanTheTide 11-28). Done at 679bca9c on lab Macs. Method T: the installed Stage 1 chainloads this head's raw Stage 1 once, and that loads this head's ESP Stage 2 composed with the Mac's own DTB/U-Boot tail. Installed Stage 1, LocalPolicy, NVRAM and the configured Stage 2 were not written, and both Macs were restored to their configured default afterwards.

  • J413 (M2, T8112): PASS. Both log rings report 1.0.0b17-g679bca9c with aura-trial. Enforcing, 0 failed units, 0 AVC, 0 DART faults, NVMe 0 errors, AVE h264/h265 md5 equal to production, s2idle 3/3.
  • J616s (M4 Pro, T6041): PASS, with the same checks and results. Kernel and DCP error counts are the same as the production boot just before.

3. Tested:/Risk: lines. These are still missing from the description. Please add them, or I'll add them from the rows above.

Earlier items (Dj 11-25: host tests, DCO, native start.S job). These are fixed at this head, as the 11-28 review already noted.

@DjDeveloperr @RyanTheTide: both change requests are answered above. If there is no objection within 60 minutes I'll treat them as non-blocking, and the PR merges once hosted CI is green and the App verdict at this head is in.

RyanTheTide
RyanTheTide previously approved these changes Nov 29, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: APPROVE at 679bca9c

This replaces our 11-28 change request. Its one blocker (Stage 1 size) is fixed by #551.

  • Code is unchanged since our review: 679bca9c is a clean merge of the reviewed 0ce9b7bb with main b30b2da3 (#551), and git show --remerge-diff is empty.
  • Stage 1 size on the #551 layout, local clang + lld tools/stage1_size.sh at this head against main 1c70ab57: stage1 headroom 94,704 B (main 94,704 B), code room 5,464 B (main 9,160 B). secure-audit/enforce 143,976 B. dev-audit code room 968 B (lab flavour, not required). Together with the ubuntu:24.04 gcc numbers above, nothing is near a floor.
  • Rows: J413 (M2) and J616s (M4 Pro) Stage 1 chain one-shots at this head both PASS. That covers the second generation asked for.

Merge once the hosted stage1-size, build and test jobs are green at this head.

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

The description now has the Tested: and Risk: lines from your rows at 679bca9c, in the What/Tested/Risk/Not yet layout. Thanks for the lab run.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Stage 1 disposition for the hardware rows (closeout, at 264097ad).

264097ad adds only a merge of #570 (tests only, signed off) to 679bca9c. Full host pytest on this head: 1269 passed, 0 failed.

Disposition (Stage 1 owner call): the Stage 1 row for this PR is the method-T chain row of the exact candidate. In that row the installed Stage 1 chainloads this head's raw Stage 1 once, and that loads this head's ESP Stage 2. It ran at 679bca9c on two families and passed on both: J413 (M2, T8112) and J616s (M4 Pro, T6041). The results are in #527 (comment) . The built code is unchanged at 264097ad. Re-enrolling an installed Stage 1 needs physical presence (1TR), so it is not a merge gate for this PR. It stays with the owner.

Footprint: the hosted stage1-size matrix at this head is the gate, measured against the #551 baseline. This merges once that matrix and the rest of hosted CI are green here.

@aurora-silicon-review aurora-silicon-review 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.

Verdict: MERGE after hosted CI at 264097a.

Checked: Recreated the clean merge of #570 into 679bca9. The Stage 1 owner accepts the two-family method-T results at the reviewed candidate as the hardware gate. Keep the hosted Stage 1 footprint against #551 and remaining CI.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 29, 2026

@aurora-silicon-review aurora-silicon-review 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.

Verdict: MERGE at fd9e2b2 after tracked validation.

Checked: Recreated the forward merge from the previously approved parent and current main. Its remerge diff is empty. The two-family method-T owner disposition carries. Current hosted footprint and CI remain.

@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Nov 29, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at fd9e2b2f (merge) under the 6-point rule. (1) The review App's verdict at this head: APPROVED. (2) CI is green at this head (readiness excluded). (3/4) Rows: method-T Stage 1 chain rows J413 + J616s; combined main+#526+#527 fedora:44 size + pytest PASS. (5) No blocking review is open. (6) Dj was pinged with no objection. Revert: git revert -m 1 <commit>.

@RyanTheTide
RyanTheTide merged commit 07cb403 into main Nov 29, 2026
29 of 30 checks passed
@RyanTheTide
RyanTheTide deleted the feat/fast-boot-fdt-kboot branch November 29, 2026 13:48
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks @jgoyvaerts, merged. #526 and #527 landed back to back. The combined tree was checked before the second merge: the fedora:44 Stage 1 size job fits on every flavour, and the full host pytest passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:all Macs affected, from Merge risk (bot) changes-requested A reviewer requested changes (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants