@@ -7,57 +7,57 @@ declare -A core_ids
77
88# shellcheck disable=SC2012
99for cpu in $( ls -1d /sys/devices/system/cpu/cpu* | sort --version-sort) ; do
10- [[ $( basename $cpu ) =~ ^cpu[0-9]+$ ]] || continue
11-
12- # Reenable stuff in case we are rerunning this script.
13- [ -f $cpu /online ] && echo 1 > $cpu /online
14- if [ -f $cpu /cpufreq/scaling_governor ]; then
15- chmod u+w $cpu /cpufreq/scaling_governor
16- fi
17-
18- # Set governor to performance and do not allow changes later on.
19- if [ -f $cpu /cpufreq/scaling_governor ]; then
20- echo performance > $cpu /cpufreq/scaling_governor
21- chmod a-w $cpu /cpufreq/scaling_governor
22- fi
23-
24- # Disable all but one thread on each core. Both core_id and physical_package_id are
25- # numbers it must be ensured that for the following examples are seen as distinct:
26- # - core_id=1, physical_package=11
27- # - core_id=11, physycal_package=1
28- # Simple concatenation would result in the string '111' for both cores. Though `cat`
29- # adds a newline after each file, we do not want to rely on `cat` to always add this
30- # 'delimiter'.
31- core_id=$( cat $cpu /topology/core_id | tr -d ' \n' ) ' -' $( cat $cpu /topology/physical_package_id | tr -d ' \n' )
32- if [[ ${core_ids[$core_id]:- } ]]; then
33- echo 0 > $cpu /online
34- else
35- core_ids[$core_id ]=1
36- fi
10+ [[ $( basename $cpu ) =~ ^cpu[0-9]+$ ]] || continue
11+
12+ # Reenable stuff in case we are rerunning this script.
13+ [ -f $cpu /online ] && echo 1 > $cpu /online
14+ if [ -f $cpu /cpufreq/scaling_governor ]; then
15+ chmod u+w $cpu /cpufreq/scaling_governor
16+ fi
17+
18+ # Set governor to performance and do not allow changes later on.
19+ if [ -f $cpu /cpufreq/scaling_governor ]; then
20+ echo performance > $cpu /cpufreq/scaling_governor
21+ chmod a-w $cpu /cpufreq/scaling_governor
22+ fi
23+
24+ # Disable all but one thread on each core. Both core_id and physical_package_id are
25+ # numbers it must be ensured that for the following examples are seen as distinct:
26+ # - core_id=1, physical_package=11
27+ # - core_id=11, physycal_package=1
28+ # Simple concatenation would result in the string '111' for both cores. Though `cat`
29+ # adds a newline after each file, we do not want to rely on `cat` to always add this
30+ # 'delimiter'.
31+ core_id=$( cat $cpu /topology/core_id | tr -d ' \n' ) ' -' $( cat $cpu /topology/physical_package_id | tr -d ' \n' )
32+ if [[ ${core_ids[$core_id]:- } ]]; then
33+ echo 0 > $cpu /online
34+ else
35+ core_ids[$core_id ]=1
36+ fi
3737done
3838
3939DIR_INTEL=/sys/devices/system/cpu/intel_pstate
4040DIR_AMD=/sys/devices/system/cpu/cpufreq
4141if [ -d $DIR_INTEL ]; then
42- # now disable turbo boost
43- FILE=$DIR_INTEL /no_turbo
44- echo -n 1 > $FILE || echo " Could not write to '$FILE ', ignoring for now..."
45- if [ $( cat $FILE ) -ne 1 ]; then
46- echo " Error: turboboost still enabled!"
47- exit 1
48- fi
49-
50- # increase freq from powersaving to normal, but don't overclock
51- echo 100 > $DIR_INTEL /min_perf_pct
52- echo 100 > $DIR_INTEL /max_perf_pct
42+ # now disable turbo boost
43+ FILE=$DIR_INTEL /no_turbo
44+ echo -n 1 > $FILE || echo " Could not write to '$FILE ', ignoring for now..."
45+ if [ $( cat $FILE ) -ne 1 ]; then
46+ echo " Error: turboboost still enabled!"
47+ exit 1
48+ fi
49+
50+ # increase freq from powersaving to normal, but don't overclock
51+ echo 100 > $DIR_INTEL /min_perf_pct
52+ echo 100 > $DIR_INTEL /max_perf_pct
5353elif [ -d $DIR_AMD ]; then
54- # now disable boosting
55- FILE=$DIR_AMD /boost
56- echo -n 0 > $FILE || echo " Could not write to '$FILE ', ignoring for now..."
57- if [ $( cat $FILE ) -ne 0 ]; then
58- echo " Error: turboboost still enabled!"
59- exit 1
60- fi
54+ # now disable boosting
55+ FILE=$DIR_AMD /boost
56+ echo -n 0 > $FILE || echo " Could not write to '$FILE ', ignoring for now..."
57+ if [ $( cat $FILE ) -ne 0 ]; then
58+ echo " Error: turboboost still enabled!"
59+ exit 1
60+ fi
6161else
62- echo " Warning: kernel (turbo) boost config not found in '$DIR_INTEL ' or '$DIR_AMD '."
62+ echo " Warning: kernel (turbo) boost config not found in '$DIR_INTEL ' or '$DIR_AMD '."
6363fi
0 commit comments