|
6 | 6 | import os |
7 | 7 | import shutil |
8 | 8 | import subprocess |
9 | | -from pathlib import Path |
| 9 | +from abc import ABC, abstractmethod |
10 | 10 | from enum import Enum |
11 | | -from utils.result import BenchmarkMetadata, BenchmarkTag, Result |
| 11 | +from pathlib import Path |
| 12 | + |
| 13 | +from psutil import Process |
| 14 | + |
12 | 15 | from options import options |
13 | | -from utils.utils import download, run |
14 | | -from abc import ABC, abstractmethod |
15 | | -from utils.unitrace import get_unitrace |
16 | 16 | from utils.flamegraph import get_flamegraph |
17 | 17 | 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 |
18 | 21 |
|
19 | 22 |
|
20 | 23 | class TracingType(Enum): |
@@ -167,6 +170,8 @@ def run_bench( |
167 | 170 | log.debug(f"FlameGraph perf data: {perf_data_file}") |
168 | 171 | log.debug(f"FlameGraph command: {' '.join(command)}") |
169 | 172 |
|
| 173 | + command = self.taskset_cmd() + command |
| 174 | + |
170 | 175 | try: |
171 | 176 | result = run( |
172 | 177 | command=command, |
@@ -268,6 +273,24 @@ def get_metadata(self) -> dict[str, BenchmarkMetadata]: |
268 | 273 | ) |
269 | 274 | } |
270 | 275 |
|
| 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 | + |
271 | 294 |
|
272 | 295 | class Suite(ABC): |
273 | 296 | @abstractmethod |
|
0 commit comments