From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D63A83D47C0; Tue, 8 Sep 2026 20:59:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788901159; cv=none; b=M/H3BK7XB0Y+D5ZCVSdmmJGaKlcSbdOXTPHWPw0LjMc5T7bHVFzRJV/8hvev/lUwLKXszEesLx5MLmVZ+90T+48bmFBwmwRmxOC1I7xs9w2pLKmdsTMMCmPYXvPo/YPnT5U5HASWcZuf4NzfLtWvYaxNs58/qKsPnjX27erIya0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788901159; c=relaxed/simple; bh=LB9T7y9hXziw5kYzoWlATIyn+dzyDLeA+KV1Dtb+tR0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bZj/C47roIp9DkTGBUzLDYcfCddNpVCA6I5N9O12GXopXwp3uvP0B9eRSDD5zwY5fO0gjV6EZSltQbs2s+wH3ny5W8jAZTaNU7B/28Dm9YMim3+O5w7zbL/a4pXwIJqFWcChik+nyHkaY070g758Jr/WhwUtdCmcIM0g2HrlPRY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l2H8oEfy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l2H8oEfy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1D881F00A3D; Tue, 8 Sep 2026 20:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788901157; bh=KP4DPjtGqjYlZDY/C6oiw5PNNFH4xgYFq5gb3vP/9DM=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=l2H8oEfyiisTrkmWPXFPkrb9zX+PnNqQLPTWl+vHf3NsuP+fCsXMWBsX7BjXJYlWZ nqqgTPf7uY55PDIAWtwo6hXNTbMnaLlGNx4ryMRpe/nOzVqpEzc5iWLw2JLhb8Co05 9s1SasDqfvP91H8sdwcoy4A7YTh8DB0wv+Bi/OoXlL2MblT9cgvSRSaEexFHujfFy6 8P4N8pmqaNnNKGCxCVliu0/Kec45kp7oMDRUSzS6XwAjYJU0gH5oVqdZOxDseQyQO1 Jh1owZbgK0zD6cmR+j9o1TGHMmkFGwpKic4yhyualkluEnQUYWO/YKOT5YBaGeN1wf Oue7w0xvvFlNw== From: "Lorenzo Stoakes (ARM)" Date: Tue, 08 Sep 2026 21:55:20 +0100 Subject: [PATCH 20/23] kbuild: rust: parallelise rustc front end Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260908-build-speedup-v1-20-5dc1ac01672d@kernel.org> References: <20260908-build-speedup-v1-0-5dc1ac01672d@kernel.org> In-Reply-To: <20260908-build-speedup-v1-0-5dc1ac01672d@kernel.org> To: Linus Torvalds , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Masahiro Yamada , Alexey Gladkov , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Arnd Bergmann , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Ilias Apalodimas , 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?= , Jonathan Corbet , Randy Dunlap Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org, Jens Axboe , "Lorenzo Stoakes (ARM)" X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3115; i=ljs@kernel.org; h=from:subject:message-id; bh=LB9T7y9hXziw5kYzoWlATIyn+dzyDLeA+KV1Dtb+tR0=; b=owGbwMvMwCV2fu7ZrsZH9SKMp9WSGLIWlFnEMd3Ve9ZQVLbpj4/Z9s0fLu8KN58+tafn1S/fR l1FmWdTO0pZGMS4GGTFFFmefxHfHyQSNq/zgr8bzBxWJpAhDFycAjCR0CuMDFOjrd+XSqqK1Lpq xpUur5gszfvmzYl5k5X2XJzc+WaJ1SNGhteOwtIX8jW6gl0FqjNPhzDoas99cHsCh5ZbR+ar/1f 9uAA= X-Developer-Key: i=ljs@kernel.org; a=openpgp; fpr=E7F417BF5214569E89D04F46CF9DCD8A81E27F14 Rust crates are compiled in a serial chain on the critical path - core, bindings, kernel crates and then the drivers - each a rustc invocation. With CONFIG_RUST set and every rust driver enabled, the entire chain takes around 25 seconds on a 128-thread machine, with the associated C code taking 24 seconds. Each time a change is made to any of the bindings, it triggers a rebuild. Use the -Zthreads option to have rustc perform builds in parallel. This has been available since rust 1.84 (rust-lang/rust#132282), and the kernel requires rust 1.85 or above. A future -j/--jobs option is planned for rustc:(rust-lang/compiler-team#1005), so check to see if this available and if so use it. If the user's rustc supports neither, then it falls back gracefully and neither are used. The threads are taken from make's jobserver, so a parallel build is not oversubscribed. It was found that benefits level off at 8 threads (16 was found to be around the same, and 32 slower). Generated output was confirmed byte-for-byte identical. Observed build time changes (using rustc 1.98, clang): before after core.o 7.7s 4.9s bindings.o 4.3s 3.1s kernel.o 2.0s 1.4s clean build 39.3s 34.6s touch rust/kernel/lib.rs 12.9s 12.1s touch rust/bindings/bindings_helper.h 19.5s 17.5s Whole build, 128-thread Threadripper 9980X, best of N runs: before after delta ------------------------------- x86 defconfig+RUST, clean 41.0s 36.4s -4.6s (-11%) x86 defconfig+RUST, touch lib.rs 8.3s 7.7s -0.56s (-7%) Assisted-by: LLM Signed-off-by: Lorenzo Stoakes (ARM) --- Makefile | 4 ++++ init/Kconfig | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Makefile b/Makefile index 997fc7ebe096..7d23d7b64be3 100644 --- a/Makefile +++ b/Makefile @@ -1204,6 +1204,10 @@ KBUILD_RUSTFLAGS += --remap-path-prefix=$(srcroot)/= --remap-path-scope=macro endif endif +ifdef CONFIG_RUST +KBUILD_RUSTFLAGS += $(if $(CONFIG_RUSTC_HAS_JOBS),-j8,$(if $(CONFIG_RUSTC_HAS_ZTHREADS),-Zthreads=8)) +endif + # include additional Makefiles when needed include-y := scripts/Makefile.warn include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug diff --git a/init/Kconfig b/init/Kconfig index 3c92c87254a3..4096a306e2ab 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -231,6 +231,13 @@ config RUSTC_HAS_FILE_AS_C_STR config RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS def_bool RUSTC_VERSION >= 109800 +# rustc's parallel front end: -j is the coming spelling, -Zthreads the current one +config RUSTC_HAS_JOBS + def_bool $(rustc-option,-j8) + +config RUSTC_HAS_ZTHREADS + def_bool $(rustc-option,-Zthreads=8) + config PAHOLE_VERSION int default "$(PAHOLE_VERSION)" -- 2.55.0