diff options
author | Zhizhou Yang <zhizhouy@google.com> | 2019-11-05 18:12:42 -0800 |
---|---|---|
committer | Zhizhou Yang <zhizhouy@google.com> | 2019-11-12 01:22:47 +0000 |
commit | 5e83ee9c31d48d49669dc4e4b4fffbd7f759be9b (patch) | |
tree | 51a7f6239119250768a7babf46311ae883ed5743 /crosperf/schedv2.py | |
parent | 31e0e81c1bcdbf082c91eff9ad16828aadd08df3 (diff) | |
download | toolchain-utils-5e83ee9c31d48d49669dc4e4b4fffbd7f759be9b.tar.gz |
crosperf: migrate all device setup code to a separate utils file
This patch extracts all the device setup code which interacts with DUT
to a single utils file, and be put into a wrapper class. This will help
migrating all related code to telemetry_Crosperf for skylab runs.
BUG=chromium:1020655
TEST=Passed all unittests; tested with simple experiment on kevin.
Change-Id: I2edcd7bb2d8cd0255d3ae6d380a5983c24427d98
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1895500
Tested-by: Zhizhou Yang <zhizhouy@google.com>
Reviewed-by: Zhizhou Yang <zhizhouy@google.com>
Reviewed-by: Denis Nikitin <denik@chromium.org>
Commit-Queue: Zhizhou Yang <zhizhouy@google.com>
Diffstat (limited to 'crosperf/schedv2.py')
-rw-r--r-- | crosperf/schedv2.py | 157 |
1 files changed, 7 insertions, 150 deletions
diff --git a/crosperf/schedv2.py b/crosperf/schedv2.py index dea3cdd3..d15f18c0 100644 --- a/crosperf/schedv2.py +++ b/crosperf/schedv2.py @@ -9,7 +9,6 @@ from __future__ import division from __future__ import print_function import sys -import time import traceback from collections import defaultdict @@ -21,6 +20,7 @@ import test_flag from machine_image_manager import MachineImageManager from cros_utils import command_executer from cros_utils import logger +from cros_utils.device_setup_utils import DutWrapper class DutWorker(Thread): @@ -49,153 +49,6 @@ class DutWorker(Thread): # suite_runner.Terminate and updates timeline. self._active_br.Terminate() - def _kerncmd_update_needed(self, intel_pstate): - """Check whether kernel cmdline update is needed. - - Args: - intel_pstate: kernel command line argument (active, passive, no_hwp) - - Returns: - True if update is needed. - """ - - ce = command_executer.GetCommandExecuter() - good = 0 - - # Check that dut platform supports hwp - cmd = "grep -q '^flags.*hwp' /proc/cpuinfo" - ret_code = ce.CrosRunCommand( - cmd, - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - if ret_code != good: - # Intel hwp is not supported, update is not needed. - return False - - kern_cmdline_cmd = 'grep -q "intel_pstate=%s" /proc/cmdline' % intel_pstate - ret_code = ce.CrosRunCommand( - kern_cmdline_cmd, - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - self._logger.LogOutput('grep /proc/cmdline returned %d' % ret_code) - if (intel_pstate and ret_code == good or - not intel_pstate and ret_code != good): - # No need to updated cmdline if: - # 1. We are setting intel_pstate and we found it is already set. - # 2. Not using intel_pstate and it is not in cmdline. - return False - - # Otherwise we need to update intel_pstate. - return True - - def _update_kerncmd_intel_pstate(self, intel_pstate): - """Update kernel command line. - - Args: - intel_pstate: kernel command line argument (active, passive, no_hwp) - """ - - ce = command_executer.GetCommandExecuter() - good = 0 - - # First phase is to remove rootfs verification to allow cmdline change. - remove_verif_cmd = ' '.join([ - '/usr/share/vboot/bin/make_dev_ssd.sh', - '--remove_rootfs_verification', - '--partition %d', - ]) - # Command for partition 2. - verif_part2_failed = ce.CrosRunCommand( - remove_verif_cmd % 2, - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - # Command for partition 4 - # Some machines in the lab use partition 4 to boot from, - # so cmdline should be update for both partitions. - verif_part4_failed = ce.CrosRunCommand( - remove_verif_cmd % 4, - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - if verif_part2_failed or verif_part4_failed: - self._logger.LogFatal( - 'ERROR. Failed to update kernel cmdline on partition %d.\n' - 'Remove verification failed with status %d' % - (2 if verif_part2_failed else 4, verif_part2_failed or - verif_part4_failed)) - - ce.CrosRunCommand( - 'reboot && exit', - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - # Give enough time for dut to complete reboot - # TODO(denik): Replace with the function checking machine availability. - time.sleep(30) - - # Second phase to update intel_pstate in kernel cmdline. - kern_cmdline = '\n'.join([ - 'tmpfile=$(mktemp)', - 'partnumb=%d', - 'pstate=%s', - # Store kernel cmdline in a temp file. - '/usr/share/vboot/bin/make_dev_ssd.sh --partition ${partnumb}' - ' --save_config ${tmpfile}', - # Remove intel_pstate argument if present. - "sed -i -r 's/ intel_pstate=[A-Za-z_]+//g' ${tmpfile}.${partnumb}", - # Insert intel_pstate with a new value if it is set. - '[[ -n ${pstate} ]] &&' - ' sed -i -e \"s/ *$/ intel_pstate=${pstate}/\" ${tmpfile}.${partnumb}', - # Save the change in kernel cmdline. - # After completion we have to reboot. - '/usr/share/vboot/bin/make_dev_ssd.sh --partition ${partnumb}' - ' --set_config ${tmpfile}' - ]) - kern_part2_cmdline_cmd = kern_cmdline % (2, intel_pstate) - self._logger.LogOutput( - 'Command to change kernel command line: %s' % kern_part2_cmdline_cmd) - upd_part2_failed = ce.CrosRunCommand( - kern_part2_cmdline_cmd, - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - # Again here we are updating cmdline for partition 4 - # in addition to partition 2. Without this some machines - # in the lab might fail. - kern_part4_cmdline_cmd = kern_cmdline % (4, intel_pstate) - self._logger.LogOutput( - 'Command to change kernel command line: %s' % kern_part4_cmdline_cmd) - upd_part4_failed = ce.CrosRunCommand( - kern_part4_cmdline_cmd, - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - if upd_part2_failed or upd_part4_failed: - self._logger.LogFatal( - 'ERROR. Failed to update kernel cmdline on partition %d.\n' - 'intel_pstate update failed with status %d' % - (2 if upd_part2_failed else 4, upd_part2_failed or upd_part4_failed)) - - ce.CrosRunCommand( - 'reboot && exit', - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - # Wait 30s after reboot. - time.sleep(30) - - # Verification phase. - # Check that cmdline was updated. - # Throw an exception if not. - kern_cmdline_cmd = 'grep -q "intel_pstate=%s" /proc/cmdline' % intel_pstate - ret_code = ce.CrosRunCommand( - kern_cmdline_cmd, - chromeos_root=self._sched.get_labels(0).chromeos_root, - machine=self._dut.name) - if (intel_pstate and ret_code != good or - not intel_pstate and ret_code == good): - # Kernel cmdline doesn't match input intel_pstate. - self._logger.LogFatal( - 'ERROR. Failed to update kernel cmdline. ' - 'Final verification failed with status %d' % ret_code) - - self._logger.LogOutput('Kernel cmdline updated successfully.') - def run(self): """Do the "run-test->(optionally reimage)->run-test" chore. @@ -238,8 +91,12 @@ class DutWorker(Thread): else: self._logger.LogOutput('Update kernel cmdline if necessary ' 'and reboot') - if self._kerncmd_update_needed(intel_pstate): - self._update_kerncmd_intel_pstate(intel_pstate) + run_on_dut = DutWrapper( + self._sched.get_labels(0).chromeos_root, + self._dut.name, + logger=self._logger) + if run_on_dut.KerncmdUpdateNeeded(intel_pstate): + run_on_dut.UpdateKerncmdIntelPstate(intel_pstate) # Execute the br. self._execute_benchmark_run(br) |