Skip to content

smp: let the build override MAX_CPUS (default stays 32) - #40

Closed
TripleU613 wants to merge 2 commits into
omacom:integration/aurorafrom
TripleU613:max-cpus-override
Closed

TripleU613 wants to merge 2 commits into
omacom:integration/aurorafrom
TripleU613:max-cpus-override

Conversation

@TripleU613

@TripleU613 TripleU613 commented Nov 8, 2026 •

Copy link
Copy Markdown

Base: integration/aurora 7f6df96. Two commits (the override + a review follow-up), src/smp_asm.h only (+4/−1). No dependencies.

Problem: MAX_CPUS (32, needed for T6032) sizes secondary_stacks[MAX_CPUS][0x10000], most of the zero-filled raw image, so each CPU slot costs 64 KiB of file size. A T6050 stage 1 built on the #30–#36 stack is 0x420000. rolotrealanis98's m5pro-linux patch 0014 reports that the iBoot raw-image path boots 0x410000 but not 0x4D0000 (REPORTED, not reproduced here). That patch reduces MAX_CPUS as a fixed edit.

Change: #ifndef MAX_CPUS, so the default stays 32. A smaller build passes EXTRA_CFLAGS=-DMAX_CPUS=<n>, the same channel as the other -D switches; C and start.S both see it. Correction (review follow-up): only the generic smp_init() path refuses a cpu-id ≥ MAX_CPUS. T8152 indexes its per-CPU arrays by a literal 0..11. So the second commit makes smp_init_t8152() return -1 when MAX_CPUS < 12, before touching any per-CPU array; smp_start_t8152() then starts nothing. It also adds _Static_assert(0 < MAX_CPUS <= 64) (the CPU masks are u64). Changing MAX_CPUS needs make clean.

Validation (offline, host builds only; not booted):

  • On this base, clang 23.1.3, 13 pre-existing warnings:

    • default build byte-identical to the base (m1n1.bin sha256 prefix 11a271b6, 0x400000);
    • -DMAX_CPUS=24: 0x380000.
  • A separate audit on the T6050 (M5 Max, J714c): boot from disk through the Omarchy chain #30–wdt: leave the watchdog armed when the boot-args say m1n1.wdt=keep #36 stack: default stage 1 / ESP stage 2 builds are byte-identical to that stack. With -DMAX_CPUS=24 both are 0x3A0000 and rebuild byte-identically.

  • T8152 bounds host test (tests/run-t8152-smp-bounds.sh): builds the real smp_init_t8152() from src/smp.c against a fake 12-CPU J873g ADT with ASan/UBSan.

    • MAX_CPUS 8 and 11: refused with -1, no out-of-bounds access.
    • 12, 24 and 32: all 12 CPUs taken.
    • Negative control on the first commit's smp.c: UBSan reports index 8 out of bounds for type 'int[8]' and index 11 … 'int[11]'.
  • After the fix, on this base: the default build is still byte-identical to the base, -DMAX_CPUS=24 is unchanged (0x380000), and -DMAX_CPUS=8 builds (0x280000).

No Signed-off-by: @TripleU613 reviews and adds it. Prepared with AI assistance (Claude Opus 5.5), disclosed in the commit trailer.

MAX_CPUS sizes secondary_stacks[MAX_CPUS][0x10000], which is most of the
zero-filled raw image: each CPU slot costs 64 KiB of file size. 32 is
needed for T6032 (M3 Ultra) and stays the default. A build for a smaller
SoC can now pass EXTRA_CFLAGS=-DMAX_CPUS=<n> (C and start.S both see it,
like the other -D build switches), e.g. 24 for T6050 (M5 Pro/Max, at most
18 cores), saving 0x80000. That keeps a T6050 stage 1 below the stage-1
size limit reported on the iBoot raw-image path (0x410000 boots,
0x4D0000 does not).

A build with a smaller MAX_CPUS does not support SoCs with more cores:
smp.c already refuses a cpu-id >= MAX_CPUS ("increase MAX_CPUS").

Tested: OFFLINE, host build only (clang 23.1.3). The default build is
unchanged; with -DMAX_CPUS=24 the CHAINLOADING stage 1 and the
ESP_STAGE2 stage 2 are both 0x3A0000 and rebuild byte-identically. Not
booted on hardware in this form. Rolando Trevino's m5pro-linux 0014 makes
the same reduction as a fixed edit.

Prepared with AI assistance (Claude Opus 5.5); the owner reviews and signs
off before submission.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the earlier clean-rebuild documentation suggestion still open.

Findings

  1. P2 CPU limit changes stay stale ▶

Summary

Allows builds to override MAX_CPUS while keeping the default at 32.

  • Builds can use fewer CPU slots while keeping 32 as the default.
  • T8152 startup stops when a build has fewer than 12 CPU slots.

No new findings.

Reviews (2) · Last reviewed commit: "smp: T8152: refuse a MAX_CPUS below 12 u..." · Reviewed by Greptile

Comment thread src/smp_asm.h Resolved
Comment thread src/smp_asm.h
#define __SMP_ASM_H__

#define MAX_CPUS 32
/* Override at build time, e.g. EXTRA_CFLAGS=-DMAX_CPUS=24, to shrink secondary_stacks. */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 CPU limit changes stay stale

The example should mention that changing MAX_CPUS requires a clean rebuild. The build rules do not track EXTRA_CFLAGS, and the generated configuration header does not record this value. Reusing a build directory can leave the old image size or mix objects built with different CPU limits.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@TripleU613
TripleU613 marked this pull request as draft November 8, 2026 03:37
… test

Review follow-up to the MAX_CPUS override.
Correction to the override commit's text: only the generic smp_init()
path refuses a cpu-id >= MAX_CPUS. The T8152 path indexes cpu_nodes,
cpu_info, spin_table and secondary_stacks by a literal 0..11
(smp_init_t8152, smp_start_t8152, smp_secondary_entry via smp_id()).

- smp_init_t8152() now returns -1 before touching any per-CPU array
  when MAX_CPUS < 12. smp_start_t8152() already returns while
  smp_initialized is false, so no T8152 secondary is started and
  smp_secondary_entry() is never reached; m1n1 stays on one CPU.
- _Static_assert(MAX_CPUS > 0 && MAX_CPUS <= 64): the started/failed
  CPU masks are u64.
- tests/run-t8152-smp-bounds.sh builds the real smp_init_t8152() (taken
  from src/smp.c) against a fake 12-CPU J873g ADT with ASan/UBSan for
  MAX_CPUS 8, 11, 12, 24 and 32. Below 12 it must refuse with no
  out-of-bounds access; from 12 it must take all 12 CPUs. On the code
  before this commit, 8 and 11 report "index out of bounds".

Changing MAX_CPUS needs a clean rebuild (`make clean`): it lives in a
header, and objects built with another value would be reused.

Tested: OFFLINE (host builds and the host test). Not booted.

Prepared with AI assistance (Claude Opus 5.5); the owner reviews and signs
off before submission.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TripleU613
TripleU613 marked this pull request as ready for review November 8, 2026 03:43
@TripleU613

Copy link
Copy Markdown
Author

Closing: consolidating all my M5/J714s work into one place, https://github.com/betizzel/omarchy-m5 (this series is preserved as a git-am mbox in patches/upstream-prs/). Thanks for the reviews.

@TripleU613 TripleU613 closed this Nov 9, 2026
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.

1 participant