From 5652d166cfa7433c4ca82867ecaaeecbcfaf7e56 Mon Sep 17 00:00:00 2001 From: Rem01Gaming Date: Wed, 19 Jun 2024 21:00:26 +0700 Subject: [PATCH] Add apply previous settings feature Signed-off-by: Rem01Gaming --- Makefile | 4 +- dpkg-conf/control | 2 +- share/database_util.sh | 53 ++++++ share/exec_storedcmd.sh | 39 ++++ share/{init => }/init_run.sh | 17 +- share/{utils/menu => }/menu_helper.sh | 22 +-- share/settings.sh | 60 ++++++ share/utils/cpu/cpu_util.sh | 260 +++++++++++++++++--------- share/utils/dram/dram_devfreq.sh | 18 +- share/utils/dram/mtk_dram.sh | 11 +- share/utils/dram/qcom_dram.sh | 19 +- share/utils/gpu/adreno_idler.sh | 29 ++- share/utils/gpu/gpu_devfreq.sh | 70 +++++-- share/utils/gpu/gpu_omap.sh | 16 +- share/utils/gpu/gpu_powervr.sh | 64 ------- share/utils/gpu/gpu_qcom_kgsl2.sh | 16 +- share/utils/gpu/gpu_qcom_kgsl3.sh | 16 +- share/utils/gpu/gpu_tegra.sh | 12 +- share/utils/gpu/gpu_util.sh | 10 +- share/utils/gpu/mtk_ged.sh | 72 +++++-- share/utils/gpu/simple_gpu_algo.sh | 22 ++- share/utils/memory/memory_util.sh | 101 ++++++++-- share/utils/misc/misc_util.sh | 106 +++++++++-- share/utils/net/net_util.sh | 99 +++++++--- src/okm | 27 ++- 25 files changed, 870 insertions(+), 295 deletions(-) create mode 100644 share/database_util.sh create mode 100644 share/exec_storedcmd.sh rename share/{init => }/init_run.sh (91%) rename share/{utils/menu => }/menu_helper.sh (94%) create mode 100644 share/settings.sh delete mode 100644 share/utils/gpu/gpu_powervr.sh diff --git a/Makefile b/Makefile index 11bd8b5..d25cc1a 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ install: @printf " ノノ㇏ V ノ|ノ\n" @printf " ⠁⠁\n" @printf "\033[1;38;2;254;228;208m[+] origami-kernel installed, run with 'okm'\033[0m\n" - + uninstall: rm -f $(PREFIX)/bin/okm $(PREFIX)/bin/origami-sudo rm -rf $(PREFIX)/share/origami-kernel @@ -49,7 +49,7 @@ uninstall: install-dependence: @echo "\033[1;38;2;254;228;208m[+] Installing dependencines...\033[0m" @apt install root-repo -y - @apt install fzf fzy git jq -y + @apt install fzf fzy git jq sqlite -y pack-deb: @mkdir -v $(O) diff --git a/dpkg-conf/control b/dpkg-conf/control index 2dfc21b..7fad95d 100644 --- a/dpkg-conf/control +++ b/dpkg-conf/control @@ -4,5 +4,5 @@ Maintainer: Rem01Gaming Installed-Size: 1500 Version: 1.1.0 Homepage: https://github.com/Rem01Gaming/origami_kernel_manager -Depends: fzf, fzy, jq, curl +Depends: fzf, fzy, jq, curl, sqlite Description: Yet another kernel manager. diff --git a/share/database_util.sh b/share/database_util.sh new file mode 100644 index 0000000..bd6bbba --- /dev/null +++ b/share/database_util.sh @@ -0,0 +1,53 @@ +#!/data/data/com.termux/files/usr/bin/origami-sudo bash +# This file is part of Origami Kernel Manager. +# +# Origami Kernel Manager is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Origami Kernel Manager is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Origami Kernel Manager. If not, see . +# +# Copyright (C) 2023-2024 Rem01Gaming + +database_path="/data/origami-kernel/okm.db" + +sql_query() { + echo "$1" | sqlite3 $database_path +} + +if [ ! -f $database_path ]; then + sql_query "CREATE TABLE tb_storecmd (id TEXT PRIMARY KEY, command TEXT NOT NULL, risky BOOLEAN NOT NULL);" + sql_query "CREATE TABLE tb_info (risk_acceptence BOOLEAN NOT NULL, execstoredcmd BOOLEAN NOT NULL, execstoredcmd_risky BOOLEAN NOT NULL);" + sql_query "INSERT INTO tb_info (risk_acceptence, execstoredcmd, execstoredcmd_risky) VALUES (FALSE, FALSE, FALSE);" + sql_query "PRAGMA auto_vacuum = FULL;" +fi + +risk_acceptence() { + sql_query "SELECT risk_acceptence FROM tb_info;" +} + +accept_risk() { + sql_query "UPDATE tb_info SET risk_acceptence = TRUE;" +} + +execstoredcmd_db() { + sql_query "UPDATE tb_info SET execstoredcmd = $1;" +} + +execstoredcmd_risky_db() { + sql_query "UPDATE tb_info SET execstoredcmd_risky = $1;" +} + +# usage: command2db "identifier" "command" "risky (boolean)" +command2db() { + if [ -f /dev/okm-execstoredcmd ]; then + sql_query "INSERT INTO tb_storecmd (id, command, risky) VALUES ('$1', '$2', $3) ON CONFLICT(id) DO UPDATE SET command='$2', risky=$3;" + fi +} diff --git a/share/exec_storedcmd.sh b/share/exec_storedcmd.sh new file mode 100644 index 0000000..fe2af38 --- /dev/null +++ b/share/exec_storedcmd.sh @@ -0,0 +1,39 @@ +#!/data/data/com.termux/files/usr/bin/origami-sudo bash +# This file is part of Origami Kernel Manager. +# +# Origami Kernel Manager is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Origami Kernel Manager is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Origami Kernel Manager. If not, see . +# +# Copyright (C) 2023-2024 Rem01Gaming + +execstoredcmd_allow_risky="$(sql_query "SELECT execstoredcmd_risky FROM tb_info;")" + +execstoredcmd() { + while IFS='|' read -r command risky; do + if [ "$risky" -eq 1 ] && [ "$execstoredcmd_allow_risky" -eq 1 ]; then + eval "$command" + elif [ "$risky" -eq 0 ]; then + eval "$command" + fi + done < <(sql_query "SELECT command, risky FROM tb_storecmd;") +} + +init_execstoredcmd() { + read -r -p "Apply previous settings? [Y/n]: " input + case $input in + [Yy]*) + echo "Applying settings..." + execstoredcmd + ;; + esac +} diff --git a/share/init/init_run.sh b/share/init_run.sh similarity index 91% rename from share/init/init_run.sh rename to share/init_run.sh index e2a84aa..fc190dd 100644 --- a/share/init/init_run.sh +++ b/share/init_run.sh @@ -49,6 +49,9 @@ gpu=$(dumpsys SurfaceFlinger | grep GLES | awk -F ': ' '{print $2}' | tr -d '\n' gpu_devfreq_paths_array=( "$(find /sys/class/devfreq "*.mali" -print -quit 2>/dev/null)" + "/sys/devices/platform/dfrgx/devfreq/dfrgx" + "/sys/class/kgsl/kgsl-3d0/devfreq" + "$(find /sys/class/devfreq "*kgsl-3d0" -print -quit 2>/dev/null)" ) for path in ${gpu_devfreq_paths_array[@]}; do @@ -62,22 +65,18 @@ if [ -d /proc/gpufreq ]; then gpu_node_id=1 elif [ -d /proc/gpufreqv2 ]; then gpu_node_id=2 -elif [ ! -z $gpu_devfreq_path ]; then +elif [ -d $gpu_devfreq_path ]; then # Compensate for Mediatek devices. Mali devfreq interface still exists on Mediatek devices, it just don't fucking work because they injected gpufreq and ged trash into mali driver. gpu_node_id=0 elif [ -d /sys/devices/platform/kgsl-2d0.0/kgsl ]; then gpu_node_id=3 elif [ -d /sys/devices/platform/kgsl-3d0.0/kgsl ]; then gpu_node_id=4 -elif [ -d /sys/class/kgsl/kgsl-3d0 ]; then - gpu_node_id=5 elif [ -d /sys/devices/platform/omap/pvrsrvkm.0 ]; then - gpu_node_id=6 + gpu_node_id=5 elif [ -d /sys/kernel/tegra_gpu ]; then - gpu_node_id=7 -elif [ -d /sys/devices/platform/dfrgx/devfreq ]; then - gpu_node_id=8 + gpu_node_id=6 elif [ -d /sys/kernel/gpu ]; then - gpu_node_id=9 + gpu_node_id=7 fi # DRAM info @@ -110,7 +109,7 @@ if [[ $soc == "Qualcomm" ]] && [ -z $dram_devfreq_path ]; then done fi -# Check for Mediatek's DRAM gebbrish implementation +# Check for Mediatek's DRAM implementation if [[ $soc == "Mediatek" ]] && [ -z $dram_devfreq_path ]; then mtk_dram_paths_array=( "$(find /sys/devices/platform -name "*.dvfsrc" -print -quit 2>/dev/null)/helio-dvfsrc" diff --git a/share/utils/menu/menu_helper.sh b/share/menu_helper.sh similarity index 94% rename from share/utils/menu/menu_helper.sh rename to share/menu_helper.sh index 04841ec..e604d2a 100644 --- a/share/utils/menu/menu_helper.sh +++ b/share/menu_helper.sh @@ -32,6 +32,12 @@ fzy_select() { echo $selected_option } +apply() { + chmod 644 $2 >/dev/null 2>&1 + echo $1 >$2 2>/dev/null + chmod 444 $2 >/dev/null 2>&1 +} + color_blocks() { colors=( "\e[48;5;0m \e[0m" "\e[48;5;1m \e[0m" "\e[48;5;2m \e[0m" "\e[48;5;3m \e[0m" @@ -52,10 +58,10 @@ color_blocks() { menu_value_tune() { echo echo -e "${1}" | fold -s -w ${LINE} - echo -e "\nUse ( ↑ ↓ ) to increase or decrease value\nUse HOME or END to exit\n" + echo -e "\nUse ( ↑ ↓ ) to increase or decrease value\nUse HOME or END to exit.\n" number=$(cat ${2}) - x=${5} + local x=${5} print_number() { printf "\r%s%s" "value: " "$number " @@ -75,12 +81,10 @@ menu_value_tune() { ((number -= x)) fi ;; - *) break ;; + H | F) break ;; esac - chmod 644 $2 >/dev/null 2>&1 - echo $number >$2 2>/dev/null - chmod 444 $2 >/dev/null 2>&1 + apply $number $2 done } @@ -100,9 +104,3 @@ print_existing_folders() { echo "${existing_folders[*]}" fi } - -apply() { - chmod 644 $2 >/dev/null 2>&1 - echo $1 >$2 2>/dev/null - chmod 444 $2 >/dev/null 2>&1 -} diff --git a/share/settings.sh b/share/settings.sh new file mode 100644 index 0000000..dfb2ce4 --- /dev/null +++ b/share/settings.sh @@ -0,0 +1,60 @@ +#!/data/data/com.termux/files/usr/bin/origami-sudo bash +# This file is part of Origami Kernel Manager. +# +# Origami Kernel Manager is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Origami Kernel Manager is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Origami Kernel Manager. If not, see . +# +# Copyright (C) 2023-2024 Rem01Gaming + +execstoredcmd_switch() { + case $(fzf_select "Enable Disable" "Apply previous settings from last session: ") in + Enable) execstoredcmd_db TRUE ;; + Disable) execstoredcmd_db FALSE ;; + esac +} + +execstoredcmd_risky_switch() { + case $(fzf_select "Enable Disable" "Allow risky execution: ") in + Enable) execstoredcmd_risky_db TRUE ;; + Disable) execstoredcmd_risky_db FALSE ;; + esac +} + +settings_menu() { + while true; do + clear + echo -e "\e[30;48;2;254;228;208;38;2;0;0;0m Origami Kernel Manager ${VERSION}$(yes " " | sed $(($LINE - 30))'q' | tr -d '\n')\033[0m" + echo -e "\e[38;2;254;228;208m" + echo -e " _________ [] Apply previous settings: $(sql_query "SELECT execstoredcmd FROM tb_info;")" + echo -e " / /\\ [] Allow risky execution: $(sql_query "SELECT execstoredcmd_risky FROM tb_info;")" + echo -e " / / \\ " + echo -e " / / \\ " + echo -e "/________/ \\ " + echo -e "\\ \\ / " + echo -e " \\ \\ / " + echo -e " \\ \\ / " + echo -e " \\________\\/ " + echo -e "\n//////////////" + echo -e "$(yes "─" | sed ${LINE}'q' | tr -d '\n')\n" + echo -e "[] OKM Settings\033[0m" + + # Hide cursor + tput civis + + case $(fzy_select "Apply previous settings\nAllow risky execution\nBack to main menu" "") in + "Apply previous settings") execstoredcmd_switch ;; + "Allow risky execution") execstoredcmd_risky_switch ;; + "Back to main menu") break ;; + esac + done +} diff --git a/share/utils/cpu/cpu_util.sh b/share/utils/cpu/cpu_util.sh index aff3ed2..7746559 100644 --- a/share/utils/cpu/cpu_util.sh +++ b/share/utils/cpu/cpu_util.sh @@ -17,12 +17,7 @@ # Copyright (C) 2023-2024 Rem01Gaming cpu_cluster_handle() { - case $nr_clusters in - 2) cluster_selected=$(fzf_select "little big" "Select cpu cluster: ") ;; - 3) cluster_selected=$(fzf_select "little big prime" "Select cpu cluster: ") ;; - esac - - case $cluster_selected in + case $1 in little) cluster_need_set=0 ;; big) cluster_need_set=1 ;; prime) cluster_need_set=2 ;; @@ -45,12 +40,29 @@ cpu_cluster_handle() { } cpu_set_gov() { - if [[ $is_big_little == 1 ]]; then - cpu_cluster_handle - local gov_selected=$(fzf_select "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)" "Select CPU Governor: ") + if [ $is_big_little -eq 1 ]; then + if [[ $1 == "-exec" ]]; then + gov_selected=$2 + cluster_selected=$3 + else + case $nr_clusters in + 2) cluster_selected=$(fzf_select "little big" "Select cpu cluster: ") ;; + 3) cluster_selected=$(fzf_select "little big prime" "Select cpu cluster: ") ;; + esac + cpu_cluster_handle $cluster_selected + local gov_selected=$(fzf_select "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)" "Select CPU Governor: ") + command2db cpu.$cluster_selected.governor "cpu_set_gov -exec $gov_selected $cluster_selected" FALSE + fi + apply $gov_selected /sys/devices/system/cpu/cpufreq/policy${first_cpu_oncluster}/scaling_governor else - local gov_selected=$(fzf_select "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)" "Select CPU Governor: ") + if [[ $1 == "-exec" ]]; then + gov_selected=$2 + else + local gov_selected=$(fzf_select "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)" "Select CPU Governor: ") + command2db cpu.governor "cpu_set_gov -exec $gov_selected" FALSE + fi + for ((cpu = 0; cpu < cores; cpu++)); do cpu_dir="/sys/devices/system/cpu/cpu${cpu}" if [ -d "$cpu_dir" ]; then @@ -61,7 +73,7 @@ cpu_set_gov() { } cpu_set_freq() { - if [[ $soc == Mediatek ]] && [ -d /proc/ppm ]; then + if [[ $soc == Mediatek ]] && [ -d /proc/ppm ] && [[ $1 != "-exec" ]]; then if [[ "$(cat /proc/ppm/enabled)" != "ppm is enabled" ]]; then echo -e "\n[-] Enable Performance and Power Management First" echo "[*] Hit enter to back to main menu" @@ -75,70 +87,113 @@ cpu_set_freq() { fi fi - if [[ $is_big_little == 1 ]]; then - cpu_cluster_handle + if [ $is_big_little -eq 1 ]; then + if [[ $1 == "-exec" ]]; then + freq=$2 + cluster_selected=$3 + max_min=$4 + else + case $nr_clusters in + 2) cluster_selected=$(fzf_select "little big" "Select cpu cluster: ") ;; + 3) cluster_selected=$(fzf_select "little big prime" "Select cpu cluster: ") ;; + 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: ") + command2db cpu.$cluster_selected.${max_min}_freq "cpu_set_freq -exec $freq $cluster_selected $max_min" FALSE + fi + if [[ $soc == Mediatek ]] && [ -d /proc/ppm ]; then - local freq=$(fzf_select "$(cat /sys/devices/system/cpu/cpufreq/policy${first_cpu_oncluster}/scaling_available_frequencies)" "Select ${1} CPU freq for ${cluster_selected} cluster: ") - apply "${cluster_need_set} $freq" /proc/ppm/policy/hard_userlimit_${1}_cpu_freq + apply "$cluster_need_set $freq" /proc/ppm/policy/hard_userlimit_${max_min}_cpu_freq else - local freq=$(fzf_select "$(cat /sys/devices/system/cpu/cpufreq/policy${first_cpu_oncluster}/scaling_available_frequencies)" "Select ${1} CPU freq for ${cluster_selected} cluster: ") - apply $freq /sys/devices/system/cpu/cpufreq/policy${first_cpu_oncluster}/scaling_${1}_freq + apply $freq /sys/devices/system/cpu/cpufreq/policy${first_cpu_oncluster}/scaling_${max_min}_freq fi else + if [[ $1 == "-exec" ]]; then + freq=$2 + max_min=$3 + else + max_min=$1 + local freq=$(fzf_select "$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies)" "Select $max_min CPU frequency: ") + command2db cpu.${max_min}_freq "cpu_set_freq -exec $freq $max_min" FALSE + fi + if [[ $soc == Mediatek ]] && [ -d /proc/ppm ]; then - local freq=$(fzf_select "$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies)" "Select ${1} CPU frequency: ") - apply "0 $freq" /proc/ppm/policy/hard_userlimit_${1}_cpu_freq + apply "0 $freq" /proc/ppm/policy/hard_userlimit_${max_min}_cpu_freq else - local freq=$(fzf_select "$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies)" "Select ${1} CPU frequency: ") - apply $freq /sys/devices/system/cpu/cpufreq/policy0/scaling_${1}_freq + for ((cpu = 0; cpu < cores; cpu++)); do + cpu_dir="/sys/devices/system/cpu/cpu${cpu}" + if [ -d "$cpu_dir" ]; then + apply "$freq" "${cpu_dir}/cpufreq/scaling_${max_min}_freq" + fi + done fi fi } cpu_core_ctrl() { - cpu_dir="/sys/devices/system/cpu" + if [[ $1 == "-exec" ]]; then + apply $3 /sys/devices/system/cpu/cpu$2/online + else + cpu_dir="/sys/devices/system/cpu" + + while true; do + options=("cpu0 Online (system essential) ✅") + + # Add options for each CPU core + for ((cpu = 1; cpu <= cores; cpu++)); do + online_status=$(<"${cpu_dir}/cpu${cpu}/online") + if [[ $online_status == 1 ]]; then + status_label="Online ✅" + else + status_label="Offline ❌" + fi + options+=("cpu${cpu} $status_label") + done - while true; do - options=("cpu0 Online (system essential) ✅") - - # Add options for each CPU core - for ((cpu = 1; cpu <= cores; cpu++)); do - online_status=$(<"${cpu_dir}/cpu${cpu}/online") - if [[ $online_status == 1 ]]; then - status_label="Online ✅" - else - status_label="Offline ❌" - fi - options+=("cpu${cpu} $status_label") + # Add a separator and "Back to the main menu" option + options+=(" " "Back to the main menu") + + selected=$(printf '%s\n' "${options[@]}" | fzf --reverse --cycle --prompt "CPU core control") + + case $selected in + "Back to the main menu") break ;; + " ") ;; + *) + cpu_number=$(echo "${selected}" | cut -d' ' -f1 | sed 's/cpu//') + online_status=$(<"${cpu_dir}/cpu${cpu_number}/online") + new_status=$((1 - online_status)) + apply "$new_status" "${cpu_dir}/cpu${cpu_number}/online" + command2db cpu.core_ctl.cpu$cpu_number "cpu_core_ctrl -exec $new_status $cpu_number" FALSE + ;; + esac done - - # Add a separator and "Back to the main menu" option - options+=(" " "Back to the main menu") - - selected=$(printf '%s\n' "${options[@]}" | fzf --reverse --cycle --prompt "CPU core control") - - case $selected in - "Back to the main menu") break ;; - " ") ;; - *) - cpu_number=$(echo "${selected}" | cut -d' ' -f1 | sed 's/cpu//') - online_status=$(<"${cpu_dir}/cpu${cpu_number}/online") - new_status=$((1 - online_status)) - apply "${new_status}" "${cpu_dir}/cpu${cpu_number}/online" - ;; - esac - done + fi } mtk_cpufreq_cci_mode() { - case $(fzf_select "Normal Performance" "Mediatek CPU CCI mode: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Normal Performance" "Mediatek CPU CCI mode: ") + command2db cpu.mtk.cci_mode "mtk_cpufreq_cci_mode -exec $selected" FALSE + fi + + case $selected in Performance) apply 1 /proc/cpufreq/cpufreq_cci_mode ;; Normal) apply 0 /proc/cpufreq/cpufreq_cci_mode ;; esac } mtk_cpufreq_power_mode() { - case $(fzf_select "Normal Low-power Make Performance" "Mediatek CPU Power mode: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Normal Low-power Make Performance" "Mediatek CPU Power mode: ") + command2db cpu.mtk.power_mode "mtk_cpufreq_power_mode -exec $selected" FALSE + fi + + case $selected in Performance) apply 3 /proc/cpufreq/cpufreq_power_mode ;; Low-power) apply 1 /proc/cpufreq/cpufreq_power_mode ;; Make) apply 2 /proc/cpufreq/cpufreq_power_mode ;; @@ -169,45 +224,72 @@ cpu_gov_param() { } mtk_ppm_policy() { - fetch_state() { - cat /proc/ppm/policy_status | grep 'PPM_' | while read line; do echo $line; done - } - - tput cuu 1 - echo -e "\e[38;2;254;228;208m[] Performance and Power Management Menu\033[0m" + if [[ $1 == "-exec" ]]; then + if [[ $2 == "policy" ]]; then + apply "$3 $4" /proc/ppm/policy_status + else + apply $3 /proc/ppm/enabled + fi + else + fetch_state() { + cat /proc/ppm/policy_status | grep 'PPM_' | while read line; do echo $line; done + } - while true; do - selected=$(fzy_select "PPM $(cat /proc/ppm/enabled | awk '{print $3}')\n \n$(fetch_state)\n \nBack to the main menu" "") - - if [[ $selected == "Back to the main menu" ]]; then - break - elif [[ "$(echo $selected | awk '{print $1}')" == "PPM" ]]; then - case "$(cat /proc/ppm/enabled | awk '{print $3}')" in - enabled) apply 0 /proc/ppm/enabled ;; - disabled) apply 1 /proc/ppm/enabled ;; - esac - elif [[ $selected != " " ]]; then - idx=$(echo "$selected" | awk '{print $1}' | awk -F'[][]' '{print $2}') - current_status=$(echo $selected | awk '{print $3}') - - if [[ $current_status == *enabled* ]]; then - new_status=0 - else - new_status=1 + tput cuu 1 + echo -e "\e[38;2;254;228;208m[] Performance and Power Management Menu\033[0m" + + while true; do + selected=$(fzy_select "PPM $(cat /proc/ppm/enabled | awk '{print $3}')\n \n$(fetch_state)\n \nBack to the main menu" "") + + if [[ $selected == "Back to the main menu" ]]; then + break + elif [[ "$(echo $selected | awk '{print $1}')" == "PPM" ]]; then + case "$(cat /proc/ppm/enabled | awk '{print $3}')" in + enabled) + apply 0 /proc/ppm/enabled + command2db cpu.mtk.enable_ppm "mtk_ppm_policy -exec 0" FALSE + ;; + disabled) + apply 1 /proc/ppm/enabled + command2db cpu.mtk.enable_ppm "mtk_ppm_policy -exec 1" FALSE + ;; + esac + elif [[ $selected != " " ]]; then + idx=$(echo "$selected" | awk '{print $1}' | awk -F'[][]' '{print $2}') + current_status=$(echo $selected | awk '{print $3}') + + if [[ $current_status == *enabled* ]]; then + new_status=0 + else + new_status=1 + fi + + apply "$idx $new_status" /proc/ppm/policy_status + command2db cpu.mtk.ppm_policy$idx "mtk_ppm_policy -exec policy $idx $new_status" FALSE fi - - apply "$idx $new_status" /proc/ppm/policy_status - fi - unset options - done + unset options + done + fi } mtk_cpu_volt_offset() { - case $(fzf_select_n "Little cluster\nBig cluster\nCache Coherent Interconnect (CCI)" "Select CPU Part to voltage offset: ") in - "Little cluster") menu_value_tune "Offset Voltage for CPU Little cluster\nOffset will take original voltage from Operating Performance Point (OPP) and add or subtract the given voltage, you can use it for Overvolting or Undervolting." /proc/eem/EEM_DET_L/eem_offset 50 -50 1 ;; - "Big cluster") menu_value_tune "Offset Voltage for CPU Big cluster\nOffset will take original voltage from Operating Performance Point (OPP) and add or subtract the given voltage, you can use it for Overvolting or Undervolting." /proc/eem/EEM_DET_B/eem_offset 50 -50 1 ;; - "Cache Coherent Interconnect (CCI)") menu_value_tune "Offset Voltage for CPU CCI\nOffset will take original voltage from Operating Performance Point (OPP) and add or subtract the given voltage, you can use it for Overvolting or Undervolting." /proc/eem/EEM_DET_CCI/eem_offset 50 -50 1 ;; - esac + if [[ $1 == "-exec" ]]; then + local offset=$2 + local selected=$3 + apply $offset /proc/eem/$selected/eem_offset + else + local path=() + for dir in /proc/eem/EEM_DET_*; do + if [[ $dir != *GPU* ]] && [ -f $dir/eem_offset ]; then + path+=($(basename $dir)) + fi + done + local selected=$(fzf_select "$(echo ${path[@]})" "Select CPU Part to voltage offset: ") + menu_value_tune "Offset Voltage for CPU $selected\nOffset will take original voltage from Operating Performance Point (OPP) and add or subtract the given voltage, you can use it for Overvolting or Undervolting.\nOne tick is equal to 6,25mV." /proc/eem/$selected/eem_offset 50 -50 1 + local offset=$number + command2db cpu.mtk.volt_offset "mtk_cpu_volt_offset -exec $offset $selected" TRUE + unset path + fi } cpu_menu() { @@ -217,13 +299,13 @@ cpu_menu() { "[] big.LITTLE: ${is_big_little}" ) - if [[ $is_big_little == 1 ]]; then + if [ $is_big_little -eq 1 ]; then header_info+=( "[] big.LITTLE Clusters: ${nr_clusters}" "[] Little Scaling freq: $(cat /sys/devices/system/cpu/cpu$(echo ${cluster0} | awk '{print $1}')/cpufreq/scaling_min_freq)KHz - $(cat /sys/devices/system/cpu/cpu$(echo ${cluster0} | awk '{print $1}')/cpufreq/scaling_max_freq)KHz" "[] Big Scaling freq: $(cat /sys/devices/system/cpu/cpu$(echo ${cluster1} | awk '{print $1}')/cpufreq/scaling_min_freq)KHz - $(cat /sys/devices/system/cpu/cpu$(echo ${cluster1} | awk '{print $1}')/cpufreq/scaling_max_freq)KHz" ) - + if [[ $nr_clusters == 3 ]]; then header_info+=("[] Prime Scaling freq: $(cat /sys/devices/system/cpu/cpu$(echo ${cluster2} | awk '{print $1}')/cpufreq/scaling_min_freq)KHz - $(cat /sys/devices/system/cpu/cpu$(echo ${cluster2} | awk '{print $1}')/cpufreq/scaling_max_freq)KHz") fi diff --git a/share/utils/dram/dram_devfreq.sh b/share/utils/dram/dram_devfreq.sh index 6f23ff0..06e049a 100644 --- a/share/utils/dram/dram_devfreq.sh +++ b/share/utils/dram/dram_devfreq.sh @@ -17,11 +17,25 @@ # Copyright (C) 2023-2024 Rem01Gaming dram_devfreq_set_freq() { - apply $(fzf_select "$(cat ${dram_devfreq_path}/available_frequencies)" "Select ${1} freq: ") ${dram_devfreq_path}/${1}_freq + if [[ $1 == "-exec" ]]; then + local freq=$2 + local max_min=$3 + else + local max_min=$1 + local freq=$(fzf_select "$(cat ${dram_devfreq_path}/available_frequencies)" "Select $max_min freq: ") + command2db dram.devfreq.${max_min}_freq "dram_devfreq_set_freq -exec $freq $max_min" FALSE + fi + apply $freq ${dram_devfreq_path}/${max_min}_freq } dram_devfreq_set_gov() { - apply $(fzf_select "$(cat ${dram_devfreq_path}/available_governors)" "Select Governor: ") ${dram_devfreq_path}/governor + if [[ $1 == "-exec" ]]; then + local selected_gov=$2 + else + local selected_gov=$(fzf_select "$(cat ${dram_devfreq_path}/available_governors)" "Select Governor: ") + command2db dram.devfreq.governor "dram_devfreq_set_gov -exec $selected_gov" FALSE + fi + apply $selected_gov ${dram_devfreq_path}/governor } dram_devfreq_menu() { diff --git a/share/utils/dram/mtk_dram.sh b/share/utils/dram/mtk_dram.sh index 8b497ad..ecebbbc 100644 --- a/share/utils/dram/mtk_dram.sh +++ b/share/utils/dram/mtk_dram.sh @@ -17,9 +17,14 @@ # Copyright (C) 2023-2024 Rem01Gaming mtk_dram_set_freq() { - opp_table="[OPP-1]: Enable DVFS\n$(cat $mtk_dram_opp_table_path | awk '{sub(/\n$/,""); printf("%s\\n", $0)}' | grep "^\[")" - opp_selected="$(fzf_select_n "${opp_table%\\n}" "Set frequency for DRAM (NO DVFS): ")" - opp_num=$(echo "$opp_selected" | grep -o '\[[^]]*\]' | grep -oE '[+-]?[0-9]+') + if [[ $1 == "-exec" ]]; then + local opp_num=$2 + else + local opp_table="[OPP-1]: Enable DVFS\n$(cat $mtk_dram_opp_table_path | awk '{sub(/\n$/,""); printf("%s\\n", $0)}' | grep "^\[")" + local opp_selected="$(fzf_select_n "${opp_table%\\n}" "Set frequency for DRAM (NO DVFS): ")" + local opp_num=$(echo "$opp_selected" | grep -o '\[[^]]*\]' | grep -oE '[+-]?[0-9]+') + command2db dram.mtk.freq_lock "mtk_dram_set_freq -exec $opp_num" FALSE + fi apply $opp_num $mtk_dram_req_opp_path } diff --git a/share/utils/dram/qcom_dram.sh b/share/utils/dram/qcom_dram.sh index 9a83716..13f4050 100644 --- a/share/utils/dram/qcom_dram.sh +++ b/share/utils/dram/qcom_dram.sh @@ -17,14 +17,27 @@ # Copyright (C) 2023-2024 Rem01Gaming dram_qcom_set_freq() { - local freq=$(fzf_select "$(cat $qcom_dram_path/available_frequencies)" "Select ${1} freq: ") - for path in $qcom_dram_path/*/$1_freq; do + if [[ $1 == "-exec" ]]; then + local freq=$2 + local max_min=$3 + else + local max_min=$1 + local freq=$(fzf_select "$(cat $qcom_dram_path/available_frequencies)" "Select $max_min freq: ") + command2db dram.qcom.${max_min}_freq "dram_qcom_set_freq -exec $freq $max_min" FALSE + fi + for path in $qcom_dram_path/*/${max_min}_freq; do apply $freq $path done } dram_qcom_set_boost_freq() { - apply $(fzf_select "$(cat $qcom_dram_path/available_frequencies)" "Select boost frequency: ") $qcom_dram_path/boost_freq + if [[ $1 == "-exec" ]]; then + local freq=$2 + else + local freq=$(fzf_select "$(cat $qcom_dram_path/available_frequencies)" "Select boost frequency: ") + command2db dram.qcom.boost_freq "dram_qcom_set_boost_freq -exec $freq" FALSE + fi + apply $freq $qcom_dram_path/boost_freq } dram_qcom_menu() { diff --git a/share/utils/gpu/adreno_idler.sh b/share/utils/gpu/adreno_idler.sh index b417112..f466548 100644 --- a/share/utils/gpu/adreno_idler.sh +++ b/share/utils/gpu/adreno_idler.sh @@ -17,20 +17,41 @@ # Copyright (C) 2023-2024 Rem01Gaming adreno_idler_switch() { - case $(fzf_select "Disable Enable" "Simple GPU Algorithm: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Disable Enable" "Simple GPU Algorithm: ") + command2db gpu.adreno_idler.switch "adreno_idler_switch -exec $selected" FALSE + fi + case $selected in Disable) apply N /sys/module/simple_gpu_algorithm/parameters/simple_gpu_activate ;; Enable) apply Y /sys/module/simple_gpu_algorithm/parameters/simple_gpu_activate ;; esac } adreno_idler_wait() { - menu_value_tune "Adreno Ilde Wait\nNumber of events to wait before ramping down the frequency, Adreno idler will more actively try to ramp down the frequency if this is set to a lower value." /sys/module/adreno_idler/parameters/adreno_idler_idlewait 99 0 1 + if [[ $1 == "-exec" ]]; then + apply $2 /sys/module/adreno_idler/parameters/adreno_idler_idlewait + else + menu_value_tune "Adreno Idle Wait\nNumber of events to wait before ramping down the frequency, Adreno idler will more actively try to ramp down the frequency if this is set to a lower value." /sys/module/adreno_idler/parameters/adreno_idler_idlewait 99 0 1 + command2db gpu.adreno_idler.idle_wait "adreno_idler_wait -exec $number" FALSE + fi } adreno_idler_down_diferential() { - menu_value_tune "Adreno Idler Down Diferential" /sys/module/adreno_idler/parameters/adreno_idler_downdifferential 99 0 1 + if [[ $1 == "-exec" ]]; then + apply $2 /sys/module/adreno_idler/parameters/adreno_idler_downdifferential + else + menu_value_tune "Adreno Idler Down Diferential" /sys/module/adreno_idler/parameters/adreno_idler_downdifferential 99 0 1 + command2db gpu.adreno_idler.down_diferential "adreno_idler_down_diferential -exec $number" FALSE + fi } adreno_idler_workload() { - menu_value_tune "Adreno Idler Workload\nThreshold for determining if the given workload is idle, Adreno idler will more actively try to ramp down the frequency if this is set to a higher value." /sys/module/adreno_idler/parameters/adreno_idler_idleworkload 10000 1000 10 + if [[ $1 == "-exec" ]]; then + apply $2 /sys/module/adreno_idler/parameters/adreno_idler_idleworkload + else + menu_value_tune "Adreno Idler Workload\nThreshold for determining if the given workload is idle, Adreno idler will more actively try to ramp down the frequency if this is set to a higher value." /sys/module/adreno_idler/parameters/adreno_idler_idleworkload 10000 1000 10 + command2db gpu.adreno_idler.workload "adreno_idler_workload -exec $number" FALSE + fi } diff --git a/share/utils/gpu/gpu_devfreq.sh b/share/utils/gpu/gpu_devfreq.sh index 9c4e7c3..d4511f5 100644 --- a/share/utils/gpu/gpu_devfreq.sh +++ b/share/utils/gpu/gpu_devfreq.sh @@ -16,39 +16,85 @@ # # Copyright (C) 2023-2024 Rem01Gaming +source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/simple_gpu_algo.sh +source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/adreno_idler.sh + gpu_devfreq_set_freq() { - apply $(fzf_select "$(cat ${gpu_devfreq_path}/available_frequencies)" "Select ${1} freq: ") ${gpu_devfreq_path}/${1}_freq + if [[ $1 == "-exec" ]]; then + local freq=$2 + local max_min=$3 + else + local max_min=$1 + local freq=$(fzf_select "$(cat ${gpu_devfreq_path}/available_frequencies)" "Select $max_min freq: ") + command2db gpu.generic.${max_min}_freq "gpu_devfreq_set_freq -exec $freq $max_min" FALSE + fi + apply $freq ${gpu_devfreq_path}/${max_min}_freq } gpu_devfreq_set_gov() { - apply $(fzf_select "$(cat ${gpu_devfreq_path}/available_governors)" "Select Governor: ") ${gpu_devfreq_path}/governor + if [[ $1 == "-exec" ]]; then + local selected_gov=$2 + else + local selected_gov=$(fzf_select "$(cat ${gpu_devfreq_path}/available_governors)" "Select Governor: ") + command2db gpu.devfreq.governor "gpu_devfreq_set_gov -exec $selected_gov" FALSE + fi + apply ${gpu_devfreq_path}/governor } gpu_devfreq_menu() { while true; do + header_info=( + "[] GPU: ${gpu}" + "[] GPU Scalling freq: $(cat ${gpu_devfreq_path}/max_freq)KHz - $(cat ${gpu_devfreq_path}/min_freq)KHz" + "[] GPU Governor: $(cat ${gpu_devfreq_path}/governor)" + ) + options="Set max freq\nSet min freq\nSet Governor\n" + + if [ -d /sys/module/simple_gpu_algorithm ]; then + options="${options}Enable Simple GPU Algorithm\nSimple GPU Laziness\nSimple GPU Ramp threshold\n" + fi + + if [ -d /sys/module/adreno_idler/parameters ]; then + options="${options}Enable Adreno Idler\nAdreno Idle Workload\nAdreno Wait Idle\nAdreno Idle Differential\n" + header_info+=( + "[] Adreno Idler: $(cat /sys/module/adreno_idler/parameters/adreno_idler_active)" + "[] Adreno Idle Workload: $(cat /sys/module/adreno_idler/parameters/adreno_idler_idleworkload)" + ) + fi + clear echo -e "\e[30;48;2;254;228;208;38;2;0;0;0m Origami Kernel Manager ${VERSION}$(yes " " | sed $((LINE - 30))'q' | tr -d '\n')\033[0m" echo -e "\e[38;2;254;228;208m" - echo -e " _________ [] GPU Scalling freq: $(cat ${gpu_devfreq_path}/max_freq)KHz - $(cat ${gpu_devfreq_path}/min_freq)KHz" | cut -c 1-${LINE} - echo -e " / /\\ [] GPU Governor: $(cat ${gpu_devfreq_path}/governor)" - echo -e " / / \\ " - echo -e ' / / \ ' - echo -e '/________/ \ ' - echo -e '\ \ / ' - echo -e ' \ \ / ' - echo -e ' \ \ / ' - echo -e ' \________\/ ' + echo -e " _________ ${header_info[0]}" | cut -c 1-${LINE} + echo -e " / /\\ ${header_info[1]}" | cut -c 1-${LINE} + echo -e " / / \\ ${header_info[2]}" + echo -e " / / \ ${header_info[3]}" + echo -e "/________/ \ ${header_info[4]}" + echo -e "\ \ / ${header_info[5]}" + echo -e " \ \ / ${header_info[6]}" + echo -e " \ \ / ${header_info[7]}" + echo -e " \________\/ ${header_info[8]}" echo -e "\n//////////////" echo -e "$(yes "─" | sed ${LINE}'q' | tr -d '\n')\n" echo -e "[] GPU Control\033[0m" tput civis + unset header_info - case $(fzy_select "Set max freq\nSet min freq\nSet Governor\nBack to main menu" "") in + case $(fzy_select "$options\nBack to main menu" "") in "Set max freq") gpu_devfreq_set_freq max ;; "Set min freq") gpu_devfreq_set_freq min ;; "Set Governor") gpu_devfreq_set_gov ;; + "Enable Simple GPU Algorithm") simple_gpu_switch ;; + "Simple GPU Laziness") simple_gpu_laziness ;; + "Simple GPU Ramp threshold") simple_gpu_ramp_threshold ;; + "Enable Adreno Idler") adreno_idler_switch ;; + "Adreno Idle Workload") adreno_idler_workload ;; + "Adreno Wait Idle") adreno_idler_wait ;; + "Adreno Idle Differential") adreno_idler_down_diferential ;; "Back to main menu") break ;; esac + + unset options done } diff --git a/share/utils/gpu/gpu_omap.sh b/share/utils/gpu/gpu_omap.sh index 28b61b6..dddd96a 100644 --- a/share/utils/gpu/gpu_omap.sh +++ b/share/utils/gpu/gpu_omap.sh @@ -17,11 +17,23 @@ # Copyright (C) 2023-2024 Rem01Gaming gpu_omap_set_max_freq() { - apply $(fzf_select "$gpu_available_freqs" "Select ${1} freq: ") $gpu_max_freq_path + if [[ $1 == "-exec" ]]; then + local freq=$2 + else + local freq=$(fzf_select "$gpu_available_freqs" "Select max freq: ") + command2db gpu.omap.max_freq "gpu_omap_set_max_freq -exec $freq" FALSE + fi + apply $freq $gpu_max_freq_path } gpu_omap_set_gov() { - apply $(fzf_select "$gpu_available_governors" "Select Governor: ") $gpu_governor_path + if [[ $1 == "-exec" ]]; then + local selected_gov=$2 + else + local selected_gov=$(fzf_select "$gpu_available_governors" "Select Governor: ") + command2db gpu.omap.governor "gpu_omap_set_gov -exec $selected_gov" FALSE + fi + apply $selected_gov $gpu_governor_path } gpu_omap_menu() { diff --git a/share/utils/gpu/gpu_powervr.sh b/share/utils/gpu/gpu_powervr.sh deleted file mode 100644 index 9987f5f..0000000 --- a/share/utils/gpu/gpu_powervr.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/data/data/com.termux/files/usr/bin/bash -# This file is part of Origami Kernel Manager. -# -# Origami Kernel Manager is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Origami Kernel Manager is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Origami Kernel Manager. If not, see . -# -# Copyright (C) 2023-2024 Rem01Gaming - -gpu_powervr_set_freq() { - case $1 in - max) local node_path=$gpu_max_freq_path ;; - min) local node_path=$gpu_min_freq_path ;; - esac - apply $(fzf_select "$gpu_available_freqs" "Select ${1} freq: ") $node_path -} - -gpu_powervr_set_gov() { - apply $(fzf_select "$gpu_available_governors" "Select Governor: ") $gpu_governor_path -} - -gpu_powervr_menu() { - gpu_available_freqs="$(cat /sys/devices/platform/dfrgx/devfreq/dfrgx/available_frequencies)" - gpu_min_freq_path="/sys/devices/platform/dfrgx/devfreq/dfrgx/min_freq" - gpu_max_freq_path="/sys/devices/platform/dfrgx/devfreq/dfrgx/max_freq" - gpu_available_governors="$(cat /sys/devices/platform/dfrgx/devfreq/dfrgx/available_frequencies)" - gpu_governor_path="/sys/devices/platform/dfrgx/devfreq/dfrgx/governor" - - while true; do - clear - echo -e "\e[30;48;2;254;228;208;38;2;0;0;0m Origami Kernel Manager ${VERSION}$(yes " " | sed $((LINE - 30))'q' | tr -d '\n')\033[0m" - echo -e "\e[38;2;254;228;208m" - echo -e " _________ [] GPU: ${gpu}" | cut -c 1-${LINE} - echo -e " / /\\ [] GPU Scalling freq: $(cat $gpu_min_freq_path)KHz - $(cat $gpu_max_freq_path)KHz" | cut -c 1-${LINE} - echo -e " / / \\ [] GPU Governor: $(cat $gpu_governor_path)" - echo -e ' / / \ ' - echo -e '/________/ \ ' - echo -e '\ \ / ' - echo -e ' \ \ / ' - echo -e ' \ \ / ' - echo -e ' \________\/ ' - echo -e "\n//////////////" - echo -e "$(yes "─" | sed ${LINE}'q' | tr -d '\n')\n" - echo -e "[] GPU Control\033[0m" - - tput civis - - case $(fzy_select "Set max freq\nSet min freq\nSet Governor\nBack to main menu" "") in - "Set max freq") gpu_powervr_set_freq max ;; - "Set min freq") gpu_powervr_set_freq min ;; - "Set Governor") gpu_powervr_set_gov ;; - "Back to main menu") break ;; - esac - done -} diff --git a/share/utils/gpu/gpu_qcom_kgsl2.sh b/share/utils/gpu/gpu_qcom_kgsl2.sh index fc4fee7..3478d24 100644 --- a/share/utils/gpu/gpu_qcom_kgsl2.sh +++ b/share/utils/gpu/gpu_qcom_kgsl2.sh @@ -17,11 +17,23 @@ # Copyright (C) 2023-2024 Rem01Gaming gpu_qcom_kgsl2_set_max_freq() { - apply $(fzf_select "$gpu_available_freqs" "Select ${1} freq: ") $gpu_max_freq_path + if [[ $1 == "-exec" ]]; then + local freq=$2 + else + local freq=$(fzf_select "$gpu_available_freqs" "Select max freq: ") + command2db gpu.qcom.kgsl2.max_freq "gpu_qcom_kgsl2_set_max_freq -exec $freq" FALSE + fi + apply $freq $gpu_max_freq_path } gpu_qcom_kgsl2_set_gov() { - apply $(fzf_select "$gpu_available_governors" "Select Governor: ") $gpu_governor_path + if [[ $1 == "-exec" ]]; then + local selected_gov=$2 + else + local selected_gov=$(fzf_select "$gpu_available_governors" "Select Governor: ") + command2db gpu.qcom.kgsl2.governor "gpu_qcom_kgsl2_set_gov -exec $selected_gov" FALSE + fi + apply $selected_gov $gpu_governor_path } gpu_qcom_kgsl2_menu() { diff --git a/share/utils/gpu/gpu_qcom_kgsl3.sh b/share/utils/gpu/gpu_qcom_kgsl3.sh index 0f1f7ac..3be150a 100644 --- a/share/utils/gpu/gpu_qcom_kgsl3.sh +++ b/share/utils/gpu/gpu_qcom_kgsl3.sh @@ -17,11 +17,23 @@ # Copyright (C) 2023-2024 Rem01Gaming gpu_qcom_kgsl3_set_max_freq() { - apply $(fzf_select "$gpu_available_freqs" "Select ${1} freq: ") $gpu_max_freq_path + if [[ $1 == "-exec" ]]; then + local freq=$2 + else + local freq=$(fzf_select "$gpu_available_freqs" "Select max freq: ") + command2db gpu.qcom.kgsl3.max_freq "gpu_qcom_kgsl3_set_max_freq -exec $freq" FALSE + fi + apply $freq $gpu_max_freq_path } gpu_qcom_kgsl3_set_gov() { - apply $(fzf_select "$gpu_available_governors" "Select Governor: ") $gpu_governor_path + if [[ $1 == "-exec" ]]; then + local selected_gov=$2 + else + local selected_gov=$(fzf_select "$gpu_available_governors" "Select Governor: ") + command2db gpu.qcom.kgsl3.governor "gpu_qcom_kgsl3_set_gov -exec $selected_gov" FALSE + fi + apply $selected_gov $gpu_governor_path } gpu_qcom_kgsl3_menu() { diff --git a/share/utils/gpu/gpu_tegra.sh b/share/utils/gpu/gpu_tegra.sh index 0baf720..c4cc4f0 100644 --- a/share/utils/gpu/gpu_tegra.sh +++ b/share/utils/gpu/gpu_tegra.sh @@ -17,11 +17,19 @@ # Copyright (C) 2023-2024 Rem01Gaming gpu_tegra_set_freq() { - case $1 in + if [[ $1 == "-exec" ]]; then + local freq=$2 + local max_min=$3 + else + local max_min=$1 + local freq=$(fzf_select "$gpu_available_freqs" "Select $max_min freq: ") + command2db gpu.tegra.${max_min}_freq "gpu_tegra_set_freq -exec $freq $max_min" FALSE + fi + case $max_min in max) local node_path=$gpu_max_freq_path ;; min) local node_path=$gpu_min_freq_path ;; esac - apply $(fzf_select "$gpu_available_freqs" "Select ${1} freq: ") $node_path + apply $freq $node_path } gpu_tegra_menu() { diff --git a/share/utils/gpu/gpu_util.sh b/share/utils/gpu/gpu_util.sh index abb3fcc..55f2d47 100644 --- a/share/utils/gpu/gpu_util.sh +++ b/share/utils/gpu/gpu_util.sh @@ -23,8 +23,6 @@ source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/gpu_tegra. source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/gpu_omap.sh source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/gpu_qcom_kgsl2.sh source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/gpu_qcom_kgsl3.sh -source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/gpu_qcom_kgsl3-devfreq.sh -source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/gpu_powervr.sh source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/gpu_generic.sh gpu_menu() { @@ -40,11 +38,9 @@ gpu_menu() { 2) mtk_gpufreqv2_menu ;; 3) gpu_qcom_kgsl2_menu ;; 4) gpu_qcom_kgsl3_menu ;; - 5) gpu_qcom_kgsl3-devfreq_menu ;; - 6) gpu_omap_menu ;; - 7) gpu_tegra_menu ;; - 8) gpu_powervr_menu ;; - 9) gpu_generic_menu ;; + 5) gpu_omap_menu ;; + 6) gpu_tegra_menu ;; + 7) gpu_generic_menu ;; esac fi } diff --git a/share/utils/gpu/mtk_ged.sh b/share/utils/gpu/mtk_ged.sh index 8113ce1..2be0cb0 100644 --- a/share/utils/gpu/mtk_ged.sh +++ b/share/utils/gpu/mtk_ged.sh @@ -17,55 +17,97 @@ # Copyright (C) 2023-2024 Rem01Gaming ged_max_freq() { - if [[ $gpu_node_id == 1 ]]; then - index=$(grep "$(fzf_select "$gpu_available_freqs" "Maximum GPU Frequency: ")" /proc/gpufreq/gpufreq_opp_dump | awk '{print $1}') - elif [[ $gpu_node_id == 2 ]]; then - index=$(grep "$(fzf_select "$gpu_available_freqs" "Maximum GPU Frequency: ")" /proc/gpufreqv2/gpu_working_opp_table | awk '{print $1}') + if [[ $1 == "-exec" ]]; then + local index=$2 + else + if [[ $gpu_node_id == 1 ]]; then + local index=$(grep "$(fzf_select "$gpu_available_freqs" "Maximum GPU Frequency: ")" /proc/gpufreq/gpufreq_opp_dump | awk '{print $1}') + elif [[ $gpu_node_id == 2 ]]; then + local index=$(grep "$(fzf_select "$gpu_available_freqs" "Maximum GPU Frequency: ")" /proc/gpufreqv2/gpu_working_opp_table | awk '{print $1}') + fi + local index=${index:1:-1} + command2db gpu.ged.max_freq "ged_max_freq -exec $index" FALSE fi - apply ${index:1:-1} /sys/kernel/ged/hal/custom_upbound_gpu_freq + apply $index /sys/kernel/ged/hal/custom_upbound_gpu_freq } ged_min_freq() { - if [[ $gpu_node_id == 1 ]]; then - index=$(grep "$(fzf_select "$gpu_available_freqs" "Maximum GPU Frequency: ")" /proc/gpufreq/gpufreq_opp_dump | awk '{print $1}') - elif [[ $gpu_node_id == 2 ]]; then - index=$(grep "$(fzf_select "$gpu_available_freqs" "Maximum GPU Frequency: ")" /proc/gpufreqv2/gpu_working_opp_table | awk '{print $1}') + if [[ $1 == "-exec" ]]; then + local index=$2 + else + if [[ $gpu_node_id == 1 ]]; then + index=$(grep "$(fzf_select "$gpu_available_freqs" "Maximum GPU Frequency: ")" /proc/gpufreq/gpufreq_opp_dump | awk '{print $1}') + elif [[ $gpu_node_id == 2 ]]; then + index=$(grep "$(fzf_select "$gpu_available_freqs" "Maximum GPU Frequency: ")" /proc/gpufreqv2/gpu_working_opp_table | awk '{print $1}') + fi + local index=${index:1:-1} + command2db gpu.ged.min_freq "ged_min_freq -exec $index" FALSE fi - apply ${index:1:-1} /sys/kernel/ged/hal/custom_boost_gpu_freq + apply $index /sys/kernel/ged/hal/custom_boost_gpu_freq } mtk_ged_dvfs() { - case $(fzf_select "Enable Disable" "GPU DVFS: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "GPU DVFS: ") + command2db gpu.ged.dvfs "mtk_ged_dvfs -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /sys/module/ged/parameters/gpu_dvfs_enable ;; Disable) apply 0 /sys/module/ged/parameters/gpu_dvfs_enable ;; esac } mtk_ged_boost() { - case $(fzf_select "Enable Disable" "GED Boosting: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "GED Boosting: ") + command2db gpu.ged.boost "mtk_ged_boost -exec $selceted" FALSE + fi + case $selected in Enable) apply 1 /sys/module/ged/parameters/ged_boost_enable ;; Disable) apply 0 /sys/module/ged/parameters/ged_boost_enable ;; esac } mtk_ged_extra_boost() { - case $(fzf_select "Enable Disable" "GED Boost extra: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "GED Boost extra: ") + command2db gpu.ged.extra_boost "mtk_ged_extra_boost -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /sys/module/ged/parameters/boost_extra ;; Disable) apply 0 /sys/module/ged/parameters/boost_extra ;; esac } mtk_ged_gpu_boost() { - case $(fzf_select "Enable Disable" "GED GPU Boost: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "GED GPU Boost: ") + command2db gpu.ged.gpu_boost "mtk_ged_gpu_boost -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /sys/module/ged/parameters/boost_gpu_enable ;; Disable) apply 0 /sys/module/ged/parameters/boost_gpu_enable ;; esac } mtk_ged_game_mode() { - case $(fzf_select "Enable Disable" "GED Game mode: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "GED Game mode: ") + command2db gpu.ged.game_mode "mtk_ged_game_mode -exec $selceted" FALSE + fi + case $selected in Enable) apply 1 /sys/module/ged/parameters/gx_game_mode ;; Disable) apply 0 /sys/module/ged/parameters/gx_game_mode ;; esac diff --git a/share/utils/gpu/simple_gpu_algo.sh b/share/utils/gpu/simple_gpu_algo.sh index 2d26568..5d24839 100644 --- a/share/utils/gpu/simple_gpu_algo.sh +++ b/share/utils/gpu/simple_gpu_algo.sh @@ -17,16 +17,32 @@ # Copyright (C) 2023-2024 Rem01Gaming simple_gpu_switch() { - case $(fzf_select "Disable Enable" "Simple GPU Algorithm: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Disable Enable" "Simple GPU Algorithm: ") + command2db gpu.simple_gpu_algo.switch "simple_gpu_switch -exec $selected" FALSE + fi + case $selected in Disable) apply 0 /sys/module/simple_gpu_algorithm/parameters/simple_gpu_activate ;; Enable) apply 1 /sys/module/simple_gpu_algorithm/parameters/simple_gpu_activate ;; esac } simple_gpu_laziness() { - menu_value_tune "Simple GPU Laziness\nThis increases the threshold to ramp up or down GPU frequencies. The lower it is, the more performance you get." /sys/module/simple_gpu_algorithm/parameters/simple_laziness 10 0 1 + if [[ $1 == "-exec" ]]; then + apply $2 /sys/module/simple_gpu_algorithm/parameters/simple_laziness + else + menu_value_tune "Simple GPU Laziness\nThis increases the threshold to ramp up or down GPU frequencies. The lower it is, the more performance you get." /sys/module/simple_gpu_algorithm/parameters/simple_laziness 10 0 1 + command2db gpu.simple_gpu_algo.laziness "simple_gpu_laziness -exec $number" FALSE + fi } simple_gpu_ramp_threshold() { - menu_value_tune "Simple GPU Ramp threshold\nThis increases the number of times the GPU governor ramp down requests. The higher it is, the more performance you get." /sys/module/simple_gpu_algorithm/parameters/simple_ramp_threshold 10 0 1 + if [[ $1 == "-exec" ]]; then + apply $2 /sys/module/simple_gpu_algorithm/parameters/simple_ramp_threshold + else + menu_value_tune "Simple GPU Ramp threshold\nThis increases the number of times the GPU governor ramp down requests. The higher it is, the more performance you get." /sys/module/simple_gpu_algorithm/parameters/simple_ramp_threshold 10 0 1 + command2db gpu.simple_gpu_algo.ramp_theshold "simple_gpu_ramp_threshold -exec $number" FALSE + fi } diff --git a/share/utils/memory/memory_util.sh b/share/utils/memory/memory_util.sh index ee5e2f0..9b89813 100644 --- a/share/utils/memory/memory_util.sh +++ b/share/utils/memory/memory_util.sh @@ -17,62 +17,135 @@ # Copyright (C) 2023-2024 Rem01Gaming memory_drop_cache() { - echo $(fzf_select "0 1 2 3" "Memory drop cache mode: ") >/proc/sys/vm/drop_caches + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "0 1 2 3" "Memory drop cache mode: ") + command2db vm.drop_cache "memory_drop_cache -exec $selected" FALSE + fi + echo $selected >/proc/sys/vm/drop_caches } memory_swappiness() { - menu_value_tune "Swappiness\ndetermines how often the operating system swaps data from RAM to the swap space on the disk." /proc/sys/vm/swappiness 200 0 1 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/swappiness + else + menu_value_tune "Swappiness\ndetermines how often the operating system swaps data from RAM to the swap space on the disk." /proc/sys/vm/swappiness 200 0 1 + command2db vm.swappiness "memory_swappiness -exec $number" FALSE + fi } memory_min_free_kbytes() { - menu_value_tune "Minimum amount of free memory\nminimum amount of free memory (in kilobytes) that should always be available to the system." /proc/sys/vm/min_free_kbytes 22520 128 8 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/min_free_kbytes + else + menu_value_tune "Minimum amount of free memory\nminimum amount of free memory (in kilobytes) that should always be available to the system." /proc/sys/vm/min_free_kbytes 22520 128 8 + command2db vm.min_free_kbytes "memory_min_free_kbytes -exec $number" FALSE + fi } memory_extra_free_kbytes() { - menu_value_tune "Extra free kbytes\nadditional buffer of free memory (in kilobytes) reserved for critical system tasks." /proc/sys/vm/extra_free_kbytes 100520 128 24 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/extra_free_kbytes + else + menu_value_tune "Extra free kbytes\nadditional buffer of free memory (in kilobytes) reserved for critical system tasks." /proc/sys/vm/extra_free_kbytes 100520 128 24 + command2db vm.extra_free_kbytes "memory_extra_free_kbytes -exec $number" FALSE + fi } memory_vfs_cache_pressure() { - menu_value_tune "VFS Cache pressure\naggressively the system reclaims memory used for file system metadata." /proc/sys/vm/vfs_cache_pressure 1024 8 2 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/vfs_cache_pressure + else + menu_value_tune "VFS Cache pressure\naggressively the system reclaims memory used for file system metadata." /proc/sys/vm/vfs_cache_pressure 1024 8 2 + command2db vm.vfs_cache_pressure "memory_vfs_cache_pressure -exec $number" FALSE + fi } memory_overcommit_ratio() { - menu_value_tune "Overcommit ratio\ninfluences the system's willingness to allocate more memory than physically available." /proc/sys/vm/overcommit_ratio 100 0 1 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/overcommit_ratio + else + menu_value_tune "Overcommit ratio\ninfluences the system's willingness to allocate more memory than physically available." /proc/sys/vm/overcommit_ratio 100 0 1 + command2db vm.overcommit_ratio "memory_overcommit_ratio -exec $number" FALSE + fi } memory_dirty_ratio() { - menu_value_tune "Dirty ratio\nmaximum percentage of system memory that can be filled with "dirty" pages." /proc/sys/vm/dirty_ratio 100 0 1 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/dirty_ratio + else + menu_value_tune "Dirty ratio\nmaximum percentage of system memory that can be filled with "dirty" pages." /proc/sys/vm/dirty_ratio 100 0 1 + command2db vm.dirty_ratio "memory_dirty_ratio -exec $number" FALSE + fi } memory_dirty_background_ratio() { - menu_value_tune "Dirty background ratio\nmaximum percentage of system memory that can be filled with "dirty" pages before the background process starts writing them to the disk." /proc/sys/vm/dirty_background_ratio 100 0 1 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/dirty_background_ratio + else + menu_value_tune "Dirty background ratio\nmaximum percentage of system memory that can be filled with "dirty" pages before the background process starts writing them to the disk." /proc/sys/vm/dirty_background_ratio 100 0 1 + command2db vm.dirty_background_ratio "memory_dirty_background_ratio -exec $number" FALSE + fi } memory_dirty_writeback_centisecs() { - menu_value_tune "Dirty writeback centisecs\ndetermines the interval in centiseconds between background processes checking and writing "dirty" data (modified but unsaved) to the disk." /proc/sys/vm/dirty_writeback_centisecs 10000 10 10 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/dirty_writeback_centisecs + else + menu_value_tune "Dirty writeback centisecs\ndetermines the interval in centiseconds between background processes checking and writing "dirty" data (modified but unsaved) to the disk." /proc/sys/vm/dirty_writeback_centisecs 10000 10 10 + command2db vm.dirty_writeback_centisecs "memory_dirty_writeback_centisecs -exec $number" FALSE + fi } memory_dirty_expire_centisecs() { - menu_value_tune "Dirty expire centisecs\nmaximum age in centiseconds for "dirty" pages (modified but unsaved data) in the system." /proc/sys/vm/dirty_expire_centisecs 10000 10 10 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/vm/dirty_expire_centisecs + else + menu_value_tune "Dirty expire centisecs\nmaximum age in centiseconds for "dirty" pages (modified but unsaved data) in the system." /proc/sys/vm/dirty_expire_centisecs 10000 10 10 + command2db vm.dirty_expire_centisecs "memory_dirty_expire_centisecs -exec $number" FALSE + fi } laptop_mode() { - apply $(fzf_select "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" "Laptop mode: ") /proc/sys/vm/laptop_mode + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" "Laptop mode: ") + command2db vm.laptop_mode "laptop_mode -exec $selected" FALSE + fi + apply $selected /proc/sys/vm/laptop_mode } oom_kill_alloc() { - case $(fzf_select "Yes No" "Kill allocating task: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Yes No" "Kill allocating task: ") + command2db vm.oom_kill_allocating_task "oom_kill_alloc -exec $selected" FALSE + fi + case $selected in Yes) apply 1 /proc/sys/vm/oom_kill_allocating_task ;; No) apply 0 /proc/sys/vm/oom_kill_allocating_task ;; esac } slmk_minfree() { - menu_value_tune "Simple LMK minfree\nfree at least this much memory per reclaim." /sys/module/simple_lmk/parameters/slmk_minfree 512 8 2 + if [[ $1 == "-exec" ]]; then + apply $2 /sys/module/simple_lmk/parameters/slmk_minfree + else + menu_value_tune "Simple LMK minfree\nfree at least this much memory per reclaim." /sys/module/simple_lmk/parameters/slmk_minfree 512 8 2 + command2db simple_lmk.minfree "slmk_minfree -exec $number" FALSE + fi } slmk_timeout() { - menu_value_tune "Simple LMK timeout\nwait until all of the victims it kills have their memory freed." /sys/module/simple_lmk/parameters/slmk_timeout 1000 50 2 + if [[ $1 == "-exec" ]]; then + apply $2 /sys/module/simple_lmk/parameters/slmk_timeout + else + menu_value_tune "Simple LMK timeout\nwait until all of the victims it kills have their memory freed." /sys/module/simple_lmk/parameters/slmk_timeout 1000 50 2 + command2db simple_lmk.timeout "slmk_timeout -exec $number" FALSE + fi } memory_menu() { diff --git a/share/utils/misc/misc_util.sh b/share/utils/misc/misc_util.sh index b372240..8be6669 100644 --- a/share/utils/misc/misc_util.sh +++ b/share/utils/misc/misc_util.sh @@ -17,8 +17,13 @@ # Copyright (C) 2023-2024 Rem01Gaming thermal_gov_set() { - chmod 0644 /sys/class/thermal/thermal_zone0/available_policies - local thermal_policy=$(fzf_select "$(cat /sys/class/thermal/thermal_zone0/available_policies)" "Select Thermal governor (apply globally): ") + if [[ $1 == "-exec" ]]; then + local thermal_policy=$2 + else + chmod 0644 /sys/class/thermal/thermal_zone0/available_policies + local thermal_policy=$(fzf_select "$(cat /sys/class/thermal/thermal_zone0/available_policies)" "Select Thermal governor (apply globally): ") + command2db thermal.governor "thermal_gov_set -exec $thermal_policy" FALSE + fi for thermal in $(ls /sys/class/thermal); do if [ -f /sys/class/thermal/${thermal}/policy ]; then apply $thermal_policy /sys/class/thermal/${thermal}/policy @@ -27,77 +32,148 @@ thermal_gov_set() { } io_sched_set() { - local block_target=$(fzf_select "$(print_existing_folders /sys/block mmcblk0 mmcblk1 $(echo sd{a..z}) dm-0)" "Select block you wanted to change I/O sched: ") - apply $(fzf_select "$(cat /sys/block/${block_target}/queue/scheduler | sed 's/\[//g; s/\]//g')" "Select I/O Scheduler: ") /sys/block/${block_target}/queue/scheduler + if [[ $1 == "-exec" ]]; then + local block_target=$2 + local io_sched=$3 + else + local block_target=$(fzf_select "$(print_existing_folders /sys/block mmcblk0 mmcblk1 $(echo sd{a..z}) dm-0)" "Select block you wanted to change I/O sched: ") + local io_sched=$(fzf_select "$(cat /sys/block/${block_target}/queue/scheduler | sed 's/\[//g; s/\]//g')" "Select I/O Scheduler: ") + command2db io.scheduler "io_sched_set -exec $block_target $io_sched" FALSE + fi + apply $io_sched /sys/block/${block_target}/queue/scheduler } dt2w_switch() { - case $(fzf_select "Enable Disable" "Double tap to wake: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "Double tap to wake: ") + command2db dt2w.switch "dt2w_switch -exec $selected" FALSE + fi + case $selected in Enable) apply 1 $dt2w_path ;; Disable) apply 0 $dt2w_path ;; esac } selinux_switch() { - case $(fzf_select "enforcing permissive" "Selinux mode: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "enforcing permissive" "Selinux mode: ") + command2db selinux.mode "selinux_switch -exec $selected" FALSE + fi + case $selected in enforcing) setenforce 1 ;; permissive) setenforce 0 ;; esac } touchpanel_game_mode() { - case $(fzf_select "Enable Disable" "Touchpanel Game mode: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "Touchpanel Game mode: ") + command2db oplus.tp.game_switch_enable "touchpanel_game_mode -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /proc/touchpanel/game_switch_enable ;; Disable) apply 0 /proc/touchpanel/game_switch_enable ;; esac } touchpanel_limit() { - case $(fzf_select "Enable Disable" "Touchpanel limit: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "Touchpanel limit: ") + command2db oplus.tp.limit_enable "touchpanel_limit -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /proc/touchpanel/oplus_tp_limit_enable ;; Disable) apply 0 /proc/touchpanel/oplus_tp_limit_enable ;; esac } touchpanel_direction_fix() { - case $(fzf_select "Enable Disable" "Touchpanel direction fix: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "Touchpanel direction fix: ") + command2db oplus.tp.direction "touchpanel_direction_fix -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /proc/touchpanel/oplus_tp_direction ;; Disable) apply 0 /proc/touchpanel/oplus_tp_direction ;; esac } mtk_vibrator_ctrl() { - menu_value_tune "Mediatek Vibrator control\nSet strength of vibration globally on Mediatek devices" /sys/kernel/thunderquake_engine/level $(cat /sys/kernel/thunderquake_engine/max) $(cat /sys/kernel/thunderquake_engine/min) 1 + if [[ $1 == "-exec" ]]; then + apply $2 /sys/kernel/thunderquake_engine/level + else + menu_value_tune "Mediatek Vibrator control\nSet strength of vibration globally on Mediatek devices" /sys/kernel/thunderquake_engine/level $(cat /sys/kernel/thunderquake_engine/max) $(cat /sys/kernel/thunderquake_engine/min) 1 + command2db mtk.thunderquake_engine "mtk_vibrator_ctrl -exec $number" FALSE + fi } mtk_pbm_switch() { - case $(fzf_select "Enable Disable" "Mediatek Power Budget Management: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "Mediatek Power Budget Management: ") + command2db mtk.pbm.switch "mtk_pbm_switch -exec $selected" FALSE + fi + case $selected in Enable) apply "stop 0" /proc/pbm/pbm_stop ;; Disable) apply "stop 1" /proc/pbm/pbm_stop ;; esac } mtk_apu_set_freq() { - opp_selected=$(fzf_select_n "$(seq -1 $(cat /sys/module/mmdvfs_pmqos/parameters/dump_setting | grep -o '\[[^]]*\]' | grep -oE '[+-]?[0-9]+' | sort -n | tail -n 1))" "Select frequency for APUs (NO DVFS) : ") + if [[ $1 == "-exec" ]]; then + local opp_selected=$2 + else + local opp_selected=$(fzf_select_n "$(seq -1 $(cat /sys/module/mmdvfs_pmqos/parameters/dump_setting | grep -o '\[[^]]*\]' | grep -oE '[+-]?[0-9]+' | sort -n | tail -n 1))" "Select frequency for APUs (NO DVFS) : ") + command2db mtk.apu.freq "mtk_apu_set_freq -exec $selected" TRUE + fi apply $opp_selected /sys/module/mmdvfs_pmqos/parameters/force_step } mtk_batoc_current_limit() { - case $(fzf_select "Enable Disable" "Mediatek's batoc Current limit: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "Mediatek's batoc Current limit: ") + command2db mtk.batoc_current_limit.switch "mtk_batoc_current_limit -exec $selected" FALSE + fi + case $selected in Enable) apply "stop 0" /proc/mtk_batoc_throttling/battery_oc_protect_stop ;; Disable) apply "stop 1" /proc/mtk_batoc_throttling/battery_oc_protect_stop ;; esac } mtk_eara_thermal_switch() { - case $(fzf_select "Enable Disable" "Enable Eara thermal: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "Enable Eara thermal: ") + command2db mtk.eara_thermal.switch "mtk_eara_thermal_switch -exec $selected" FALSE + fi + case $selected in Enable) apply "1" /sys/kernel/eara_thermal/enable ;; Disable) apply "0" /sys/kernel/eara_thermal/enable ;; esac } mtk_eara_thermal_fake_throttle() { - case $(fzf_select "Enable Disable" "Fake throttle Eara thermal: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "Fake throttle Eara thermal: ") + command2db mtk.eara_thermal.fake_throttle "mtk_eara_thermal_fake_throttle -exec $selected" FALSE + fi + case $selected in Enable) apply "1" /sys/kernel/eara_thermal/fake_throttle ;; Disable) apply "0" /sys/kernel/eara_thermal/fake_throttle ;; esac diff --git a/share/utils/net/net_util.sh b/share/utils/net/net_util.sh index d67ff54..9cd795a 100644 --- a/share/utils/net/net_util.sh +++ b/share/utils/net/net_util.sh @@ -17,33 +17,67 @@ # Copyright (C) 2023-2024 Rem01Gaming tcp_congestion_change() { - apply $(fzf_select "$(cat /proc/sys/net/ipv4/tcp_available_congestion_control)" "Select TCP Congestion: ") /proc/sys/net/ipv4/tcp_congestion_control + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "$(cat /proc/sys/net/ipv4/tcp_available_congestion_control)" "Select TCP Congestion: ") + command2db net.ipv4.tcp_congestion_control "tcp_congestion_change -exec $selected" FALSE + fi + apply $selected /proc/sys/net/ipv4/tcp_congestion_control } tcp_low_latency() { - case $(fzf_select "Enable Disable" "TCP Low latency mode: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "TCP Low latency mode: ") + command2db net.ipv4.tcp_low_latency "tcp_low_latency -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /proc/sys/net/ipv4/tcp_low_latency ;; Disable) apply 0 /proc/sys/net/ipv4/tcp_low_latency ;; esac } tcp_syncookies() { - case $(fzf_select "Enable Disable" "SYN Cookies: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable" "SYN Cookies: ") + command2db net.ipv4.tcp_syncookies "tcp_syncookies -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /proc/sys/net/ipv4/tcp_syncookies ;; Disable) apply 0 /proc/sys/net/ipv4/tcp_syncookies ;; esac } tcp_max_syn_backlog() { - menu_value_tune "TCP Max SYN Backlog\ndetermines the maximum number of pending connection requests (SYN requests) that can be held in the queue before the system starts rejecting new connection attempts." /proc/sys/net/ipv4/tcp_max_syn_backlog 32400 128 2 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/net/ipv4/tcp_max_syn_backlog + else + menu_value_tune "TCP Max SYN Backlog\ndetermines the maximum number of pending connection requests (SYN requests) that can be held in the queue before the system starts rejecting new connection attempts." /proc/sys/net/ipv4/tcp_max_syn_backlog 32400 128 2 + command2db net.ipv4.tcp_max_syn_backlog "tcp_max_syn_backlog -exec $number" FALSE + fi } tcp_keepalive_time() { - menu_value_tune "TCP Keepalive time\nDetermine how long a TCP connection should remain idle before the operating system sends a keepalive probe to check if the connection is still active." /proc/sys/net/ipv4/tcp_keepalive_time 32400 128 2 + if [[ $1 == "-exec" ]]; then + apply $2 /proc/sys/net/ipv4/tcp_keepalive_time + else + menu_value_tune "TCP Keepalive time\nDetermine how long a TCP connection should remain idle before the operating system sends a keepalive probe to check if the connection is still active." /proc/sys/net/ipv4/tcp_keepalive_time 32400 128 2 + command2db net.ipv4.tcp_keepalive_time "tcp_keepalive_time -exec $number" FALSE + fi } tcp_reuse_socket() { - case $(fzf_select "Enable Disable enable-for-loopback-traffic-only" "TCP Reuse socket: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Enable Disable enable-for-loopback-traffic-only" "TCP Reuse socket: ") + command2db net.ipv4.tcp_tw_reuse "tcp_reuse_socket -exec $selected" FALSE + fi + case $selected in Enable) apply 1 /proc/sys/net/ipv4/tcp_tw_reuse ;; Disable) apply 0 /proc/sys/net/ipv4/tcp_tw_reuse ;; enable-for-loopback-traffic-only) apply 2 /proc/sys/net/ipv4/tcp_tw_reuse ;; @@ -51,39 +85,56 @@ tcp_reuse_socket() { } tcp_ecn() { - case $(fzf_select "0 1 2" "TCP Explicit Congestion Notification (ECN): ") in - 0) apply 0 /proc/sys/net/ipv4/tcp_ecn ;; - 1) apply 1 /proc/sys/net/ipv4/tcp_ecn ;; - 2) apply 2 /proc/sys/net/ipv4/tcp_ecn ;; - esac + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "0 1 2" "TCP Explicit Congestion Notification (ECN): ") + command2db net.ipv4.tcp_ecn "tcp_ecn -exec $selected" FALSE + fi + apply $selected /proc/sys/net/ipv4/tcp_ecn } tcp_fastopen() { - case $(fzf_select "0 1 2 3" "TCP Fastopen (TFO): ") in - 0) apply 0 /proc/sys/net/ipv4/tcp_fastopen ;; - 1) apply 1 /proc/sys/net/ipv4/tcp_fastopen ;; - 2) apply 2 /proc/sys/net/ipv4/tcp_fastopen ;; - 3) apply 3 /proc/sys/net/ipv4/tcp_fastopen ;; - esac + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "0 1 2 3" "TCP Fastopen (TFO): ") + command2db net.ipv4.tcp_fastopen "tcp_fastopen -exec $selected" FALSE + fi + apply $selected /proc/sys/net/ipv4/tcp_fastopen } tcp_sack() { - case $(fzf_select "Disable Enable" "TCP Select Acknowledgments (SACKS): ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Disable Enable" "TCP Select Acknowledgments (SACKS): ") + command2db net.ipv4.tcp_sack "tcp_sack -exec $selected" FALSE + fi + case $selected in Disable) apply 0 /proc/sys/net/ipv4/tcp_sack ;; Enable) apply 1 /proc/sys/net/ipv4/tcp_sack ;; esac } tcp_timestamps() { - case $(fzf_select "0 1 2" "TCP Timestamps: ") in - 0) apply 0 /proc/sys/net/ipv4/tcp_timestamps ;; - 1) apply 1 /proc/sys/net/ipv4/tcp_timestamps ;; - 2) apply 2 /proc/sys/net/ipv4/tcp_timestamps ;; - esac + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "0 1 2" "TCP Timestamps: ") + command2db net.ipv4.tcp_timestamps "tcp_timestamps -exec $selected" FALSE + fi + apply $selected /proc/sys/net/ipv4/tcp_timestamps } bpf_jit_harden() { - case $(fzf_select "Disable enable-for-unprivileged-users enable-for-all-users" "BPF JIT harden: ") in + if [[ $1 == "-exec" ]]; then + local selected=$2 + else + local selected=$(fzf_select "Disable enable-for-unprivileged-users enable-for-all-users" "BPF JIT harden: ") + command2db net.core.bpf_jit_harden "bpf_jit_harden -exec $selected" FALSE + fi + case $selected in enable-for-all-users) apply 2 /proc/sys/net/core/bpf_jit_harden ;; enable-for-unprivileged-users) apply 1 /proc/sys/net/core/bpf_jit_harden ;; Disable) apply 0 /proc/sys/net/core/bpf_jit_harden ;; diff --git a/src/okm b/src/okm index 0a78090..a8ef808 100644 --- a/src/okm +++ b/src/okm @@ -17,17 +17,22 @@ # Copyright (C) 2023-2024 Rem01Gaming # Check dependencies -if ! hash fzf fzy 2>/dev/null; then - echo -e "\033[38;5;196m[!] hash fzf fzy\033[0m\n[-] Environment has missing dependencies" && exit 127 +if ! hash fzf fzy jq curl sqlite3; then + echo -e "[-] Environment has missing dependencies" && exit 127 fi +[ ! -d /data/origami-kernel ] && mkdir /data/origami-kernel + # Dirty fix for check4update root_gid_hack() { su -lp $SUDO_GID -c "$@" } -source /data/data/com.termux/files/usr/share/origami-kernel/init/init_run.sh -source /data/data/com.termux/files/usr/share/origami-kernel/utils/menu/menu_helper.sh +source /data/data/com.termux/files/usr/share/origami-kernel/menu_helper.sh +source /data/data/com.termux/files/usr/share/origami-kernel/database_util.sh +source /data/data/com.termux/files/usr/share/origami-kernel/settings.sh +source /data/data/com.termux/files/usr/share/origami-kernel/init_run.sh +source /data/data/com.termux/files/usr/share/origami-kernel/exec_storedcmd.sh source /data/data/com.termux/files/usr/share/origami-kernel/utils/cpu/cpu_util.sh source /data/data/com.termux/files/usr/share/origami-kernel/utils/gpu/gpu_util.sh source /data/data/com.termux/files/usr/share/origami-kernel/utils/dram/dram_util.sh @@ -46,8 +51,13 @@ VERSION="v1.1.0" trap "tput cnorm" EXIT +if [ $(sql_query "SELECT execstoredcmd FROM tb_info;") -eq 1 ] && [ ! -f /dev/okm-execstoredcmd ] && [ $(risk_acceptence) -eq 1 ]; then + init_execstoredcmd + touch /dev/okm-execstoredcmd +fi + # User agreement -if [ ! -f /data/origami-kernel/agreed ]; then +if [ $(risk_acceptence) -eq 0 ]; then clear echo -e "Origami Kernel Manager ${VERSION}" echo -e "Copyright (c) 2023-2024 Rem01Gaming\n" @@ -55,7 +65,7 @@ if [ ! -f /data/origami-kernel/agreed ]; then echo -e "Origami Kernel Manager offers advanced root functions that could potentially harm your device if used incorrectly or in combination with other software, tweaks, or modules. Please be cautious as Origami Kernel Manager does not take responsibility for any damages resulting from the misuse of this software.\n\nIf you are not well-versed in how root access functions, it's advisable to refrain from utilizing the root options until you have a complete understanding of the associated risks.\n\nThis software is licensed under the GNU General Public License v3.0. It comes with NO WARRANTY AND LIABILITY. By using this software, you acknowledge and accept full responsibility for its use. You agree that any actions taken with this software that negatively impact your device are not the responsibility of the developer.\n\n" | fold -s -w ${LINE} read -p "Type 'I AGREE' to continue: " a1 case $a1 in - "I AGREE") mkdir /data/origami-kernel && touch /data/origami-kernel/agreed ;; + "I AGREE") accept_risk ;; *) clear && echo -e "\033[38;5;196m[-] Not agreed, Aborted.\033[0m" && exit 0 ;; esac fi @@ -118,7 +128,7 @@ check4update() { curl -o ~/origami-kernel.deb -L https://github.com/Rem01Gaming/origami_kernel_manager/releases/download/$latest_release/origami-kernel.deb >/dev/null 2>&1 echo "[*] Installing update..." [ ! -f ~/origami-kernel.deb ] && echo "[-] Error while downloading update file" && exit 1 - root_gid_hack $TERMUX_PATH/apt remove origami-kernel -y >/dev/null 2>&1 + root_gid_hack $TERMUX_PATH/apt remove origami-kernel -y >/dev/null 2>&1 root_gid_hack $TERMUX_PATH/apt install ~/origami-kernel.deb -y >/dev/null 2>&1 rm -f ~/origami-kernel.deb echo "[+] Update successfully, please re-run origami-kernel." @@ -161,7 +171,7 @@ main_menu() { # Hide cursor tput civis - case $(fzy_select "CPU control\nGPU control\nDRAM control\nMemory settings\nNetworking settings\nMiscellaneous settings\nCharging controller\nDisplay color calibration\nShow License\nCheck for update\nDonate me\nJoin my telegram channel\nExit" "") in + case $(fzy_select "CPU control\nGPU control\nDRAM control\nMemory settings\nNetworking settings\nMiscellaneous settings\nCharging controller\nDisplay color calibration\nOKM Settings\nShow License\nCheck for update\nDonate me\nJoin my telegram channel\nExit" "") in "CPU control") cpu_menu ;; "GPU control") gpu_menu ;; "DRAM control") dram_menu ;; @@ -170,6 +180,7 @@ main_menu() { "Miscellaneous settings") misc_menu ;; "Charging controller") batt_menu ;; "Display color calibration") disp_menu ;; + "OKM Settings") settings_menu ;; "Show License") show_license ;; "Check for update") check4update ;; "Join my telegram channel") nohup /system/bin/am start -a android.intent.action.VIEW -d https://t.me/rem01schannel >/dev/null 2>&1 ;;