Skip to content

Commit ba626b3

Browse files
meisterTDOMjudge @ NWERC
authored andcommitted
Update script to work with arbritrary number of CPU cores.
1 parent a9d6dfe commit ba626b3

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

icpc-wf/disable-turboboost_ht

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,23 @@
11
#!/bin/bash -e
22

3-
# let's disable threads on different cores
4-
cpu0=$(cat /sys/devices/system/cpu/cpu0/topology/core_id)
5-
cpu1=$(cat /sys/devices/system/cpu/cpu1/topology/core_id)
6-
cpu2=$(cat /sys/devices/system/cpu/cpu2/topology/core_id)
7-
cpu3=$(cat /sys/devices/system/cpu/cpu3/topology/core_id)
8-
93
# set governor to performance
10-
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
11-
echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
12-
echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
13-
echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
4+
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
5+
echo performance > $i
6+
done
147

158
# do not allow changes later on
169
chmod -w /sys/devices/system/cpu/cpu?/cpufreq/scaling_governor
1710

18-
# disable last thread
19-
echo 0 > /sys/devices/system/cpu/cpu3/online
20-
21-
# disable thread with different core id
22-
if [ $cpu3 -ne $cpu2 ]; then
23-
echo 0 > /sys/devices/system/cpu/cpu2/online
24-
elif [ $cpu3 -ne $cpu1 ]; then
25-
echo 0 > /sys/devices/system/cpu/cpu1/online
26-
elif [ $cpu3 -ne $cpu0 ]; then
27-
echo 0 > /sys/devices/system/cpu/cpu0/online
28-
else
29-
# found no thread with different core id
30-
exit -1
31-
fi
32-
11+
# disable all but on thread on each core
12+
declare -A core_ids
13+
for i in /sys/devices/system/cpu/cpu?/topology/core_id; do
14+
core_id=$(cat $i)
15+
if [[ ${core_ids[$core_id]} ]]; then
16+
echo 0 > $(dirname $i)/../online
17+
else
18+
core_ids[$core_id]=1
19+
fi
20+
done
3321

3422
# now disable turbo boost
3523
echo -n 1 > /sys/devices/system/cpu/intel_pstate/no_turbo

0 commit comments

Comments
 (0)