2023-06-23 10:57:57 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2023-10-24 16:00:57 +00:00
|
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
2023-06-23 10:57:57 +00:00
|
|
|
|
|
|
|
get_gpu_power_profile() {
|
|
|
|
cat /sys/class/drm/card0/device/power_dpm_state 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
gpu_power_profile() {
|
|
|
|
for card in /sys/class/drm/card*/device/power_dpm_state
|
|
|
|
do
|
|
|
|
if [ -e "${card}" ]
|
|
|
|
then
|
|
|
|
echo ${1} >${card} 2>/dev/null
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
get_gpu_performance_level() {
|
2023-11-07 23:46:44 +00:00
|
|
|
case ${HW_ARCH} in
|
|
|
|
x86_64)
|
|
|
|
cat /sys/class/drm/card0/device/power_dpm_force_performance_level 2>/dev/null
|
|
|
|
;;
|
|
|
|
aarch64)
|
|
|
|
get_setting system.gpuperf
|
|
|
|
;;
|
|
|
|
esac
|
2023-06-23 10:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gpu_performance_level() {
|
2023-11-07 23:46:44 +00:00
|
|
|
case ${HW_ARCH} in
|
|
|
|
x86_64)
|
|
|
|
for card in /sys/class/drm/card*/device/power_dpm_force_performance_level
|
|
|
|
do
|
|
|
|
if [ -e "${card}" ]
|
|
|
|
then
|
|
|
|
echo ${1} >${card} 2>/dev/null
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
aarch64)
|
|
|
|
case ${1} in
|
|
|
|
profile_peak)
|
|
|
|
set_gpu_gov performance
|
|
|
|
;;
|
|
|
|
auto|profile_standard)
|
|
|
|
set_gpu_gov ondemand
|
|
|
|
;;
|
|
|
|
low)
|
|
|
|
set_gpu_gov powersave
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
2023-06-23 10:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pcie_aspm_policy() {
|
2023-06-28 11:41:10 +00:00
|
|
|
PCIEPOWERSAVE=$(get_setting system.power.pcie)
|
2023-07-16 15:26:02 +00:00
|
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
|
|
|
if [ "${PCIEPOWERSAVE}" = "1" ] &&
|
|
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
2023-06-26 10:15:15 +00:00
|
|
|
then
|
2023-07-16 15:26:02 +00:00
|
|
|
if [ -e "/sys/module/pcie_aspm/parameters/policy" ]
|
|
|
|
then
|
|
|
|
echo ${1} >/sys/module/pcie_aspm/parameters/policy 2>/dev/null
|
|
|
|
fi
|
2023-06-23 10:57:57 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_perftune() {
|
2023-06-28 11:41:10 +00:00
|
|
|
CPUPOWERSAVE=$(get_setting system.power.cpu)
|
2023-07-16 15:26:02 +00:00
|
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
|
|
|
if [ "${CPUPOWERSAVE}" = "1" ] && \
|
|
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
2023-06-26 10:15:15 +00:00
|
|
|
then
|
2023-07-16 15:26:02 +00:00
|
|
|
CPU="$(awk '/vendor_id/ {print $3;exit}' /proc/cpuinfo)"
|
|
|
|
if [ "${CPU}" = "AuthenticAMD" ]
|
2023-06-23 10:57:57 +00:00
|
|
|
then
|
|
|
|
if [ "${1}" = "battery" ]
|
|
|
|
then
|
2023-07-16 15:26:02 +00:00
|
|
|
ryzenadj --power-saving >/dev/null 2>&1
|
2023-06-23 10:57:57 +00:00
|
|
|
else
|
2023-07-16 15:26:02 +00:00
|
|
|
ryzenadj --max-performance >/dev/null 2>&1
|
2023-06-23 10:57:57 +00:00
|
|
|
fi
|
2023-07-16 15:26:02 +00:00
|
|
|
elif [ "${CPU}" = "GenuineIntel" ]
|
|
|
|
then
|
|
|
|
for policy in $(find /sys/devices/system/cpu/cpufreq/policy*/ -name energy_performance_preference)
|
|
|
|
do
|
|
|
|
if [ "${1}" = "battery" ]
|
|
|
|
then
|
|
|
|
echo power >${policy} >/dev/null 2>&1
|
|
|
|
else
|
|
|
|
echo performance >${policy} >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2023-06-23 10:57:57 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_powersave() {
|
2023-07-16 15:26:02 +00:00
|
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
2023-06-28 11:41:10 +00:00
|
|
|
AUDIOPOWERSAVE=$(get_setting system.power.audio)
|
2023-07-16 15:26:02 +00:00
|
|
|
if [ "${AUDIOPOWERSAVE}" = "1" ] &&
|
|
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
2023-06-26 10:15:15 +00:00
|
|
|
then
|
2023-07-16 15:26:02 +00:00
|
|
|
for MODULE in snd_hda_intel snd_ac97_codec
|
|
|
|
do
|
|
|
|
if [ -e "/sys/module/${MODULE}/parameters/power_save" ]
|
|
|
|
then
|
|
|
|
echo ${1} >/sys/module/${MODULE}/parameters/power_save 2>/dev/null
|
|
|
|
fi
|
|
|
|
done
|
2023-06-26 10:15:15 +00:00
|
|
|
fi
|
2023-06-23 10:57:57 +00:00
|
|
|
}
|
|
|
|
|
2023-06-28 11:41:10 +00:00
|
|
|
runtime_power_management() {
|
2023-07-16 15:26:02 +00:00
|
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
2023-06-28 11:41:10 +00:00
|
|
|
RTPM=$(get_setting system.power.rtpm)
|
2023-07-16 15:26:02 +00:00
|
|
|
if [ "${RTPM}" = "1" ] &&
|
|
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
2023-06-26 10:15:15 +00:00
|
|
|
then
|
2023-09-05 18:25:37 +00:00
|
|
|
find /sys/devices/{platform,pci*} -type f -name control -print0 2>/dev/null | \
|
2023-07-16 15:26:02 +00:00
|
|
|
while read -r -d '' DEVICE
|
|
|
|
do
|
|
|
|
echo ${1} >"${DEVICE}" 2>/dev/null
|
2023-09-05 18:25:37 +00:00
|
|
|
echo ${2} >"${DEVICE/control/autosuspend_delay_ms}" 2>/dev/null
|
2023-07-16 15:26:02 +00:00
|
|
|
done
|
2023-09-13 21:12:05 +00:00
|
|
|
fi
|
|
|
|
}
|
2023-09-05 18:25:37 +00:00
|
|
|
|
2023-09-13 21:12:05 +00:00
|
|
|
scsi_link_power_management() {
|
|
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
|
|
|
RTPM=$(get_setting system.power.rtpm)
|
|
|
|
if [ "${RTPM}" = "1" ] &&
|
|
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
|
|
|
then
|
|
|
|
find /sys/class/scsi_host/host*/ -type f -name link_power_management_policy -print0 2>/dev/null | \
|
|
|
|
while read -r -d '' DEVICE
|
|
|
|
do
|
|
|
|
echo "${1}" >"${DEVICE}" 2>/dev/null
|
|
|
|
done
|
2023-06-26 10:15:15 +00:00
|
|
|
fi
|
2023-06-23 10:57:57 +00:00
|
|
|
}
|
2023-06-24 12:07:48 +00:00
|
|
|
|
2023-06-28 11:41:10 +00:00
|
|
|
wake_events() {
|
2023-07-16 15:26:02 +00:00
|
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
2023-06-28 11:41:10 +00:00
|
|
|
WAKEEVENTS=$(get_setting system.power.wakeevents)
|
2023-07-16 15:26:02 +00:00
|
|
|
if [ "${WAKEEVENTS}" = "1" ] && \
|
|
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
2023-06-26 10:15:15 +00:00
|
|
|
then
|
2023-07-16 15:26:02 +00:00
|
|
|
for device in $(find /sys/devices/{platform,pci*} -type f -name wakeup 2>/dev/null)
|
|
|
|
do
|
|
|
|
echo ${1} >${device} 2>/dev/null
|
|
|
|
done
|
2023-06-26 10:15:15 +00:00
|
|
|
fi
|
2023-06-28 00:38:41 +00:00
|
|
|
}
|