Skip to content

Commit e5b651a

Browse files
committed
Pin benchmarks to 4 cores in all suites
1 parent 394029a commit e5b651a

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

devops/scripts/benchmarks/benches/base.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
import os
77
import shutil
88
import subprocess
9-
from pathlib import Path
9+
from abc import ABC, abstractmethod
1010
from enum import Enum
11-
from utils.result import BenchmarkMetadata, BenchmarkTag, Result
11+
from pathlib import Path
12+
13+
from psutil import Process
14+
1215
from options import options
13-
from utils.utils import download, run
14-
from abc import ABC, abstractmethod
15-
from utils.unitrace import get_unitrace
1616
from utils.flamegraph import get_flamegraph
1717
from utils.logger import log
18+
from utils.result import BenchmarkMetadata, BenchmarkTag, Result
19+
from utils.unitrace import get_unitrace
20+
from utils.utils import download, run
1821

1922

2023
class TracingType(Enum):
@@ -167,6 +170,8 @@ def run_bench(
167170
log.debug(f"FlameGraph perf data: {perf_data_file}")
168171
log.debug(f"FlameGraph command: {' '.join(command)}")
169172

173+
command = self.taskset_cmd() + command
174+
170175
try:
171176
result = run(
172177
command=command,
@@ -268,6 +273,24 @@ def get_metadata(self) -> dict[str, BenchmarkMetadata]:
268273
)
269274
}
270275

276+
def taskset_cmd(self) -> list[str]:
277+
"""Returns a list of strings with taskset usage for core pinning.
278+
Pin compute benchmarks to a CPU cores set to ensure consistent results
279+
and non-zero CPU count measurements (e.g. avoid E-cores). Exactly 4 cores
280+
with the maximum frequency are pinned by default to satisfy multiple threads benchmarks.
281+
"""
282+
available_cores = Process().cpu_affinity()
283+
core_frequencies = []
284+
for core in available_cores: # type: ignore
285+
with open(
286+
f"/sys/devices/system/cpu/cpu{core}/cpufreq/cpuinfo_max_freq"
287+
) as f:
288+
freq = int(f.read().strip())
289+
core_frequencies.append((core, freq))
290+
core_frequencies.sort(key=lambda x: x[1], reverse=True)
291+
cores_list = ",".join([str(core) for core, _ in core_frequencies[:4]])
292+
return ["taskset", "-c", cores_list]
293+
271294

272295
class Suite(ABC):
273296
@abstractmethod

devops/scripts/benchmarks/benches/compute.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6-
import copy
76
import csv
87
import io
98
import math
109
from enum import Enum
1110
from itertools import product
1211
from pathlib import Path
13-
from psutil import Process
1412

1513
from git_project import GitProject
1614
from options import options
@@ -418,24 +416,6 @@ def run(
418416
command += self.bin_args(run_trace)
419417
env_vars.update(self.extra_env_vars())
420418

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-
available_cores = Process().cpu_affinity()
425-
# Get 4 cores with the highest available frequency.
426-
core_frequencies = []
427-
for core in available_cores:
428-
with open(
429-
f"/sys/devices/system/cpu/cpu{core}/cpufreq/cpuinfo_max_freq"
430-
) as f:
431-
freq = int(f.read().strip())
432-
core_frequencies.append((core, freq))
433-
core_frequencies.sort(key=lambda x: x[1], reverse=True)
434-
available_cores = [core for core, _ in core_frequencies[:4]]
435-
cores_list = ",".join([str(core) for core in available_cores])
436-
437-
command = ["taskset", "-c", cores_list] + command
438-
439419
result = self.run_bench(
440420
command, env_vars, run_trace=run_trace, force_trace=force_trace
441421
)

0 commit comments

Comments
 (0)