Skip to content

Commit

Permalink
Convert script from tab to spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vasseur authored and vmcj committed Oct 25, 2024
1 parent 0b0ee14 commit ef93e0c
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions provision-contest/disable-turboboost_ht
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,57 @@ declare -A core_ids

# shellcheck disable=SC2012
for cpu in $(ls -1d /sys/devices/system/cpu/cpu* | sort --version-sort) ; do
[[ $(basename $cpu) =~ ^cpu[0-9]+$ ]] || continue

# Reenable stuff in case we are rerunning this script.
[ -f $cpu/online ] && echo 1 > $cpu/online
if [ -f $cpu/cpufreq/scaling_governor ]; then
chmod u+w $cpu/cpufreq/scaling_governor
fi

# Set governor to performance and do not allow changes later on.
if [ -f $cpu/cpufreq/scaling_governor ]; then
echo performance > $cpu/cpufreq/scaling_governor
chmod a-w $cpu/cpufreq/scaling_governor
fi

# Disable all but one thread on each core. Both core_id and physical_package_id are
# numbers it must be ensured that for the following examples are seen as distinct:
# - core_id=1, physical_package=11
# - core_id=11, physycal_package=1
# Simple concatenation would result in the string '111' for both cores. Though `cat`
# adds a newline after each file, we do not want to rely on `cat` to always add this
# 'delimiter'.
core_id=$(cat $cpu/topology/core_id | tr -d '\n')'-'$(cat $cpu/topology/physical_package_id | tr -d '\n')
if [[ ${core_ids[$core_id]:-} ]]; then
echo 0 > $cpu/online
else
core_ids[$core_id]=1
fi
[[ $(basename $cpu) =~ ^cpu[0-9]+$ ]] || continue

# Reenable stuff in case we are rerunning this script.
[ -f $cpu/online ] && echo 1 > $cpu/online
if [ -f $cpu/cpufreq/scaling_governor ]; then
chmod u+w $cpu/cpufreq/scaling_governor
fi

# Set governor to performance and do not allow changes later on.
if [ -f $cpu/cpufreq/scaling_governor ]; then
echo performance > $cpu/cpufreq/scaling_governor
chmod a-w $cpu/cpufreq/scaling_governor
fi

# Disable all but one thread on each core. Both core_id and physical_package_id are
# numbers it must be ensured that for the following examples are seen as distinct:
# - core_id=1, physical_package=11
# - core_id=11, physycal_package=1
# Simple concatenation would result in the string '111' for both cores. Though `cat`
# adds a newline after each file, we do not want to rely on `cat` to always add this
# 'delimiter'.
core_id=$(cat $cpu/topology/core_id | tr -d '\n')'-'$(cat $cpu/topology/physical_package_id | tr -d '\n')
if [[ ${core_ids[$core_id]:-} ]]; then
echo 0 > $cpu/online
else
core_ids[$core_id]=1
fi
done

DIR_INTEL=/sys/devices/system/cpu/intel_pstate
DIR_AMD=/sys/devices/system/cpu/cpufreq
if [ -d $DIR_INTEL ]; then
# now disable turbo boost
FILE=$DIR_INTEL/no_turbo
echo -n 1 > $FILE || echo "Could not write to '$FILE', ignoring for now..."
if [ $(cat $FILE) -ne 1 ]; then
echo "Error: turboboost still enabled!"
exit 1
fi

# increase freq from powersaving to normal, but don't overclock
echo 100 > $DIR_INTEL/min_perf_pct
echo 100 > $DIR_INTEL/max_perf_pct
# now disable turbo boost
FILE=$DIR_INTEL/no_turbo
echo -n 1 > $FILE || echo "Could not write to '$FILE', ignoring for now..."
if [ $(cat $FILE) -ne 1 ]; then
echo "Error: turboboost still enabled!"
exit 1
fi

# increase freq from powersaving to normal, but don't overclock
echo 100 > $DIR_INTEL/min_perf_pct
echo 100 > $DIR_INTEL/max_perf_pct
elif [ -d $DIR_AMD ]; then
# now disable boosting
FILE=$DIR_AMD/boost
echo -n 0 > $FILE || echo "Could not write to '$FILE', ignoring for now..."
if [ $(cat $FILE) -ne 0 ]; then
echo "Error: turboboost still enabled!"
exit 1
fi
# now disable boosting
FILE=$DIR_AMD/boost
echo -n 0 > $FILE || echo "Could not write to '$FILE', ignoring for now..."
if [ $(cat $FILE) -ne 0 ]; then
echo "Error: turboboost still enabled!"
exit 1
fi
else
echo "Warning: kernel (turbo) boost config not found in '$DIR_INTEL' or '$DIR_AMD'."
echo "Warning: kernel (turbo) boost config not found in '$DIR_INTEL' or '$DIR_AMD'."
fi

0 comments on commit ef93e0c

Please sign in to comment.