132 lines
3.5 KiB
Bash
132 lines
3.5 KiB
Bash
#!/bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# Copyright (C) 2023-present - The JELOS Project (https://github.com/JustEnoughLinuxOS) (https://github.com/fewtarius)
|
|
|
|
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() {
|
|
cat /sys/class/drm/card0/device/power_dpm_force_performance_level 2>/dev/null
|
|
}
|
|
|
|
gpu_performance_level() {
|
|
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
|
|
}
|
|
|
|
pcie_aspm_policy() {
|
|
PCIEPOWERSAVE=$(get_setting system.power.pcie)
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
|
if [ "${PCIEPOWERSAVE}" = "1" ] &&
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
|
then
|
|
if [ -e "/sys/module/pcie_aspm/parameters/policy" ]
|
|
then
|
|
echo ${1} >/sys/module/pcie_aspm/parameters/policy 2>/dev/null
|
|
fi
|
|
fi
|
|
}
|
|
|
|
cpu_perftune() {
|
|
CPUPOWERSAVE=$(get_setting system.power.cpu)
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
|
if [ "${CPUPOWERSAVE}" = "1" ] && \
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
|
then
|
|
CPU="$(awk '/vendor_id/ {print $3;exit}' /proc/cpuinfo)"
|
|
if [ "${CPU}" = "AuthenticAMD" ]
|
|
then
|
|
if [ "${1}" = "battery" ]
|
|
then
|
|
ryzenadj --power-saving >/dev/null 2>&1
|
|
else
|
|
ryzenadj --max-performance >/dev/null 2>&1
|
|
fi
|
|
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
|
|
fi
|
|
}
|
|
|
|
audio_powersave() {
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
|
AUDIOPOWERSAVE=$(get_setting system.power.audio)
|
|
if [ "${AUDIOPOWERSAVE}" = "1" ] &&
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
|
then
|
|
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
|
|
fi
|
|
}
|
|
|
|
runtime_power_management() {
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
|
RTPM=$(get_setting system.power.rtpm)
|
|
if [ "${RTPM}" = "1" ] &&
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
|
then
|
|
find /sys/devices/{platform,pci*} -type f -name control -print0 2>/dev/null | \
|
|
while read -r -d '' DEVICE
|
|
do
|
|
echo ${1} >"${DEVICE}" 2>/dev/null
|
|
echo ${2} >"${DEVICE/control/autosuspend_delay_ms}" 2>/dev/null
|
|
done
|
|
fi
|
|
}
|
|
|
|
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
|
|
fi
|
|
}
|
|
|
|
wake_events() {
|
|
POWERSAVEENABLED=$(get_setting system.powersave)
|
|
WAKEEVENTS=$(get_setting system.power.wakeevents)
|
|
if [ "${WAKEEVENTS}" = "1" ] && \
|
|
[ "${POWERSAVEENABLED}" = "1" ]
|
|
then
|
|
for device in $(find /sys/devices/{platform,pci*} -type f -name wakeup 2>/dev/null)
|
|
do
|
|
echo ${1} >${device} 2>/dev/null
|
|
done
|
|
fi
|
|
}
|