From 6d7e92052f44af7e10a7f0ab66d23ff163179780 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Wed, 26 Oct 2022 01:18:13 +0200 Subject: [PATCH] WIP Laptop power --- .../files/etc/udev/rules.d/99-powersave.rules | 2 ++ .../files/usr/local/sbin/power-saver-mode | 14 ++++++++++ .../files/usr/local/sbin/unlimited-power | 26 +++++++++++++++++++ roles/laptop/tasks/powersave.yml | 24 +++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 roles/laptop/files/etc/udev/rules.d/99-powersave.rules create mode 100644 roles/laptop/files/usr/local/sbin/power-saver-mode create mode 100644 roles/laptop/files/usr/local/sbin/unlimited-power create mode 100644 roles/laptop/tasks/powersave.yml diff --git a/roles/laptop/files/etc/udev/rules.d/99-powersave.rules b/roles/laptop/files/etc/udev/rules.d/99-powersave.rules new file mode 100644 index 0000000..060eee5 --- /dev/null +++ b/roles/laptop/files/etc/udev/rules.d/99-powersave.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/local/sbin/power-saver-mode" +SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/local/sbin/unlimited-power" \ No newline at end of file diff --git a/roles/laptop/files/usr/local/sbin/power-saver-mode b/roles/laptop/files/usr/local/sbin/power-saver-mode new file mode 100644 index 0000000..e999f97 --- /dev/null +++ b/roles/laptop/files/usr/local/sbin/power-saver-mode @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# Enable back all CPUs +echo 1 | tee /sys/devices/system/cpu/cpu[2-7]/online +echo 1 | tee /sys/devices/system/cpu/cpu1[0-5]/online + +# Set CPU to governor to powersave +cpupower frequency-set --governor ondemand + +# Set brightness to 120 / 255 +echo 200 | tee /sys/class/backlight/amdgpu_bl0/brightness + +# Enable bluetooth +rfkill unblock bluetooth diff --git a/roles/laptop/files/usr/local/sbin/unlimited-power b/roles/laptop/files/usr/local/sbin/unlimited-power new file mode 100644 index 0000000..dd3cd7e --- /dev/null +++ b/roles/laptop/files/usr/local/sbin/unlimited-power @@ -0,0 +1,26 @@ +#!/usr/bin/env sh + +# Limit 8C/16T CPU to 2C/4T +echo 0 | tee /sys/devices/system/cpu/cpu[2-7]/online +echo 0 | tee /sys/devices/system/cpu/cpu1[0-5]/online + +# Set CPU to governor to powersave +cpupower frequency-set --governor powersave + +# Set brightness to 120 / 255 +echo 120 | tee /sys/class/backlight/amdgpu_bl0/brightness + +# Disable bluetooth +rfkill block bluetooth + +# TODO disable some services +# systemctl disable containerd.service +# systemctl disable docker.service +# systemctl disable bluetooth.service +# systemctl disable libvirtd.service +# systemctl disable winbind.service +# systemctl disable snapd.service +# systemctl disable cups.service +# systemctl disable avahi-daemon.service + +# TODO exit steam diff --git a/roles/laptop/tasks/powersave.yml b/roles/laptop/tasks/powersave.yml new file mode 100644 index 0000000..01bcc64 --- /dev/null +++ b/roles/laptop/tasks/powersave.yml @@ -0,0 +1,24 @@ +- name: install required packages for script + become: yes + apt: + update_cache: yes + pkg: + - linux-tools-common + - linux-tools-generic + +- name: copy scripts + become: yes + copy: + src: "usr/local/sbin/{{item}}" + dest: "/usr/local/sbin/{{item}}" + mode: '0755' + loop: + - power-saver-mode + - unlimited-power + +- name: add udev rules + become: yes + copy: + src: etc/udev/rules.d/99-powersave.rules + dest: /etc/udev/rules.d/99-powersave.rules + mode: '0755'