From c47782e93ed2c1619f15840a83530bc93aa165ea Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Mon, 31 Mar 2025 23:57:56 +0200 Subject: [PATCH 1/4] Add support for PYPERF_CPU_AFFINITY --- bench_runner/templates/_benchmark.src.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bench_runner/templates/_benchmark.src.yml b/bench_runner/templates/_benchmark.src.yml index bd58badd..0f65dda0 100644 --- a/bench_runner/templates/_benchmark.src.yml +++ b/bench_runner/templates/_benchmark.src.yml @@ -221,7 +221,7 @@ jobs: - name: Tune system if: ${{ steps.should_run.outputs.should_run != 'false' }} run: | - sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH venv/bin/python -m pyperf system ${{ inputs.perf && 'reset' || 'tune' }} + sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH venv/bin/python -m pyperf system ${{ inputs.perf && 'reset' || 'tune ${PYPERF_CPU_AFFINITY:+--affinity="$PYPERF_CPU_AFFINITY"}' }} - name: Tune for (Linux) perf if: ${{ steps.should_run.outputs.should_run != 'false' && inputs.perf }} run: | @@ -232,6 +232,10 @@ jobs: run: | rm -rf ~/.debug/* venv/bin/python -m bench_runner run_benchmarks ${{ inputs.perf && 'perf' || 'benchmark' }} cpython/python ${{ inputs.fork }} ${{ inputs.ref }} ${{ inputs.benchmarks || 'all' }} ${{ env.flags }} --run_id ${{ github.run_id }} + - name: Untune system + if: ${{ steps.should_run.outputs.should_run != 'false' }} + run: | + sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH venv/bin/python -m pyperf system reset # Pull again, since another job may have committed results in the meantime - name: Pull benchmarking if: ${{ steps.should_run.outputs.should_run != 'false' && !inputs.perf }} From 022a5db7259d3d7c63c51403e9b030596d85c288 Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Tue, 1 Apr 2025 00:27:42 +0200 Subject: [PATCH 2/4] Run pyperformance with --affinity if CPU_AFFINITY (renamed from PYPERF_CPU_AFFINITY) is set, as well. --- bench_runner/scripts/run_benchmarks.py | 3 +++ bench_runner/templates/_benchmark.src.yml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bench_runner/scripts/run_benchmarks.py b/bench_runner/scripts/run_benchmarks.py index d677b8be..e502f841 100644 --- a/bench_runner/scripts/run_benchmarks.py +++ b/bench_runner/scripts/run_benchmarks.py @@ -82,6 +82,9 @@ def run_benchmarks( if extra_args is None: extra_args = [] + if (affinity := os.environ.get('CPU_AFFINITY')): + extra_args.append(f'--affinity={affinity}') + args = [ sys.executable, "-m", diff --git a/bench_runner/templates/_benchmark.src.yml b/bench_runner/templates/_benchmark.src.yml index 0f65dda0..3072073f 100644 --- a/bench_runner/templates/_benchmark.src.yml +++ b/bench_runner/templates/_benchmark.src.yml @@ -221,7 +221,7 @@ jobs: - name: Tune system if: ${{ steps.should_run.outputs.should_run != 'false' }} run: | - sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH venv/bin/python -m pyperf system ${{ inputs.perf && 'reset' || 'tune ${PYPERF_CPU_AFFINITY:+--affinity="$PYPERF_CPU_AFFINITY"}' }} + sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH venv/bin/python -m pyperf system ${{ inputs.perf && 'reset' || 'tune ${CPU_AFFINITY:+--affinity="$CPU_AFFINITY"}' }} - name: Tune for (Linux) perf if: ${{ steps.should_run.outputs.should_run != 'false' && inputs.perf }} run: | From 40a44f23fdf184c347aba91e3995fe46170f5cea Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Fri, 4 Apr 2025 13:49:03 +0200 Subject: [PATCH 3/4] Reformat. --- bench_runner/scripts/run_benchmarks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bench_runner/scripts/run_benchmarks.py b/bench_runner/scripts/run_benchmarks.py index e502f841..566120e0 100644 --- a/bench_runner/scripts/run_benchmarks.py +++ b/bench_runner/scripts/run_benchmarks.py @@ -82,8 +82,8 @@ def run_benchmarks( if extra_args is None: extra_args = [] - if (affinity := os.environ.get('CPU_AFFINITY')): - extra_args.append(f'--affinity={affinity}') + if affinity := os.environ.get("CPU_AFFINITY"): + extra_args.append(f"--affinity={affinity}") args = [ sys.executable, From bc9107b203304a17d4858f1fe7a48b4763d15b2b Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Fri, 4 Apr 2025 13:59:33 +0200 Subject: [PATCH 4/4] Fix pyright error. --- bench_runner/scripts/run_benchmarks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench_runner/scripts/run_benchmarks.py b/bench_runner/scripts/run_benchmarks.py index 566120e0..a5db8884 100644 --- a/bench_runner/scripts/run_benchmarks.py +++ b/bench_runner/scripts/run_benchmarks.py @@ -66,7 +66,7 @@ def run_benchmarks( benchmarks: str, /, test_mode: bool = False, - extra_args: Iterable[str] | None = None, + extra_args: list[str] | None = None, ) -> None: if benchmarks.strip() == "": benchmarks = "all"