Laptop: Difference between revisions

From NixOS Wiki
imported>AmnesiaAmesia
m Added initial text about powertop
imported>AmnesiaAmesia
m Added example for auto-cpufreq and corrected small mistakes
Line 3: Line 3:


==== tlp ====
==== tlp ====
A common tool used to save power on laptops is tlp, which have sensible defaults for most laptops. To enable tlp you simply just write <code>services.tlp.enable = true;</code> in your configraion.nix. However if you need a specific configuration you can do as shown in the example here below.
A common tool used to save power on laptops is tlp, which has sensible defaults for most laptops. To enable tlp you simply just write <code>services.tlp.enable = true;</code> in your configraion.nix. However, if you need a specific configuration, you can do as shown in the example here below.


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
Line 26: Line 26:


==== auto-cpufreq ====
==== auto-cpufreq ====
Another tool used for power management is auto-cpufreq which aims to replace tlp. When using auto-cpufreq it is therefore recommended to disable tlp as these tools are conflicting each other. However NixOS does allow for using both at the same time and you therefore run them in tandem at your own risk. To enable the service just add <code>services.auto-cpufreq.enable = true;</code> to your configuration.nix
Another tool used for power management is auto-cpufreq which aims to replace tlp. When using auto-cpufreq it is therefore recommended to disable tlp as these tools are conflicting with each other. However, NixOS does allow for using both at the same time, and you therefore run them in tandem at your own risk. To enable the service, just add <code>services.auto-cpufreq.enable = true;</code> to your configuration.nix
 
Example of how to configure auto-cpufreq:
<syntaxHighlight lang=nix>
services.auto-cpufreq.enable = true;
services.auto-cpufreq.settings = {
  battery = {
    governor = "powersave";
    turbo = "never";
  };
  charger = {
    governor = "performance";
    turbo = "auto";
  };
};
</syntaxHighlight>


==== Powertop ====
==== Powertop ====
Powertop is a power analysis tool, but it also has a feature refered to as auto tune which will enable powersaving settings on your device. These powersaving settings should be almost the same as those enable by tlp, although you powertop enales usb autosuspend per default. This can make your input devices such as the keyboard unresponsive for some time when it has been suspended. To enable write  <code>powerManagement.powertop.enable = true;</code>.
Powertop is a power analysis tool, but it also has a feature referred to as auto-tune which will enable power saving settings on your device. These power saving settings should be almost the same as those enabled by tlp, although you powertop enables usb autosuspend per default. This can make your input devices such as the keyboard unresponsive for some time when it has been suspended. To enable powetop write  <code>powerManagement.powertop.enable = true;</code> and it should be noted that this also enables the auto-tune feature of powertop.


== Troubleshooting ==
== Troubleshooting ==

Revision as of 08:28, 19 June 2023

Power management

NixOS has several tools to help you manage the power on your system.

tlp

A common tool used to save power on laptops is tlp, which has sensible defaults for most laptops. To enable tlp you simply just write services.tlp.enable = true; in your configraion.nix. However, if you need a specific configuration, you can do as shown in the example here below.

services.tlp = {
      enable = true;
      settings = {
        CPU_SCALING_GOVERNOR_ON_AC = "performance";
        CPU_SCALING_GOVERNOR_ON_BAT = "powersave";

        CPU_ENERGY_PERF_POLICY_ON_BAT = "powersave";
        CPU_ENERGY_PERF_POLICY_ON_AC = "performance";

        CPU_SCALING_MIN_FREQ_ON_AC = 800000;
        CPU_SCALING_MAX_FREQ_ON_AC = 5000000;
        CPU_SCALING_MIN_FREQ_ON_BAT = 800000;
        CPU_SCALING_MAX_FREQ_ON_BAT = 2600000;
      };
    };

This example enables tlp and sets the minimum and maximum frequencies for the cpu based on whether it is plugged into power or not. It also changes the cpu scaling governor based on this.

auto-cpufreq

Another tool used for power management is auto-cpufreq which aims to replace tlp. When using auto-cpufreq it is therefore recommended to disable tlp as these tools are conflicting with each other. However, NixOS does allow for using both at the same time, and you therefore run them in tandem at your own risk. To enable the service, just add services.auto-cpufreq.enable = true; to your configuration.nix

Example of how to configure auto-cpufreq:

services.auto-cpufreq.enable = true;
services.auto-cpufreq.settings = {
  battery = {
     governor = "powersave";
     turbo = "never";
  };
  charger = {
     governor = "performance";
     turbo = "auto";
  };
};

Powertop

Powertop is a power analysis tool, but it also has a feature referred to as auto-tune which will enable power saving settings on your device. These power saving settings should be almost the same as those enabled by tlp, although you powertop enables usb autosuspend per default. This can make your input devices such as the keyboard unresponsive for some time when it has been suspended. To enable powetop write powerManagement.powertop.enable = true; and it should be noted that this also enables the auto-tune feature of powertop.

Troubleshooting

My laptops runs hot when on power, but not on battery

If you use tlp and experience this issue a simple solution can be to tell tlp to always run in battery mode.

services.tlp = {
      enable = true;
      settings = {
	TLP_DEFAULT_MODE = "BAT";
	TLP_PERSISTENT_DEFAULT = 1;
      };
    };