From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796416127; b=t5xelKB7UfHFMm8R2QpjnVyq+fOdgD5/02spWMK9646H7HGvCzjkLmPwxowEAppc7UPK oVcXe/y3DZRMoSkK5A8hh9TW/ehhsJrVcG2lfkPn3X2P3C9X1DaWOdTU7cKXntGVyYWkV l1Jhmn4GPLVKuvjksP/GhbRGcjLHmeV5TUicfcLly6YP86NxAbJ+4ffl+2Vape2ZVOkJR W1jxfP0xD+v4nULH33GM3k3NFYipTQqTbBofqSQAurq1m30KpaKP2/aHm+FYUMVIQca+v XZXs0GZHpadkSpeZeKWV9tA4lDzlSMpBAt8DfXZ944b0JQrSc47HAByZOJnJ+nRaepQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796416127; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=gEIiCpOTqPjci9LBgad06fmd4agar9BQpTTrrkb0yKo=; b=iu6K96IbCh4QjZBqM+11WH9iXtaBBOEgMG9K1oQ3qOp+X4/qJznliRvrXCSKAJBmf1lQ wLK/DQHEal12CwY4D8McyisEEGZ3HDRTxhbFV6FQpDbXUbjkE+otl5xsDJrN+sk1jX2Ii R324J/3nEsCr52uxiD8r9nqr3YpLNSN7X7Q4aeLb9LZiJDpvCEXf979u0JP1RzAZmb1yz AaFIElNkwY/MF8LNPbBrC2BUI6sQLVP9RsIRAy07nQSq6hn0gmeRhmIL2Qd+WjT5i/URY kW+56Iy8OGUgGtkJjUuEI2XOjjTuUW6lFraYitoKIs7j39NVNqF+IzIEi0WRiYNbmmg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J1VjMvN5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 579CD606A322; Fri, 4 Dec 2026 20:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J1VjMvN5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83B141F0093B; Fri, 4 Dec 2026 20:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796416127; bh=gEIiCpOTqPjci9LBgad06fmd4agar9BQpTTrrkb0yKo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=J1VjMvN5ztuwTdnzDPioHbtgCvEvC0veZi6ieseR16dwWSxyNB9CnCdzcqqjXkfBh nybcvhgH7QvtsLbJb3UzMdQjqC8SMUd4UqT8k/dLKWmYmCF02GWkDQ+wPypmJyFxwL U9l/vzzPSo40oySPXjXt//R09KYDvpiv92c0U+c4BGUaFkbY8UaVoOZ6LhpYYzAif9 lqvE3s5Jn6xFvZTRQW8RboA23R5scCbiau8YXyyzgtMztHMTgbk9xbeotiVqGE37+G xUfC7bF4IR2091SYMn7Z0x2baWs9PNFRH2DrMqzhnPilquwp1x6wrMYoUCCnI2ncdY qbKqcx4Sjeuew== From: "Lorenzo Stoakes (ARM)" Date: Fri, 04 Dec 2026 20:27:38 +0000 Subject: [PATCH v7 7/7] kbuild: build rust crates in parallel with the rest of the build X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-build-speedup-v7-7-19a89034d8d1@kernel.org> References: <20261204-build-speedup-v7-0-19a89034d8d1@kernel.org> In-Reply-To: <20261204-build-speedup-v7-0-19a89034d8d1@kernel.org> To: Linus Torvalds , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Geert Uytterhoeven , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Josh Poimboeuf , Peter Zijlstra , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , Nicolas Schier , Kees Cook Cc: ljs@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4608; i=ljs@kernel.org; h=from:subject:message-id; bh=YrMgcfw0iKwiNTgr8GoTeIHKGoFjr/h8vZK95LQjFV0=; b=owGbwMvMwCV2fu7ZrsZH9SKMp9WSGLKFlex+H5Ob59R5NpZN/i5X7F3eJ/taaxb1P2yPOLH+/ rsN3HMUOkpZGMS4GGTFFFmefxHfHyQSNq/zgr8bzBxWJpAhDFycAjARcyFGhk8rew/91p97acOF bWlPd9T4vA2TN3x5T9G+Y4bGxzbm2iaGf3o3C347sxx4Xcf/7NXN1+nxttbvruZFyye1J6S73N2 8jgkA X-Developer-Key: i=ljs@kernel.org; a=openpgp; fpr=E7F417BF5214569E89D04F46CF9DCD8A81E27F14 When CONFIG_RUST is specified make prepare builds all of the rust components before descending into the tree. This means nothing can be done until all of these are compiled, resulting in a stall at the start of every clean CONFIG_RUST build. This also implicitly slows down every rust-capable LLVM allmodconfig build as this enables the CONFIG_RUST option. Fix this by allowing rust crates to be built alongside the C code. Remove the rust build from the make prepare step, then establish a dependency between rust code located elsewhere in the tree upon rust components contained in rust/. Do this by establishing a top-level list of directories containing rust code, KBUILD_RUST_DIRS, upon which the dependency is expressed. Finally, ensure that no rust code is located elsewhere and fail the build if any is found to ensure that nothing is missed in future. Care is taken to ensure the rust/ dependency is also established for any module being built to account for external rust modules which rely upon it, and that only one rust/ build will be performed at any one time. External rust modules builds are unaffected - make modules_prepare ... (where ... are other goals) will build rust/ first. The rustdoc and rusttest goals invoke rust/ directly rather than via Kbuild, so build rust/ first there too. Every Rust and C object was confirmed to be byte-for-byte identical after this change. Whole build, 128-thread Threadripper 9980X, best of N runs: before after delta ------------------------------- x86 defconfig+RUST, clean 36.5s 32.6s -3.9s (-11%) x86 allmodconfig, clean 297.0s 278.3s -18.7s (-6%) Signed-off-by: Lorenzo Stoakes (ARM) --- Kbuild | 5 +++++ Makefile | 17 ++++++++++++++++- scripts/Makefile.build | 5 ++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Kbuild b/Kbuild index a6a0192dea08..9670556059dd 100644 --- a/Kbuild +++ b/Kbuild @@ -115,3 +115,8 @@ obj-$(CONFIG_NET) += net/ obj-y += virt/ obj-y += $(ARCH_DRIVERS) obj-$(CONFIG_DRM_HEADER_TEST) += include/ + +# Rust code elsewhere in the tree depends upon rust/. +ifdef CONFIG_RUST +$(KBUILD_RUST_DIRS): | rust +endif diff --git a/Makefile b/Makefile index b41f613e42e4..879d124e1f69 100644 --- a/Makefile +++ b/Makefile @@ -1416,11 +1416,14 @@ prepare0: archprepare $(Q)$(MAKE) $(build)=. prepare $(Q)$(MAKE) $(build)=scripts/mod +ifdef CONFIG_RUST +export KBUILD_RUST_DIRS := drivers lib mm samples +endif + # All the preparing.. prepare: prepare0 ifdef CONFIG_RUST +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh - $(Q)$(MAKE) $(build)=rust endif PHONY += remove-stale-files @@ -1767,6 +1770,14 @@ modules: modules_prepare # Target to prepare building external modules modules_prepare: prepare $(Q)$(MAKE) $(build)=scripts scripts/module.lds +ifdef CONFIG_RUST +# Avoid two instances of rust/ being built at any one time. +ifneq ($(filter modules_prepare,$(MAKECMDGOALS)),) +ifeq ($(filter all vmlinux modules %Image% dtbs rustdoc rusttest,$(MAKECMDGOALS)),) + $(Q)$(MAKE) $(build)=rust +endif +endif +endif endif # CONFIG_MODULES @@ -2035,13 +2046,17 @@ rustavailable: # Documentation target # # Using the singular to avoid running afoul of `no-dot-config-targets`. +# +# rust/ is built alongside the rest of the tree, so must be built first here. PHONY += rustdoc rustdoc: prepare + $(Q)$(MAKE) $(build)=rust $(Q)$(MAKE) $(build)=rust $@ # Testing target PHONY += rusttest rusttest: prepare + $(Q)$(MAKE) $(build)=rust $(Q)$(MAKE) $(build)=rust $@ # Formatting targets diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 0c4ec5b71658..5fad2bc6130e 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -381,8 +381,11 @@ quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ $(cmd_ld_single)) \ $(cmd_objtool) +rust-dir-ok = $(or $(KBUILD_EXTMOD),$(filter rust $(KBUILD_RUST_DIRS),$(firstword $(subst /, ,$@)))) + +# Ensure that any rust code located elsewhere from rust/ is listed in KBUILD_RUST_DIRS. define rule_rustc_o_rs - $(call cmd_and_fixdep,rustc_o_rs) + $(if $(rust-dir-ok),,$(error $@: Rust code in a directory not listed in KBUILD_RUST_DIRS, see the top Makefile))$(call cmd_and_fixdep,rustc_o_rs) $(call cmd,gen_objtooldep) endef -- 2.56.1