Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better pin frequency #178

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 57 additions & 46 deletions provision-contest/disable-turboboost_ht
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,68 @@ 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
for boundary in min max; do
if [ -f $cpu/cpufreq/scaling_${boundary}_freq ]; then
chmod u+w $cpu/cpufreq/scaling_${boundary}_freq
fi
done

# 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

# Hardware maximum performance.
if [ -f $cpu/cpufreq/scaling_min_freq ] && [ -f $cpu/cpufreq/scaling_max_freq ]; then
cp $cpu/cpufreq/scaling_{max,min}_freq
chmod a-w $cpu/cpufreq/scaling_{max,min}_freq
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
Loading