qosmio / openwrt-ipq

This repository is a mirror of https://git.openwrt.org/openwrt/openwrt.git It is for reference only and is not active for check-ins. We will continue to accept Pull Requests here. They will be merged via staging trees then into openwrt.git.
Other
118 stars 40 forks source link

kernel-build.mk: Fix multi-core build warning. #10

Closed zxlhhyccc closed 1 week ago

zxlhhyccc commented 1 week ago

In the case of multi-core compilation, the warning prompts to add a "+" sign.

warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
qosmio commented 1 week ago

The kernel already compiles with multiple jobs.

# 8 jobs
❯ make target/linux/compile V=s -j8

And check the number of compilations happening

❯ ps -f -C aarch64-openwrt-linux-musl-gcc
UID          PID    PPID  C STIME TTY          TIME CMD
qosmio     3186740 3186705  0 20:35 pts/8    00:00:00 /data/code/openwrt/ipq/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc -mlittle-endian -fma
qosmio     3186838 3186763  0 20:35 pts/8    00:00:00 /data/code/openwrt/ipq/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc -mlittle-endian -fma
qosmio     3186902 3186897  0 20:35 pts/8    00:00:00 /data/code/openwrt/ipq/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc -mlittle-endian -fma
qosmio     3186917 3186886  0 20:35 pts/8    00:00:00 /data/code/openwrt/ipq/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc -mlittle-endian -fma
qosmio     3186925 3186908  0 20:35 pts/8    00:00:00 /data/code/openwrt/ipq/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc -mlittle-endian -fma
qosmio     3186946 3186943  0 20:35 pts/8    00:00:00 /data/code/openwrt/ipq/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc -mlittle-endian -fma
qosmio     3186947 3186919  0 20:35 pts/8    00:00:00 /data/code/openwrt/ipq/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc -mlittle-endian -fma
qosmio     3186957 3186954  0 20:35 pts/8    00:00:00 /data/code/openwrt/ipq/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc -mlittle-endian -fma
# 4 jobs
❯ make target/linux/compile V=s -j4
❯ ps -C aarch64-openwrt-linux-musl-gcc
    PID TTY          TIME CMD
3184789 pts/8    00:00:00 aarch64-openwrt
3184823 pts/8    00:00:00 aarch64-openwrt
3184833 pts/8    00:00:00 aarch64-openwrt
3184841 pts/8    00:00:00 aarch64-openwrt

The message you're seeing doesn't even occur until the kernel is finished compiling

...
  LD [M]  net/ipv6/netfilter/nf_defrag_ipv6.ko
  LD [M]  net/ipv6/netfilter/nf_reject_ipv6.ko
  LD [M]  net/ipv6/netfilter/nft_reject_ipv6.ko
  LD [M]  net/ipv6/netfilter/nft_fib_ipv6.ko
  LD [M]  net/ipv6/ip6_udp_tunnel.ko
  LD [M]  net/bridge/netfilter/nft_meta_bridge.ko
  LD [M]  net/bridge/netfilter/nft_reject_bridge.ko
  LD [M]  net/bridge/netfilter/nf_conntrack_bridge.ko
  LD [M]  net/dns_resolver/dns_resolver.ko
  LD [M]  net/qrtr/qrtr.ko
  LD [M]  net/qrtr/qrtr-smd.ko
make[4]: Leaving directory '/data/code/openwrt/ipq/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.54'
# If .config did not change, use the previous timestamp to avoid package rebuilds
cmp -s /data/code/openwrt/ipq/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.54/.config /data/code/openwrt/ipq/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.54/.config.modules.save && mv /data/code/openwrt/ipq/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.54/.config.modules.save /data/code/openwrt/ipq/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.54/.config; cp -fpR /data/code/openwrt/ipq/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.54/.config /data/code/openwrt/ipq/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.54/.config.modules.save
touch /data/code/openwrt/ipq/build_dir/target-aarch64_cortex-a53_musl/linux-qualcommax_ipq807x/linux-6.6.54/.modules
make -C image compile TARGET_BUILD=
make[4]: Entering directory '/data/code/openwrt/ipq/target/linux/qualcommax'

# It's already done compiling before you even get this message
make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
make[4]: Nothing to be done for 'compile'.
make[4]: Leaving directory '/data/code/openwrt/ipq/target/linux/qualcommax/image'
make[3]: Leaving directory '/data/code/openwrt/ipq/target/linux/qualcommax'
make[2]: Leaving directory '/data/code/openwrt/ipq/target/linux'

Check what's actually happening

Before compile calls image, compile and TARGET_BUILD= it calls $(LINUX_DIR)/.modules

156:  compile: $(LINUX_DIR)/.modules
157:    $(MAKE) -C image compile TARGET_BUILD=
136:  $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
137:    $(Kernel/CompileModules)
138:    touch $$@

The actual module compilation happens in $(Kernel/CompileModules)

137: define Kernel/CompileModules/Default
138:    rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
139:    +$(KERNEL_MAKE) $(if $(KERNELNAME),$(KERNELNAME),all) modules
140:    # If .config did not change, use the previous timestamp to avoid package rebuilds
141:    cmp -s $(LINUX_DIR)/.config $(LINUX_DIR)/.config.modules.save && \
142:        mv $(LINUX_DIR)/.config.modules.save $(LINUX_DIR)/.config; \
143:    $(CP) $(LINUX_DIR)/.config $(LINUX_DIR)/.config.modules.save
144: endef

And it's already set to build in parallel

+$(KERNEL_MAKE)