From 2b2e637652902d2da1f9c97f47df4d2c2184aa42 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Mon, 18 Nov 2024 22:12:57 +0000 Subject: [PATCH] Add support for explicitly request a specific scaling governor Signed-off-by: Stefan Marr --- rebench/denoise.py | 32 +++++++++++++++++++++++++------- rebench/denoise_client.py | 5 ++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/rebench/denoise.py b/rebench/denoise.py index ec7f1347..57dbf6c3 100644 --- a/rebench/denoise.py +++ b/rebench/denoise.py @@ -186,6 +186,7 @@ def _reset_shielding() -> Union[str, bool]: # For intel_pstate systems, there's only powersave and performance SCALING_GOVERNOR_POWERSAVE = "powersave" SCALING_GOVERNOR_PERFORMANCE = "performance" +DEFAULT_SCALING_GOVERNOR = SCALING_GOVERNOR_PERFORMANCE def _read_scaling_governor() -> Optional[str]: @@ -201,10 +202,12 @@ def _read_scaling_governor() -> Optional[str]: def _set_scaling_governor(governor, num_cores) -> str: - assert governor in (SCALING_GOVERNOR_POWERSAVE, SCALING_GOVERNOR_PERFORMANCE), ( - "The scaling governor is expected to be 'performance' or 'powersave', but was " - + governor - ) + if governor not in (SCALING_GOVERNOR_POWERSAVE, SCALING_GOVERNOR_PERFORMANCE): + print( + "The scaling governor is expected to be 'performance' or 'powersave', but was " + + governor + ) + sys.exit(EXIT_CODE_INVALID_SETTINGS) if not num_cores: return "failed: num-cores not set" @@ -368,9 +371,8 @@ def _minimize_noise(args) -> dict: result["no_turbo"] = "succeeded" if r is True else r if args.use_scaling_governor: - result["scaling_governor"] = _set_scaling_governor( - SCALING_GOVERNOR_PERFORMANCE, num_cores - ) + scaling_governor = args.scaling_governor or DEFAULT_SCALING_GOVERNOR + result["scaling_governor"] = _set_scaling_governor(scaling_governor, num_cores) if args.use_mini_perf_sampling: r = _configure_perf_sampling(args.for_profiling) @@ -515,6 +517,14 @@ def _shell_options(): dest="use_scaling_governor", help="Don't try setting scaling governor", ) + parser.add_argument( + "-g", + "--governor", + action="store", + default=None, + dest="scaling_governor", + help=f"Scaling Governor to set. Default value is '{DEFAULT_SCALING_GOVERNOR}'.", + ) parser.add_argument( "-P", "--without-min-perf-sampling", @@ -564,6 +574,7 @@ def _shell_options(): EXIT_CODE_NUM_CORES_UNSET = 2 EXIT_CODE_NO_COMMAND_SELECTED = 3 EXIT_CODE_EXEC_FAILED = 4 +EXIT_CODE_INVALID_SETTINGS = 5 def _report_init(result: dict, args): @@ -630,6 +641,13 @@ def main_func(): paths.set_cset(args.cset_path) + if args.use_scaling_governor is False and args.scaling_governor is not None: + print( + "Error: Option -g|--governor can only be set " + "when --without-scaling-governor is not set." + ) + return EXIT_CODE_INVALID_SETTINGS + result = {} if args.command == "init": diff --git a/rebench/denoise_client.py b/rebench/denoise_client.py index ed02b2b5..50809ee3 100644 --- a/rebench/denoise_client.py +++ b/rebench/denoise_client.py @@ -6,7 +6,7 @@ from typing import Optional, Tuple from cpuinfo import get_cpu_info -from .denoise import paths +from .denoise import paths, DEFAULT_SCALING_GOVERNOR from .model.denoise import Denoise from .output import output_as_str from .ui import escape_braces @@ -120,6 +120,9 @@ def _add_denoise_options(cmd: list[str], requested: Denoise): options_to_disable += "S" if not requested.requested_scaling_governor: options_to_disable += "G" + elif requested.scaling_governor != DEFAULT_SCALING_GOVERNOR: + cmd.append("-g") + cmd.append(requested.scaling_governor) if not requested.requested_no_turbo: options_to_disable += "T" if not requested.requested_minimize_perf_sampling: