2022-02-27 03:14:27 +00:00
|
|
|
#!/bin/bash
|
2023-10-23 22:44:47 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2023-10-24 16:00:57 +00:00
|
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
2022-02-05 14:23:32 +00:00
|
|
|
|
|
|
|
. /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
|
2023-01-26 02:49:54 +00:00
|
|
|
echo all
|
2023-07-25 21:06:19 +00:00
|
|
|
echo default
|
2023-01-26 01:41:09 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 00:41:58 +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))
|
2023-01-02 22:47:44 +00:00
|
|
|
MODE=${2}
|
|
|
|
if [ -z "${MODE}" ]
|
|
|
|
then
|
|
|
|
MODE=0
|
|
|
|
fi
|
|
|
|
case ${1} in
|
2023-07-17 11:54:46 +00:00
|
|
|
default)
|
|
|
|
return
|
|
|
|
;;
|
2023-01-02 22:47:44 +00:00
|
|
|
all)
|
2023-01-26 00:41:58 +00:00
|
|
|
THREADS=0
|
2023-01-02 22:47:44 +00:00
|
|
|
MODE="1"
|
|
|
|
;;
|
2023-01-26 02:49:54 +00:00
|
|
|
0)
|
|
|
|
THREADS=1
|
|
|
|
;;
|
2023-01-02 22:47:44 +00:00
|
|
|
*)
|
2023-01-26 00:41:58 +00:00
|
|
|
THREADS=${1}
|
2023-01-02 22:47:44 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2023-01-26 02:49:54 +00:00
|
|
|
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-02 22:47:44 +00:00
|
|
|
|
2023-01-26 01:41:09 +00:00
|
|
|
for thread in $(seq ${THREADS} 1 ${AVAILABLE_THREADS})
|
2023-01-02 22:47:44 +00:00
|
|
|
do
|
2023-01-26 00:41:58 +00:00
|
|
|
echo ${MODE} | tee /sys/devices/system/cpu/cpu${thread}/online >/dev/null 2>&1
|
2023-01-02 22:47:44 +00:00
|
|
|
done
|
|
|
|
}
|
2022-06-01 21:22:25 +00:00
|
|
|
|
|
|
|
set_cpu_gov() {
|
2023-01-02 20:37:06 +00:00
|
|
|
for POLICY in $(ls /sys/devices/system/cpu/cpufreq 2>/dev/null | grep policy[0-9])
|
2022-02-05 22:40:57 +00:00
|
|
|
do
|
2023-01-02 20:48:29 +00:00
|
|
|
if [ -e "/sys/devices/system/cpu/cpufreq/${POLICY}/scaling_governor" ]
|
2022-10-05 10:22:07 +00:00
|
|
|
then
|
2023-01-02 20:47:33 +00:00
|
|
|
echo $1 >/sys/devices/system/cpu/cpufreq/${POLICY}/scaling_governor 2>/dev/null
|
2022-10-05 10:22:07 +00:00
|
|
|
fi
|
2022-02-05 22:40:57 +00:00
|
|
|
done
|
2022-06-01 21:22:25 +00:00
|
|
|
}
|
2022-02-05 22:40:57 +00:00
|
|
|
|
2022-06-01 21:22:25 +00:00
|
|
|
set_dmc_gov() {
|
2022-10-05 10:22:07 +00:00
|
|
|
if [ -e "${DMC_FREQ}/governor" ]
|
|
|
|
then
|
2023-07-12 22:27:00 +00:00
|
|
|
for governor in $1 dmc_$1 simple_$1
|
|
|
|
do
|
2023-07-19 15:29:53 +00:00
|
|
|
echo ${governor} >${DMC_FREQ}/governor 2>/dev/null
|
2023-07-12 22:27:00 +00:00
|
|
|
if [ "$?" = 0 ]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
2022-10-05 10:22:07 +00:00
|
|
|
fi
|
2022-06-01 21:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_gpu_gov() {
|
2022-10-05 10:22:07 +00:00
|
|
|
if [ -e "${GPU_FREQ}/governor" ]
|
|
|
|
then
|
2023-07-12 22:27:00 +00:00
|
|
|
for governor in $1 dmc_$1 simple_$1
|
|
|
|
do
|
2023-07-19 15:29:53 +00:00
|
|
|
echo ${governor} >${GPU_FREQ}/governor 2>/dev/null
|
2023-07-12 22:27:00 +00:00
|
|
|
if [ "$?" = 0 ]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
2022-10-05 10:22:07 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-01-26 00:41:58 +00:00
|
|
|
onlinethreads() {
|
|
|
|
set_online_threads ${1} ${2}
|
2023-01-02 22:47:44 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 10:56:46 +00:00
|
|
|
performance() {
|
2022-06-01 21:22:25 +00:00
|
|
|
set_cpu_gov performance
|
|
|
|
set_dmc_gov performance
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 10:56:46 +00:00
|
|
|
ondemand() {
|
2022-06-01 21:22:25 +00:00
|
|
|
set_cpu_gov ondemand
|
2023-07-12 22:27:00 +00:00
|
|
|
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
|
2023-07-12 22:27:00 +00:00
|
|
|
set_dmc_gov ondemand
|
2022-06-01 10:56:46 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 14:23:32 +00:00
|
|
|
powersave() {
|
2022-06-01 21:22:25 +00:00
|
|
|
set_cpu_gov powersave
|
|
|
|
set_dmc_gov powersave
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|