diff options
author | Alexandre Rames <alexandre.rames@linaro.org> | 2016-08-10 16:25:35 +0100 |
---|---|---|
committer | Serban Constantinescu <serban.constantinescu@linaro.org> | 2016-08-16 20:50:57 +0100 |
commit | 0b1133a5c4f7e93f561332328dd4f3d11862ac51 (patch) | |
tree | 6884589d54450d7090296dfbbfb8cda0ae2d2f32 | |
parent | 3f7a89146de668ddf355086600923d6167117735 (diff) | |
download | art-build-scripts-0b1133a5c4f7e93f561332328dd4f3d11862ac51.tar.gz |
Revert "Revert "Update `set_cpu_freq.sh` to allow restoring CPUs to a default config.""
Fixed to check that `online` exists before writing to it.
This reverts commit ee4aea45fa9f32ff4d49a0ea724f3df3cac3585e.
Change-Id: If4e6c5f9df0316676ce66fd6d33f26967e52bf2c
-rwxr-xr-x | benchmarks/benchmarks_run_target.sh | 16 | ||||
-rw-r--r-- | devices/config/angler.sh | 14 | ||||
-rw-r--r-- | devices/config/bullhead.sh | 14 | ||||
-rw-r--r-- | devices/config/flounder.sh | 8 | ||||
-rw-r--r-- | devices/cpu_freq_utils.sh | 98 | ||||
-rwxr-xr-x | devices/set_cpu_freq.sh | 95 | ||||
-rwxr-xr-x | tests/test_art_target.sh | 6 |
7 files changed, 155 insertions, 96 deletions
diff --git a/benchmarks/benchmarks_run_target.sh b/benchmarks/benchmarks_run_target.sh index bda1aab1..30c2d2ef 100755 --- a/benchmarks/benchmarks_run_target.sh +++ b/benchmarks/benchmarks_run_target.sh @@ -193,14 +193,17 @@ run_all_benchmarks() { get_device_settings "${target_device}" "${local_path}/../devices/config" || exit 1 if ${DEVICE_IS_BIG_LITTLE}; then - safe "${local_path}/../devices/set_cpu_freq.sh" --little + safe "${local_path}/../devices/set_cpu_freq.sh" --little --pin_freq run_benchmarks "$1" "${target_device}" "${LITTLE_CPUS_NAME}" - safe "${local_path}/../devices/set_cpu_freq.sh" --big + safe "${local_path}/../devices/set_cpu_freq.sh" --big --pin_freq run_benchmarks "$1" "${target_device}" "${BIG_CPUS_NAME}" else - safe "${local_path}/../devices/set_cpu_freq.sh" + safe "${local_path}/../devices/set_cpu_freq.sh" --all --pin_freq run_benchmarks "$1" "${target_device}" "${CPUS_NAME}" fi + + # Be a good citizen and restore the CPUs configuration to defaults. + safe "${local_path}/../devices/set_cpu_freq.sh" --default } main() { @@ -214,12 +217,6 @@ main() { 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." @@ -242,7 +239,6 @@ main() { 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/config/angler.sh b/devices/config/angler.sh index f0f214f0..787407c8 100644 --- a/devices/config/angler.sh +++ b/devices/config/angler.sh @@ -2,14 +2,28 @@ # Helper script used for setting the Nexus 6P frequency. # shellcheck disable=SC2034 +NUMBER_OF_CPUS=8 +# shellcheck disable=SC2034 DEVICE_IS_BIG_LITTLE=true # shellcheck disable=SC2034 LITTLE_CPUS=(0 1 2 3) # shellcheck disable=SC2034 BIG_CPUS=(4 5 6 7) # shellcheck disable=SC2034 +CPUS=(0 1 2 3 4 5 6 7) +# shellcheck disable=SC2034 TARGET_FREQ=1248000 # shellcheck disable=SC2034 LITTLE_CPUS_NAME=a53 # shellcheck disable=SC2034 BIG_CPUS_NAME=a57 + +# Default CPU config. +# shellcheck disable=SC2034 +LITTLE_CPUS_DEFAULT_MIN_FREQ=384000 +# shellcheck disable=SC2034 +LITTLE_CPUS_DEFAULT_MAX_FREQ=1555200 +# shellcheck disable=SC2034 +BIG_CPUS_DEFAULT_MIN_FREQ=633600 +# shellcheck disable=SC2034 +BIG_CPUS_DEFAULT_MAX_FREQ=1958400 diff --git a/devices/config/bullhead.sh b/devices/config/bullhead.sh index 48f43efe..85ceeb43 100644 --- a/devices/config/bullhead.sh +++ b/devices/config/bullhead.sh @@ -2,14 +2,28 @@ # Helper script used for setting the Nexus 5X frequency. # shellcheck disable=SC2034 +NUMBER_OF_CPUS=6 +# shellcheck disable=SC2034 DEVICE_IS_BIG_LITTLE=true # shellcheck disable=SC2034 LITTLE_CPUS=(0 1 2 3) # shellcheck disable=SC2034 BIG_CPUS=(4 5) # shellcheck disable=SC2034 +CPUS=(0 1 2 3 4 5) +# shellcheck disable=SC2034 TARGET_FREQ=1248000 # shellcheck disable=SC2034 LITTLE_CPUS_NAME=a53 # shellcheck disable=SC2034 BIG_CPUS_NAME=a57 + +# Default CPU config. +# shellcheck disable=SC2034 +LITTLE_CPUS_DEFAULT_MIN_FREQ=384000 +# shellcheck disable=SC2034 +LITTLE_CPUS_DEFAULT_MAX_FREQ=1440000 +# shellcheck disable=SC2034 +BIG_CPUS_DEFAULT_MIN_FREQ=633600 +# shellcheck disable=SC2034 +BIG_CPUS_DEFAULT_MAX_FREQ=1824000 diff --git a/devices/config/flounder.sh b/devices/config/flounder.sh index 5610ca13..5442fe6e 100644 --- a/devices/config/flounder.sh +++ b/devices/config/flounder.sh @@ -2,6 +2,8 @@ # Helper script used for setting the Nexus 9 frequency. # shellcheck disable=SC2034 +NUMBER_OF_CPUS=2 +# shellcheck disable=SC2034 DEVICE_IS_BIG_LITTLE=false # shellcheck disable=SC2034 CPUS=(0 1) @@ -9,3 +11,9 @@ CPUS=(0 1) TARGET_FREQ=1224000 # shellcheck disable=SC2034 CPUS_NAME=denver + +# Default CPU config. +# shellcheck disable=SC2034 +CPUS_DEFAULT_MIN_FREQ=510000 +# shellcheck disable=SC2034 +CPUS_DEFAULT_MAX_FREQ=2460750 diff --git a/devices/cpu_freq_utils.sh b/devices/cpu_freq_utils.sh index d5ed5c39..2c52d3a1 100644 --- a/devices/cpu_freq_utils.sh +++ b/devices/cpu_freq_utils.sh @@ -37,15 +37,24 @@ set_state_cpus() { local output new_status for cpu; do - # adb shell does not report return status properly, so at least check - # that no unexpected message was printed. - output=$(safe adb_shell_strip "echo ${state} > ${sys_cpu_path}/cpu${cpu}/online") - # If the kernel refuses to do the operation, the operation might fail - # without any message printed, check that the new status is what we expect. - new_status=$(safe adb_shell_strip "cat ${sys_cpu_path}/cpu${cpu}/online") - if [[ ${output} || ${new_status} != ${state} ]]; then - log E "Failed to set CPU ${cpu} to state ${state}: ${output}" - return 1 + local online_file="${sys_cpu_path}/cpu${cpu}/online" + # Check whether the CPU has an associated `online` file. + if [[ $(safe adb_shell_strip "[[ -f ${online_file} ]] && echo y || echo n") == "n" ]]; then + # Only raise an error if we were trying to disable CPU. + if [[ $state -eq 0 ]]; then + log E "Could not write to $online_file" + fi + else + # adb shell does not report return status properly, so at least check + # that no unexpected message was printed. + output=$(safe adb_shell_strip "echo ${state} > $online_file") + # If the kernel refuses to do the operation, the operation might fail + # without any message printed, check that the new status is what we expect. + new_status=$(safe adb_shell_strip "cat $online_file") + if [[ ${output} || ${new_status} != ${state} ]]; then + log E "Failed to set CPU ${cpu} to state ${state}: ${output}" + return 1 + fi fi done @@ -130,40 +139,47 @@ 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 +# ${1} - max frequency +# ${2} - min frequency +# ${1-#} - CPU indexes +configure_cpus_to_interactive() { + local -r max_freq=$1 + local -r min_freq=$2 + shift 2 + + local output= + for cpu; do + output+=$(safe adb_shell_strip "echo interactive > \ + ${sys_cpu_path}/cpu${cpu}/cpufreq/scaling_governor") + # `scaling_max_freq` must be set before `scaling_min_freq`. See + # https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt. + output+=$(safe adb_shell_strip "echo $max_freq > \ + ${sys_cpu_path}/cpu${cpu}/cpufreq/scaling_max_freq") + output+=$(safe adb_shell_strip "echo $min_freq > \ + ${sys_cpu_path}/cpu${cpu}/cpufreq/scaling_min_freq") done + + if [[ ${output} ]]; then + log E "${output}" + return 1 + else + return 0 + fi } +set_default_cpu_config() { + validate_cpus "$@" || return 1 -# 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" + if ${DEVICE_IS_BIG_LITTLE}; then + safe enable_cpus "${BIG_CPUS[@]}" + safe enable_cpus "${LITTLE_CPUS[@]}" + safe configure_cpus_to_interactive \ + "$BIG_CPUS_DEFAULT_MAX_FREQ" "$BIG_CPUS_DEFAULT_MIN_FREQ" "${BIG_CPUS[@]}" + safe configure_cpus_to_interactive \ + "$LITTLE_CPUS_DEFAULT_MAX_FREQ" "$LITTLE_CPUS_DEFAULT_MIN_FREQ" "${LITTLE_CPUS[@]}" + else + safe enable_cpus "${CPUS[@]}" + safe configure_cpus_to_interactive \ + "$CPUS_DEFAULT_MAX_FREQ" "$CPUS_DEFAULT_MIN_FREQ" "${CPUS[@]}" + fi } diff --git a/devices/set_cpu_freq.sh b/devices/set_cpu_freq.sh index 97abc580..f4709357 100755 --- a/devices/set_cpu_freq.sh +++ b/devices/set_cpu_freq.sh @@ -11,13 +11,14 @@ declare -A options target_device= init_options() { - options["big"]="false" - options["little"]="false" + options["cpus"]="all" + options["pin_freq"]="false" + options["default"]="false" } validate_options() { - if ${options["big"]} && ${options["little"]}; then - log E "Both --big and --little set. You need to only use one of these clusters at a time." + if ${options["default"]} && ( ${options["pin_freq"]} || [[ "${options["cpus"]}" != "all" ]] ); then + log E "The option \`--default\` is incompatible with \`--pin_freq\`, \`--big\`, and \`--little\` options." exit 1 fi } @@ -25,31 +26,19 @@ validate_options() { usage() { log I "$0" log I "This script should be used for frequency scaling your device." - log I "The script expects a 64bit flounder (Nexus 9) or bullhead (Nexus 5X) connected." log I " -h|--help - help" log I " -v|--verbose - verbose" log I "-------------------------------------------" - log I "CPU clusters to be turned on and scaled:" - log I " --big - Big cluster in a big.LITTLE SoC." - log I " --little - Little cluster in a big.LITTLE SoC." + log I " --all - Enable all CPUs (default)." + log I " --big - Enable only the big cluster in a big.LITTLE SoC." + log I " --little - Enable only the little cluster in a big.LITTLE SoC." + log I "" + log I " --pin_freq - Pin the frequency of enabled cores." + log I " --default - Restore the CPUs to the default configuration." log I "" - log I "Note: For SoCs with a single cluster none of the options above need to be specified." log I "-------------------------------------------" } -set_option() { - local current_option=${1#"--"} - # shellcheck disable=SC2144 - # shellcheck disable=SC2102 - if [[ -v options[${current_option}] ]]; then - options[${current_option}]="true" - else - # There might be something wrong with the option parser since this option - # does not have a default. - abort - fi -} - arguments_parser() { init_options while [[ $# -gt 0 ]]; do @@ -61,8 +50,14 @@ arguments_parser() { usage exit 0 ;; - --big|--little) - set_option "$1" + --all|--big|--little) + options["cpus"]=${1#--} + ;; + --pin_freq) + options["pin_freq"]="true" + ;; + --default) + options["default"]="true" ;; *) log E "Invalid option: $1" @@ -80,27 +75,37 @@ print_freq() { } set_device_freq() { - if ${DEVICE_IS_BIG_LITTLE}; then - if ${options["little"]}; then - log I "Setting cpu freq for the little cluster (freq = $(print_freq))." - safe enable_cpus "${LITTLE_CPUS[@]}" - safe disable_cpus "${BIG_CPUS[@]}" - safe set_freq_cpus "${TARGET_FREQ}" "${LITTLE_CPUS[@]}" - elif ${options["big"]}; then - log I "Setting cpu freq for the big cluster (freq = $(print_freq))." - safe enable_cpus "${BIG_CPUS[@]}" - safe disable_cpus "${LITTLE_CPUS[@]}" - safe set_freq_cpus "${TARGET_FREQ}" "${BIG_CPUS[@]}" - else - log E "Device ${target_device} is big.LITTLE, please specify a cluster." - fi - else - if ! ${options["big"]} && ! ${options["little"]}; then - log I "Setting cpu freq for the single cluster (freq = $(print_freq))." - safe set_freq_cpus "${TARGET_FREQ}" "${CPUS[@]}" - else - log E "Device ${target_device} is single-cluster, do not specify a cluster." - fi + if ! ${DEVICE_IS_BIG_LITTLE} && [[ ${options["cpus"]} != "all" ]]; then + log E "Device ${target_device} is single-cluster, do not use \`--big\` or \`little\` options." + fi + + if ${options["default"]}; then + log I "Restoring CPUs configuration to defaults." + set_default_cpu_config + exit 0 + fi + + local -a cpus_to_configure + + if [[ ${options["cpus"]} == "all" ]]; then + log I "Enabling all CPUs." + cpus_to_configure=("${CPUS[@]}") + safe enable_cpus "${cpus_to_configure[@]}" + elif [[ ${options["cpus"]} == "big" ]]; then + log I "Enabling only the big cluster." + safe enable_cpus "${BIG_CPUS[@]}" + safe disable_cpus "${LITTLE_CPUS[@]}" + cpus_to_configure=("${BIG_CPUS[@]}") + elif [[ ${options["cpus"]} == "little" ]]; then + log I "Enabling only the little cluster." + safe enable_cpus "${LITTLE_CPUS[@]}" + safe disable_cpus "${BIG_CPUS[@]}" + cpus_to_configure=("${LITTLE_CPUS[@]}") + fi + + if ${options["pin_freq"]}; then + log I "Pinning the frequency." + safe set_freq_cpus "${TARGET_FREQ}" "${cpus_to_configure[@]}" fi } diff --git a/tests/test_art_target.sh b/tests/test_art_target.sh index 5733e7f6..49bd65ef 100755 --- a/tests/test_art_target.sh +++ b/tests/test_art_target.sh @@ -275,6 +275,10 @@ build_target() { end_section "build_target_$1" "$?" } +configure_cpus() { + safe "${local_path}/../devices/set_cpu_freq.sh" --default +} + device_setup() { start_section "device_setup_$1" # Get adb root - needed otherwise device_cleanup() would fail. @@ -407,6 +411,8 @@ main() { # Build target. build_target "${bits}" + configure_cpus + # Setup & sync device. device_setup "${bits}" device_cleanup "${bits}" |