[clang] [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf (PR #119117)

Tom Stellard via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 7 22:09:02 PST 2024


https://github.com/tstellar created https://github.com/llvm/llvm-project/pull/119117

This fixes the llvm-support build that generates the profile data. However, I'm wondering if maybe we should disable llvm-suppot and only run hello-world with -DCLANG_BOLT=perf.  The bolt optimizations with perf only give about a 3% performance increase (although maybe with hw counters this would be better) and it takes a very long time to convert all the perf profiles to the fdata format.

>From 1760788d8decf90791044e199564e8336110b713 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Thu, 5 Dec 2024 15:01:27 +0000
Subject: [PATCH] [clang][perf-training] Fix profiling with -DCLANG_BOLT=perf

This fixes the llvm-support build that generates the profile data.
However, I'm wondering if maybe we should disable llvm-suppot and
only run hello-world with -DCLANG_BOLT=perf.  The bolt optimizations
with perf only give about a 3% performance increase (although maybe
with hw counters this would be better) and it takes a very long
time to convert all the perf profiles to the fdata format.
---
 clang/utils/perf-training/bolt.lit.cfg        | 22 +++++++++++++++----
 .../perf-training/llvm-support/build.test     |  4 ++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/clang/utils/perf-training/bolt.lit.cfg b/clang/utils/perf-training/bolt.lit.cfg
index 1d0cf9a8a17a8e..7687a5a5cd2e68 100644
--- a/clang/utils/perf-training/bolt.lit.cfg
+++ b/clang/utils/perf-training/bolt.lit.cfg
@@ -8,21 +8,32 @@ import subprocess
 
 clang_bolt_mode = config.clang_bolt_mode.lower()
 clang_binary = "clang"
-perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py perf "
+perf_wrapper = f"{config.python_exe} {config.perf_helper_dir}/perf-helper.py perf"
 
 if clang_bolt_mode == "instrument":
     perf_wrapper = ""
     clang_binary = config.clang_bolt_name
 elif clang_bolt_mode == "lbr":
-    perf_wrapper += " --lbr -- "
+    perf_wrapper += " --lbr --"
 elif clang_bolt_mode == "perf":
-    perf_wrapper += " -- "
+    perf_wrapper += " --"
 else:
     assert 0, "Unsupported CLANG_BOLT_MODE variable"
 
-config.clang = perf_wrapper + os.path.realpath(
+clang_nowrapper = os.path.realpath(
     lit.util.which(clang_binary, config.clang_tools_dir)
 ).replace("\\", "/")
+config.clang = f'{perf_wrapper} {clang_nowrapper}'
+
+# We need to limit the number of build jobs with perf in order to avoid this
+# error:
+# 
+# | Permission error mapping pages.
+# | Consider increasing /proc/sys/kernel/perf_event_mlock_kb,
+# | or try again with a smaller value of -m/--mmap_pages.
+ninja_args = ""
+if ninja_args != "instrument":
+    ninja_args = "-j1"
 
 config.name = "Clang Perf Training"
 config.suffixes = [
@@ -52,3 +63,6 @@ config.substitutions.append(("%test_root", config.test_exec_root))
 config.substitutions.append(('%cmake_generator', config.cmake_generator))
 config.substitutions.append(('%cmake', config.cmake_exe))
 config.substitutions.append(('%llvm_src_dir', config.llvm_src_dir))
+config.substitutions.append(('%perf_cmake_compiler_launcher', perf_wrapper.replace(' ', ';')))
+config.substitutions.append(('%nowrapper_clang', clang_nowrapper))
+config.substitutions.append(('%ninja_args', ninja_args))
diff --git a/clang/utils/perf-training/llvm-support/build.test b/clang/utils/perf-training/llvm-support/build.test
index f29a594c846869..1f4d76502a3757 100644
--- a/clang/utils/perf-training/llvm-support/build.test
+++ b/clang/utils/perf-training/llvm-support/build.test
@@ -1,2 +1,2 @@
-RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir -DCMAKE_C_COMPILER=%clang -DCMAKE_CXX_COMPILER=%clang -DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
-RUN: %cmake --build %t -v --target LLVMSupport
+RUN: %cmake -G %cmake_generator -B %t -S %llvm_src_dir -DCMAKE_CXX_COMPILER_LAUNCHER="%perf_cmake_compiler_launcher" -DCMAKE_C_COMPILER="%nowrapper_clang" -DCMAKE_CXX_COMPILER="%nowrapper_clang" -DCMAKE_CXX_FLAGS="--driver-mode=g++" -DCMAKE_BUILD_TYPE=Release
+RUN: %cmake --build %t %ninja_args -v --target LLVMSupport



More information about the cfe-commits mailing list