From ac75bbc47637e5e46fd7b8d1b153348f0d306b99 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 5 Jul 2022 17:45:16 -0400 Subject: [PATCH] transform sleep comment into optionally includable expression --- lenovo/thinkpad/p50/default.nix | 46 ++------------------------------- lenovo/thinkpad/p50/sleep.nix | 41 +++++++++++++++++++++++++++++ lenovo/thinkpad/p51/default.nix | 46 ++------------------------------- lenovo/thinkpad/p51/sleep.nix | 41 +++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 88 deletions(-) create mode 100644 lenovo/thinkpad/p50/sleep.nix create mode 100644 lenovo/thinkpad/p51/sleep.nix diff --git a/lenovo/thinkpad/p50/default.nix b/lenovo/thinkpad/p50/default.nix index f9bdee9..f1f6038 100644 --- a/lenovo/thinkpad/p50/default.nix +++ b/lenovo/thinkpad/p50/default.nix @@ -22,50 +22,8 @@ }; }; - # Sleep - # ----- - # - # The system will not resume from sleep properly while on battery power in - # either offload mode or sync mode. When it tries to resume, it gets to a - # state with a cursor in the top left hand side of the panel, the power LED - # goes from flashing to solid, and thereafter cannot be interacted with (even - # over SSH) and must be power cycled forcefully. Sometimes it doesn't even - # finish going to sleep before this behavior kicks in. - # - # When on AC, the machine either wakes up from sleep before being asked to - # (or maybe never gets to sleep state), or it goes into a sleep state and it - # appears consistently resume properly when it does. - # - # But the machine actually sleeps and resumes reliably when tlp is disabled - # fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be - # enough to allow it to work when tlp is active. I couldn't figure out a - # more granular way to get it working, despite trying to do a per-device - # binary search via powertop. - # - # My personal configuration to make this work looks like this: - # - # {config, lib, ...}: - # - # { - # services.tlp = { - # settings = { - # # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. - # DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; - # - # # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 - # # can't resume from sleep and P50 can't go to sleep. - # AHCI_RUNTIME_PM_ON_AC = "on"; - # AHCI_RUNTIME_PM_ON_BAT = "on"; - # - # # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep - # RUNTIME_PM_ON_AC = "on"; - # RUNTIME_PM_ON_BAT = "on"; - # }; - # }; - # } - # - # I'm thinking this is too aggressive to put into shared config, and folks may - # be concerned with the hit on battery life. + # See sleep.nix inside this directory for code that allows the system to + # sleep properly (out of the box, it will not) at the cost of battery life. # # throttled vs. thermald # ----------------------- diff --git a/lenovo/thinkpad/p50/sleep.nix b/lenovo/thinkpad/p50/sleep.nix new file mode 100644 index 0000000..fb2f6f8 --- /dev/null +++ b/lenovo/thinkpad/p50/sleep.nix @@ -0,0 +1,41 @@ +# Sleep +# ----- +# +# Without this configuration, the system will not resume from sleep properly +# while on battery power in either offload mode or sync mode. When it tries to +# resume, it gets to a state with a cursor in the top left hand side of the +# panel, the power LED goes from flashing to solid, and thereafter cannot be +# interacted with (even over SSH) and must be power cycled forcefully. +# Sometimes it doesn't even finish going to sleep before this behavior kicks +# in. +# +# When on AC, the machine either wakes up from sleep before being asked to +# (or maybe never gets to sleep state), or it goes into a sleep state and it +# appears consistently resume properly when it does. +# +# But the machine actually sleeps and resumes reliably when tlp is disabled +# fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be +# enough to allow it to work when tlp is active. This will negatively effect +# battery life. I couldn't figure out a more granular way to get it working, +# despite trying to do a per-device binary search via powertop. +# + +{config, lib, ...}: + +{ + services.tlp = { + settings = { + # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. + DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; + + # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 + # can't resume from sleep and P50 can't go to sleep. + AHCI_RUNTIME_PM_ON_AC = "on"; + AHCI_RUNTIME_PM_ON_BAT = "on"; + + # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep + RUNTIME_PM_ON_AC = "on"; + RUNTIME_PM_ON_BAT = "on"; + }; + }; +} diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix index 9fa0419..01d3c65 100644 --- a/lenovo/thinkpad/p51/default.nix +++ b/lenovo/thinkpad/p51/default.nix @@ -23,50 +23,8 @@ }; }; - # Sleep - # ----- - # - # The system will not resume from sleep properly while on battery power in - # either offload mode or sync mode. When it tries to resume, it gets to a - # state with a cursor in the top left hand side of the panel, the power LED - # goes from flashing to solid, and thereafter cannot be interacted with (even - # over SSH) and must be power cycled forcefully. Sometimes it doesn't even - # finish going to sleep before this behavior kicks in. - # - # When on AC, the machine either wakes up from sleep before being asked to - # (or maybe never gets to sleep state), or it goes into a sleep state and it - # appears consistently resume properly when it does. - # - # But the machine actually sleeps and resumes reliably when tlp is disabled - # fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be - # enough to allow it to work when tlp is active. I couldn't figure out a - # more granular way to get it working, despite trying to do a per-device - # binary search via powertop. - # - # My personal configuration to make sleep work looks like this: - # - # {config, lib, ...}: - # - # { - # services.tlp = { - # settings = { - # # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. - # DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; - # - # # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 - # # can't resume from sleep and P50 can't go to sleep. - # AHCI_RUNTIME_PM_ON_AC = "on"; - # AHCI_RUNTIME_PM_ON_BAT = "on"; - # - # # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep - # RUNTIME_PM_ON_AC = "on"; - # RUNTIME_PM_ON_BAT = "on"; - # }; - # }; - # } - # - # I'm thinking this is too aggressive to put into shared config, and folks may - # be concerned with the hit on battery life. + # See sleep.nix inside this directory for code that allows the system to + # sleep properly (out of the box, it will not) at the cost of battery life. # # throttled vs. thermald # ----------------------- diff --git a/lenovo/thinkpad/p51/sleep.nix b/lenovo/thinkpad/p51/sleep.nix new file mode 100644 index 0000000..fb2f6f8 --- /dev/null +++ b/lenovo/thinkpad/p51/sleep.nix @@ -0,0 +1,41 @@ +# Sleep +# ----- +# +# Without this configuration, the system will not resume from sleep properly +# while on battery power in either offload mode or sync mode. When it tries to +# resume, it gets to a state with a cursor in the top left hand side of the +# panel, the power LED goes from flashing to solid, and thereafter cannot be +# interacted with (even over SSH) and must be power cycled forcefully. +# Sometimes it doesn't even finish going to sleep before this behavior kicks +# in. +# +# When on AC, the machine either wakes up from sleep before being asked to +# (or maybe never gets to sleep state), or it goes into a sleep state and it +# appears consistently resume properly when it does. +# +# But the machine actually sleeps and resumes reliably when tlp is disabled +# fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be +# enough to allow it to work when tlp is active. This will negatively effect +# battery life. I couldn't figure out a more granular way to get it working, +# despite trying to do a per-device binary search via powertop. +# + +{config, lib, ...}: + +{ + services.tlp = { + settings = { + # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. + DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; + + # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 + # can't resume from sleep and P50 can't go to sleep. + AHCI_RUNTIME_PM_ON_AC = "on"; + AHCI_RUNTIME_PM_ON_BAT = "on"; + + # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep + RUNTIME_PM_ON_AC = "on"; + RUNTIME_PM_ON_BAT = "on"; + }; + }; +}