casaroli opened a new pull request, #21845:
URL: https://github.com/apache/nuttx/pull/21845

   ## Summary
   
   Each make process of a build parses `tools/Config.mk` and the arch 
`Toolchain.defs` again. Three `$(shell)` commands in these files run again in 
each make process, with the same result each time. One configure and build of 
qemu-armv8a:nsh starts 1115 shells, and these three commands start about 280 of 
them. This PR runs each of them once and gives the result to the sub-makes in 
the environment, as `tools/Config.mk` already does for `DEFINE_PREFIX` and 
`INCDIR_PREFIX`.
   
   - tools/Config.mk: Look for bash once per build. `command -v bash` ran in 
each make process (169 times in qemu-armv8a:nsh). `BASHCMD` is now set only 
when it is not defined, and it is exported.
   - build: Compare GCCVER with 12 once per build. `GCCVER` is exported, but 
`expr "$(GCCVER)" \>= 12` ran in each make process (106 times in 
qemu-armv8a:nsh), in arch/arm, arch/arm64, arch/risc-v (two places) and 
libs/libxx/libcxx. The result is now exported in `GCCVER_GE_12`, together with 
the `GCCVER` that it is for (`GCCVER_GE_12_FOR`). A sub-make with a different 
`GCCVER` (the ameba boards set their own) compares again. The comparison stays 
in each file, because 3 efm32 boards include their `Toolchain.defs` before 
`tools/Config.mk`.
   - tools/Unix.mk: Update .version once per make invocation. 
`tools/version.sh` starts several git commands. It ran in each parse of the 
top-level Makefile, also in its sub-makes: 3 times in one `configure.sh`, 
because `olddefconfig` runs `clean_context` and `apps_preconfig` as sub-makes. 
Now the first run exports `NUTTX_VERSION_UPDATED`, and the sub-makes do not run 
it again.
   
   ## Impact
   
   Make build only. CMake does not run these commands. The values are the same 
as before, so `.config`, `include/nuttx/config.h` and all build commands do not 
change (see Testing). The build environment gets 4 new variables: `BASHCMD`, 
`GCCVER_GE_12`, `GCCVER_GE_12_FOR` and `NUTTX_VERSION_UPDATED`. A `BASHCMD` in 
the environment of `make` is now used; before, the makefile replaced it. 
Windows native builds do not use the changed lines of `tools/Config.mk` and 
`tools/Unix.mk`, and the `GCCVER` comparison runs the same `$(shell expr ...)` 
as before, so its result does not change. Documentation: no page describes 
these variables, so no change.
   
   ## Testing
   
   Same output: for each configuration, `configure.sh`, a real `make context`, 
then `make -n V=1` (all build commands), on master and with this PR. `.config`, 
`include/nuttx/config.h` and the full `make -n` output are identical:
   
   - GNU make 3.81 (macOS): qemu-armv8a:nsh, qemu-armv8a:knsh (kernel), 
stm32f4discovery:nsh, stm32f4discovery:kostest (protected), efm32-g8xx-stk:nsh 
(Toolchain.defs before Config.mk), rv-virt:nsh64, rv-virt:knsh64 (kernel; both 
risc-v comparisons), sim:nsh, sabre-6quad:libcxx (libcxx).
   - GNU make 4.4: qemu-armv8a:nsh, rv-virt:nsh64, stm32f4discovery:kostest. 
The only difference is the line number in the expected `make -n` error message 
for the link inputs (tools/Unix.mk has 5 more lines).
   - pke8721daf:nsh (ameba, `GCCVER` 10): `.config` and `make -n` output 
identical. Its context needs Linux prebuilt tools, so `config.h` was not made 
on macOS.
   
   The `GCCVER` cache alone, with GNU make 3.81 and 4.4: a top-level make with 
`GCCVER` 13, then sub-makes with 13, 10, an empty value, 9, and a sub-make of 
the sub-make with 9. Each result is the same as a plain `expr`; `expr` runs 4 
times instead of 6.
   
   Shells that make starts (configure, `make context`, `make -n`):
   
   | configuration | master | this PR |
   |---|---|---|
   | qemu-armv8a:nsh | 1115 | 841 (-25%) |
   | rv-virt:nsh64 | 1410 | 997 (-29%) |
   | stm32f4discovery:nsh | 860 | 634 (-26%) |
   
   Time on macOS (arm64, no other load), `configure.sh` 10 times per tree, 
alternating, median:
   
   | configuration | master wall / CPU | this PR wall / CPU |
   |---|---|---|
   | qemu-armv8a:nsh | 3.86 s / 3.92 s | 3.45 s / 3.33 s |
   | rv-virt:nsh64 | 3.75 s / 3.90 s | 3.44 s / 3.32 s |
   | stm32f4discovery:nsh | 3.88 s / 4.00 s | 3.49 s / 3.39 s |
   
   Full builds of the same 3 configurations (`make -j8`, warm ccache, 3 runs 
per tree): no difference larger than the noise (-2% to +2%). In the CI 
container on a Linux host with other load: no difference larger than the noise.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   
   Not tested: Windows native builds, a build of every configuration (CI does 
that).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to