From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.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 5C9C73C5842 for ; Thu, 4 Jun 2026 19:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780602978; cv=none; b=C07SgPNnsCaGugr1QvXw5RYyio+rEZZ5pIX7IQre5DLNWIXwVS6OPsL+XlDOyBoSsd3OnUCA/ZmU24n5vZ3LrlYaOgjBkXSjGUnvdGVi9gH9NbN+h4O1HNjOhmTuefKwVd9LE2NJuHM16pHeCBsA2dbNUNIKTuq9XVVU9BU7NNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780602978; c=relaxed/simple; bh=ALDVVdFoylq7o2r85tA1n/hqs9RaRelCbsQQ0XyQREQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BtARVwtdWEDPHXZXoFIxG/iUIBbCSmYXD22mAiPpmr9SbIsDzSaenyYVLE7lnXQMhXmdwQ5ZygW/UTP/1ruarDfOUeUfUCHeMrEtH82r7NENjNf7SRTgtkGBJ94fojpr8X8xgrgLjBw2h7YbmyYU3MAyn7SjKGCM+M17napGHXI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--xur.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BobC0uch; arc=none smtp.client-ip=74.125.82.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--xur.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BobC0uch" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-137dbe27199so80120c88.1 for ; Thu, 04 Jun 2026 12:56:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780602975; x=1781207775; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=8+SbulTiJWlvIk3jVLfJBqtlKmu5w1xAGHRbaSG4jXs=; b=BobC0uchrF7THxR9XqJc7q1vN+lwr1BmLAKyGbrb2u2GYgFaqvPShVT/xKha6fYQsA taz3bZFFDujb/BbvT3cS3/YzzmPHrZxeq8qWOoHOVKyyLJd/XJvKWqSn70OKQfm02OWb TSFZETtLPyiDcPGov/3a8HK8jX4zbNgiHGP+VZTy0Gp2hAds5BugWY2PGFLulU5e0I4e ICD9QelNFuRbd7auC/hB5vNYRdTCReAHEotofXLlo79K9MBmDZ3nZG74WXGWBLWwtsw1 9WGsOnG3LDcXXDd0SZNKf+jYKez/afpEq9pd2IIHlY5Ro6jjprgY8OHu96pYaWOjOB9g gXNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780602975; x=1781207775; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=8+SbulTiJWlvIk3jVLfJBqtlKmu5w1xAGHRbaSG4jXs=; b=Cdh+KAyBJUH64ImjCRTFVcMKgmGMS/F0bERk3WmLlTLloK71R6mxC0+6P6I65+IzCB VYBxCLSWKVVx/w3Jv5XrEXuMkn5L9On07Vi9JiUeD/MaV2HrHNrKoicxOPQm7p3OHfZ2 BvIyjXQlprzoToBKmCeWnI6eMQzC7SNZ/HQP6JIZh2TBiqbeCj7UhGlTAdUuoGBIWi9P YN//uz4KQ98yUmjRu+2hnYidEP5rivcs97mNRy3Z65dUc+G/YuyYBIwWtPffAGrxqG2v rN+CdBYLycFv9ygWC0QP7dedb79RRw9vXG7UkwCkhqNWp7+g9Vj0fQdszEwMh+D4X1CD SL8A== X-Forwarded-Encrypted: i=1; AFNElJ8f8FPBc1oAmbGpw9vecEXswrk7+/YtfNr3T5s4CEuNOhIkqndCg3nWo6E7hs2uUzBaAFRkdYXkJyWxuVg=@vger.kernel.org X-Gm-Message-State: AOJu0YxUHueW7VvuQVvmwjUp9IGh3QEaZE9XK81QRtVJkcZxT4V/uQ0q fSqW+/jkx03K52EEjN7CJNOR7JAfeOUplvEiec+3Rw/Ru6u4lhZ6wIC2Msnc99LLOJQIVA== X-Received: from dlbrp10.prod.google.com ([2002:a05:7022:160a:b0:137:e7d3:1490]) (user=xur job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6b99:b0:137:e532:f53f with SMTP id a92af1059eb24-1380672bf32mr266541c88.34.1780602975084; Thu, 04 Jun 2026 12:56:15 -0700 (PDT) Date: Thu, 4 Jun 2026 12:56:07 -0700 In-Reply-To: <20260604195612.3757860-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260604195612.3757860-1-xur@google.com> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog Message-ID: <20260604195612.3757860-2-xur@google.com> Subject: [PATCH v4 1/2] kconfig: Remove the architecture specific config for AutoFDO From: xur@google.com To: Yabin Cui , Will Deacon , Han Shen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Kees Cook , Nathan Chancellor , Nicolas Schier , Linus Walleij , Arnd Bergmann , Mathieu Desnoyers , Rong Xu , Miguel Ojeda , Peter Zijlstra , Jinjie Ruan , Lukas Bulwahn , linux-kernel@vger.kernel.org, Juergen Gross , Helge Deller , Ryan Roberts , Marc Zyngier , Ard Biesheuvel , Vincent Donnefort , Alice Ryhl Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: Rong Xu The CONFIG_AUTOFDO_CLANG option currently depends on ARCH_SUPPORTS_AUTOFDO_CLANG, but this dependency seems unnecessary. Remove ARCH_SUPPORTS_AUTOFDO_CLANG and allow users to control AutoFDO builds solely through CONFIG_AUTOFDO_CLANG. This simplifies the kconfig and avoids potential confusion. Expand the AutoFDO documentation to include instructions for arm64. Contributor acknowledgments: * SPE instructions: Daniel Hoekwater * ETM instructions: Yabin Cui Signed-off-by: Rong Xu Suggested-by: Will Deacon Tested-by: Yabin Cui Reviewed-by: Kees Cook --- Documentation/dev-tools/autofdo.rst | 41 +++++++++++++++++++++++++++++ arch/Kconfig | 4 --- arch/x86/Kconfig | 1 - 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Documentation/dev-tools/autofdo.rst b/Documentation/dev-tools/= autofdo.rst index bcf06e7d6ffa..ae03c4dfedc1 100644 --- a/Documentation/dev-tools/autofdo.rst +++ b/Documentation/dev-tools/autofdo.rst @@ -61,6 +61,9 @@ process consists of the following steps: the AutoFDO profile via offline tools. =20 The support requires a Clang compiler LLVM 17 or later. +Current supported architectures include x86/x86_64 (via LBR) and +arm64 (via SPE or ETM). + =20 Preparation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -141,6 +144,35 @@ Here is an example workflow for AutoFDO kernel: =20 $ perf record --pfm-events RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a -N= -b -c -o -- =20 + - For arm64 with SPE: + + There are a few kernel features that must be enabled to collect SPE p= rofiles on Arm. + Below is a list of the required features: + + - CONFIG_ARM_SPE_PMU=3Dy + - CONFIG_PID_IN_CONTEXTIDR=3Dy + - kpti=3Doff + + Use the following command to generate SPE perf data file:: + + $ perf record -e ' arm_spe_0/branch_filter=3D1,load_filter=3D0,store= _filter=3D0/' -a -c -N --no-switch-events -o -- + + - For arm64 with ETM trace: + + Follow the instructions in `Linaro OpenCSD document + `_ + to record ETM traces for AutoFDO:: + + $ perf record -e cs_etm/@tmc_etr0/k -a -o -- + $ perf inject -i -o --itrace=3Di500009il + + For ARM platforms running Android, follow the instructions in `Androi= d simpleperf + document `_ + to record ETM traces for AutoFDO:: + + $ simpleperf record -e cs-etm:k -a -o -- + $ simpleperf inject -i -o --symdir = + 4) (Optional) Download the raw perf file to the host machine. =20 5) To generate an AutoFDO profile, two offline tools are available: @@ -162,6 +194,15 @@ Here is an example workflow for AutoFDO kernel: =20 $ llvm-profdata merge -o ... = =20 + For arm64 SPE, use the following command:: + + $ create_llvm_prof --binary=3D --profile=3D --pr= ofiler=3Dperf_spe --format=3Dextbinary --out=3D + + For arm64 ETM, use the following command:: + + $ create_llvm_prof --binary=3D --profile=3D= --profiler=3Dtext -format=3Dextbinary -out=3D + + 6) Rebuild the kernel using the AutoFDO profile file with the same config = as step 1, (Note CONFIG_AUTOFDO_CLANG needs to be enabled):: =20 diff --git a/arch/Kconfig b/arch/Kconfig index 0848932d1c8e..5e878924939a 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -879,12 +879,8 @@ config LTO_CLANG_THIN_DIST module-specific compiler options, and simplifies debugging. endchoice =20 -config ARCH_SUPPORTS_AUTOFDO_CLANG - bool - config AUTOFDO_CLANG bool "Enable Clang's AutoFDO build (EXPERIMENTAL)" - depends on ARCH_SUPPORTS_AUTOFDO_CLANG depends on CC_IS_CLANG help This option enables Clang=E2=80=99s AutoFDO build. When diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f3f7cb01d69d..10bf3984102e 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -130,7 +130,6 @@ config X86 select ARCH_SUPPORTS_LTO_CLANG select ARCH_SUPPORTS_LTO_CLANG_THIN select ARCH_SUPPORTS_RT - select ARCH_SUPPORTS_AUTOFDO_CLANG select ARCH_SUPPORTS_PROPELLER_CLANG if X86_64 select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if X86_CX8 --=20 2.54.0.1032.g2f8565e1d1-goog