Skip to content

Commit

Permalink
cpu: Handle missing scaling_available_frequencies on Intel CPU
Browse files Browse the repository at this point in the history
Signed-off-by: Rem01Gaming <[email protected]>
  • Loading branch information
Rem01Gaming committed Oct 15, 2024
1 parent 6e18281 commit 1f06ae7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
42 changes: 28 additions & 14 deletions share/init_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,36 @@ fi
chipset="$(echo $chipset | tr ' ' '\n' | sort -u | tr '\n' ' ')"

cores=$(($(nproc --all) - 1))
ARCH=$(uname -m)

# Normalize architecture names
case "$ARCH" in
x86_64) ARCH="x86_64" ;; # 64-bit x86
i686 | i386) ARCH="x86" ;; # 32-bit x86
aarch64) ARCH="arm64" ;; # 64-bit ARM
armv7* | armv8* | armhf) ARCH="arm" ;; # 32-bit ARM
*) ARCH="unknown" ;; # Default case if unknown
esac

policy_folders=($(ls -d /sys/devices/system/cpu/cpufreq/policy* | sort -V))
nr_clusters=${#policy_folders[@]}

if [ $nr_clusters -gt 1 ]; then
is_big_little=1
cluster0=$(cat ${policy_folders[0]}/related_cpus 2>/dev/null)
cluster1=$(cat ${policy_folders[1]}/related_cpus 2>/dev/null)
cluster2=$(cat ${policy_folders[2]}/related_cpus 2>/dev/null)

if [ $(cat /sys/devices/system/cpu/cpufreq/policy$(echo ${cluster0} | awk '{print $1}')/scaling_available_frequencies | awk '{print $1}') -gt $(cat /sys/devices/system/cpu/cpufreq/policy$(echo ${cluster1} | awk '{print $1}')/scaling_available_frequencies | awk '{print $1}') ]; then
# If the frequency of cluster0 (little cpu) is bigger than cluster1 (big cpu)
# then there's a chance if it's swapped, correct it.
cluster0=$(cat ${policy_folders[1]}/related_cpus 2>/dev/null)
cluster1=$(cat ${policy_folders[0]}/related_cpus 2>/dev/null)
if [[ "$ARCH" == "*arm*" ]]; then
policy_folders=($(ls -d /sys/devices/system/cpu/cpufreq/policy* | sort -V))
nr_clusters=${#policy_folders[@]}

if [ $nr_clusters -gt 1 ]; then
is_big_little=1
cluster0=$(cat ${policy_folders[0]}/related_cpus 2>/dev/null)
cluster1=$(cat ${policy_folders[1]}/related_cpus 2>/dev/null)
cluster2=$(cat ${policy_folders[2]}/related_cpus 2>/dev/null)

if [ $(cat /sys/devices/system/cpu/cpufreq/policy$(echo ${cluster0} | awk '{print $1}')/scaling_available_frequencies | awk '{print $1}') -gt $(cat /sys/devices/system/cpu/cpufreq/policy$(echo ${cluster1} | awk '{print $1}')/scaling_available_frequencies | awk '{print $1}') ]; then
# If the frequency of cluster0 (little cpu) is bigger than cluster1 (big cpu)
# then there's a chance if it's swapped, correct it.
cluster0=$(cat ${policy_folders[1]}/related_cpus 2>/dev/null)
cluster1=$(cat ${policy_folders[0]}/related_cpus 2>/dev/null)
fi
fi
else
is_big_little=0
fi

# GPU info
Expand Down
21 changes: 20 additions & 1 deletion share/utils/cpu/cpu_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ elif [[ $soc == Qualcomm ]]; then
source $PREFIX/share/origami-kernel/utils/cpu/qcom_cpubus.sh
fi

intel_scaling_available_frequencies() {
NumSteps=$(cat /sys/devices/system/cpu/intel_pstate/num_pstates)
MinFreq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq)
MaxFreq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq)
LastFreq=$MinFreq
StepRate=$((($MaxFreq - $MinFreq) / $NumSteps))
for ((n = 0; n <= $NumSteps; n++)); do
echo $LastFreq
LastFreq=$(($LastFreq + $StepRate))
done
}

cpu_cluster_handle() {
case $1 in
little) cluster_need_set=0 ;;
Expand Down Expand Up @@ -105,7 +117,14 @@ cpu_set_freq() {
esac
cpu_cluster_handle $cluster_selected
max_min=$1
local freq=$(fzf_select "$(cat /sys/devices/system/cpu/cpufreq/policy${first_cpu_oncluster}/scaling_available_frequencies)" "Select $max_min CPU freq for $cluster_selected cluster: ")

if [ $soc == "Intel" ]; then
local available_freq="$(intel_scaling_available_frequencies)"
else
local available_freq="$(cat /sys/devices/system/cpu/cpufreq/policy${first_cpu_oncluster}/scaling_available_frequencies)"
fi

local freq=$(fzf_select "$available_freq" "Select $max_min CPU freq for $cluster_selected cluster: ")
command2db cpu.$cluster_selected.${max_min}_freq "cpu_set_freq -exec $freq $cluster_selected $max_min" FALSE
fi

Expand Down

0 comments on commit 1f06ae7

Please sign in to comment.