From 914cc11a393427256a5efc19665ee873b16895c2 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Wed, 25 Aug 2021 18:45:47 +0800 Subject: [PATCH] contrib: add surface pro 5 thermald configuration --- .../SurfacePro5/40-surface-power.rules | 38 ++++++++ contrib/thermald/SurfacePro5/README.md | 42 ++++++++ .../SurfacePro5/thermal-conf.xml.auto.cool | 85 +++++++++++++++++ .../SurfacePro5/thermal-conf.xml.auto.mobile | 95 +++++++++++++++++++ .../thermal-conf.xml.auto.performance | 75 +++++++++++++++ .../SurfacePro5/thermal-cpu-cdev-order.xml | 18 ++++ contrib/thermald/SurfacePro5/thermald.service | 14 +++ 7 files changed, 367 insertions(+) create mode 100644 contrib/thermald/SurfacePro5/40-surface-power.rules create mode 100644 contrib/thermald/SurfacePro5/README.md create mode 100644 contrib/thermald/SurfacePro5/thermal-conf.xml.auto.cool create mode 100644 contrib/thermald/SurfacePro5/thermal-conf.xml.auto.mobile create mode 100644 contrib/thermald/SurfacePro5/thermal-conf.xml.auto.performance create mode 100644 contrib/thermald/SurfacePro5/thermal-cpu-cdev-order.xml create mode 100644 contrib/thermald/SurfacePro5/thermald.service diff --git a/contrib/thermald/SurfacePro5/40-surface-power.rules b/contrib/thermald/SurfacePro5/40-surface-power.rules new file mode 100644 index 000000000..018e1f5f2 --- /dev/null +++ b/contrib/thermald/SurfacePro5/40-surface-power.rules @@ -0,0 +1,38 @@ +# Use `udevadm monitor` 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 +# KERNEL - the kernel uevent +# +# KERNEL[3565.169206] change /devices/LNXSYSTM:00/ACPI0003:00/power_supply/ADP1 (power_supply) +# UDEV [3565.178952] change /devices/LNXSYSTM:00/ACPI0003:00/power_supply/ADP1 (power_supply) +# KERNEL[3565.179618] change /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1 (power_supply) +# UDEV [3565.195004] change /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1 (power_supply) +# KERNEL[3587.183562] change /devices/LNXSYSTM:00/ACPI0003:00/power_supply/ADP1 (power_supply) +# UDEV [3587.190598] change /devices/LNXSYSTM:00/ACPI0003:00/power_supply/ADP1 (power_supply) +# KERNEL[3587.207545] change /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1 (power_supply) +# UDEV [3587.216793] change /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1 (power_supply) +# +# Then, use `udevadm info --path /devices/LNXSYSTM:00/ACPI0003:00/power_supply/ADP1 to find out +# the events we can use: +# P: /devices/LNXSYSTM:00/ACPI0003:00/power_supply/ADP1 +# L: 0 +# E: DEVPATH=/devices/LNXSYSTM:00/ACPI0003:00/power_supply/ADP1 +# E: POWER_SUPPLY_NAME=ADP1 +# E: POWER_SUPPLY_TYPE=Mains +# 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 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 restart thermald" diff --git a/contrib/thermald/SurfacePro5/README.md b/contrib/thermald/SurfacePro5/README.md new file mode 100644 index 000000000..56b0a3b33 --- /dev/null +++ b/contrib/thermald/SurfacePro5/README.md @@ -0,0 +1,42 @@ +# thermald configuration tweaked for Surface Pro 5 + +- thermald configuration starting point: https://github.com/intel/dptfxtract + - by default it uses sensor "GEN4", which is for the NVME drive, not good. + - pch_skylake is a better choice here. +- Takes care of `surface profile set {low-power|performance}` on power supply events. +- Restarts thermald on power events to load corresponding thermal profiles. +- There are 3 thermal profiles here: + - `thermal-conf.xml.auto.performance`: activated on AC power. + Runs at peak performance (~25watts) until reaching 60 degrees. + Stabilized at ~15watts under heavy load. + - `thermal-conf.xml.auto.mobile`: activated on battery. + Throttles early for ~15watts. + Throttles to ~8watts for heavy load. + Try to keep the device cool. + - `thermal-conf.xml.auto.cool`: reserved. + +Basically, we are just using RAPL here to throttle the power (in watts), not +the frequency of the CPU, and it's more fine-grained and aligned with our +thermal targets. + +See 40-surface-power.rules for more details on how to obtain info about sensors +and cooling devices. + +## Installation + +- Make sure to install `surface-control` +- Install `40-surface-power.rules` to `/usr/lib/udev/rules.d/` +- Install `thermal-conf.xml*` to `/etc/thermald/` + - `thermal-conf.xml.auto` will be linked dynamically by the udev rule file. +- 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. +- `systemctl daemon-reload` +- `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. diff --git a/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.cool b/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.cool new file mode 100644 index 000000000..14be11d35 --- /dev/null +++ b/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.cool @@ -0,0 +1,85 @@ + + + + + Auto generated + Surface Pro + QUIET + + 0 + 3000 + 25000 + 28000 + 32000 + 500 + + + + auto_zone_0 + + + pch_skylake + 46000 + Passive + + B0D4 + 20 + 15000000 + + + + pch_skylake + 49000 + Passive + + B0D4 + 20 + 13000000 + + + + pch_skylake + 52000 + Passive + + B0D4 + 20 + 11000000 + + + + pch_skylake + 56000 + Passive + + B0D4 + 20 + 9000000 + + + + pch_skylake + 59000 + Passive + + B0D4 + 15 + 7000000 + + + + pch_skylake + 62000 + Passive + + B0D4 + 10 + 6000000 + + + + + + + + diff --git a/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.mobile b/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.mobile new file mode 100644 index 000000000..538d6a585 --- /dev/null +++ b/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.mobile @@ -0,0 +1,95 @@ + + + + + Auto generated + Surface Pro + QUIET + + 0 + 3000 + 15000 + 28000 + 32000 + 500 + + + + auto_zone_0 + + + pch_skylake + 39000 + Passive + + B0D4 + 10 + 15000000 + + + + pch_skylake + 43000 + Passive + + B0D4 + 10 + 10000000 + + + + pch_skylake + 47000 + Passive + + B0D4 + 10 + 8000000 + + + + pch_skylake + 49000 + Passive + + B0D4 + 10 + 6000000 + + + + pch_skylake + 51000 + Passive + + B0D4 + 5 + 5000000 + + + + pch_skylake + 53000 + Passive + + B0D4 + 5 + 4000000 + + + + pch_skylake + 54000 + Passive + + B0D4 + 5 + 3000000 + + + + + + + + diff --git a/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.performance b/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.performance new file mode 100644 index 000000000..fb06d3360 --- /dev/null +++ b/contrib/thermald/SurfacePro5/thermal-conf.xml.auto.performance @@ -0,0 +1,75 @@ + + + + + Auto generated + Surface Pro + QUIET + + 0 + 3000 + 15000 + 28000 + 32000 + 500 + + + + auto_zone_0 + + + pch_skylake + 54000 + Passive + + B0D4 + 10 + 15000000 + + + + pch_skylake + 58000 + Passive + + B0D4 + 10 + 13000000 + + + + pch_skylake + 60000 + Passive + + B0D4 + 5 + 9000000 + + + + pch_skylake + 62000 + Passive + + B0D4 + 5 + 7000000 + + + + pch_skylake + 63000 + Passive + + B0D4 + 5 + 6000000 + + + + + + + + diff --git a/contrib/thermald/SurfacePro5/thermal-cpu-cdev-order.xml b/contrib/thermald/SurfacePro5/thermal-cpu-cdev-order.xml new file mode 100644 index 000000000..e690c5a26 --- /dev/null +++ b/contrib/thermald/SurfacePro5/thermal-cpu-cdev-order.xml @@ -0,0 +1,18 @@ + + + + + + rapl_controller + intel_pstate + intel_powerclamp + cpufreq + Processor + + diff --git a/contrib/thermald/SurfacePro5/thermald.service b/contrib/thermald/SurfacePro5/thermald.service new file mode 100644 index 000000000..9445c2a4d --- /dev/null +++ b/contrib/thermald/SurfacePro5/thermald.service @@ -0,0 +1,14 @@ +[Unit] +Description=Thermal Daemon Service +ConditionVirtualization=no + +[Service] +Type=dbus +SuccessExitStatus=1 +BusName=org.freedesktop.thermald +ExecStart=/usr/sbin/thermald --systemd --dbus-enable + +[Install] +WantedBy=multi-user.target +Alias=dbus-org.freedesktop.thermald.service +