mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-01 21:52:12 +08:00
perf(nuttx): build the NuttX libraries with parallel make jobs
Each NuttX library and the apps are built by a make invocation that ninja treats as a single opaque custom command, so they compiled one file at a time. Run them through a wrapper that honours a job count given to the toplevel build (e.g. `make px4_fmu-v5x_default -j1`), which reaches it through MAKEFLAGS, and otherwise uses the number of CPUs available to the process. Unlike CMake's logical core count, nproc respects docker --cpuset-cpus. A load limit keeps the concurrently running NuttX makes from oversubscribing the host. Mark the toplevel cmake build recipe as a sub-make with '+'. GNU make before 4.4 (e.g. Ubuntu 22.04/24.04) passes its jobserver as pipe file descriptors, which it otherwise closes for that recipe, leaving the NuttX makes to fall back to serial builds. Mention how to disable parallel builds in the docker docs. Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
1 parent
355b900829
commit
c2875ad6a2
4 files changed
+24
-4
No files matched your search
@@ -210,7 +210,7 @@ define cmake-build
|
||||
|| (rm -rf $(BUILD_DIR)); \
|
||||
fi
|
||||
@# run the build for the specified target
|
||||
@cmake --build $(BUILD_DIR) -- $(PX4_MAKE_ARGS) $(ARGS)
|
||||
+@cmake --build $(BUILD_DIR) -- $(PX4_MAKE_ARGS) $(ARGS)
|
||||
endef
|
||||
|
||||
# check if the options we want to build with in CMAKE_ARGS match the ones which are already configured in the cache inside BUILD_DIR
|
||||
|
||||
@@ -256,7 +256,7 @@ The bug is not reproducible, so it is likely a hardware or OS problem.
|
||||
c++: internal compiler error: Killed (program cc1plus)
|
||||
```
|
||||
|
||||
Try disabling parallel builds.
|
||||
Try disabling parallel builds, e.g. `make px4_fmu-v5x_default -j1`.
|
||||
|
||||
**Allow Docker Control from the VM Host**
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ set(APPS_DIR ${NUTTX_SRC_DIR}/apps)
|
||||
# NuttX build
|
||||
###############################################################################
|
||||
|
||||
# The NuttX libraries and apps are built by make invocations that ninja treats
|
||||
# as single opaque steps. Run them through a wrapper that adds parallel jobs.
|
||||
set(NUTTX_MAKE ${CMAKE_CURRENT_SOURCE_DIR}/tools/px4_nuttx_make.sh)
|
||||
|
||||
configure_file(${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/Make.defs.in ${CMAKE_CURRENT_BINARY_DIR}/nuttx/Make.defs)
|
||||
|
||||
set(EXTRA_NUTTX_CONFIG_FILE ${CMAKE_CURRENT_BINARY_DIR}/extra_config_options)
|
||||
@@ -155,7 +159,7 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/apps/libapps.a
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/px4.pdat ${APPS_DIR}/builtin/registry/px4.pdat
|
||||
COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${APPS_DIR}/builtin/registry/.updated
|
||||
COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${APPS_DIR}/builtin/builtin_list.c
|
||||
COMMAND make --no-print-directory --silent TOPDIR="${NUTTX_DIR}" > ${CMAKE_CURRENT_BINARY_DIR}/nuttx_apps.log
|
||||
COMMAND ${NUTTX_MAKE} --no-print-directory --silent TOPDIR="${NUTTX_DIR}" > ${CMAKE_CURRENT_BINARY_DIR}/nuttx_apps.log
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${APPS_DIR}/libapps.a ${CMAKE_CURRENT_BINARY_DIR}/apps/libapps.a
|
||||
DEPENDS ${nuttx_apps_files} nuttx_context ${NUTTX_DIR}/include/nuttx/config.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/px4.bdat
|
||||
@@ -190,7 +194,7 @@ function(add_nuttx_dir nuttx_lib nuttx_lib_dir kernel extra target)
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/nuttx/${nuttx_lib_dir}/lib${nuttx_lib}.a
|
||||
BYPRODUCTS ${nuttx_${nuttx_lib}_byproducts}
|
||||
COMMAND make -C ${nuttx_lib_dir} --no-print-directory --silent ${nuttx_lib_target} TOPDIR="${NUTTX_DIR}" KERNEL=${kernel} EXTRAFLAGS=${extra} ${bindir_arg}
|
||||
COMMAND ${NUTTX_MAKE} -C ${nuttx_lib_dir} --no-print-directory --silent ${nuttx_lib_target} TOPDIR="${NUTTX_DIR}" KERNEL=${kernel} EXTRAFLAGS=${extra} ${bindir_arg}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NUTTX_DIR}/${nuttx_lib_dir}/lib${nuttx_lib}.a ${CMAKE_CURRENT_BINARY_DIR}/nuttx/${nuttx_lib_dir}/lib${nuttx_lib}.a
|
||||
DEPENDS
|
||||
${nuttx_lib_files}
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
# Run make for a NuttX library or the NuttX apps with parallel jobs.
|
||||
#
|
||||
# If the build was started with an explicit job count, e.g.
|
||||
# `make px4_fmu-v5x_default -j1`, MAKEFLAGS carries it (and with GNU make 4.4
|
||||
# its jobserver) through ninja to here, so honour it. Otherwise use the number
|
||||
# of CPUs this process may run on, which, unlike the host's core count,
|
||||
# respects limits like docker --cpuset-cpus. The load limit keeps the NuttX
|
||||
# makes that ninja runs concurrently from oversubscribing the host.
|
||||
|
||||
case " ${MAKEFLAGS} " in
|
||||
*" -j"*) exec make "$@" ;;
|
||||
esac
|
||||
|
||||
jobs=$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
|
||||
exec make -j"${jobs}" -l"${jobs}" "$@"
|
||||
Reference in new issue
Block a user