Skip to content

Commit 10804b3

Browse files
committed
[Benchmarks] Pin benchmarks to small set of cores
For better results stability, pin benchmark binaries to four cores with the maximum available frequency.
1 parent 574ba2b commit 10804b3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

devops/actions/run-tests/benchmark/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ runs:
7979
shell: bash
8080
run: |
8181
# Compute the core range for the first NUMA node; second node is used by
82-
# UMF. Skip the first 4 cores as the kernel is likely to schedule more
82+
# UMF. Skip the first 3 cores as the kernel is likely to schedule more
8383
# work on these.
8484
CORES="$(lscpu | awk '
8585
/NUMA node0 CPU|On-line CPU/ {line=$0}
8686
END {
8787
split(line, a, " ")
8888
split(a[4], b, ",")
89-
sub(/^0/, "4", b[1])
89+
sub(/^0/, "3", b[1])
9090
print b[1]
9191
}')"
9292
echo "CPU core range to use: $CORES"

devops/scripts/benchmarks/benches/compute.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from enum import Enum
1111
from itertools import product
1212
from pathlib import Path
13+
from psutil import Process
1314

1415
from git_project import GitProject
1516
from options import options
@@ -417,6 +418,24 @@ def run(
417418
command += self.bin_args(run_trace)
418419
env_vars.update(self.extra_env_vars())
419420

421+
# Pin compute benchmarks to a CPU cores set to ensure consistent results
422+
# and non-zero CPU count measurements (e.g. avoid E-cores). 4 max freq cores
423+
# are pinned by default to satisfy multiple threads benchmarks.
424+
425+
available_cores = Process().cpu_affinity()
426+
# Get 4 cores with the highest available frequency.
427+
core_frequencies = []
428+
for core in available_cores:
429+
with open(
430+
f"/sys/devices/system/cpu/cpu{core}/cpufreq/cpuinfo_max_freq"
431+
) as f:
432+
freq = int(f.read().strip())
433+
core_frequencies.append((core, freq))
434+
core_frequencies.sort(key=lambda x: x[1], reverse=True)
435+
available_cores = [core for core, _ in core_frequencies[:4]]
436+
437+
command = ["taskset", "-c"] + [str(core) for core in available_cores] + command
438+
420439
result = self.run_bench(
421440
command, env_vars, run_trace=run_trace, force_trace=force_trace
422441
)

0 commit comments

Comments
 (0)