Premessa dell'autore:
Quote:
You can always use a userspace governer. I've attached the one I use.
Every five seconds (you can make it faster if you wish, but that seems
about right for my usage patterns), the program reads the load
average, and decides whether to adjust the CPU frequency. If the one
second load average is above $FASTTRESHHOLD, the frequency will be
stepped up by $FASTINC; otherwise if it's above $SLOWTHRESHHOLD, it's
incremented by $SLOWINC. If the 15-second load average is below
$DECTHRESSHOLD, the frequency is stepped downwards by $DEC. So you
get fast increases, and slow decreases, but becasue the time constant
for the decrease is long, you can get good response for a load spike,
then fairly rapid decrease. The aim is to keep the load average
around 0.9.
|
Codice:
#!/bin/sh
# Seconds to sleep between adjustments
INTERVAL=5
# The controller increments the throttling state by FASTINC
# if the load average is over FASTTRHESHHOLD.
# Thresholds are in percentage points load average -- i.e., the one
# second load average of 1.0 corresponds to a threshold of 100.
FASTINC=3
FASTTHRESHOLD=100
# Slow increment
SLOWINC=1
SLOWTHRESHOLD=80
# Decrement
DEC=1
DECTHRESHOLD=500
cd /sys/devices/system/cpu/cpu0/cpufreq
# Do some parameter checks.
[ $FASTTHRESHOLD -le $SLOWTHRESHOLD ] && {
echo >&2 "Fast Threshold $FASTTHRESHOLD must be greater than the"
echo >&2 "slow threshold $SLOWTHRESHOLD"
exit 1
}
[ \( $SLOWINC -ge 1 \) -a \( $FASTINC -ge 1 \) -a \( $DEC -ge 1 \) ] || {
echo >&2 "Increments must all be small integers in the range 1 to 7"
exit 1
}
# convert a two dec place number to an int scaled by 100.
function to_int()
{
val=$1
OIFS="$IFS"
IFS="."
set $val
IFS="$OIFS"
expr $1 \* 100 + $2
}
# get load averages
function loadavg()
{
read onesec fivesec fifteensec rest < /proc/loadavg
onesec=`to_int $onesec`
fifteensec=`to_int $fifteensec`
}
function getspeeds()
{
echo userspace > scaling_governor
set `cat scaling_available_frequencies`
i=0
for j
do
i=`expr $i + 1`
eval speed$i=$j
done
nspeeds=$i
}
# Get current throttling factor.
# This can be changed automatically by the BIOS in response to power
# events (e.g., AC coming on line).
function throttle() {
< scaling_cur_freq read curfreq
i=1;
while [ $i -lt $nspeeds ]
do
eval [ \$speed$i -eq 0$curfreq ] && expr $nspeeds - $i
i=`expr $i + 1`
done
}
function set_speed() {
x=`expr $nspeeds - $1`
eval speed=\$speed$x
echo $speed > scaling_setspeed
}
# Increase the effective processor speed.
function up()
{
[ $current_throttle -eq 0 ] || {
current_throttle=`expr $current_throttle - $1`
[ $current_throttle -lt 0 ] && current_throttle=0
set_speed $current_throttle
}
}
# Decrease the effective processor speed.
function down()
{
[ $current_throttle -eq $nspeeds ] || {
current_throttle=`expr $current_throttle + $1`
[ $current_throttle -gt $nspeeds ] && current_throttle=$nspeeds
set_speed $current_throttle
}
}
getspeeds
current_throttle=`throttle`
while sleep $INTERVAL
do
loadavg
# Go up fast, then tail off.
#
if [ $onesec -gt $FASTTHRESHOLD ]
then
up $FASTINC
elif [ $onesec -gt $SLOWTHRESHOLD ]
then
up $SLOWINC
elif [ $fifteensec -lt $DECTHRESHOLD ]
then
down $DEC
fi
done
Quello che io voglio faccia:
--> aumenti la frequenza velocemente nel tempo ma con a passi molto piccoli indipendentemente dalla richiesta della CPU. Mi spiego. Ondemand e Powernowd aumentano velocemente nel tempo ma in base al carico di lavoro. Se vedono che la cpu lavora al 100% loro aumentano subito la frequenza (e qui mi sta bene) ma settano subito la frequenza massima. Io voglio che nel caso specificato la frequenza non sia cmq quella massima ma che l'aumento avvenga prontamente. Riassumendo: aumento pronto ma graduale.
--> appena cala la richiesta di potenza immediato abbassamento della cpu.
INTERESSANTE:
http://n-dimensional.de/projects/cpufreq/algorithms.txt