Skip to content

Commit

Permalink
cpufreqctl: ensuring POSIX compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDerumigny committed Nov 6, 2022
1 parent cd42f5f commit dff5513
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions tool/cpufreqctl
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,32 @@ not_supported ()
}

# echo min/max/avg/rnd of a space-separated list of numbers
# $1 number of element
# $2 space-separated list of numbers
compute_min_max_avg_rnd ()
{
measures=($1)
nb_measures=${#measures[@]}
nb_measures=$1
measures=$2
max=0
min=${measures[0]}
min=10000000
tot=0
for i in "${measures[@]}"; do
tot=$(($tot + $i))
idx=0
rnd_id=$(shuf -i 0-$((nb_measures-1)) -n 1)
for i in $measures; do
tot=$((tot + i))
if [ "$i" -gt "$max" ]; then
max=$i
fi
if [ "$i" -lt "$min" ]; then
min=$i
fi
if [ "$idx" -eq "$rnd_id" ]; then
rnd=$i
fi
idx=$((idx+1))
done
avg=$(($tot/$nb_measures))
rnd_id=$(($RANDOM % $nb_measures))
rnd=${measures[$rnd_id]}
avg=$((tot/nb_measures))

echo --min "${min}" --max "${max}" --avg "${avg}" --rnd "${rnd}"
}

Expand Down Expand Up @@ -200,7 +207,8 @@ fake_info_current ()
{
fake_init
measures=$(shuf -i 800000-3600000 -n 12)
report_info_current $(compute_min_max_avg_rnd "$measures")
num_cores=12
report_info_current $(compute_min_max_avg_rnd "$num_cores" "$measures")
}

intel_pstate_supported ()
Expand Down Expand Up @@ -285,7 +293,8 @@ intel_pstate_info_frequencies ()
intel_pstate_info_current ()
{
measures=$(cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq)
report_info_current $(compute_min_max_avg_rnd "$measures")
num_cores=$(getconf _NPROCESSORS_ONLN)
report_info_current $(compute_min_max_avg_rnd "$num_cores" "$measures")
}

cpufreq_supported ()
Expand Down Expand Up @@ -463,7 +472,8 @@ cpufreq_info_frequencies ()
cpufreq_info_current ()
{
measures=$(cat /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq)
report_info_current $(compute_min_max_avg_rnd "$measures")
num_cores=$(getconf _NPROCESSORS_ONLN)
report_info_current $(compute_min_max_avg_rnd "$num_cores" "$measures")
}

backend_select()
Expand Down Expand Up @@ -1701,4 +1711,6 @@ main()
done
}

main "$@"
for i in $(seq 1000); do
main "$@" > /dev/null
done

0 comments on commit dff5513

Please sign in to comment.