diff options
-rwxr-xr-x | benchmarks/benchmarks_run_target.sh | 9 | ||||
-rw-r--r-- | devices/cpu_freq_utils.sh | 38 | ||||
-rw-r--r-- | utils/utils.sh | 2 |
3 files changed, 49 insertions, 0 deletions
diff --git a/benchmarks/benchmarks_run_target.sh b/benchmarks/benchmarks_run_target.sh index 075e637..042216b 100755 --- a/benchmarks/benchmarks_run_target.sh +++ b/benchmarks/benchmarks_run_target.sh @@ -212,6 +212,13 @@ main() { fi start_timer "${target_timer_name}" + + # We need to set up an android environment to have access to `adb` for the CPU + # config backup helpers. + setup_android_target "arm_krait-eng" + local -r backup_cpus_config_dir=$(mktemp -d) + backup_device_cpus_config "$backup_cpus_config_dir" + for bits in 32 64; do if ! ${options["${bits}bit"]}; then log I "Skipping ${bits}bit benchmarks." @@ -233,6 +240,8 @@ main() { # Set freq. run_all_benchmarks "${bits}" done + + restore_device_cpus_config "$backup_cpus_config_dir" stop_timer "${target_timer_name}" log S "$0 Finished!" 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" +} diff --git a/utils/utils.sh b/utils/utils.sh index 8593e69..47480a4 100644 --- a/utils/utils.sh +++ b/utils/utils.sh @@ -46,6 +46,8 @@ init_coloured_logging() { init_shell() { enable_error_on_unset_expansion + # Use extended globs for pattern matching. + shopt -s extglob } # Log function. |