From 8699afc51fc0b1e581675fdd8ba53cab0fc1be1d Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 14 Jan 2025 13:19:29 -0600 Subject: [PATCH 1/7] Add BOLT support to reusable Ubuntu workflow --- .github/workflows/reusable-ubuntu.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/reusable-ubuntu.yml b/.github/workflows/reusable-ubuntu.yml index 46c542940c8483..a30eb1834c8756 100644 --- a/.github/workflows/reusable-ubuntu.yml +++ b/.github/workflows/reusable-ubuntu.yml @@ -11,6 +11,11 @@ on: required: false type: boolean default: false + bolt-optimizations: + description: Whether to enable BOLT optimizations + required: false + type: boolean + default: false os: description: OS to run the job required: true @@ -81,6 +86,7 @@ jobs: --enable-safety --with-openssl="$OPENSSL_DIR" ${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }} + ${{ fromJSON(inputs.bolt-optimizations) && '--enable-bolt' || '' }} - name: Build CPython out-of-tree if: ${{ inputs.free-threading }} working-directory: ${{ env.CPYTHON_BUILDDIR }} From 254b55315ba8002e3b1a506a2af84691aeba9010 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 14 Jan 2025 13:22:03 -0600 Subject: [PATCH 2/7] Add BOLT to build matrix --- .github/workflows/build.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9adf860632e8a2..112bb366fffab8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -231,6 +231,7 @@ jobs: name: >- Ubuntu ${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }} + ${{ fromJSON(matrix.bolt) && '(bolt)' || '' }} needs: check_source if: needs.check_source.outputs.run_tests == 'true' strategy: @@ -238,6 +239,9 @@ jobs: free-threading: - false - true + bolt: + - false + - true os: - ubuntu-24.04 - ubuntu-24.04-aarch64 @@ -246,10 +250,14 @@ jobs: exclude: - os: ubuntu-24.04-aarch64 is-fork: true + # Do not test BOLT with free-threading, to conserve resources + - bolt: true + free-threading: true uses: ./.github/workflows/reusable-ubuntu.yml with: config_hash: ${{ needs.check_source.outputs.config_hash }} free-threading: ${{ matrix.free-threading }} + bolt-optimizations: ${{ matrix.bolt }} os: ${{ matrix.os }} build_ubuntu_ssltests: From 9b179cb3006b311b686b4ee198ef0136ce058299 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 14 Jan 2025 14:04:55 -0600 Subject: [PATCH 3/7] Install Clang Copied from the JIT workflow --- .github/workflows/reusable-ubuntu.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/reusable-ubuntu.yml b/.github/workflows/reusable-ubuntu.yml index a30eb1834c8756..e198c1a1440373 100644 --- a/.github/workflows/reusable-ubuntu.yml +++ b/.github/workflows/reusable-ubuntu.yml @@ -39,6 +39,12 @@ jobs: run: echo "::add-matcher::.github/problem-matchers/gcc.json" - name: Install dependencies run: sudo ./.github/workflows/posix-deps-apt.sh + - name: Install Clang + if: ${{ fromJSON(inputs.bolt-optimizations) }} + run: | + sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh 19 + sudo apt-get install bolt-19 + echo PATH="$(llvm-config-19 --bindir):$PATH" >> $GITHUB_ENV - name: Configure OpenSSL env vars run: | echo "MULTISSL_DIR=${GITHUB_WORKSPACE}/multissl" >> "$GITHUB_ENV" From 684ece4831d2ae6462a9b030f7d8b198c1214280 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 14 Jan 2025 17:02:56 -0600 Subject: [PATCH 4/7] Skip BOLT CI on aarch64 --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 112bb366fffab8..c6866f0fe8329f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -253,6 +253,9 @@ jobs: # Do not test BOLT with free-threading, to conserve resources - bolt: true free-threading: true + # BOLT currently crashes during instrumentation on aarch64 + - os: ubuntu-24.04-aarch64 + bolt: true uses: ./.github/workflows/reusable-ubuntu.yml with: config_hash: ${{ needs.check_source.outputs.config_hash }} From 03be9327c5e98a018dd5444b1bf2f8c79dc91698 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 14 Jan 2025 17:04:42 -0600 Subject: [PATCH 5/7] Ignore `test_unpickle_module_race` during BOLT profiling --- .github/workflows/reusable-ubuntu.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-ubuntu.yml b/.github/workflows/reusable-ubuntu.yml index e198c1a1440373..0c3e2863f49429 100644 --- a/.github/workflows/reusable-ubuntu.yml +++ b/.github/workflows/reusable-ubuntu.yml @@ -39,7 +39,7 @@ jobs: run: echo "::add-matcher::.github/problem-matchers/gcc.json" - name: Install dependencies run: sudo ./.github/workflows/posix-deps-apt.sh - - name: Install Clang + - name: Install Clang and BOLT if: ${{ fromJSON(inputs.bolt-optimizations) }} run: | sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh 19 @@ -84,7 +84,10 @@ jobs: key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }} - name: Configure CPython out-of-tree working-directory: ${{ env.CPYTHON_BUILDDIR }} + # `test_unpickle_module_race` writes to the source directory, which is + # read-only during builds — so we exclude it from profiling with BOLT. run: >- + PROFILE_TASK='-m test --pgo --ignore test_unpickle_module_race' ../cpython-ro-srcdir/configure --config-cache --with-pydebug From 01cb8d821fb23d0d9f5040f0e04da5eb156e3322 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 15 Jan 2025 08:45:16 -0600 Subject: [PATCH 6/7] Skip perf trampoline tests when BOLT instrumented --- Lib/test/test_perf_profiler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py index 1e74990878007a..6f1fd8d38e4ea0 100644 --- a/Lib/test/test_perf_profiler.py +++ b/Lib/test/test_perf_profiler.py @@ -47,6 +47,7 @@ def tearDown(self) -> None: for file in files_to_delete: file.unlink() + @unittest.skipIf(support.check_bolt_optimized, "fails on BOLT instrumented binaries") def test_trampoline_works(self): code = """if 1: def foo(): @@ -100,6 +101,7 @@ def baz(): "Address should contain only hex characters", ) + @unittest.skipIf(support.check_bolt_optimized, "fails on BOLT instrumented binaries") def test_trampoline_works_with_forks(self): code = """if 1: import os, sys @@ -160,6 +162,7 @@ def baz(): self.assertIn(f"py::bar_fork:{script}", child_perf_file_contents) self.assertIn(f"py::baz_fork:{script}", child_perf_file_contents) + @unittest.skipIf(support.check_bolt_optimized, "fails on BOLT instrumented binaries") def test_sys_api(self): code = """if 1: import sys From 5f9c410c654afc06795e4fc798d57a3a24b25e54 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 16 Jan 2025 15:05:13 -0600 Subject: [PATCH 7/7] Move `bolt` flags into alphabetical order --- .github/workflows/build.yml | 6 +++--- .github/workflows/reusable-ubuntu.yml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c6866f0fe8329f..8a70cde3d8bc13 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -236,10 +236,10 @@ jobs: if: needs.check_source.outputs.run_tests == 'true' strategy: matrix: - free-threading: + bolt: - false - true - bolt: + free-threading: - false - true os: @@ -259,8 +259,8 @@ jobs: uses: ./.github/workflows/reusable-ubuntu.yml with: config_hash: ${{ needs.check_source.outputs.config_hash }} - free-threading: ${{ matrix.free-threading }} bolt-optimizations: ${{ matrix.bolt }} + free-threading: ${{ matrix.free-threading }} os: ${{ matrix.os }} build_ubuntu_ssltests: diff --git a/.github/workflows/reusable-ubuntu.yml b/.github/workflows/reusable-ubuntu.yml index 0c3e2863f49429..686e8fe1abc980 100644 --- a/.github/workflows/reusable-ubuntu.yml +++ b/.github/workflows/reusable-ubuntu.yml @@ -6,13 +6,13 @@ on: config_hash: required: true type: string - free-threading: - description: Whether to use free-threaded mode + bolt-optimizations: + description: Whether to enable BOLT optimizations required: false type: boolean default: false - bolt-optimizations: - description: Whether to enable BOLT optimizations + free-threading: + description: Whether to use free-threaded mode required: false type: boolean default: false