Create a global variable that will look for number of cpus for a platform and use it in multiple functions to make the code simplier to read.
Signed-off-by: Lisa Nguyen lisa.nguyen@linaro.org --- Changes from v1 to v2: - Edit the command to grab the number of cpus by adding the -1v option, showing the cpu numbers in order for testing per Sanjay's suggestion
cpufreq/cpufreq_05.sh | 6 +++--- cpuhotplug/cpuhotplug_sanity.sh | 1 - include/functions.sh | 13 +++++-------- include/thermal_functions.sh | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/cpufreq/cpufreq_05.sh b/cpufreq/cpufreq_05.sh index 93fce78..1f0dd8d 100755 --- a/cpufreq/cpufreq_05.sh +++ b/cpufreq/cpufreq_05.sh @@ -62,7 +62,7 @@ supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "ondem if [ -z "$supported" ]; then log_skip "ondemand not supported" else - for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do + for cpu in $cpus; do switch_ondemand $cpu done check_governor $cpu 'ondemand' @@ -72,7 +72,7 @@ supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "conse if [ -z "$supported" ]; then log_skip "conservative not supported" else - for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do + for cpu in $cpus; do switch_conservative $cpu done check_governor $cpu 'conservative' @@ -82,7 +82,7 @@ supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "users if [ -z "$supported" ]; then log_skip "userspace not supported" else - for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do + for cpu in $cpus; do switch_userspace $cpu done
diff --git a/cpuhotplug/cpuhotplug_sanity.sh b/cpuhotplug/cpuhotplug_sanity.sh index d9b6af8..2ad24ff 100755 --- a/cpuhotplug/cpuhotplug_sanity.sh +++ b/cpuhotplug/cpuhotplug_sanity.sh @@ -33,7 +33,6 @@ fi
check_cpuhotplug_sysfs_entry() {
- cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") cpunum=$(ls $CPU_PATH | grep "cpu[0-9].*" -c)
if [ $cpunum -eq 1 ]; then diff --git a/include/functions.sh b/include/functions.sh index e0f08fb..7a113b6 100644 --- a/include/functions.sh +++ b/include/functions.sh @@ -30,6 +30,7 @@ TEST_NAME=$(basename ${0%.sh}) PREFIX=$TEST_NAME INC=0 CPU= +cpus=$(ls -1v $CPU_PATH | grep "cpu[0-9].*") pass_count=0 fail_count=0 skip_count=0 @@ -86,7 +87,6 @@ for_each_cpu() { local func=$1 shift 1
- cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") for cpu in $cpus; do INC=0 CPU=/$cpu @@ -339,8 +339,8 @@ save_governors() { governors_backup= local index=0
- for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do - governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor) + for cpu in $cpus; do + governors_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) index=$((index + 1)) done } @@ -350,9 +350,9 @@ restore_governors() { local index=0 local oldgov=
- for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do + for cpu in $cpus; do oldgov=${governors_backup[$index]} - echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor + echo $oldgov > $CPU_PATH/$cpu/cpufreq/scaling_governor index=$((index + 1)) done } @@ -361,8 +361,6 @@ save_frequencies() {
frequencies_backup= local index=0 - local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") - local cpu=
for cpu in $cpus; do frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) @@ -374,7 +372,6 @@ restore_frequencies() {
local index=0 local oldfreq= - local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
for cpu in $cpus; do oldfreq=${frequencies_backup[$index]} diff --git a/include/thermal_functions.sh b/include/thermal_functions.sh index a51240b..c25e1d8 100644 --- a/include/thermal_functions.sh +++ b/include/thermal_functions.sh @@ -184,7 +184,7 @@ check_scaling_freq() { local index=0
local flag=0 - for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do + for cpu in $cpus; do if [ $before_freq_list[$index] -ne $afterf_req_list[$index] ] ; then flag=1 fi @@ -197,7 +197,7 @@ store_scaling_maxfreq() { scale_freq= local index=0
- for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do + for cpu in $cpus; do scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) index=$((index + 1)) done