From 122d84623f498799bfb5ca4bfbfeb73e2cd00053 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 29 Aug 2021 01:35:21 +0800 Subject: [PATCH 1/5] contrib: thermald: merge power adapter udev rules --- .../surface_pro_5/40-surface-power.rules | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/contrib/thermald/surface_pro_5/40-surface-power.rules b/contrib/thermald/surface_pro_5/40-surface-power.rules index 56dcd2050..7f0808557 100644 --- a/contrib/thermald/surface_pro_5/40-surface-power.rules +++ b/contrib/thermald/surface_pro_5/40-surface-power.rules @@ -23,14 +23,18 @@ # E: POWER_SUPPLY_ONLINE=0 # E: SUBSYSTEM=power_supply + + # Plugged -SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/logger -t surface power supply online" -SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/surface profile set performance" -SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/ln -sf /etc/thermald/thermal-conf.xml.auto.performance /etc/thermald/thermal-conf.xml.auto" -SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/systemctl try-restart thermald" +ACTION=="change", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_NAME}=="ADP1", ENV{POWER_SUPPLY_ONLINE}=="1" \ +, RUN+="/usr/bin/logger -t surface power supply online" \ +, RUN+="/usr/bin/surface profile set performance" \ +, RUN+="/usr/bin/ln -sf /etc/thermald/thermal-conf.xml.auto.performance /etc/thermald/thermal-conf.xml.auto" \ +, RUN+="/usr/bin/systemctl try-restart thermald" # Unplugged -SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/logger -t surface power supply offline" -SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/surface profile set low-power" -SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/ln -sf /etc/thermald/thermal-conf.xml.auto.mobile /etc/thermald/thermal-conf.xml.auto" -SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/systemctl try-restart thermald" +ACTION=="change", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_NAME}=="ADP1", ENV{POWER_SUPPLY_ONLINE}=="0" \ +, RUN+="/usr/bin/logger -t surface power supply offline" \ +, RUN+="/usr/bin/surface profile set low-power" \ +, RUN+="/usr/bin/ln -sf /etc/thermald/thermal-conf.xml.auto.mobile /etc/thermald/thermal-conf.xml.auto" \ +, RUN+="/usr/bin/systemctl try-restart thermald" From 103c6c96b759958e05b8c98060bf4e1ca895569b Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 29 Aug 2021 19:39:51 +0800 Subject: [PATCH 2/5] add pci and cpu power control --- .../surface_pro_5/40-surface-power.rules | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/contrib/thermald/surface_pro_5/40-surface-power.rules b/contrib/thermald/surface_pro_5/40-surface-power.rules index 7f0808557..ba89b57ef 100644 --- a/contrib/thermald/surface_pro_5/40-surface-power.rules +++ b/contrib/thermald/surface_pro_5/40-surface-power.rules @@ -1,4 +1,4 @@ -# Use `udevadm monitor` to find out what's going on (e.g. unplugged) +# Use `udevadm monitor -ap` to find out what's going on (e.g. unplugged) # For example: # monitor will print the received events for: # UDEV - the event which udev sends out after rule processing @@ -28,6 +28,18 @@ # Plugged ACTION=="change", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_NAME}=="ADP1", ENV{POWER_SUPPLY_ONLINE}=="1" \ , RUN+="/usr/bin/logger -t surface power supply online" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo on > /sys/bus/pci/devices/0000:00:00.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo on > /sys/bus/pci/devices/0000:00:02.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo on > /sys/bus/pci/devices/0000:00:1c.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo on > /sys/bus/pci/devices/0000:00:1c.4/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo on > /sys/bus/pci/devices/0000:00:1d.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo on > /sys/bus/pci/devices/0000:00:1f.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo on > /sys/bus/pci/devices/0000:01:00.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo powersave > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo powersave > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo powersave > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo'" \ , RUN+="/usr/bin/surface profile set performance" \ , RUN+="/usr/bin/ln -sf /etc/thermald/thermal-conf.xml.auto.performance /etc/thermald/thermal-conf.xml.auto" \ , RUN+="/usr/bin/systemctl try-restart thermald" @@ -35,6 +47,18 @@ ACTION=="change", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_NAME}=="ADP1", ENV # Unplugged ACTION=="change", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_NAME}=="ADP1", ENV{POWER_SUPPLY_ONLINE}=="0" \ , RUN+="/usr/bin/logger -t surface power supply offline" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo auto > /sys/bus/pci/devices/0000:00:00.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo auto > /sys/bus/pci/devices/0000:00:02.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo auto > /sys/bus/pci/devices/0000:00:1c.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo auto > /sys/bus/pci/devices/0000:00:1c.4/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo auto > /sys/bus/pci/devices/0000:00:1d.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo auto > /sys/bus/pci/devices/0000:00:1f.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo auto > /sys/bus/pci/devices/0000:01:00.0/power/control'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo powersave > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo powersave > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo powersave > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor'" \ +, RUN+="/usr/bin/sh -c '/usr/bin/echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'" \ , RUN+="/usr/bin/surface profile set low-power" \ , RUN+="/usr/bin/ln -sf /etc/thermald/thermal-conf.xml.auto.mobile /etc/thermald/thermal-conf.xml.auto" \ , RUN+="/usr/bin/systemctl try-restart thermald" From d2e82ef57b286acf66eec633470946e8461d3416 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Fri, 3 Sep 2021 00:20:44 +0800 Subject: [PATCH 3/5] update readme --- contrib/thermald/surface_pro_5/README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contrib/thermald/surface_pro_5/README.md b/contrib/thermald/surface_pro_5/README.md index 56b0a3b33..f2259af54 100644 --- a/contrib/thermald/surface_pro_5/README.md +++ b/contrib/thermald/surface_pro_5/README.md @@ -22,6 +22,13 @@ thermal targets. See 40-surface-power.rules for more details on how to obtain info about sensors and cooling devices. +## Bonus + +40-surface-power.rules also contains power-related tweaks for: +- `surface profile`: currently low-power vs. performance +- Various PCIe powersaving strategies +- Intel p-state control for turbo-boost + ## Installation - Make sure to install `surface-control` @@ -35,8 +42,3 @@ and cooling devices. - `systemctl restart udev` - `systemctl restart thermald` -## TODO - -- I tried to update cpufreq governor and turbo in udev event triggers but it - didn't work. -- You can install `cpufreqctl` for that. From 90479a68418692fb7ef9a5bfff3968a447ea04ab Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Fri, 3 Sep 2021 00:26:01 +0800 Subject: [PATCH 4/5] add sysctl startup settings --- contrib/thermald/surface_pro_5/50-surface.conf | 2 ++ contrib/thermald/surface_pro_5/README.md | 1 + 2 files changed, 3 insertions(+) create mode 100644 contrib/thermald/surface_pro_5/50-surface.conf diff --git a/contrib/thermald/surface_pro_5/50-surface.conf b/contrib/thermald/surface_pro_5/50-surface.conf new file mode 100644 index 000000000..9279a6216 --- /dev/null +++ b/contrib/thermald/surface_pro_5/50-surface.conf @@ -0,0 +1,2 @@ +kernel.nmi_watchdog=0 +vm.dirty_writeback_centisecs=1500 diff --git a/contrib/thermald/surface_pro_5/README.md b/contrib/thermald/surface_pro_5/README.md index f2259af54..9e09f0589 100644 --- a/contrib/thermald/surface_pro_5/README.md +++ b/contrib/thermald/surface_pro_5/README.md @@ -38,6 +38,7 @@ and cooling devices. - Install `thermal-cpu-cdev-order.xml` to `/etc/thermald/` - Install `thermald.service` to `/lib/systemd/system/` and overwrite the old one. - Maybe install to `/usr/lib/systemd/system/` too. +- Install `50-surface.conf` to `/etc/sysctl.d/` - `systemctl daemon-reload` - `systemctl restart udev` - `systemctl restart thermald` From 8ced0e1155bed14cb3f18523d534a2dedd1e8068 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Fri, 3 Sep 2021 00:27:25 +0800 Subject: [PATCH 5/5] update readme --- contrib/thermald/surface_pro_5/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/thermald/surface_pro_5/README.md b/contrib/thermald/surface_pro_5/README.md index 9e09f0589..2f2fa56b9 100644 --- a/contrib/thermald/surface_pro_5/README.md +++ b/contrib/thermald/surface_pro_5/README.md @@ -29,6 +29,8 @@ and cooling devices. - Various PCIe powersaving strategies - Intel p-state control for turbo-boost +50-surface.conf contains sysctl tweaks advised by `powertop`. + ## Installation - Make sure to install `surface-control`