kernel/build.sh smp builds the SMP kernel (kw_defconfig + kw_smp.config,
kwemu with atomics) from the same tree into vendor/build/kernel-smp; all
builds both kernels, and every bundle refresh adds the UP-to-SMP patch
when the SMP kernel is the same build of the tree (KW_SMP=1 requires it,
KW_SMP=0 leaves it out). kernel stays the UP-only quick loop. The patch is
cached in kernel-smp/up.kwpatch. Fixed build stamps (user, host, a build
id hashed from the tree and kwemu sources, the tree's newest commit date)
make kernels and patch reproducible while every other build keeps its own
banner for snapshot matching. Configs are checked against their fragments
after a reconfigure. KW_BUILD, KOUT_SMP, KWEMU_SMP and LINUX_REPO make the
script runnable against another tree and output root.
bundle.mjs --smp refuses two kernels that are not the UP and SMP builds
of one tree (banner, KW_ABI_VERSION, wasm_cpu_start, memory type), with
--smp-optional to warn instead and --smp-patch to reuse a cached patch.
The release workflow builds both kernels, runs kwtest on 2 CPUs and the
kernel patch tests (unexercised).
kernel/tools/bundle.mjs --smp adds unkernel.kernel.smp.kwpatch: a
bsdiff-style patch (kwdiff.mjs) from the bundle's kernel to the SMP
build, after renumbering the base's function, global and type indices
and moving its data addresses to the target's (kwremap.mjs,
js/core/kremap.ts). With more than one CPU asked, loadKernelModule()
and the CLI derive the SMP kernel from it (js/core/kpatch.ts, hashes
checked); one CPU or a bundle without the section behaves as before.
test/kpatch.test.ts round-trips synthetic data and, given KPATCH_UP and
KPATCH_SMP, the real kernels.