Remove unused variables and rename some variables to avoid conflicts since they are global. Also, renaming variables will make it easier to understand what variables are assigned to them.
Signed-off-by: Lisa Nguyen lisa.nguyen@linaro.org --- cpuhotplug/cpuhotplug_02.sh | 6 +- cpuhotplug/cpuhotplug_03.sh | 5 +- cpuhotplug/cpuhotplug_04.sh | 1 - cpuhotplug/cpuhotplug_07.sh | 1 - include/functions.sh | 136 +++++++++++++++++++++--------------------- include/thermal_functions.sh | 45 +++++++------- thermal/thermal_01.sh | 22 ++++--- 7 files changed, 103 insertions(+), 113 deletions(-)
diff --git a/cpuhotplug/cpuhotplug_02.sh b/cpuhotplug/cpuhotplug_02.sh index 2c87861..c21d1b6 100755 --- a/cpuhotplug/cpuhotplug_02.sh +++ b/cpuhotplug/cpuhotplug_02.sh @@ -29,7 +29,7 @@
check_state() { cpu=$1 - dirpath=$CPU_PATH/$1 + dirpath=$CPU_PATH/$cpu shift 1
if [ "$cpu" = "cpu0" ]; then @@ -39,7 +39,7 @@ check_state() { set_offline $cpu state=$(get_online $cpu)
- check "cpu is offline" "test $state -eq 0" + check "$cpu is offline" "test $state -eq 0" if [ $? -ne 0 ]; then set_online $cpu return 1 @@ -48,7 +48,7 @@ check_state() { set_online $cpu state=$(get_online $cpu)
- check "cpu is online" "test $state -eq 1" + check "$cpu is online" "test $state -eq 1" if [ $? -ne 0 ]; then return 1 fi diff --git a/cpuhotplug/cpuhotplug_03.sh b/cpuhotplug/cpuhotplug_03.sh index 689fc8a..96f4685 100755 --- a/cpuhotplug/cpuhotplug_03.sh +++ b/cpuhotplug/cpuhotplug_03.sh @@ -30,7 +30,6 @@ check_affinity_fails() { cpu=$1 cpuid=$(echo $cpu | awk '{print substr($0,4)}') - dirpath=$CPU_PATH/$1
if [ "$cpu" = "cpu0" ]; then is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0 @@ -38,9 +37,9 @@ check_affinity_fails() {
set_offline $cpu
- taskset -c $cpuid /bin/true + taskset -c $cpuid /bin/true 2> /dev/null ret=$? - check "setting affinity on cpu fails" "test $ret -ne 0" + check "setting affinity on $cpu fails" "test $ret -ne 0"
set_online $cpu
diff --git a/cpuhotplug/cpuhotplug_04.sh b/cpuhotplug/cpuhotplug_04.sh index 18a8e9c..37a6923 100755 --- a/cpuhotplug/cpuhotplug_04.sh +++ b/cpuhotplug/cpuhotplug_04.sh @@ -32,7 +32,6 @@ check_task_migrate() { cpu=$1 cpuid=$(echo $cpu | awk '{print substr($0,4)}') cpumask=$((1 << cpuid)) - dirpath=$CPU_PATH/$1
if [ "$cpu" = "cpu0" ]; then is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0 diff --git a/cpuhotplug/cpuhotplug_07.sh b/cpuhotplug/cpuhotplug_07.sh index 2e81f28..dbd7bff 100755 --- a/cpuhotplug/cpuhotplug_07.sh +++ b/cpuhotplug/cpuhotplug_07.sh @@ -31,7 +31,6 @@ UEVENT_READER="../utils/uevent_reader"
check_notification() { cpu=$1 - cpuid=$(echo $cpu | awk '{print substr($0,4)}')
if [ "$cpu" = "cpu0" ]; then is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0 diff --git a/include/functions.sh b/include/functions.sh index 97930ae..b5c9666 100644 --- a/include/functions.sh +++ b/include/functions.sh @@ -95,13 +95,13 @@ log_skip() {
for_each_cpu() {
- func=$1 + cpu_func=$1 shift 1
for cpu in $cpus; do INC=0 CPU=/$cpu - $func $cpu $@ + $cpu_func $cpu $@ done
return 0 @@ -109,14 +109,14 @@ for_each_cpu() {
for_each_governor() {
- cpu=$1 - func=$2 - dirpath=$CPU_PATH/$cpu/cpufreq - governors=$(cat $dirpath/scaling_available_governors) + gov_cpu=$1 + gov_func=$2 + cpufreq_dirpath=$CPU_PATH/$gov_cpu/cpufreq + governors=$(cat $cpufreq_dirpath/scaling_available_governors) shift 2
for governor in $governors; do - $func $cpu $governor $@ + $gov_func $gov_cpu $governor $@ done
return 0 @@ -124,14 +124,14 @@ for_each_governor() {
for_each_frequency() {
- cpu=$1 - func=$2 - dirpath=$CPU_PATH/$cpu/cpufreq - frequencies=$(cat $dirpath/scaling_available_frequencies) + freq_cpu=$1 + freq_func=$2 + cpufreq_dirpath=$CPU_PATH/$freq_cpu/cpufreq + frequencies=$(cat $cpufreq_dirpath/scaling_available_frequencies) shift 2
for frequency in $frequencies; do - $func $cpu $frequency $@ + $freq_func $freq_cpu $frequency $@ done
return 0 @@ -139,40 +139,40 @@ for_each_frequency() {
set_governor() {
- cpu=$1 - dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor + gov_cpu=$1 + scaling_gov_dirpath=$CPU_PATH/$gov_cpu/cpufreq/scaling_governor newgov=$2
- echo $newgov > $dirpath + echo $newgov > $scaling_gov_dirpath }
get_governor() {
- cpu=$1 - dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor + gov_cpu=$1 + scaling_gov_dirpath=$CPU_PATH/$gov_cpu/cpufreq/scaling_governor
- cat $dirpath + cat $scaling_gov_dirpath }
wait_latency() { - cpu=$1 - dirpath=$CPU_PATH/$cpu/cpufreq - gov=$(cat $dirpath/scaling_governor) + wait_latency_cpu=$1 + cpufreq_dirpath=$CPU_PATH/$wait_latency_cpu/cpufreq + gov=$(cat $cpufreq_dirpath/scaling_governor)
# consider per-policy governor case - if [ -e $CPU_PATH/$cpu/cpufreq/$gov ]; then - sampling_rate=$(cat $CPU_PATH/$cpu/cpufreq/$gov/sampling_rate) + if [ -e $CPU_PATH/$wait_latency_cpu/cpufreq/$gov ]; then + sampling_rate=$(cat $CPU_PATH/$wait_latency_cpu/cpufreq/$gov/sampling_rate) else sampling_rate=$(cat $CPU_PATH/cpufreq/$gov/sampling_rate) fi sampling_rate=$((sampling_rate * 1000)) # unit nsec
- latency=$(cat $dirpath/cpuinfo_transition_latency) + latency=$(cat $cpufreq_dirpath/cpuinfo_transition_latency) if [ $? -ne 0 ]; then return 1 fi
- nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w) + nrfreq=$(cat $cpufreq_dirpath/scaling_available_frequencies | wc -w) if [ $? -ne 0 ]; then return 1 fi @@ -189,14 +189,14 @@ frequnit() { ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) mhz=$(echo "scale=1;($freq / 1000)" | bc -l)
- res=$(echo "($ghz > 1.0)" | bc -l) - if [ "$res" = "1" ]; then + ghz_value=$(echo "($ghz > 1.0)" | bc -l) + if [ "$ghz_value" = "1" ]; then echo $ghz GHz return 0 fi
- res=$(echo "($mhz > 1.0)" | bc -l) - if [ "$res" = "1" ];then + mhz_value=$(echo "($mhz > 1.0)" | bc -l) + if [ "$mhz_value" = "1" ];then echo $mhz MHz return 0 fi @@ -206,71 +206,71 @@ frequnit() {
set_frequency() {
- cpu=$1 - dirpath=$CPU_PATH/$cpu/cpufreq + freq_cpu=$1 + cpufreq_dirpath=$CPU_PATH/$freq_cpu/cpufreq newfreq=$2 - setfreqpath=$dirpath/scaling_setspeed + setfreqpath=$cpufreq_dirpath/scaling_setspeed
echo $newfreq > $setfreqpath - wait_latency $cpu + wait_latency $freq_cpu }
get_frequency() { - cpu=$1 - dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq - cat $dirpath + freq_cpu=$1 + scaling_cur_freq=$CPU_PATH/$freq_cpu/cpufreq/scaling_cur_freq + cat $scaling_cur_freq }
get_max_frequency() { - cpu=$1 - dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq - cat $dirpath + freq_cpu=$1 + scaling_max_freq=$CPU_PATH/$freq_cpu/cpufreq/scaling_max_freq + cat $scaling_max_freq }
get_min_frequency() { - cpu=$1 - dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq - cat $dirpath + freq_cpu=$1 + scaling_min_freq=$CPU_PATH/$freq_cpu/cpufreq/scaling_min_freq + cat $scaling_min_freq }
set_online() { - cpu=$1 - dirpath=$CPU_PATH/$cpu + current_cpu=$1 + current_cpu_path=$CPU_PATH/$current_cpu
- if [ "$cpu" = "cpu0" ]; then + if [ "$current_cpu" = "cpu0" ]; then return 0 fi
- echo 1 > $dirpath/online + echo 1 > $current_cpu_path/online }
set_offline() { - cpu=$1 - dirpath=$CPU_PATH/$cpu + current_cpu=$1 + current_cpu_path=$CPU_PATH/$current_cpu
- if [ "$cpu" = "cpu0" ]; then + if [ "$current_cpu" = "cpu0" ]; then return 0 fi
- echo 0 > $dirpath/online + echo 0 > $current_cpu_path/online }
get_online() { - cpu=$1 - dirpath=$CPU_PATH/$cpu + current_cpu=$1 + current_cpu_path=$CPU_PATH/$current_cpu
- cat $dirpath/online + cat $current_cpu_path/online }
check() {
- descr=$1 - func=$2 + check_descr=$1 + check_func=$2 shift 2;
- log_begin "checking $descr" + log_begin "checking $check_descr"
- $func $@ + $check_func $@ if [ $? -ne 0 ]; then log_end "Err" return 1 @@ -289,12 +289,12 @@ check_file() { }
check_cpufreq_files() { - - dirpath=$CPU_PATH/$1/cpufreq + cpu_id=$1 + cpufreq_files_dir=$CPU_PATH/$cpu_id/cpufreq shift 1
for i in $@; do - check_file $i $dirpath || return 1 + check_file $i $cpufreq_files_dir || return 1 done
return 0 @@ -302,22 +302,20 @@ check_cpufreq_files() {
check_sched_mc_files() {
- dirpath=$CPU_PATH - for i in $@; do - check_file $i $dirpath || return 1 + check_file $i $CPU_PATH || return 1 done
return 0 }
check_topology_files() { - - dirpath=$CPU_PATH/$1/topology + cpu=$1 + topology_files_dir=$CPU_PATH/$cpu/topology shift 1
for i in $@; do - check_file $i $dirpath || return 1 + check_file $i $topology_files_dir || return 1 done
return 0 @@ -325,17 +323,17 @@ check_topology_files() {
check_cpuhotplug_files() {
- dirpath=$CPU_PATH/$1 + cpuhotplug_files_dir=$CPU_PATH/$1 shift 1
for i in $@; do - if [ `echo $dirpath | grep -c "cpu0"` -eq 1 ]; then + if [ `echo $cpuhotplug_files_dir | grep -c "cpu0"` -eq 1 ]; then if [ $hotplug_allow_cpu0 -eq 0 ]; then continue fi fi
- check_file $i $dirpath || return 1 + check_file $i $cpuhotplug_files_dir || return 1 done
return 0 diff --git a/include/thermal_functions.sh b/include/thermal_functions.sh index 56a0a3e..56f9d33 100644 --- a/include/thermal_functions.sh +++ b/include/thermal_functions.sh @@ -30,13 +30,12 @@ MAX_CDEV=0-50 check_valid_temp() { file=$1 zone_name=$2 - dir=$THERMAL_PATH/$2 + dir=$THERMAL_PATH/$zone_name
- temp_file=$dir/$1 - func=cat + temp_file=$dir/$file shift 2;
- temp_val=$($func $temp_file) + temp_val=$(cat $temp_file) descr="'$zone_name'/'$file' ='$temp_val'" log_begin "checking $descr"
@@ -52,23 +51,22 @@ check_valid_temp() {
for_each_thermal_zone() {
- func=$1 + thermal_func=$1 shift 1
- zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") + thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
- ALL_ZONE=$zone - for zone in $zones; do + for thermal_zone in $zones; do INC=0 - $func $zone $@ + $thermal_func $thermal_zone $@ done
return 0 }
get_total_trip_point_of_zone() { - - zone_path=$THERMAL_PATH/$1 + zone=$1 + zone_path=$THERMAL_PATH/$zone count=0 shift 1 trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") @@ -113,8 +111,8 @@ for_each_binding_of_zone() { check_valid_binding() { trip_point=$1 zone_name=$2 - dirpath=$THERMAL_PATH/$2 - temp_file=$2/$1 + dirpath=$THERMAL_PATH/$zone_name + temp_file=$zone_name/$trip_point trip_point_val=$(cat $dirpath/$trip_point) get_total_trip_point_of_zone $zone_name trip_point_max=$? @@ -134,8 +132,8 @@ check_valid_binding() { validate_trip_bindings() { zone_name=$1 bind_no=$2 - dirpath=$THERMAL_PATH/$1 - trip_point=cdev$2_trip_point + dirpath=$THERMAL_PATH/$zone_name + trip_point=cdev"$bind_no"_trip_point shift 2
check_file $trip_point $dirpath || return 1 @@ -145,9 +143,9 @@ validate_trip_bindings() { validate_trip_level() { zone_name=$1 trip_no=$2 - dirpath=$THERMAL_PATH/$1 - trip_temp=trip_point_$2_temp - trip_type=trip_point_$2_type + dirpath=$THERMAL_PATH/$zone_name + trip_temp=trip_point_"$trip_no"_temp + trip_type=trip_point_"$trip_no"_type shift 2
check_file $trip_temp $dirpath || return 1 @@ -157,19 +155,18 @@ validate_trip_level() {
for_each_cooling_device() {
- func=$1 + cdev_func=$1 shift 1
- devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']") - if [ "$devices" = "" ]; then + cooling_devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']") + if [ "$cooling_devices" = "" ]; then log_skip "no cooling devices" return 0 fi
- ALL_DEVICE=$devices - for device in $devices; do + for cooling_device in $cooling_devices; do INC=0 - $func $device $@ + $cdev_func $cooling_device $@ done
return 0 diff --git a/thermal/thermal_01.sh b/thermal/thermal_01.sh index e11c884..94bb26b 100755 --- a/thermal/thermal_01.sh +++ b/thermal/thermal_01.sh @@ -31,21 +31,19 @@ ATTRIBUTES="mode temp type uevent"
check_thermal_zone_attributes() { - - dirpath=$THERMAL_PATH/$1 zone_name=$1 + dirpath=$THERMAL_PATH/$zone_name shift 1 - for i in $ATTRIBUTES; do - check_file $i $dirpath || return 1 + for attribute in $ATTRIBUTES; do + check_file $attribute $dirpath || return 1 done
check_valid_temp "temp" $zone_name || return 1 }
check_thermal_zone_mode() { - - dirpath=$THERMAL_PATH/$1 zone_name=$1 + dirpath=$THERMAL_PATH/$zone_name shift 1 prev_mode=$(cat $dirpath/mode) echo -n enabled > $dirpath/mode @@ -62,17 +60,17 @@ check_thermal_zone_mode() {
check_thermal_zone_trip_level() {
- all_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - for i in $all_zones; do - for_each_trip_point_of_zone $i "validate_trip_level" || return 1 + thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") + for thermal_zone in $thermal_zones; do + for_each_trip_point_of_zone $thermal_zone "validate_trip_level" || return 1 done }
check_thermal_zone_bindings() {
- all_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - for i in $all_zones; do - for_each_binding_of_zone $i "validate_trip_bindings" || return 1 + thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") + for thermal_zone in $thermal_zones; do + for_each_binding_of_zone $thermal_zone "validate_trip_bindings" || return 1 done }