Skip to content

Commit ca79cda

Browse files
committed
Combined sleep values, improved check_diff calculations
1 parent e44f235 commit ca79cda

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

temp.sh

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
prf() { printf %s\\n "$*" ; }
44

5-
s="0"; max_t="0"; tdiff="0"; display=""; new_spd="0"; num_gpus="0"; CDPATH=""
6-
num_fans="0"; current_t="0"; z=$0; fname=""; check_diff1=""; check_diff2=""
5+
max_t="0"; tdiff="0"; display=""; new_spd="0"; num_gpus="0"; CDPATH=""
6+
num_fans="0"; current_t="0"; z=$0; fname=""; check_diff1="0"; check_diff2="0"
77
fcurve_len="0"; num_gpus_loop="0"; declare -a old_t=(); declare -a exp_sp=()
88
mnt=0; mxt=0; ot=0; declare -a es=(); fcurve_len2="0"; declare -a exp_sp2=()
9-
max_t2="0"; num_fans_loop="0"; debug="0"; e="0"; gpu_cmd="nvidia-settings"
9+
max_t2="0"; num_fans_loop="0"; debug="0"; e="0"; sleep_override=""
10+
gpu_cmd="nvidia-settings"
1011

1112
usage="Usage: $(basename "$0") [OPTION]...
1213
@@ -16,6 +17,7 @@ where:
1617
-D run in daemon mode (background process)
1718
-h show this help text
1819
-l enable logging to stdout
20+
-s set the sleep time (in seconds)
1921
-v show the current version of this script"
2022

2123
{ \unalias command; \unset -f command; } >/dev/null 2>&1
@@ -38,13 +40,14 @@ else
3840
fi
3941
conf_file=$(dirname -- "$conf_file")"/config"
4042

41-
while getopts ":h :c: :d: :D :l :v :x" opt; do
43+
while getopts ":h :c: :d: :D :l :v :x :s:" opt; do
4244
case $opt in
4345
c) conf_file="$OPTARG";;
4446
d) display="-c $OPTARG";;
4547
h) e=1; prf "$usage" >&2;;
4648
D) e=1; nohup ./temp.sh >/dev/null 2>&1 &;;
4749
l) debug="1";;
50+
s) sleep_override="$OPTARG";;
4851
v) e=1; prf "Version 17";;
4952
x) gpu_cmd="../nssim/nssim nvidia-settings";;
5053
\?) e=1; prf "Invalid option: -$OPTARG" >&2;;
@@ -97,10 +100,10 @@ finish() {
97100
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98101
echo_info() {
99102
if [ "$new_spd" -ne "${es[$((ot-mnt))]}" ]; then z="y"; else z="n"; fi
100-
prf " t=$current_t oldt=$ot tdiff=$tdiff slp=$s gpu=$gpu
101-
nspd?=${es[$((current_t-mnt))]} nspd=$new_spd cd=$chd maxt=$mxt
102-
mint=$mnt oldspd=${es[$((ot-mnt))]} fan=$fan z=$z
103-
"
103+
e=" t=$current_t oldt=$ot tdiff=$tdiff slp=$sleep_time gpu=$gpu z=$z"
104+
e="$e nspd?=${es[$((current_t-mnt))]} nspd=$new_spd cd=$chd maxt=$mxt"
105+
e="$e mint=$mnt oldspd=${es[$((ot-mnt))]} fan=$fan"
106+
prf "$e"
104107
}
105108

106109
loop_cmds() {
@@ -114,9 +117,7 @@ loop_cmds() {
114117
tdiff="$((current_t-ot))"
115118
fi
116119

117-
if [ "$tdiff" -lt "$chd" ]; then
118-
s="$short_s"
119-
else
120+
if [ "$tdiff" -ge "$chd" ]; then
120121
if [ "$current_t" -lt "$mnt" ]; then
121122
new_spd="0"
122123
elif [ "$current_t" -lt "$mxt" ]; then
@@ -128,6 +129,7 @@ loop_cmds() {
128129
set_speed "$new_spd"
129130
fi
130131
old_t["$fan"]="$current_t"
132+
tdiff="0"
131133
fi
132134
fi
133135

@@ -144,6 +146,8 @@ if ! [ -f "$conf_file" ]; then
144146
fi
145147
source "$conf_file"; prf "Configuration file: $conf_file"
146148

149+
if ! [ -z "$sleep_override" ]; then sleep_time="$sleep_override"; fi
150+
147151
# Check for any user errors in config file
148152
if ! [ "${#fcurve[@]}" -eq "${#tcurve[@]}" ]; then
149153
prf "fcurve and tcurve don't match up!"; exit 1
@@ -190,8 +194,8 @@ done
190194
for i in $(seq 0 "$((fcurve_len2-1))"); do
191195
check_diff2="$((check_diff2+tcurve2[$((i+1))]-tcurve2[i]))"
192196
done
193-
check_diff1="$(((check_diff1/fcurve_len)-long_s+short_s-1))"
194-
check_diff2="$(((check_diff2/fcurve_len2)-long_s+short_s-1))"
197+
check_diff1="$(((check_diff1/(fcurve_len-1))-sleep_time))"
198+
check_diff2="$(((check_diff2/(fcurve_len2-1))-sleep_time))"
195199

196200
set_fan_control "$num_gpus_loop" "1"
197201

@@ -245,20 +249,18 @@ if [ "$num_gpus" -eq "1" ]; then
245249
fan="$default_fan"
246250
set_stuff "$fan"
247251
while true; do
248-
s="$long_s"
249252
ot="${old_t[$fan]}"
250253
loop_cmds
251-
sleep "$s"
254+
sleep "$sleep_time"
252255
done
253256
else
254257
prf "Started process for n-GPUs and n-Fans"
255258
while true; do
256-
s="$long_s"
257259
for fan in $(seq 0 "$num_fans_loop"); do
258260
set_stuff "$fan"
259261
ot="${old_t[$fan]}"
260262
loop_cmds
261263
done
262-
sleep "$s"
264+
sleep "$sleep_time"
263265
done
264266
fi

0 commit comments

Comments
 (0)