From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C087628FF; Tue, 29 Oct 2024 00:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730160902; cv=none; b=m4L3kb2dscsO0ydNt0t331jkc4cY6iiR/ZRNF9rIE702C7NVYer3nBHJAdRsJ4yfSHFrnhQrEo8tMj7DZUhaMQuWhDiMRime1erErQPDehIpEF/lBy5BLMIlkipsAKgRxuNS+Ux98/5qo5FXdGuGPUivjoLXXg306QZwvOKyX/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730160902; c=relaxed/simple; bh=pWqN4qoaerNcZqwVzZ3/W+y/IZE3cckdHP0roXePaZQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nzPpayKFmUzGNP0o136Mjmxqwa50BZQZ5zQu3s0Xyoaq1HHHrWgjnMAyjrPzW3IRlFkSACrlNb3yZN/FL/Cx8N6myO7xnjT+yOaEjwoMxevwazYdWH3UtkLZvkdWF6RnSC8/zotBEFgVgN4B9Wt4O1d3/OBtPHxSJNBxAI5bluI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iGBVoLgZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iGBVoLgZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E578C4CEC3; Tue, 29 Oct 2024 00:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730160902; bh=pWqN4qoaerNcZqwVzZ3/W+y/IZE3cckdHP0roXePaZQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iGBVoLgZnsC1rYrU4j34a6TD7XzDT9Um67irZz0EkW5Xt9aWtQ8kgPMp9AAOmk/m3 vn3Rtlir8WVMAVL1ovPZiZFeqy+IFzqNDtI1kNMX/NBUcFQ/9I2G2H6JV1bt594yab U84T8WH1ElozKE0vhtDinN2YvMN1A0JhSPqiQolkRLPuVSqCFZF2vvIcKfWgX768KD 88RB54H8oUGIIR89jIjA8ReH+tSY3SFOjEVqRuIn5xtMO0ptUd16os333Oe71J1OBT eftp6R4P52OdKRlXH2dlWQCNibtdzOaUA7dEOmuQEzrlZ1Kb+OKTDdsf4zTrivNk3y KpM7tLtIzqhEg== Date: Mon, 28 Oct 2024 17:14:59 -0700 From: Kees Cook To: Rong Xu Cc: Alice Ryhl , Andrew Morton , Arnd Bergmann , Bill Wendling , Borislav Petkov , Breno Leitao , Brian Gerst , Dave Hansen , David Li , Han Shen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Jonathan Corbet , Josh Poimboeuf , Juergen Gross , Justin Stitt , Masahiro Yamada , "Mike Rapoport (IBM)" , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , "Paul E. McKenney" , Peter Zijlstra , Sami Tolvanen , Thomas Gleixner , Wei Yang , workflows@vger.kernel.org, Miguel Ojeda , Maksim Panchenko , "David S. Miller" , Andreas Larsson , Yonghong Song , Yabin Cui , Krzysztof Pszeniczny , Sriraman Tallam , Stephane Eranian , x86@kernel.org, linux-arch@vger.kernel.org, sparclinux@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v6 7/7] Add Propeller configuration for kernel build Message-ID: <202410281714.20A7BE8@keescook> References: <20241026051410.2819338-1-xur@google.com> <20241026051410.2819338-8-xur@google.com> Precedence: bulk X-Mailing-List: workflows@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20241026051410.2819338-8-xur@google.com> On Fri, Oct 25, 2024 at 10:14:09PM -0700, Rong Xu wrote: > Add the build support for using Clang's Propeller optimizer. Like > AutoFDO, Propeller uses hardware sampling to gather information > about the frequency of execution of different code paths within a > binary. This information is then used to guide the compiler's > optimization decisions, resulting in a more efficient binary. > > The support requires a Clang compiler LLVM 19 or later, and the > create_llvm_prof tool > (https://github.com/google/autofdo/releases/tag/v0.30.1). This > commit is limited to x86 platforms that support PMU features > like LBR on Intel machines and AMD Zen3 BRS. > > Here is an example workflow for building an AutoFDO+Propeller > optimized kernel: > > 1) Build the kernel on the host machine, with AutoFDO and Propeller > build config > CONFIG_AUTOFDO_CLANG=y > CONFIG_PROPELLER_CLANG=y > then > $ make LLVM=1 CLANG_AUTOFDO_PROFILE= > > “” is the profile collected when doing a non-Propeller > AutoFDO build. This step builds a kernel that has the same optimization > level as AutoFDO, plus a metadata section that records basic block > information. This kernel image runs as fast as an AutoFDO optimized > kernel. > > 2) Install the kernel on test/production machines. > > 3) Run the load tests. The '-c' option in perf specifies the sample > event period. We suggest using a suitable prime number, > like 500009, for this purpose. > For Intel platforms: > $ perf record -e BR_INST_RETIRED.NEAR_TAKEN:k -a -N -b -c \ > -o -- > For AMD platforms: > The supported system are: Zen3 with BRS, or Zen4 with amd_lbr_v2 > # To see if Zen3 support LBR: > $ cat proc/cpuinfo | grep " brs" > # To see if Zen4 support LBR: > $ cat proc/cpuinfo | grep amd_lbr_v2 > # If the result is yes, then collect the profile using: > $ perf record --pfm-events RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a \ > -N -b -c -o -- > > 4) (Optional) Download the raw perf file to the host machine. > > 5) Generate Propeller profile: > $ create_llvm_prof --binary= --profile= \ > --format=propeller --propeller_output_module_name \ > --out=_cc_profile.txt \ > --propeller_symorder=_ld_profile.txt > > “create_llvm_prof” is the profile conversion tool, and a prebuilt > binary for linux can be found on > https://github.com/google/autofdo/releases/tag/v0.30.1 (can also build > from source). > > "" can be something like > "/home/user/dir/any_string". > > This command generates a pair of Propeller profiles: > "_cc_profile.txt" and > "_ld_profile.txt". > > 6) Rebuild the kernel using the AutoFDO and Propeller profile files. > CONFIG_AUTOFDO_CLANG=y > CONFIG_PROPELLER_CLANG=y > and > $ make LLVM=1 CLANG_AUTOFDO_PROFILE= \ > CLANG_PROPELLER_PROFILE_PREFIX= > > Co-developed-by: Han Shen > Signed-off-by: Han Shen Looks good. Similarly isolated like FDO. :) Reviewed-by: Kees Cook -- Kees Cook