diff --git a/provision-contest/disable-turboboost_ht b/provision-contest/disable-turboboost_ht index 289d61ba..ce41e815 100755 --- a/provision-contest/disable-turboboost_ht +++ b/provision-contest/disable-turboboost_ht @@ -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