From patchwork Mon Oct 14 21:33:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Xu X-Patchwork-Id: 13835517 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 E335C1D8DEA for ; Mon, 14 Oct 2024 21:33:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728941636; cv=none; b=bZgCiu74ztv5CnxpfvpVXe09LkGaBzNQowLZJHftcett57ZtVYqDGuk1jBjfEWdg+CPQ+nALJbeb01JHFxU3LpFGyTmrBwtgIoBbNRbVfboZlAasR/QO93hC2C7nFDOfcZzB4c1O8tHpk9UXn+Rsi+02NRIXA4tMRfLobsxzKdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728941636; c=relaxed/simple; bh=sTdPsc9TlDcP9fj9qZnzf9a6N2MHYfNB5acRtfCguZg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DF6GfU2XWqzTUQw5M013nVBit1MUcN7rnn6ebkRfwq+Q0kEvSJWcrhckiMeC95hAHHWdcNo/2D1r/0nf+2/lRPl8dNqd3ZJxcjfD1UXV21K9ZHVdA21G+QcGYcqlFux438CvEx1ufPWa7jmzW0OOz7VG8BEdwg5F2KmFYozhv9o= 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=RNEU24Lw; arc=none smtp.client-ip=209.85.128.201 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="RNEU24Lw" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e000d68bb1so62704277b3.1 for ; Mon, 14 Oct 2024 14:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728941634; x=1729546434; 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=56GXdyw+jn4VfhhYEfGPQRjvArCzv+g18r0M8mTXpxs=; b=RNEU24LwnTXLNS72FqCmv4KscOL5uv+OvUTIFJ04Pm65a0YDPMeUtD5yXWX3nwzfOQ aoSSLhzocsZIxE08bUgINjyLuleO59iaeChKRlIaoXnzTPBxJqJvcgunYs5vJ7jTPVNM vekKSk1cCMtzzGAgnktS91vJSLKwhOntrpaacYnvgxeDki78uZbCf/pSozvILUAN2DuQ 2di421Tkvt/WNCkjLVJYpG8JuJiGr4UFWE2SkvyCMVTjBLmv06x8x4wTWCTNmznZPq7F VEGZ0aHJ3dOcwMgjmS3LveNHlUd7cga9chwB6DCW2KiMiVsXlJaKW5rXo4HcXra8mSdz 4bsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728941634; x=1729546434; 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=56GXdyw+jn4VfhhYEfGPQRjvArCzv+g18r0M8mTXpxs=; b=LxPX+TSSOYfAfB35c5Fe5hEJ7+5rD0YNx730naXLGhu6Mawiqn8XJTTc4QRrp3YVTT NqTyvdy3VTc1q7i+dcbQ3Huo1qI5j/8K7szHJVf/3CMn0NHL5Q5rlOfWgxpYOsLxhLYr Fq5NLu7xnItLwOsDvY1F5K9iPI3A52gtjNch6I9SFqUhGpKt1XwsBCxMOWs2/wZS+y/I qaAIbk0kMc7FB0iw2lTztZuNGLmeiQxbtVsQMSKCdBK6vc4IXpprqxwNd2pBfDEe7HHM +UuCrfD61dI8L26xdbTs2flj3TEAxLEjcdbKGSiMMx5BTM53WlpQsPFWNfC1Z1ehPNKY MGTA== X-Forwarded-Encrypted: i=1; AJvYcCVuJkFAhcNnbG2m3qWIt4cnCF++qknFnIuGv3p2Qc1/ktaEiumOeKJCOoGioKYZAMgPMhGY6ku35Nh1j2k=@vger.kernel.org X-Gm-Message-State: AOJu0YzUBI2xbOAJgpWJ+i1hNWqTlDkmqki2/N3jZ45vi7OHxgDaOLxy cKSWHTXUALx8aye6qloIycyuKWtJw3aDfUwfHog0HCb/5Rt76okusMgXfR/bPYCsig== X-Google-Smtp-Source: AGHT+IElzDMKPKvXfqSTVX42FLXp5sHgQoCjK84xdRuQSAgc4VkenrdwOMQ7N05Dp0YV3GIQSofstCY= X-Received: from xur.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2330]) (user=xur job=sendgmr) by 2002:a05:690c:2a48:b0:620:32ea:e1d4 with SMTP id 00721157ae682-6e3444b40ddmr1107757b3.0.1728941633949; Mon, 14 Oct 2024 14:33:53 -0700 (PDT) Date: Mon, 14 Oct 2024 14:33:39 -0700 In-Reply-To: <20241014213342.1480681-1-xur@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241014213342.1480681-1-xur@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241014213342.1480681-6-xur@google.com> Subject: [PATCH v4 5/6] 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 Cc: x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sriraman Tallam , Krzysztof Pszeniczny 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 --- include/asm-generic/vmlinux.lds.h | 6 ++++++ scripts/Makefile.autofdo | 2 ++ 2 files changed, 8 insertions(+) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index ace617d1af9b..20e46c0917db 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -565,9 +565,14 @@ defined(CONFIG_AUTOFDO_CLANG) __unlikely_text_start = .; \ *(.text.unlikely .text.unlikely.*) \ __unlikely_text_end = .; +#define TEXT_SPLIT \ + __split_text_start = .; \ + *(.text.split .text.split.[0-9a-zA-Z_]*) \ + __split_text_end = .; #else #define TEXT_HOT *(.text.hot .text.hot.*) #define TEXT_UNLIKELY *(.text.unlikely .text.unlikely.*) +#define TEXT_SPLIT #endif /* @@ -584,6 +589,7 @@ defined(CONFIG_AUTOFDO_CLANG) ALIGN_FUNCTION(); \ *(.text.asan.* .text.tsan.*) \ *(.text.unknown .text.unknown.*) \ + TEXT_SPLIT \ TEXT_UNLIKELY \ . = ALIGN(PAGE_SIZE); \ TEXT_HOT \ diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo index 9c9a530ef090..380042a301cc 100644 --- a/scripts/Makefile.autofdo +++ b/scripts/Makefile.autofdo @@ -11,6 +11,7 @@ endif ifdef CLANG_AUTOFDO_PROFILE CFLAGS_AUTOFDO_CLANG += -fprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -ffunction-sections + CFLAGS_AUTOFDO_CLANG += -fsplit-machine-functions endif ifdef CONFIG_LTO_CLANG_THIN @@ -18,6 +19,7 @@ ifdef CONFIG_LTO_CLANG_THIN KBUILD_LDFLAGS += --lto-sample-profile=$(CLANG_AUTOFDO_PROFILE) endif KBUILD_LDFLAGS += --mllvm=-enable-fs-discriminator=true --mllvm=-improved-fs-discriminator=true -plugin-opt=thinlto + KBUILD_LDFLAGS += -plugin-opt=-split-machine-functions endif export CFLAGS_AUTOFDO_CLANG