2023-06-23 10:57:57 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# Copyright (C) 2022-present Fewtarius (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() {
|
2023-06-26 10:15:15 +00:00
|
|
|
PCIEPOWERSAVE=$(get_setting system.pcie.powersave)
|
|
|
|
if [ ! "${PCIEPOWERSAVE}" = "1" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
2023-06-23 10:57:57 +00:00
|
|
|
if [ -e "/sys/module/pcie_aspm/parameters/policy" ]
|
|
|
|
then
|
|
|
|
echo ${1} >/sys/module/pcie_aspm/parameters/policy 2>/dev/null
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_perftune() {
|
2023-06-26 10:15:15 +00:00
|
|
|
CPUPOWERSAVE=$(get_setting system.cpu.powersave)
|
|
|
|
if [ ! "${CPUPOWERSAVE}" = "1" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
2023-06-23 10:57:57 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_powersave() {
|
2023-06-26 10:15:15 +00:00
|
|
|
AUDIOPOWERSAVE=$(get_setting system.audio.powersave)
|
|
|
|
if [ ! "${AUDIOPOWERSAVE}" = "1" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
2023-06-23 10:57:57 +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-28 00:38:41 +00:00
|
|
|
usb_powersave() {
|
2023-06-26 10:15:15 +00:00
|
|
|
USBPOWERSAVE=$(get_setting system.usb.powersave)
|
|
|
|
if [ ! "${USBPOWERSAVE}" = "1" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
2023-06-23 10:57:57 +00:00
|
|
|
find /sys/devices -name control -print0 | \
|
|
|
|
while read -r -d '' DEVICE
|
|
|
|
do
|
2023-06-28 00:38:41 +00:00
|
|
|
echo ${1} >"${DEVICE}" 2>/dev/null
|
2023-06-23 10:57:57 +00:00
|
|
|
done
|
|
|
|
}
|
2023-06-24 12:07:48 +00:00
|
|
|
|
2023-06-28 00:38:41 +00:00
|
|
|
usb_powerlevel() {
|
|
|
|
USBPOWERSAVE=$(get_setting system.usb.powersave)
|
2023-06-26 10:15:15 +00:00
|
|
|
if [ ! "${USBPOWERSAVE}" = "1" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
2023-06-24 12:07:48 +00:00
|
|
|
for device in $(find /sys/devices/pci* -name level)
|
|
|
|
do
|
|
|
|
echo ${1} >${device} 2>/dev/null
|
|
|
|
done
|
|
|
|
}
|
2023-06-28 00:38:41 +00:00
|
|
|
|
|
|
|
pci_powersave() {
|
|
|
|
PCIPOWERSAVE=$(get_setting system.pci.powersave)
|
|
|
|
if [ ! "${PCIPOWERSAVE}" = "1" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
for device in $(find /sys/devices/pci* -name wakeup)
|
|
|
|
do
|
|
|
|
echo ${1} >${device} 2>/dev/null
|
|
|
|
done
|
|
|
|
}
|