Reduce CPU frequency when laptop lid is closed
Table of Contents
I got a new Alienware M16 laptop. One thing that I had done on my old laptop was, that I had it automatically lower the CPU frequency when I closed the lid on my laptop. I don’t want it to go to sleep but also don’t need it to run full blast. Yes, the CPU governor should lower the frequency on it’s own, but this way I just force it to the lowest frequency.
These are the steps I made to do this. I am running Arch, but this should work on any linux distribution.
First you need to make sure that acpid is installed. On Arch you install it with
pacman -S extra/acpid
This will create a directory /etc/acpi. We need two files in there.
/etc/acpi/events/laptop-lid
event=button/lid.*
action=../../../etc/acpi/laptop-lid.sh %e
/etc/acpi/laptop-lid.sh
#!/bin/bash
read -r min max <<< $(/usr/bin/cpupower frequency-info | awk '/^ +hardware limits/{print $3$4" "$6$7}')
case "$1" in
button/lid)
case "$3" in
close)
logger 'LID closed'
date >> /tmp/cpupower
/usr/bin/cpupower frequency-set --min ${min} --max ${min} >> /tmp/cpupower
/usr/bin/cpupower frequency-info >> /tmp/cpupower
;;
open)
logger 'LID opened'
date >> /tmp/cpupower
/usr/bin/cpupower frequency-set --min ${min} --max ${max} >> /tmp/cpupower
/usr/bin/cpupower frequency-info >> /tmp/cpupower
;;
*)
logger "ACPI action undefined: $3"
;;
esac
;;
*)
logger "ACPI group/action undefined: $1 / $2"
;;
esac
Yes, it’s not the best to write logs to /tmp. Find a better spot for yourself.
Check the power management settings for your desktop manager and make sure, that it has nothing configured when the lid is closed. All we have to do now is start acpid and enable the service.
systemctl enable acpid.service
systemctl start acpid.service