From nobody Wed Apr 1 12:31:57 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEAB23A9DB5 for ; Tue, 31 Mar 2026 10:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774954680; cv=none; b=XD5fB9tBBMFaRjbZb2xl5a4/hB3yPnlXmDuWbIUJVDMQVjewEsR9hMKNHR0sK1+XPkbgfw4rzsh2L2fq+HgO8MAdzYYHoqhafFsCyfxYBwgwz3KX0OROFMeyPHUDfQ7UtdZvLoc/hEhWOAfyH/29mwvxsJ1qGTaSFwMM8kVuoZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774954680; c=relaxed/simple; bh=4JnYoTktQtoUtJUVdKYqmdqGFIDqGloAiz8fbauijTU=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=L5SeVzRB+DZcBDOVZlZWb9hN6ohYRGEZk49hBmm5XmSyP4kMQxpzPj7cKAXkVf1ZQhDdNfn55DZXVrsbARNp1jnw0R33UYt8/64ZxzfEFnCBoO3MOg/xT+vExXwwfuFZcQdd5rgHxuIwhFgKLB27zOEpVLhhR19K67Gp+V/qUF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OQKP+vSU; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OQKP+vSU" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-43cff5ef652so1353499f8f.2 for ; Tue, 31 Mar 2026 03:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774954676; x=1775559476; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=mM/5onz25kE6cU84lJtH4wnlOf71rK5o+L87vsB3QAM=; b=OQKP+vSURtMi95uHnHS++Tr06vJ6qY8CcXcs74MNJkkBxki4q35pPBFBvGghbEi5S7 Hn/yZbUrh9ZQ8ffKt8gpmNGwfaxFLPkrCzAIRDpgwSuNQL/nTyIhfLW5c6WiW7zf0f/X oYs9e02NOO51wLyziDpY+VPmENPicJWJUDMtmCFJOZRkRwsDcFaBFhOYwDdY038e+ay2 vCbPe7IAelHq+/3qk8a2oM5tgMt2ZMirqJiecFn5D5dlU5LYaZ4Mmu3dhEpPOHx6n33O sDaMkKBzCaJCWOWtOjtuL4DCUkCJDyM/D0DOQHAS3SWh7nIeWqCOMaYPO/dc7XEOmgkS D1Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774954676; x=1775559476; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mM/5onz25kE6cU84lJtH4wnlOf71rK5o+L87vsB3QAM=; b=PkGEZvaNpAn71yK44GQZwg1cZoY7LO2ZP0PAmDENEvP3ZnhSltSCDWeNdQsVQrwnyG OWeuHd2FBnpETF7GUbP541uRYeEyTzbh5Esh9S0WRUbNuDr8sliAdqrIvvIUXNVKvVPq 2Aq1s3/CAudtqp/M2L8Qu7ZnKR0m1AfnKodsn5ws3x1pab4rsMA8E03PaKI80s6Ved/H B8q0Hmn4EvODHuMzr+BSQRlaIEkDWiZgMUNKpemNLxhMVp/nAYhjflanUgat6T1jBBMS 8FpJ/xLum8oaWdR2rQzgO08VQqY2ke8jphfA8Br5/yJ7GThJIT5+d/k4bc69Ax9+FRTj MA0Q== X-Forwarded-Encrypted: i=1; AJvYcCVehR7eHY5B+CJVk6ulc/5FecWsXGj75UUr0cwwVbD5e1YbYZKRnk9sy87dtaCo4/FmwmO5GQKJbmZtESc=@vger.kernel.org X-Gm-Message-State: AOJu0YypJSOPElUjcl0NruibfVAtTKo2RDybIN3y4A6tIo/jMyPGWXga L1v6msN9hV+wljRKCjxwUPKemUS1WTCRCX95Fj3Hyg2Bd/98WvzlDwX+RXYoGm2B6nEV/RlBCeo 5tJyg7A5wiOs2OnJsRQ== X-Received: from wrux18.prod.google.com ([2002:a5d:6512:0:b0:439:b81f:ad99]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5d84:0:b0:43b:4d2e:a004 with SMTP id ffacd0b85a97d-43b9e981468mr28599122f8f.10.1774954676155; Tue, 31 Mar 2026 03:57:56 -0700 (PDT) Date: Tue, 31 Mar 2026 10:57:49 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAKyoy2kC/0XMQQrCMBCF4auUWRvJRDTGVe8hXZRkkga0I0kNS sndjUVw+T8e3wqZUqQMl26FRCXmyHMLtevATuMcSETXGpRUJ3mQRozPhb1jcXYSSRutPTlo70c iH1+bdB1aTzEvnN4bXPC7/gz8GwUFiiMSqVErI63rA3O40d7yHYZa6wfvtx6nnwAAAA== X-Change-Id: 20260309-autofdo-8d01e7977fed X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=4149; i=aliceryhl@google.com; h=from:subject:message-id; bh=4JnYoTktQtoUtJUVdKYqmdqGFIDqGloAiz8fbauijTU=; b=owEBbAKT/ZANAwAKAQRYvu5YxjlGAcsmYgBpy6iu3PekQeP6M6pAVikQJKtmZHXxDg+XJ8hqD fbfpF87i4SJAjIEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCacuorgAKCRAEWL7uWMY5 RjtbD/d8w5zdhv7xxN0UWADZCc6afSdbzfJG6/7I8BCoLWWCGTzrSiTU3mQp+cBkewSCzq0Z+dy ZX0SvZ5KyaWjVXz0ylpZG9Aso1KAVentkoOdkfeyvBH3uAqtRr/ufDG83tjRfiHbS2lChokqVjQ E/ATWd1KsIvGgRuKEkwqV+fUoW9ByH/l/qAMS6AINzv5OLvns0PLxfEUyWKsZb3sDUzwIVyvc1s rjPsT6zCM0Fi39iBensfm/G1WbTO8PfVNvO03BbZH8ljiYchJbh59iQtSqKPS/abMouQcU+xX0o 8w8hWPNIeVCE3v1s0tYU/GSz0RWK7mX3Z0yb8wBtujksvAddWKOoGxB0ka112Q6lmlemUWBbiFO dsOpFs9q2dWOkfMXU8ALlbAGYLzT0IxGvzop475JwXc52Yeh3QwkAqeYqoVqFu3/lGUCSdQyP/z 6nKmZxQbymGVCgZnn0jPnmmxVlI8Yef4UFEQmM4baZnfU9Ki+SUcPZR4iIBGq/JL51e6QkUifC+ 5Dzcf4ZobCbgbSYr/rNoLTmrk23IJ+S8FEASvw4l7gR1d5eMwJv3zI7kg3D7RfmJG6D4jnGdhHF Lwe0AFOBzpka4Pn6v5bPZR4eLEcBgGokyP1NCXwYQ0JLKVz/IUrzYrPoReTMSQLXCERpZjTeHCZ St9GRaQ73iiSc X-Mailer: b4 0.14.3 Message-ID: <20260331-autofdo-v2-1-eb5c5964820d@google.com> Subject: [PATCH v2] kbuild: rust: add AutoFDO support From: Alice Ryhl To: Rong Xu , Han Shen , Nathan Chancellor , Nicolas Schier , Miguel Ojeda Cc: Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Matthew Maurer , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This patch enables AutoFDO build support for Rust code within the Linux kernel. This allows Rust code to be profiled and optimized based on the profile. The RUSTFLAGS variable was suffixed with *_AUTOFDO_CLANG to match the naming of the config option, which is called CONFIG_AUTOFDO_CLANG. This implementation has been verified in Android, first by inspecting the object files and confirming that they look correct. After that, it was verified as below: 1. Running the binderAddInts benchmark [1] with Rust Binder built as rust_binder.ko module, using a Pixel 9 Pro. 2. Collecting a profile on an Pixel 10 Pro XL using the app-launch benchmark, which starts different apps many times, on a device with Rust Binder as a built-in kernel module. (C Binder was not present on the device.) 3. Using the collected profile, run the binderAddInts benchmark again with Rust Binder built both as a rust_binder.ko module, and as a built-in kernel module. 4. In both cases, Rust Binder without AutoFDO was approximately 13% slower than the AutoFDO optimized version. Built-in vs .ko did not make a measurable performance difference. All of the above was verified in conjuction with my helpers inlining series [2], which confirmed that this worked correctly for helpers too once [3] was fixed in the helpers inlining series. Link: https://android.googlesource.com/platform/system/extras/+/920f089/tes= ts/binder/benchmarks/binderAddInts.cpp [1] Link: https://lore.kernel.org/r/20260203-inline-helpers-v2-0-beb8547a03c9@g= oogle.com [2] Link: https://lore.kernel.org/r/aasPsbMEsX6iGUl8@google.com [3] Reviewed-by: Rong Xu Reviewed-by: Gary Guo Tested-by: Alice Ryhl Signed-off-by: Alice Ryhl --- Changes in v2: - Discuss RUSTFLAGS_ naming in commit message. - Update commit message with information about additional testing that has now been carried out. - Pick up tags. - Link to v1: https://lore.kernel.org/r/20260319-autofdo-v1-1-51ee2a7290cd@= google.com --- scripts/Makefile.autofdo | 6 +++++- scripts/Makefile.lib | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo index 1caf2457e585..3f08acab4549 100644 --- a/scripts/Makefile.autofdo +++ b/scripts/Makefile.autofdo @@ -3,14 +3,18 @@ # Enable available and selected Clang AutoFDO features. =20 CFLAGS_AUTOFDO_CLANG :=3D -fdebug-info-for-profiling -mllvm -enable-fs-dis= criminator=3Dtrue -mllvm -improved-fs-discriminator=3Dtrue +RUSTFLAGS_AUTOFDO_CLANG :=3D -Zdebug-info-for-profiling -Cllvm-args=3D-ena= ble-fs-discriminator=3Dtrue -Cllvm-args=3D-improved-fs-discriminator=3Dtrue =20 ifndef CONFIG_DEBUG_INFO CFLAGS_AUTOFDO_CLANG +=3D -gmlt + RUSTFLAGS_AUTOFDO_CLANG +=3D -Cdebuginfo=3Dline-tables-only endif =20 ifdef CLANG_AUTOFDO_PROFILE CFLAGS_AUTOFDO_CLANG +=3D -fprofile-sample-use=3D$(CLANG_AUTOFDO_PROFILE= ) -ffunction-sections CFLAGS_AUTOFDO_CLANG +=3D -fsplit-machine-functions + RUSTFLAGS_AUTOFDO_CLANG +=3D -Zprofile-sample-use=3D$(CLANG_AUTOFDO_PROF= ILE) -Zfunction-sections=3Dy + RUSTFLAGS_AUTOFDO_CLANG +=3D -Cllvm-args=3D-split-machine-functions endif =20 ifdef CONFIG_LTO_CLANG_THIN @@ -21,4 +25,4 @@ ifdef CONFIG_LTO_CLANG_THIN KBUILD_LDFLAGS +=3D -plugin-opt=3D-split-machine-functions endif =20 -export CFLAGS_AUTOFDO_CLANG +export CFLAGS_AUTOFDO_CLANG RUSTFLAGS_AUTOFDO_CLANG diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 0718e39cedda..eaddf6637669 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -123,6 +123,9 @@ ifeq ($(CONFIG_AUTOFDO_CLANG),y) _c_flags +=3D $(if $(patsubst n%,, \ $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(is-kernel-object))= , \ $(CFLAGS_AUTOFDO_CLANG)) +_rust_flags +=3D $(if $(patsubst n%,, \ + $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(is-kernel-object))= , \ + $(RUSTFLAGS_AUTOFDO_CLANG)) endif =20 # --- base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681 change-id: 20260309-autofdo-8d01e7977fed Best regards, --=20 Alice Ryhl