|
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): |
@@ -151,6 +154,8 @@ def run_bench( |
151 | 154 | log.debug(f"FlameGraph perf data: {perf_data_file}") |
152 | 155 | log.debug(f"FlameGraph command: {' '.join(command)}") |
153 | 156 |
|
| 157 | + command = self.taskset_cmd() + command |
| 158 | + |
154 | 159 | try: |
155 | 160 | result = run( |
156 | 161 | command=command, |
@@ -252,6 +257,16 @@ def get_metadata(self) -> dict[str, BenchmarkMetadata]: |
252 | 257 | ) |
253 | 258 | } |
254 | 259 |
|
| 260 | + def taskset_cmd(self) -> list[str]: |
| 261 | + """Returns a list of strings with taskset usage for core pinning. |
| 262 | + Pin compute benchmarks to a CPU cores set to ensure consistent results |
| 263 | + and non-zero CPU count measurements (e.g. avoid E-cores). Exactly 4 cores |
| 264 | + are pinned by default to satisfy multiple threads benchmarks. It is assumed |
| 265 | + that they have the maximum, or at least similar, frequency. |
| 266 | + """ |
| 267 | + selected_cores = [str(core) for core in Process().cpu_affinity()[:4]] # type: ignore |
| 268 | + return ["taskset", "-c", ",".join(selected_cores)] |
| 269 | + |
255 | 270 | @staticmethod |
256 | 271 | def get_adapter_full_path(): |
257 | 272 | for libs_dir_name in ["lib", "lib64"]: |
|
0 commit comments