1# -*- coding: utf-8 -*- 2# 3# Copyright 2020 The Chromium OS Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6""" 7Utils for Crosperf to setup devices. 8 9This script provides utils to set device specs. It is only used by Crosperf 10to setup device before running tests. 11 12""" 13 14from __future__ import division 15 16import logging 17import re 18import time 19 20from contextlib import contextmanager 21 22 23def run_command_on_dut(dut, command, ignore_status=False): 24 """ 25 Helper function to run command on DUT. 26 27 @param dut: The autotest host object representing DUT. 28 @param command: The command to run on DUT. 29 @ignore_status: Whether to ignore failure executing command. 30 31 @returns Return code, stdout, and stderr. 32 33 """ 34 result = dut.run(command, ignore_status=ignore_status) 35 36 ret, msg, err_msg = result.exit_status, result.stdout, result.stderr 37 38 if ret: 39 err_msg = ('Command execution on DUT %s failed.\n' 40 'Failing command: %s\n' 41 'returned %d\n' 42 'Error message: %s' % (dut.hostname, command, ret, err_msg)) 43 if ignore_status: 44 logging.warning(err_msg) 45 logging.warning('Failure is considered non-fatal. Continue.') 46 else: 47 logging.error(err_msg) 48 49 return ret, msg, err_msg 50 51 52def disable_aslr(dut): 53 """ 54 Disable ASLR on DUT. 55 56 @param dut: The autotest host object representing DUT. 57 58 """ 59 disable_aslr = ('set -e; ' 60 'if [[ -e /proc/sys/kernel/randomize_va_space ]]; then ' 61 ' echo 0 > /proc/sys/kernel/randomize_va_space; ' 62 'fi') 63 logging.info('Disable ASLR.') 64 run_command_on_dut(dut, disable_aslr) 65 66 67def set_cpu_governor(dut, governor, ignore_status=False): 68 """ 69 Setup CPU Governor on DUT. 70 71 @param dut: The autotest host object representing DUT. 72 @param governor: CPU governor for DUT. 73 @ignore_status: Whether to ignore failure executing command. 74 75 @returns Return code of the command. 76 77 """ 78 set_gov_cmd = ( 79 'for f in `ls -d /sys/devices/system/cpu/cpu*/cpufreq 2>/dev/null`; do ' 80 # Skip writing scaling_governor if cpu is offline. 81 ' [[ -e ${f/cpufreq/online} ]] && grep -q 0 ${f/cpufreq/online} ' 82 ' && continue; ' 83 ' cd $f; ' 84 ' if [[ -e scaling_governor ]]; then ' 85 ' echo %s > scaling_governor; fi; ' 86 'done; ') 87 logging.info('Setup CPU Governor: %s.', governor) 88 ret, _, _ = run_command_on_dut( 89 dut, set_gov_cmd % governor, ignore_status=ignore_status) 90 return ret 91 92 93def disable_turbo(dut): 94 """ 95 Disable Turbo and Boost on DUT. 96 97 @param dut: The autotest host object representing DUT. 98 99 """ 100 dis_turbo_boost_cmd = ( 101 # Disable Turbo in the Intel pstate driver. 102 'if [[ -e /sys/devices/system/cpu/intel_pstate/no_turbo ]]; then ' 103 ' if grep -q 0 /sys/devices/system/cpu/intel_pstate/no_turbo; then ' 104 ' echo -n 1 > /sys/devices/system/cpu/intel_pstate/no_turbo; ' 105 ' fi; ' 106 'fi; ' 107 # Disable Boost on AMD. 108 'if [[ -e /sys/devices/system/cpu/cpufreq/boost ]]; then ' 109 ' if grep -q 1 /sys/devices/system/cpu/cpufreq/boost; then ' 110 ' echo -n 0 > /sys/devices/system/cpu/cpufreq/boost; ' 111 ' fi; ' 112 'fi; ' 113 ) 114 logging.info('Disable Turbo/Boost.') 115 run_command_on_dut(dut, dis_turbo_boost_cmd) 116 117 118def setup_cpu_usage(dut, cpu_usage): 119 """ 120 Setup CPU usage. 121 122 Based on dut_config['cpu_usage'] configure CPU cores utilization. 123 124 @param dut: The autotest host object representing DUT. 125 @param cpu_usage: Big/little core usage for CPU. 126 127 """ 128 129 if cpu_usage in ('big_only', 'little_only'): 130 _, arch, _ = run_command_on_dut(dut, 'uname -m') 131 132 if arch.lower().startswith('arm') or arch.lower().startswith('aarch64'): 133 setup_arm_cores(dut, cpu_usage) 134 135 136def setup_arm_cores(dut, cpu_usage): 137 """ 138 Setup ARM big/little cores. 139 140 @param dut: The autotest host object representing DUT. 141 @param cpu_usage: Big/little core usage for CPU. 142 143 """ 144 145 # CPU implemeters/part numbers of big/LITTLE CPU. 146 # Format: dict(CPU implementer: set(CPU part numbers)) 147 LITTLE_CORES = { 148 '0x41': { 149 '0xd01', # Cortex A32 150 '0xd03', # Cortex A53 151 '0xd04', # Cortex A35 152 '0xd05', # Cortex A55 153 }, 154 } 155 BIG_CORES = { 156 '0x41': { 157 '0xd07', # Cortex A57 158 '0xd08', # Cortex A72 159 '0xd09', # Cortex A73 160 '0xd0a', # Cortex A75 161 '0xd0b', # Cortex A76 162 }, 163 } 164 165 # Values of CPU Implementer and CPU part number are exposed by cpuinfo. 166 # Format: 167 # ================= 168 # processor : 0 169 # model name : ARMv8 Processor rev 4 (v8l) 170 # BogoMIPS : 48.00 171 # Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 172 # CPU implementer : 0x41 173 # CPU architecture: 8 174 # CPU variant : 0x0 175 # CPU part : 0xd03 176 # CPU revision : 4 177 178 _, cpuinfo, _ = run_command_on_dut(dut, 'cat /proc/cpuinfo') 179 180 # List of all CPU cores: 0, 1, .. 181 proc_matches = re.findall(r'^processor\s*: (\d+)$', cpuinfo, re.MULTILINE) 182 # List of all corresponding CPU implementers 183 impl_matches = re.findall(r'^CPU implementer\s*: (0x[\da-f]+)$', cpuinfo, 184 re.MULTILINE) 185 # List of all corresponding CPU part numbers 186 part_matches = re.findall(r'^CPU part\s*: (0x[\da-f]+)$', cpuinfo, 187 re.MULTILINE) 188 assert len(proc_matches) == len(impl_matches) 189 assert len(part_matches) == len(impl_matches) 190 191 all_cores = set(proc_matches) 192 dut_big_cores = { 193 core 194 for core, impl, part in zip(proc_matches, impl_matches, part_matches) 195 if impl in BIG_CORES and part in BIG_CORES[impl] 196 } 197 dut_lit_cores = { 198 core 199 for core, impl, part in zip(proc_matches, impl_matches, part_matches) 200 if impl in LITTLE_CORES and part in LITTLE_CORES[impl] 201 } 202 203 if cpu_usage == 'big_only': 204 cores_to_enable = dut_big_cores 205 cores_to_disable = all_cores - dut_big_cores 206 elif cpu_usage == 'little_only': 207 cores_to_enable = dut_lit_cores 208 cores_to_disable = all_cores - dut_lit_cores 209 else: 210 logging.warning( 211 'cpu_usage=%s is not supported on ARM.\n' 212 'Ignore ARM CPU setup and continue.', cpu_usage) 213 return 214 215 if cores_to_enable: 216 cmd_enable_cores = ( 217 'echo 1 | tee /sys/devices/system/cpu/cpu{%s}/online' % 218 ','.join(sorted(cores_to_enable))) 219 220 cmd_disable_cores = '' 221 if cores_to_disable: 222 cmd_disable_cores = ( 223 'echo 0 | tee /sys/devices/system/cpu/cpu{%s}/online' % 224 ','.join(sorted(cores_to_disable))) 225 226 run_command_on_dut(dut, '; '.join([cmd_enable_cores, 227 cmd_disable_cores])) 228 else: 229 # If there are no cores enabled by dut_config then configuration 230 # is invalid for current platform and should be ignored. 231 logging.warning( 232 '"cpu_usage" is invalid for targeted platform.\n' 233 'dut_config[cpu_usage]=%s\n' 234 'dut big cores: %s\n' 235 'dut little cores: %s\n' 236 'Ignore ARM CPU setup and continue.', 237 cpu_usage, dut_big_cores, dut_lit_cores) 238 239 240def get_cpu_online(dut): 241 """ 242 Get online status of CPU cores. 243 244 @param dut: The autotest host object representing DUT. 245 246 @returns dict of {int(cpu_num): <0|1>}. 247 248 """ 249 get_cpu_online_cmd = ('paste -d" "' 250 ' <(ls /sys/devices/system/cpu/cpu*/online)' 251 ' <(cat /sys/devices/system/cpu/cpu*/online)') 252 _, online_output_str, _ = run_command_on_dut(dut, get_cpu_online_cmd) 253 254 # Here is the output we expect to see: 255 # ----------------- 256 # /sys/devices/system/cpu/cpu0/online 0 257 # /sys/devices/system/cpu/cpu1/online 1 258 259 cpu_online = {} 260 cpu_online_match = re.compile(r'^[/\S]+/cpu(\d+)/[/\S]+\s+(\d+)$') 261 for line in online_output_str.splitlines(): 262 match = cpu_online_match.match(line) 263 if match: 264 cpu = int(match.group(1)) 265 status = int(match.group(2)) 266 cpu_online[cpu] = status 267 # There are platforms where CPU0 can't be disables and 268 # corresponding online file is not exposed. 269 # We need to add core 0 if it is present in the list of all online 270 # CPU cores. 271 get_all_online_cmd = 'cat /sys/devices/system/cpu/online' 272 _, all_online_str, _ = run_command_on_dut(dut, get_all_online_cmd) 273 # If cpu0 not in the online list and it exists in all online CPUs 274 # add it to the online list. 275 if 0 not in cpu_online and '0' in all_online_str: 276 # Add core0 to online cores. 277 cpu_online[0] = 1 278 # At least one CPU has to be online. 279 assert cpu_online 280 281 return cpu_online 282 283 284def setup_cpu_freq(dut, freq_percent, online_cores): 285 """Setup CPU frequency. 286 287 Based on dut_config['cpu_freq_pct'] setup frequency of online CPU cores 288 to a supported value which is less or equal to (freq_pct * max_freq / 100) 289 limited by min_freq. 290 291 NOTE: scaling_available_frequencies support is required. 292 Otherwise the function has no effect. 293 294 @param dut: The autotest host object representing DUT. 295 @param freq_percent: Frequency of online CPU cores to set. 296 @param online_cores: List of online cores (non-empty). 297 298 """ 299 if len(online_cores) == 1: 300 cpu_list_shell_str = str(online_cores[0]) 301 else: 302 cpu_list_shell_str = '{' + ','.join(str(core) 303 for core in online_cores) + '}' 304 list_all_avail_freq_cmd = ('ls /sys/devices/system/cpu/cpu' + 305 cpu_list_shell_str + 306 '/cpufreq/scaling_available_frequencies') 307 # Ignore error to support general usage of frequency setup. 308 # Not all platforms support scaling_available_frequencies. 309 ret, all_avail_freq_str, _ = run_command_on_dut(dut, 310 list_all_avail_freq_cmd, 311 ignore_status=True) 312 if ret or not all_avail_freq_str: 313 # No scalable frequencies available for the core. 314 return ret 315 for avail_freq_path in all_avail_freq_str.split(): 316 # Get available freq from every scaling_available_frequency path. 317 # Error is considered fatal in run_command_on_dut(). 318 _, avail_freq_str, _ = run_command_on_dut(dut, 'cat ' + avail_freq_path) 319 assert avail_freq_str 320 321 all_avail_freq = sorted( 322 int(freq_str) for freq_str in avail_freq_str.split()) 323 min_freq = all_avail_freq[0] 324 max_freq = all_avail_freq[-1] 325 # Calculate the frequency we are targeting. 326 target_freq = round(max_freq * freq_percent / 100) 327 # More likely it's not in the list of supported frequencies 328 # and our goal is to find the one which is less or equal. 329 # Default is min and we will try to maximize it. 330 avail_ngt_target = min_freq 331 # Find the largest not greater than the target. 332 for next_largest in reversed(all_avail_freq): 333 if next_largest <= target_freq: 334 avail_ngt_target = next_largest 335 break 336 337 max_freq_path = avail_freq_path.replace('scaling_available_frequencies', 338 'scaling_max_freq') 339 min_freq_path = avail_freq_path.replace('scaling_available_frequencies', 340 'scaling_min_freq') 341 # With default ignore_status=False we expect 0 status or Fatal error. 342 run_command_on_dut( 343 dut, 'echo %s | tee %s %s' % 344 (avail_ngt_target, max_freq_path, min_freq_path)) 345 346 347def wait_cooldown(dut, cooldown_time, cooldown_temp): 348 """ 349 Wait for DUT to cool down to certain temperature. 350 351 @param cooldown_time: Cooldown timeout. 352 @param cooldown_temp: Temperature to cooldown to. 353 354 @returns Cooldown wait time. 355 356 """ 357 waittime = 0 358 timeout_in_sec = int(cooldown_time) * 60 359 # Temperature from sensors come in uCelsius units. 360 cooldown_temp_in_ucels = int(cooldown_temp) * 1000 361 sleep_interval = 30 362 363 _, all_thermal_sensors, _ = run_command_on_dut( 364 dut, 'ls /sys/class/thermal/thermal_zone*/temp') 365 _, all_thermal_sensor_types, _ = run_command_on_dut( 366 dut, 'cat /sys/class/thermal/thermal_zone*/type') 367 all_thermal_sensors = all_thermal_sensors.split('\n') 368 all_thermal_sensor_types = all_thermal_sensor_types.split('\n') 369 assert len(all_thermal_sensors) == len(all_thermal_sensor_types), ( 370 'Number of sensors must match the number of types ' 371 'read from /sys/class/thermal/thermal_zone*/type.') 372 373 monitor_thermal_sensors = [] 374 # Filter in only the relevant thermal sensors. 375 filter_in_thermal_sensors = ('cpu', 'gpu', 'soc', 'pkg', 'core') 376 for sensor_path, sensor_type in zip(all_thermal_sensors, 377 all_thermal_sensor_types): 378 if any( 379 sensor_type.startswith(cpu_type) 380 for cpu_type in filter_in_thermal_sensors): 381 # Monitor only the sensors which names start from 382 # cpu/gpu/soc/pkg/core. 383 # We don't want irrelant sensors to slow down performance testing. 384 monitor_thermal_sensors.append(sensor_path) 385 logging.info('Monitor thermal sensor %s of type %s', sensor_path, 386 sensor_type) 387 388 # Wait until any of two events occurs: 389 # 1. CPU cools down to a specified temperature. 390 # 2. Timeout cooldown_time expires. 391 # For the case when targeted temperature is not reached within specified 392 # timeout the benchmark is going to start with higher initial CPU temp. 393 # In the worst case it may affect test results but at the same time we 394 # guarantee the upper bound of waiting time. 395 # TODO(denik): Report (or highlight) "high" CPU temperature in test results. 396 # "high" should be calculated based on empirical data per platform. 397 # Based on such reports we can adjust CPU configuration or 398 # cooldown limits accordingly. 399 for sensor in monitor_thermal_sensors: 400 while waittime < timeout_in_sec: 401 err, sensor_value_str, _ = run_command_on_dut(dut, 402 'cat ' + sensor, 403 ignore_status=True) 404 # If 405 # - sensor is not readable or 406 # - sensor temperature is below threshold 407 # stop monitoring the sensor and move to the next one. 408 if err: 409 logging.warning( 410 'Sensor %s is removed from monitoring due ' 411 'to the read error %d', sensor, err) 412 break 413 elif int(sensor_value_str) <= cooldown_temp_in_ucels: 414 break 415 416 logging.debug( 417 '%s=%s is above threshold %d mC.\n' 418 'Wait %ds and check again.', sensor, sensor_value_str, 419 cooldown_temp_in_ucels, sleep_interval) 420 time.sleep(sleep_interval) 421 waittime += sleep_interval 422 423 logging.info('Cooldown wait time: %.1f min', (waittime / 60)) 424 return waittime 425 426 427def decrease_wait_time(dut): 428 """ 429 Change the ten seconds wait time for pagecycler to two seconds. 430 431 @param dut: The autotest host object representing DUT. 432 433 """ 434 FILE = '/usr/local/telemetry/src/tools/perf/page_sets/page_cycler_story.py' 435 ret = run_command_on_dut(dut, 'ls ' + FILE) 436 437 if not ret: 438 sed_command = 'sed -i "s/_TTI_WAIT_TIME = 10/_TTI_WAIT_TIME = 2/g" ' 439 run_command_on_dut(dut, sed_command + FILE) 440 441 442def stop_ui(dut): 443 """ 444 Stop UI on DUT. 445 446 @param dut: The autotest host object representing DUT. 447 448 """ 449 run_command_on_dut(dut, 'stop ui') 450 451 452def start_ui(dut): 453 """ 454 Start UI on DUT. 455 456 @param dut: The autotest host object representing DUT. 457 458 """ 459 run_command_on_dut(dut, 'start ui') 460 461 462def kern_cmd_update_needed(dut, intel_pstate): 463 """ 464 Check whether kernel cmdline update is needed. 465 466 @param dut: The autotest host object representing DUT. 467 @param intel_pstate: kernel command line argument (active, passive, 468 no_hwp). 469 470 @returns True if update is needed. 471 472 """ 473 good = 0 474 475 # Check that dut platform supports hwp 476 cmd = "grep -q '^flags.*hwp' /proc/cpuinfo" 477 ret_code, _, _ = run_command_on_dut(dut, cmd, ignore_status=True) 478 if ret_code != good: 479 # Intel hwp is not supported, update is not needed. 480 return False 481 482 kern_cmdline_cmd = 'grep -q "intel_pstate=%s" /proc/cmdline' % intel_pstate 483 ret_code, _, _ = run_command_on_dut( 484 dut, kern_cmdline_cmd, ignore_status=True) 485 logging.info('grep /proc/cmdline returned %d', ret_code) 486 if (intel_pstate and ret_code == good or 487 not intel_pstate and ret_code != good): 488 # No need to updated cmdline if: 489 # 1. We are setting intel_pstate and we found it is already set. 490 # 2. Not using intel_pstate and it is not in cmdline. 491 return False 492 493 # Otherwise we need to update intel_pstate. 494 return True 495 496 497def update_kern_cmd_intel_pstate(dut, intel_pstate): 498 """Update kernel command line. 499 500 @param dut: The autotest host object representing DUT. 501 @param intel_pstate: kernel command line argument(active, passive, 502 no_hwp). 503 504 """ 505 good = 0 506 507 # First phase is to remove rootfs verification to allow cmdline change. 508 remove_verif_cmd = ' '.join([ 509 '/usr/share/vboot/bin/make_dev_ssd.sh', 510 '--remove_rootfs_verification', 511 '--partition %d', 512 ]) 513 # Command for partition 2. 514 verif_part2_failed, _, _ = run_command_on_dut( 515 dut, remove_verif_cmd % 2, ignore_status=True) 516 # Command for partition 4 517 # Some machines in the lab use partition 4 to boot from, 518 # so cmdline should be update for both partitions. 519 verif_part4_failed, _, _ = run_command_on_dut( 520 dut, remove_verif_cmd % 4, ignore_status=True) 521 if verif_part2_failed or verif_part4_failed: 522 logging.error( 523 'ERROR. Failed to update kernel cmdline on partition %d.\n' 524 'Remove verification failed with status %d', 525 2 if verif_part2_failed else 4, verif_part2_failed or 526 verif_part4_failed) 527 528 run_command_on_dut(dut, 'reboot && exit') 529 # Give enough time for dut to complete reboot 530 # TODO(denik): Replace with the function checking machine availability. 531 time.sleep(30) 532 533 # Second phase to update intel_pstate in kernel cmdline. 534 kern_cmdline = '\n'.join([ 535 'tmpfile=$(mktemp)', 536 'partnumb=%d', 537 'pstate=%s', 538 # Store kernel cmdline in a temp file. 539 '/usr/share/vboot/bin/make_dev_ssd.sh --partition ${partnumb}' 540 ' --save_config ${tmpfile}', 541 # Remove intel_pstate argument if present. 542 "sed -i -r 's/ intel_pstate=[A-Za-z_]+//g' ${tmpfile}.${partnumb}", 543 # Insert intel_pstate with a new value if it is set. 544 '[[ -n ${pstate} ]] &&' 545 ' sed -i -e \"s/ *$/ intel_pstate=${pstate}/\" ${tmpfile}.${partnumb}', 546 # Save the change in kernel cmdline. 547 # After completion we have to reboot. 548 '/usr/share/vboot/bin/make_dev_ssd.sh --partition ${partnumb}' 549 ' --set_config ${tmpfile}' 550 ]) 551 kern_part2_cmdline_cmd = kern_cmdline % (2, intel_pstate) 552 logging.info('Command to change kernel command line: %s', 553 kern_part2_cmdline_cmd) 554 upd_part2_failed, _, _ = run_command_on_dut( 555 dut, kern_part2_cmdline_cmd, ignore_status=True) 556 # Again here we are updating cmdline for partition 4 557 # in addition to partition 2. Without this some machines 558 # in the lab might fail. 559 kern_part4_cmdline_cmd = kern_cmdline % (4, intel_pstate) 560 logging.info('Command to change kernel command line: %s', 561 kern_part4_cmdline_cmd) 562 upd_part4_failed, _, _ = run_command_on_dut( 563 dut, kern_part4_cmdline_cmd, ignore_status=True) 564 if upd_part2_failed or upd_part4_failed: 565 logging.error( 566 'ERROR. Failed to update kernel cmdline on partition %d.\n' 567 'intel_pstate update failed with status %d', 568 2 if upd_part2_failed else 4, upd_part2_failed or upd_part4_failed) 569 570 run_command_on_dut(dut, 'reboot && exit') 571 # Wait 30s after reboot. 572 time.sleep(30) 573 574 # Verification phase. 575 # Check that cmdline was updated. 576 # Throw an exception if not. 577 kern_cmdline_cmd = 'grep -q "intel_pstate=%s" /proc/cmdline' % intel_pstate 578 ret_code, _, _ = run_command_on_dut( 579 dut, kern_cmdline_cmd, ignore_status=True) 580 if (intel_pstate and ret_code != good or 581 not intel_pstate and ret_code == good): 582 # Kernel cmdline doesn't match input intel_pstate. 583 logging.error( 584 'ERROR. Failed to update kernel cmdline. ' 585 'Final verification failed with status %d', ret_code) 586 587 logging.info('Kernel cmdline updated successfully.') 588 589 590@contextmanager 591def pause_ui(dut): 592 """ 593 Stop UI before and Start UI after the context block. 594 595 Context manager will make sure UI is always resumed at the end. 596 597 @param dut: The autotest host object representing DUT. 598 599 """ 600 stop_ui(dut) 601 try: 602 yield 603 604 finally: 605 start_ui(dut) 606 607 608def setup_device(dut, dut_config): 609 """ 610 Setup device to get it ready for testing. 611 612 @param dut: The autotest host object representing DUT. 613 @param dut_config: A dictionary of DUT configurations. 614 615 @returns Wait time of cool down for this benchmark run. 616 617 """ 618 logging.info('Update kernel cmdline if necessary and reboot') 619 intel_pstate = dut_config.get('intel_pstate') 620 if intel_pstate and kern_cmd_update_needed(dut, intel_pstate): 621 update_kern_cmd_intel_pstate(dut, intel_pstate) 622 623 wait_time = 0 624 # Pause UI while configuring the DUT. 625 # This will accelerate setup (waiting for cooldown has x10 drop) 626 # and help to reset a Chrome state left after the previous test. 627 with pause_ui(dut): 628 # Unless the user turns on ASLR in the flag, we first disable ASLR 629 # before running the benchmarks 630 if not dut_config.get('enable_aslr'): 631 disable_aslr(dut) 632 633 # CPU usage setup comes first where we enable/disable cores. 634 setup_cpu_usage(dut, dut_config.get('cpu_usage')) 635 cpu_online_status = get_cpu_online(dut) 636 # List of online cores of type int (core number). 637 online_cores = [ 638 core for core, status in cpu_online_status.items() if status 639 ] 640 if dut_config.get('cooldown_time'): 641 # Setup power conservative mode for effective cool down. 642 # Set ignore status since powersave may no be available 643 # on all platforms and we are going to handle it. 644 ret = set_cpu_governor(dut, 'powersave', ignore_status=True) 645 if ret: 646 # "powersave" is not available, use "ondemand". 647 # Still not a fatal error if it fails. 648 ret = set_cpu_governor(dut, 'ondemand', ignore_status=True) 649 # TODO(denik): Run comparison test for 'powersave' and 'ondemand' 650 # on scarlet and kevin64. 651 # We might have to consider reducing freq manually to the min 652 # if it helps to reduce waiting time. 653 wait_time = wait_cooldown( 654 dut, dut_config['cooldown_time'], dut_config['cooldown_temp']) 655 656 # Setup CPU governor for the benchmark run. 657 # It overwrites the previous governor settings. 658 governor = dut_config.get('governor') 659 # FIXME(denik): Pass online cores to governor setup. 660 if governor: 661 set_cpu_governor(dut, governor) 662 663 # Disable Turbo and Setup CPU freq should ALWAYS proceed governor setup 664 # since governor may change: 665 # - frequency; 666 # - turbo/boost. 667 disable_turbo(dut) 668 if dut_config.get('cpu_freq_pct'): 669 setup_cpu_freq(dut, dut_config['cpu_freq_pct'], online_cores) 670 671 decrease_wait_time(dut) 672 # FIXME(denik): Currently we are not recovering the previous cpufreq 673 # settings since we do reboot/setup every time anyway. 674 # But it may change in the future and then we have to recover the 675 # settings. 676 return wait_time 677