Power management with udev rule "med_power_with_dipm"

Hi,

recently I noticed that the kernel from 4.15 on comes with a new power saving feature, see e.g. here: https://www.phoronix.com/scan.php?page=news_item&px=Linux-4.15-libata-power or search for “med_power_with_dipm”. Seems to work with Haswell and newer CPUs.

So I googled and found the idea that you can add a new udev-rule. I created under /etc/udev/rules.d/ the file 50-hd_power_save.rules with one line:


ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}="med_power_with_dipm"

Now, cat /sys/class/scsi_host/host*/link_power_management_policyproduces:


med_power_with_dipm
med_power_with_dipm
med_power_with_dipm

Drawback: Right now the notebook is connected to the grid. There is no need to save power, I’d prefer to have max_power.

So can somebody provide the code to make the power-management policy dependend on the state of the notebook: connected to grid or not?

Notebook runs on kernel 4.16.2.

If you read the patch documentation, it only creates the new policy and sets it as the default.
Choosing <which> policy to use as an alternative to the new default is left for something else to do,
And I can only assume that would mean when your system is under load, it will automatically switch to the original Max policy and later return to the Med policy when load has been removed.

So,
I’d guess that is what you should test…
What happens if you put your system (particularly the drive sub-system) under extreme load, and then take your sensor readings (in particular wattage draw). Unfortunately, the patch author doesn’t describe exactly how he set up his sensor readings or used an external device to measure power draw, so you may have to figure this out on your own.

TSU

Thank you for reading the docu of those patch for me! I’ll test this the other day when compiling something.

Patch is indeed working. On my Haswell (i5-4260u) I’ve got -1W in slight load (youtube video).
But what it does? Something with SATA controller powerstates, right?

Yes,
Unless I’m misreading, that’s what the code does.
Since the two biggest draws on power are the display and the disk subsystem, the potential benefit can be very significant.
Would be interesting if the patch indirectly affects CPU stepping, but I don’t see anything that would do so.

TSU

You could use laptop-mode-tools that already supports managing SATA power policy, just need to configure it with suitable policy. Or use acpid to handle AC plugged/unplugged event directly.

Your assumption is wrong.

To try to provide a more accurate answer,
I skimmed a few articles, and settled on the following ArchWiki articles as best to provide some guidance…
The main recommended “Power Management” article
https://wiki.archlinux.org/index.php/Power_management
The Laptop Tools Archwiki which was mostly to understand limitations but also how to enable/set frequency scaling
https://wiki.archlinux.org/index.php/Laptop_Mode_Tools

I also came to a personal conclusion that acpid won’t likely do what you want properly (maybe someone else will have a different opinion)

The main topic in this thread is described a few sections from the end in the first link.
From it,

  • The benefit is mainly for rotating disks (unlikely to benefit SSD)
  • Management of SATA power policy is not automatic.

Through a combination of both Wikis,
Laptop Tools describes only completely powering down the disk to save energy, but can result in latencies when powering up and severely shortening the life of the drive. This new option to lower the power draw but not power down the drive completely is potentially the best of all options with power savings without shortening the life of the drive.

So, the remaining question is how to manage your SATA power policy according to whether you’re plugged into external power or not, and the first Wiki link provides a couple suggestions but perhaps the systemd recommendation is best

Although the first reference on Power Management should be read completely for a full picture managing power states with systemd,

The section that describes what we have already discussed about creating a “medium” SATA power policy
https://wiki.archlinux.org/index.php/Power_management#SATA_Active_Link_Power_Management

An approach for systemd to run a script that manages based on whether plugged into AC or on laptop power (With some suggested scripts for what to activate in each state)
https://wiki.archlinux.org/index.php/Power_management#Using_a_script_and_an_udev_rule

Lastly,
If you’re interested in CPU frequency scaling,
There is a Laptop-Tools section for enabling and managing frequency scaling with link to main article
https://wiki.archlinux.org/index.php/Laptop_Mode_Tools#CPU_frequency

HTH,
TSU