Last active
July 3, 2018 07:38
-
-
Save ktsaou/2c4fc578bad71be7a4a0278c7a374a41 to your computer and use it in GitHub Desktop.
dell XPS9560 cpufreq fix for acpi-cpufreq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
base="/sys/devices/system/cpu/cpufreq/policy0/" | |
ME="${0}" | |
SCALING_DRIVER="$(<${base}/scaling_driver)" | |
SCALING_GOVERNOR="$(<${base}/scaling_governor)" | |
AC_ONLINE=$(</sys/class/power_supply/AC/online) | |
# install this script in udev | |
UDEV_RULES_FILE="/etc/udev/rules.d/81-xps9560-cpufreq.rules" | |
if [ ! -f ${UDEV_RULES_FILE} ] | |
then | |
echo >&2 "Installing this script at ${UDEV_RULES_FILE}" | |
cat >${UDEV_RULES_FILE} <<EOF | |
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="${ME}" | |
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="${ME}" | |
EOF | |
udevadm control --reload-rules | |
fi | |
ignore_ppc() { | |
[ "$(</sys/module/processor/parameters/ignore_ppc)" = "1" ] && return 0 | |
printf >&2 "Instructing the kernel to ignore the max CPU freq enforced by the BIOS... " | |
echo 1 >/sys/module/processor/parameters/ignore_ppc | |
if [ "$(</sys/module/processor/parameters/ignore_ppc)" != "1" ] | |
then | |
echo >&2 "FAILED" | |
else | |
echo >&2 "OK" | |
fi | |
} | |
set_energy_bias() { | |
# MSR_IA32_ENERGY_PERF_BIAS | |
# 0 is "maximum performance" and 15 is "maximum energy efficiency" | |
local bias="${1}" | |
[ $(( bias + 1 - 1 )) -lt 0 ] && bias=0 | |
[ $(( bias + 1 - 1 )) -gt 15 ] && bias=15 | |
cpupower set -b ${bias} | |
} | |
set_core_attribute() { | |
local dir="${1}" attribute="${2}" value="${3}" | |
[ "$(<${dir}/${attribute})" = "${value}" ] && return 0 | |
printf >&2 "Setting ${1}/${attribute} to ${value}... " | |
echo >${dir}/${attribute} "${value}" | |
if [ "$(<${dir}/${attribute})" != "${value}" ] | |
then | |
echo >&2 "FAILED" | |
return 1 | |
else | |
echo >&2 "OK" | |
return 0 | |
fi | |
} | |
foreach_core() { | |
local cmd="${1}" | |
shift | |
for x in /sys/devices/system/cpu/cpu*/cpufreq | |
do | |
"${cmd}" "${x}" "${@}" | |
done | |
} | |
case "${SCALING_DRIVER}" in | |
acpi-cpufreq) | |
SCALING_AVAILABLE_FREQUENCIES=( $(<${base}/scaling_available_frequencies) ) | |
SCALING_MAX_FREQ="$(<${base}/scaling_max_freq)" | |
# on Dell XPS9560, the BIOS limits the CPU to 1.5GHz - fix it | |
ignore_ppc | |
if [ ${AC_ONLINE} -eq 0 ] | |
then | |
echo >&2 "Powersaving settings" | |
logger -p info "Powersaving settings" | |
governor="powersave" | |
# use the 2nd max frequency the processor supports | |
# (ie disable turbo) | |
max_frequency="${SCALING_AVAILABLE_FREQUENCIES[1]}" | |
else | |
echo >&2 "Performance settings" | |
logger -p info "Performance settings" | |
governor="ondemand" | |
# use the max frequency the processor supports | |
max_frequency="${SCALING_AVAILABLE_FREQUENCIES[0]}" | |
fi | |
foreach_core set_core_attribute scaling_governor "${governor}" | |
foreach_core set_core_attribute scaling_max_freq "${max_frequency}" | |
echo >&2 "Done" | |
;; | |
intel_pstate) | |
echo >&2 "Using scaling driver: ${SCALING_DRIVER}" | |
echo >&2 "Add kernel boot option: intel_pstate=disable" | |
if [ ${AC_ONLINE} -eq 0 ] | |
then | |
echo >&2 "Powersaving settings" | |
logger -p info "Powersaving settings" | |
energy_preference="balance_power" | |
else | |
echo >&2 "Performance settings" | |
logger -p info "Performance settings" | |
energy_preference="balance_performance" | |
fi | |
foreach_core set_core_attribute energy_performance_preference "${energy_preference}" | |
;; | |
*) | |
echo >&2 "Unknown scaling driver: ${SCALING_DRIVER}" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment