-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautolimit
executable file
·87 lines (78 loc) · 1.97 KB
/
autolimit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
echo 0 >>/sys/devices/system/cpu/intel_pstate/no_turbo
Kp=100
Kdenom=2
DTnum=1000
DTdenom=1000
DTfloat=1 # this must equal Td/Tdenom
Ti=10
Td=5
Tddenom=10
tt="$(($1 * 1000))" # target temp in mC
echo "Target temp $tt"
e() { # compute the error
m=1000000000 # min undertemp
for temp_i in /sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_input
do
t="$(cat $temp_i)" # temp
d=$((tt - t)) # undertemp
if ((d < m)) # min() algo
then m="${d}" # update min undertemp
mi=$temp_i
mt=$t
fi
done
printf "%13s %2i/%2i" "$(cat "${mi%_input}_label")" "$((mt/1000))" "$((tt/1000))" >&2
echo "$m" # min(undertemp)
}
maxc="$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)"
minc="$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq)"
changeSpeed() {
u="$1"
c="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)"
tc=$((c + u))
if ((tc > maxc))
then tc=$maxc
fi
if ((tc < minc))
then tc=$minc
fi
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
do echo "$tc" >>$i
done
echo " set $tc $( cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq )" >&2
}
checkTrip() {
c="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)"
if (( c < minc ))
then echo "CPU TRIPPED ****************************************"
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
do echo "$minc" >>$i
prev_e=0
int=0
done
sleep 1
fi
}
prev_e=0
int=0
Tis=$(( Ti * DTdenom / DTnum ))
echo Integral time in samples: $Tis
Tds=$(( Td * DTdenom / DTnum ))
echo Differential time in samples: $Tds/$Tddenom
while true
do et=$(e)
p=$((et))
d=$(( ( ( et - prev_e ) * DTdenom ) / DTnum )) # de/dt
prev_e=$(( et ))
d=$(( $d * Tds / $Tddenom )) # Td de/dt
# echo $int $cmt $alpham
int=$(( int + et ))
i=$(( int * DTnum / DTdenom )) # int(0,t,e dt)
i=$(( i / Tis )) # int(0,t,e dt) / Ti
u=$(( $Kp * ( $p + $i + $d ) / $Kdenom ))
printf ' %8i %8i %8i %8i' $p $i $d $u >&2
changeSpeed $u
sleep $DTfloat
checkTrip
done