distribution/packages/jelos/profile.d/99-freqfunctions

126 lines
2.3 KiB
Text
Raw Normal View History

#!/bin/bash
2022-02-05 14:23:32 +00:00
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius)
. /etc/os-release
2023-01-26 01:41:09 +00:00
get_threads() {
for THREAD in $(seq 1 1 $(find /sys/devices/system/cpu -name online | wc -l))
do
echo ${THREAD}
done
echo all
echo default
2023-01-26 01:41:09 +00:00
}
set_online_threads() {
2023-01-26 01:41:09 +00:00
AVAILABLE_THREADS=$(($(find /sys/devices/system/cpu -name online | wc -l) - 1))
MODE=${2}
if [ -z "${MODE}" ]
then
MODE=0
fi
case ${1} in
default)
return
;;
all)
THREADS=0
MODE="1"
;;
0)
THREADS=1
;;
*)
THREADS=${1}
;;
esac
for thread in $(seq 0 1 ${THREADS})
do
echo 1 | tee /sys/devices/system/cpu/cpu${thread}/online >/dev/null 2>&1
done
2023-01-26 01:41:09 +00:00
for thread in $(seq ${THREADS} 1 ${AVAILABLE_THREADS})
do
echo ${MODE} | tee /sys/devices/system/cpu/cpu${thread}/online >/dev/null 2>&1
done
}
set_cpu_gov() {
for POLICY in $(ls /sys/devices/system/cpu/cpufreq 2>/dev/null | grep policy[0-9])
do
2023-01-02 20:48:29 +00:00
if [ -e "/sys/devices/system/cpu/cpufreq/${POLICY}/scaling_governor" ]
then
2023-01-02 20:47:33 +00:00
echo $1 >/sys/devices/system/cpu/cpufreq/${POLICY}/scaling_governor 2>/dev/null
fi
done
}
set_dmc_gov() {
if [ -e "${DMC_FREQ}/governor" ]
then
for governor in $1 dmc_$1 simple_$1
do
echo ${governor} >${DMC_FREQ}/governor 2>/dev/null
if [ "$?" = 0 ]
then
return
fi
done
fi
}
set_gpu_gov() {
if [ -e "${GPU_FREQ}/governor" ]
then
for governor in $1 dmc_$1 simple_$1
do
echo ${governor} >${GPU_FREQ}/governor 2>/dev/null
if [ "$?" = 0 ]
then
return
fi
done
fi
}
set_amdgpu_perf() {
for AMDGPU_PERF_DEVICE in $(find /sys/devices -name power_dpm_force_performance_level 2>/dev/null)
do
echo $1 >${AMDGPU_PERF_DEVICE} 2>/dev/null
done
2022-02-05 14:23:32 +00:00
}
onlinethreads() {
set_online_threads ${1} ${2}
}
performance() {
set_cpu_gov performance
set_amdgpu_perf profile_peak
set_gpu_gov performance
set_dmc_gov performance
2022-02-05 14:23:32 +00:00
}
ondemand() {
set_cpu_gov ondemand
set_amdgpu_perf auto
set_gpu_gov ondemand
set_dmc_gov ondemand
2022-02-05 14:23:32 +00:00
}
2022-12-21 22:24:01 +00:00
schedutil() {
set_cpu_gov schedutil
set_amdgpu_perf auto
set_gpu_gov ondemand
set_dmc_gov ondemand
}
2022-02-05 14:23:32 +00:00
powersave() {
set_cpu_gov powersave
set_amdgpu_perf low
set_gpu_gov powersave
set_dmc_gov powersave
2022-02-05 14:23:32 +00:00
}