Skip to content

Disable efficiency cores #190

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

Merged
merged 5 commits into from
Jul 30, 2025
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
53 changes: 45 additions & 8 deletions provision-contest/disable-turboboost_ht
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ set -eu -o pipefail
shopt -s extglob

declare -A core_ids
declare -a disabled_cores

disable_cpu () {
cpu="$1"
echo 0 > $cpu/online
disabled_cores+=("${cpu##*/}")
}

store_isolcpus_fact="/var/tmp/isolcpus"

# Learn all efficency cores if they exist
cpu_list=()
if [ -f /sys/devices/cpu_atom/cpus ]; then
range="$(cat /sys/devices/cpu_atom/cpus)"
IFS='-' read -r start end <<< "$range"
cpu_list=($(eval echo {$start..$end}))
fi

# shellcheck disable=SC2012
for cpu in $(ls -1d /sys/devices/system/cpu/cpu* | sort --version-sort) ; do
Expand Down Expand Up @@ -32,23 +49,44 @@ for cpu in $(ls -1d /sys/devices/system/cpu/cpu* | sort --version-sort) ; do
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:
# Disable all but one thread on each core per socket. Both core_id and physical_package_id
# are numbers so 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
# - core_id=11, physical_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')

# Disable all efficiency cores
found=0
for efficiency_core in "${cpu_list[@]}"; do
if [[ "$cpu" == "/sys/devices/system/cpu/cpu$efficiency_core" ]]; then
disable_cpu $cpu
found=1
break
fi
done
if [ "$found" -eq "1" ]; then
continue
fi

if [[ ${core_ids[$core_id]:-} ]]; then
echo 0 > $cpu/online
disable_cpu $cpu
else
core_ids[$core_id]=1
fi
done

if [ -n "${store_isolcpus_fact}" ]; then
csv_string=$(IFS=, ; echo "${disabled_cores[*]}")
echo "$csv_string" > "$store_isolcpus_fact"
fi

DIR_INTEL=/sys/devices/system/cpu/intel_pstate
DIR_AMD=/sys/devices/system/cpu/cpufreq
# Same for some ARM CPUs
FILE_AMD=$DIR_AMD/boost
if [ -d $DIR_INTEL ]; then
# now disable turbo boost
FILE=$DIR_INTEL/no_turbo
Expand All @@ -61,11 +99,10 @@ if [ -d $DIR_INTEL ]; then
# 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
elif [ -f $FILE_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 -n 0 > $FILE_AMD || echo "Could not write to '$FILE_AMD', ignoring for now..."
if [ $(cat $FILE_AMD) -ne 0 ]; then
echo "Error: turboboost still enabled!"
exit 1
fi
Expand Down