From 1f06ae75f5bd21bd1e7721be9b208b3b2410478e Mon Sep 17 00:00:00 2001 From: Rem01Gaming Date: Tue, 15 Oct 2024 08:50:16 +0700 Subject: [PATCH] cpu: Handle missing `scaling_available_frequencies` on Intel CPU Signed-off-by: Rem01Gaming --- share/init_run.sh | 42 ++++++++++++++++++++++++------------- share/utils/cpu/cpu_util.sh | 21 ++++++++++++++++++- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/share/init_run.sh b/share/init_run.sh index 6484e79..4474a3e 100644 --- a/share/init_run.sh +++ b/share/init_run.sh @@ -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 diff --git a/share/utils/cpu/cpu_util.sh b/share/utils/cpu/cpu_util.sh index 62f15e0..569297c 100644 --- a/share/utils/cpu/cpu_util.sh +++ b/share/utils/cpu/cpu_util.sh @@ -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 ;; @@ -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