diff options
author | Alexandre Rames <alexandre.rames@linaro.org> | 2016-07-01 17:25:43 +0100 |
---|---|---|
committer | Alexandre Rames <alexandre.rames@linaro.org> | 2016-07-01 17:25:43 +0100 |
commit | 25cdd0033a3f25900b72f21a10e80016299ebf4d (patch) | |
tree | 30f4591d50bcc984df37fc41bd649993dadc096e /devices | |
parent | 22e3cd4889687ffa006e930d5d101a05645655e7 (diff) |
Backup/restore CPU configuration before/after running benchmarks.
Change-Id: I611bc1e1ed09b10663f91920a49c2830cd142439
Diffstat (limited to 'devices')
-rw-r--r-- | devices/cpu_freq_utils.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/devices/cpu_freq_utils.sh b/devices/cpu_freq_utils.sh index 8132542..c31ac73 100644 --- a/devices/cpu_freq_utils.sh +++ b/devices/cpu_freq_utils.sh @@ -129,3 +129,41 @@ get_device_settings() { safe source "${cpu_freq_script}" } + +# Arguments: +# ${1} - backup directory +backup_device_cpus_config() { + local -r backup_dir="${1}" + for remote_cpu_path in $(adb_shell_strip echo "$sys_cpu_path/cpu*"); do + if [[ $remote_cpu_path =~ .*cpu([0-9]+)$ ]]; then + local cpu_index=${BASH_REMATCH[1]} + local local_cpu_path="$backup_dir/cpu$cpu_index" + safe mkdir -p "$local_cpu_path/cpufreq" + adb pull "$remote_cpu_path/online" "$local_cpu_path" + adb pull "$remote_cpu_path/cpufreq/scaling_governor" "$local_cpu_path/cpufreq/" + adb pull "$remote_cpu_path/cpufreq/scaling_setspeed" "$local_cpu_path/cpufreq/" + fi + done +} + + +# Arguments: +# $1 - backup directory +restore_device_cpus_config() { + local -r backup_dir="${1}" + for local_cpu_path in "$backup_dir"/*; do + local cpu_index=${local_cpu_path#${backup_dir}/cpu} + local remote_cpu_path="$sys_cpu_path/cpu$cpu_index" + # Note that we do not use `safe` for `online` and `scaling_setspeed`, + # because attempting to set those to their current value raises an error. + adb shell "echo \"$(cat "$local_cpu_path/online")\" > $remote_cpu_path/online" + if [[ -f "$local_cpu_path/cpufreq/scaling_governor" ]]; then + safe adb shell "echo \"$(cat "$local_cpu_path/cpufreq/scaling_governor")\" > $remote_cpu_path/cpufreq/scaling_governor" + fi + local freq=$(cat "$local_cpu_path/cpufreq/scaling_setspeed") + if [[ "$freq" =~ ^[0-9]+$ ]]; then + adb shell "echo \"$freq\" > $remote_cpu_path/cpufreq/scaling_setspeed" + fi + done + rm -rf "$backup_dir" +} |