From 1652d1fb5148a8269d3e54b4c5193c52f6e27945 Mon Sep 17 00:00:00 2001
From: Michael Vasseur <michael.vasseur@vu.nl>
Date: Fri, 25 Oct 2024 10:21:44 +0200
Subject: [PATCH 1/2] Convert script from tab to spaces

---
 provision-contest/disable-turboboost_ht | 92 ++++++++++++-------------
 1 file changed, 46 insertions(+), 46 deletions(-)

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

From 65252c18af3c2f4f5e8e525cdd32bd48dfb7aaa5 Mon Sep 17 00:00:00 2001
From: Michael Vasseur <michael.vasseur@vu.nl>
Date: Fri, 25 Oct 2024 10:20:21 +0200
Subject: [PATCH 2/2] Pin the frequency on clockspeed

---
 provision-contest/disable-turboboost_ht | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/provision-contest/disable-turboboost_ht b/provision-contest/disable-turboboost_ht
index ad00dc28..ce41e815 100755
--- a/provision-contest/disable-turboboost_ht
+++ b/provision-contest/disable-turboboost_ht
@@ -14,6 +14,11 @@ for cpu in $(ls -1d /sys/devices/system/cpu/cpu* | sort --version-sort) ; do
     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
@@ -21,6 +26,12 @@ for cpu in $(ls -1d /sys/devices/system/cpu/cpu* | sort --version-sort) ; do
         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