Power Management: Difference between revisions

Added a section to troubleshoot userspace suspend issues.
Replace deprecated sleep extraConfig option that was missed last edit
 
(7 intermediate revisions by 3 users not shown)
Line 30: Line 30:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
  systemd.services.your-service-name = {  
systemd.services.your-service-name = {  
    description = "Service description here";
  description = "Service description here";
    wantedBy = [ "post-resume.target" ];
  wantedBy = [ "post-resume.target" ];
    after = [ "post-resume.target" ];
  after = [ "post-resume.target" ];
    script = ''
  script = ''
     echo "This should show up in the journal after resuming."
     echo "This should show up in the journal after resuming."
    '';
  '';
    serviceConfig.Type = "oneshot";
  serviceConfig.Type = "oneshot";
  };
};
</syntaxhighlight>
</syntaxhighlight>


Line 48: Line 48:


Therefore, an example configuration could look like this:<syntaxhighlight lang="nix">
Therefore, an example configuration could look like this:<syntaxhighlight lang="nix">
/*
// I'm hibernating into a logical volume that's also under LUKS. Pretty cool, right?
  I'm hibernating into a logical volume that's also under LUKS. Pretty cool, right?
*/


swapDevices = [
swapDevices = [
Line 59: Line 57:


boot.resumeDevice = "/dev/dm-7";
boot.resumeDevice = "/dev/dm-7";
</syntaxhighlight>Derived from a system with the following output from <code>swapon -s</code> :<syntaxhighlight>
</syntaxhighlight>Derived from a system with the following output from <code>swapon -s</code> :<syntaxhighlight lang="text">Filename                                Type            Size          Used            Priority
Filename                                Type            Size          Used            Priority
/dev/dm-7                              partition      67108860      00
/dev/dm-7                              partition      67108860      00
/dev/zram0                              partition      32881148      032767
/dev/zram0                              partition      32881148      032767</syntaxhighlight>
 
</syntaxhighlight>


Test and use hibernation with the following command:<syntaxhighlight lang="nix">
Test and use hibernation with the following command:<syntaxhighlight lang="nix">
Line 72: Line 67:
== Tips and tricks ==
== Tips and tricks ==


=== Go into hibernate after specific suspend time ===
=== Hibernate after specified time ===
Using following configuration, your system will go from suspend into hibernate after 1 hour:<syntaxhighlight lang="nix">
Using following configuration, your system will go from suspend into hibernate after 1 hour:<syntaxhighlight lang="nix">
systemd.sleep.extraConfig = ''
systemd.sleep.settings.Sleep = {
   HibernateDelaySec=1h
   HibernateDelaySec = "1h";
'';
};
</syntaxhighlight>
</syntaxhighlight>


Or, to disable suspend entirely, consider a configuration like this:
=== Disable all sleep functionality ===
 
Some desktop environment and display manager combinations might attempt to put your machine to sleep as default behavior (i.e. SDDM and KDE Plasma 6 under Wayland).  If this is not what you want, you can define the following to block any service attempting to put your machine to sleep via systemd:
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
systemd.sleep.extraConfig = ''
systemd.sleep.settings.Sleep = {
   AllowSuspend=no
   AllowHibernation = "no";
   AllowHibernation=no
   AllowHybridSleep = "no";
   AllowHybridSleep=no
   AllowSuspend = "no";
   AllowSuspendThenHibernate=no
   AllowSuspendThenHibernate = "no";
'';
};
</syntaxhighlight>
</syntaxhighlight>


Line 141: Line 139:
After finding out which component is causing unwanted wakeups you can use the sysfs id to find out the "vendor" and "device" fields:
After finding out which component is causing unwanted wakeups you can use the sysfs id to find out the "vendor" and "device" fields:


<syntaxhighlight lang="sh">
<syntaxhighlight lang="console">
$ cat /sys/class/pci_bus/0000:04/device/0000:04:00.0/vendor
$ cat /sys/class/pci_bus/0000:04/device/0000:04:00.0/vendor
0x1987
0x1987
Line 203: Line 201:
</syntaxhighlight>
</syntaxhighlight>


The <code>pre-sleep-start</code> script referenced by <code>ExecStart</code> contained directives installed by the [[Displaylink]] package, that contained a flush operation which hung the suspend action. Starting <code>dlm.service</code> or running <code>sudo DisplayLinkManager</code> unblocks the script and made suspend work normally.  
In this case, the <code>pre-sleep-start</code> script referenced by <code>ExecStart</code> contained directives installed by the [[Displaylink]] package, that contained a flush operation which hung the suspend action. Starting <code>dlm.service</code> or running <code>sudo DisplayLinkManager</code> unblocks the script and made suspend work normally.  


==== Cancelling an existing suspend action ====
An existing suspend operation that is hung may be interrupted using <code>'''systemctl cancel'''</code> in case reboots or internet access is needed.  
An existing suspend operation that is hung may be interrupted using <code>'''systemctl cancel'''</code> in case reboots or internet access is needed.