Skip to content

Commit d614b5a

Browse files
xur-llvmmasahir0y
authored andcommitted
AutoFDO: Enable machine function split optimization for AutoFDO
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 <[email protected]> Signed-off-by: Han Shen <[email protected]> Signed-off-by: Rong Xu <[email protected]> Suggested-by: Sriraman Tallam <[email protected]> Suggested-by: Krzysztof Pszeniczny <[email protected]> Tested-by: Yonghong Song <[email protected]> Tested-by: Yabin Cui <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 9d71957 commit d614b5a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/asm-generic/vmlinux.lds.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ defined(CONFIG_AUTOFDO_CLANG)
556556
__cpuidle_text_end = .; \
557557
__noinstr_text_end = .;
558558

559+
#define TEXT_SPLIT \
560+
__split_text_start = .; \
561+
*(.text.split .text.split.[0-9a-zA-Z_]*) \
562+
__split_text_end = .;
563+
559564
#define TEXT_UNLIKELY \
560565
__unlikely_text_start = .; \
561566
*(.text.unlikely .text.unlikely.*) \
@@ -582,14 +587,14 @@ defined(CONFIG_AUTOFDO_CLANG)
582587
ALIGN_FUNCTION(); \
583588
*(.text.asan.* .text.tsan.*) \
584589
*(.text.unknown .text.unknown.*) \
590+
TEXT_SPLIT \
585591
TEXT_UNLIKELY \
586592
. = ALIGN(PAGE_SIZE); \
587593
TEXT_HOT \
588594
*(TEXT_MAIN .text.fixup) \
589595
NOINSTR_TEXT \
590596
*(.ref.text)
591597

592-
593598
/* sched.text is aling to function alignment to secure we have same
594599
* address even at second ld pass when generating System.map */
595600
#define SCHED_TEXT \

scripts/Makefile.autofdo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ endif
1010

1111
ifdef CLANG_AUTOFDO_PROFILE
1212
CFLAGS_AUTOFDO_CLANG += -fprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -ffunction-sections
13+
CFLAGS_AUTOFDO_CLANG += -fsplit-machine-functions
1314
endif
1415

1516
ifdef CONFIG_LTO_CLANG_THIN
1617
ifdef CLANG_AUTOFDO_PROFILE
1718
KBUILD_LDFLAGS += --lto-sample-profile=$(CLANG_AUTOFDO_PROFILE)
1819
endif
1920
KBUILD_LDFLAGS += --mllvm=-enable-fs-discriminator=true --mllvm=-improved-fs-discriminator=true -plugin-opt=thinlto
21+
KBUILD_LDFLAGS += -plugin-opt=-split-machine-functions
2022
endif
2123

2224
export CFLAGS_AUTOFDO_CLANG

0 commit comments

Comments
 (0)