From nobody Sun Nov 24 21:41:10 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 BA5FF1AB6C2 for ; Sat, 2 Nov 2024 17:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730569895; cv=none; b=UJqc+AI0UCtggA0yN2hkp72NKyZnM5sIQTr2q5eT8lFD0XnbMnQelAKNy0KMc2Dyu4Gd+LBWDRp4I+16mdjvbzNrfAU01MfrNHuZHqNAeLEiDBYDZagnTdsuVP3X4TGdAocu+Y6sCLRPQ80GiM5DE8JZMHasKbcvjegTTuhQY3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730569895; c=relaxed/simple; bh=tYeWMfxSx4vH4s+I4R38mJYh2p1UfaeTY/BCD1eWxkg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mqKWAM58BVC09FGaV95bMq3QoPiajdK1iPAEgLr8KGkilTXGc2r+RuBsYbxIeclu1u6vU/pmFDjVKpDbBZG+QNEVtDSyUcnJOYqdvjgssCqVXPi+mqfmhyPvyJpSH9zvcWx7OQoOfjn9Hp+Cbt8sGbwxPQ9T4x+GrhOcKw5xShI= 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=kHwEZtCo; arc=none smtp.client-ip=209.85.128.202 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="kHwEZtCo" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8a5e862eso2499247b3.0 for ; Sat, 02 Nov 2024 10:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730569888; x=1731174688; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PdWo63oS/3PygmFUI3nbDvYOqCsDTsjYHv+g+IznqpU=; b=kHwEZtCoMIDCAe0fgDU+Xuaq2nh5BXHB0TvjjBi8xT8glKzHDYuLGjov6OD3tj7E1k r4OZkzC+N+yD9lHjCBQzwrBjdFITK0VK7VS5ulAOlXaXFjDwCxbsq5iB7MfyIIargRq4 JIUIDS/IfXKxA9yPZ6Md1/DulUiMTJYxold39DRBjm7RqB8mIs8S0ufipUfsWLu/srPv ykwDtcC9ybon5LNYcNWY1u1yHXl02W0ueHSb2CvbTaexzaXfF6C9PZpKVB1bCDelJHxa jrBXdEXGEBYH4azqdITTwsYKtni/9rBOLDcBQDBgh1BEFSjiMZAxZqGfLm0jrjhIeAoG tZRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730569888; x=1731174688; h=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=PdWo63oS/3PygmFUI3nbDvYOqCsDTsjYHv+g+IznqpU=; b=E7aCKg5f/lVDmT3TfXCikB1mh8Tq6SYH/QGihWdlHJOaahRO0GLzPc+I0FL7+29VEV ZauST4LcPA4gjQgky2u7eroW7LH52vzu29ddxQny9HwwkB5TOq3cnSa1fw7f/hUPEtI8 6y4PlVYvcd+aaoSlLt5nrZyAb7CJ5hHo6g0gmxdmi9DTyQeCmvPdcM2X6OZEVJiprPkN KsqLSAVc5TvdmP2YEPu76Ur+iWM2hLoCUWPfe69xOByNh4Y+smgpwM08wgGfLBCcJD23 XgayJPaNps69Fgfa0OsGx3Q7RdZCCIzNYq2nYy5k3OfjgO4JivIHLVMpOcXQegk5ak1v qaKw== X-Forwarded-Encrypted: i=1; AJvYcCWozo3KTB/JVLcQTFpEUrZGLxgD4W4Yls1XnkApa6Hz8mSQ/I5CMwsZXKvp96vToWoKoYrN0kK+csJ2Qys=@vger.kernel.org X-Gm-Message-State: AOJu0YxTZtoxpYpSU6mPLKFT9CQTk6N/f1by5ZfvRSAHP6pgiR1ZOaUd 2q8/GAMw+HqV6FQkjs3DjRhjW2M/eOgj17/QwRzsXsDw9P45NMJ76xUQgbtDve94iQ== X-Google-Smtp-Source: AGHT+IH7LQgBzA2tMJPZhpergfNVuUy9qcXS3+8LW4j/tM/hz8d/Un776Cs1P3DAetNpOXBX+ju9Fw8= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a05:690c:200f:b0:6e2:ac0a:8982 with SMTP id 00721157ae682-6ea6413e043mr907067b3.0.1730569888405; Sat, 02 Nov 2024 10:51:28 -0700 (PDT) Date: Sat, 2 Nov 2024 10:51:13 -0700 In-Reply-To: <20241102175115.1769468-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: <20241102175115.1769468-1-xur@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241102175115.1769468-7-xur@google.com> Subject: [PATCH v7 6/7] AutoFDO: Enable machine function split optimization for AutoFDO From: Rong Xu To: 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 , Kees Cook , Masahiro Yamada , "Mike Rapoport (IBM)" , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , "Paul E. McKenney" , Peter Zijlstra , Rong Xu , 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 Cc: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable the machine function split optimization for AutoFDO in Clang. Machine function split (MFS) is a pass in the Clang compiler that splits a function into hot and cold parts. The linker groups all cold blocks across functions together. This decreases hot code fragmentation and improves iCache and iTLB utilization. MFS requires a profile so this is enabled only for the AutoFDO builds. Co-developed-by: Han Shen Signed-off-by: Han Shen Signed-off-by: Rong Xu Suggested-by: Sriraman Tallam Suggested-by: Krzysztof Pszeniczny Tested-by: Yonghong Song Tested-by: Yabin Cui Tested-by: Nathan Chancellor Reviewed-by: Kees Cook --- include/asm-generic/vmlinux.lds.h | 7 ++++++- scripts/Makefile.autofdo | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index bd64fdedabd2f..8a0bb3946cf05 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -556,6 +556,11 @@ defined(CONFIG_AUTOFDO_CLANG) __cpuidle_text_end =3D .; \ __noinstr_text_end =3D .; =20 +#define TEXT_SPLIT \ + __split_text_start =3D .; \ + *(.text.split .text.split.[0-9a-zA-Z_]*) \ + __split_text_end =3D .; + #define TEXT_UNLIKELY \ __unlikely_text_start =3D .; \ *(.text.unlikely .text.unlikely.*) \ @@ -582,6 +587,7 @@ defined(CONFIG_AUTOFDO_CLANG) ALIGN_FUNCTION(); \ *(.text.asan.* .text.tsan.*) \ *(.text.unknown .text.unknown.*) \ + TEXT_SPLIT \ TEXT_UNLIKELY \ . =3D ALIGN(PAGE_SIZE); \ TEXT_HOT \ @@ -589,7 +595,6 @@ defined(CONFIG_AUTOFDO_CLANG) NOINSTR_TEXT \ *(.ref.text) =20 - /* sched.text is aling to function alignment to secure we have same * address even at second ld pass when generating System.map */ #define SCHED_TEXT \ diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo index 6155d6fc4ca7f..1caf2457e585c 100644 --- a/scripts/Makefile.autofdo +++ b/scripts/Makefile.autofdo @@ -10,6 +10,7 @@ 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 endif =20 ifdef CONFIG_LTO_CLANG_THIN @@ -17,6 +18,7 @@ ifdef CONFIG_LTO_CLANG_THIN KBUILD_LDFLAGS +=3D --lto-sample-profile=3D$(CLANG_AUTOFDO_PROFILE) endif KBUILD_LDFLAGS +=3D --mllvm=3D-enable-fs-discriminator=3Dtrue --mllvm=3D= -improved-fs-discriminator=3Dtrue -plugin-opt=3Dthinlto + KBUILD_LDFLAGS +=3D -plugin-opt=3D-split-machine-functions endif =20 export CFLAGS_AUTOFDO_CLANG --=20 2.47.0.163.g1226f6d8fa-goog