Repository navigation
smp: let the build override MAX_CPUS (default stays 32) - #40
TripleU613 wants to merge 2 commits into
Conversation
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>
[Medium impact] The PR appears safe to merge, with the earlier clean-rebuild documentation suggestion still open. Findings
SummaryAllows builds to override
No new findings. Reviews (2) · Last reviewed commit: "smp: T8152: refuse a MAX_CPUS below 12 u..." · Reviewed by Greptile |
| #define __SMP_ASM_H__ | ||
|
|
||
| #define MAX_CPUS 32 | ||
| /* Override at build time, e.g. EXTRA_CFLAGS=-DMAX_CPUS=24, to shrink secondary_stacks. */ |
There was a problem hiding this comment.
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!
… 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>
|
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. |
Base:
integration/aurora7f6df96. Two commits (the override + a review follow-up),src/smp_asm.honly (+4/−1). No dependencies.Problem:
MAX_CPUS(32, needed for T6032) sizessecondary_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 reducesMAX_CPUSas a fixed edit.Change:
#ifndef MAX_CPUS, so the default stays 32. A smaller build passesEXTRA_CFLAGS=-DMAX_CPUS=<n>, the same channel as the other-Dswitches; C andstart.Sboth see it. Correction (review follow-up): only the genericsmp_init()path refuses a cpu-id ≥MAX_CPUS. T8152 indexes its per-CPU arrays by a literal 0..11. So the second commit makessmp_init_t8152()return -1 whenMAX_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). ChangingMAX_CPUSneedsmake clean.Validation (offline, host builds only; not booted):
On this base, clang 23.1.3, 13 pre-existing warnings:
-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=24both are 0x3A0000 and rebuild byte-identically.T8152 bounds host test (
tests/run-t8152-smp-bounds.sh): builds the realsmp_init_t8152()fromsrc/smp.cagainst a fake 12-CPU J873g ADT with ASan/UBSan.MAX_CPUS8 and 11: refused with -1, no out-of-bounds access.smp.c: UBSan reportsindex 8 out of bounds for type 'int[8]'andindex 11 … 'int[11]'.After the fix, on this base: the default build is still byte-identical to the base,
-DMAX_CPUS=24is unchanged (0x380000), and-DMAX_CPUS=8builds (0x280000).No Signed-off-by: @TripleU613 reviews and adds it. Prepared with AI assistance (Claude Opus 5.5), disclosed in the commit trailer.