Files
command-center/omp-docs/tools/linux-power-management.md
T
Frank 82dd0c7d09 docs(power): reclaim the sleep docs from the sold box; fix AGENTS.md machine facts
The sleep/wake saga (Alienware-M16a2 research + Sleep-Fix-Guide) framed a
machine sold on 2026-09-28 as 'this system' — the 2026-09-28 identifier
purge missed both because they name no hostname. blankpad probed live:
Lenovo, AMD Ryzen 5 PRO 5650U / Cezanne, unified memory, s2idle only,
no NVIDIA, no ~/GitPackages/llama.cpp.

- research/Sleep-Fix-Guide.md -> .AGENTTRASH (verbatim restatement of the
  research doc's fix steps; PowerCluster overlap census)
- Alienware doc: archive banner, 'this system' -> retired dankware
- linux-power-management.md: scope note (blankpad s2idle-only; NVIDIA
  section is dankware/future-NVIDIA territory), boilerplate AGENTS.md
  cross-ref dropped
- cachyos.md: de-pinned rolling-release kernel versions (7.1.4 doc vs
  7.2.9 live), repo list confirmed verbatim against pacman.conf, SDDM
  confirmed live, verified: 2026-10-19
- AGENTS.md: dev-workstation row rewritten for blankpad; Gitea gotcha
  corrected — remote URLs carry NO token (credential-store file, verified)

Refs #29
2026-10-19 03:46:02 -07:00

297 lines
6.6 KiB
Markdown

---
type: reference
title: Linux Power Management
description: Sleep/wake troubleshooting, NVIDIA GPU power management, and diagnostics for Linux systems.
tags:
- power-management
- sleep
- nvidia
timestamp: 2026-08-06
---
General sleep/wake configuration and diagnostics for Linux systems: systemd sleep, kernel states, NVIDIA GPU power management, wake sources, and diagnostic tools. Fleet scope: the dev workstation `blankpad` is an AMD Cezanne APU exposing **s2idle only** (`/sys/power/mem_sleep` shows no `deep`); the NVIDIA section applied to the retired **dankware** Alienware m16 R2 (see [Sleep/Wake Research](../research/index.md)) and to any future NVIDIA box.
---
## Systemd Sleep Configuration
### logind.conf (`/etc/systemd/logind.conf`)
Controls login manager behavior around sleep:
```ini
[Login]
HandlePowerKey=poweroff
HandleSleepKey=suspend
HandleHibernateKey=hibernate
HandleLidSwitch=suspend
HandleLidSwitchDocked=ignore
HoldoffTimeoutSec=5s
IdleAction=hibernate
IdleActionSec=30min
```
**Key setting**: `HoldoffTimeoutSec` — increase if sleep triggers are too aggressive.
### sleep.conf (`/etc/systemd/sleep.conf`)
Controls the actual sleep behavior:
```ini
[Sleep]
AllowSuspend=yes
AllowHibernation=yes
AllowHybridSleep=yes
HibernateMode=platform+shutdown
HibernateDelaySec=1800
```
**HibernateMode options**:
- `platform` — ACPI platform sleep (faster, firmware-dependent)
- `shutdown` — classic shutdown-to-disk (slower, more compatible)
- `shutdown+platform` — try platform first, fall back to shutdown
### Suspend-Then-Hibernate Flow
```
Suspend (RAM) --timeout--> Hibernate (disk)
|
+-- wake event --> Resume
```
### Custom Sleep Hooks
Create `/etc/systemd/system-sleep/` scripts for pre/post sleep actions:
```bash
#!/bin/bash
# /etc/systemd/system-sleep/hook
case "$1" in
pre) echo "Suspending..." ;;
post) echo "Resumed!" ;;
esac
```
---
## Kernel Sleep States
### ACPI Sleep States
| State | Name | Power | Wake Time | Description |
|-------|------|-------|-----------|-------------|
| S0 | Working | Full | Instant | System is running |
| S1 | Sleep (halted) | ~10-20W | <1s | CPU halted, RAM refresh |
| S2 | Sleep | ~5-10W | ~1s | CPU cache flushed |
| **S3** | **Sleeping Standby** | **~1-5W** | **~1-2s** | **RAM retained, most power off** |
| S4 | Hibernate | 0W | ~10-30s | RAM written to disk |
| **S5** | **Soft Off** | **0W** | **~5-10s** | **Powered off but can wake** |
### Modern ACPI Sleep States (s2idle)
Modern laptops often **only support s2idle** (S0 idle):
```bash
$ cat /sys/power/mem_sleep
[s2idle] deep
```
| Mode | Name | Power | Characteristics |
|------|------|-------|----------------|
| **s2idle** | "Suspend to Idle" | 3-8W | Shallow, firmware-managed, fast wake, higher drain |
| **deep** | S3 | 1-3W | Deeper sleep, slower wake, better battery |
### Setting Default Sleep State
Add to kernel command line (GRUB or systemd-boot):
```
mem_sleep_default=deep # Prefer S3 deep sleep
mem_sleep_default=s2idle # Force s2idle
```
**For GRUB:** Edit `/etc/default/grub`, add to `GRUB_CMDLINE_LINUX_DEFAULT`:
```
GRUB_CMDLINE_LINUX_DEFAULT="... mem_sleep_default=deep"
```
---
## NVIDIA GPU Power Management
### Enable NVIDIA Suspend Support
```bash
sudo systemctl enable nvidia-suspend.service
sudo systemctl enable nvidia-suspend-then-hibernate.service
sudo systemctl enable nvidia-hibernate.service
```
### NVIDIA Module Parameters
Edit `/etc/modprobe.d/nvidia.conf`:
```
options nvidia NVreg_PreserveVideoMemoryAllocations=1
options nvidia NVreg_EnableS0ixPowerManagement=1
```
### Check NVIDIA GPU State
```bash
# Is the NVIDIA GPU active?
lspci -vnn | grep -A 12 -i "vga"
# Force NVIDIA GPU to D3hot (fully off) before suspend
sudo tee /sys/bus/pci/devices/0000:01:00.0/power/control <<< auto
```
---
## Diagnostic Tools
### journalctl
```bash
# All sleep-related events in the last boot
journalctl -b -0 | grep -iE 'suspend|resume|sleep|wake|acpi'
# Real-time monitoring during a suspend attempt
journalctl -f &
systemctl suspend
# Wait for failure, then Ctrl+C
```
### powertop
```bash
sudo powertop # Interactive view
sudo powertop --calibrate # One-time setup
sudo powertop --auto-tune # Apply recommendations
sudo powertop --html=/tmp/report.html --csv=/tmp/report.csv
```
### tlp — Advanced Power Management
```bash
sudo pacman -S tlp tlp-rdw # Arch
sudo apt install tlp # Debian/Ubuntu
sudo systemctl enable --now tlp
sudo tlp-stat
```
### dmesg
```bash
dmesg | grep -iE 'suspend|resume|acpi|pm_'
dmesg -wH # Watch mode, human-readable
```
---
## Wake Source Management
### Checking Wake Sources
```bash
# What can wake the system?
cat /proc/acpi/wakeup | grep enabled
# What woke the system last time?
journalctl -b -1 | grep -iE 'PM: wakeup|wakeup source|acpi: wakeup'
```
### Toggling Wake Sources
```bash
# Toggle a device's wake capability
echo XHCI | sudo tee /proc/acpi/wakeup
echo RP01 | sudo tee /proc/acpi/wakeup
```
### Persistent Wake Source Configuration
Create a systemd service:
```ini
# /etc/systemd/system/config-wake-sources.service
[Unit]
Description=Configure ACPI wake sources
Before=sleep.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo XHCI > /proc/acpi/wakeup'
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
```
---
## Common Kernel Parameters
| Parameter | Description |
|-----------|-------------|
| `mem_sleep_default=deep` | Prefer S3 deep sleep |
| `pcie_aspm=force` | Force ASPM (aggressive power saving) |
| `pcie_aspm.policy=performance` | Disable ASPM (fixes some issues) |
| `acpi_osi=!` | Hide OS identity from ACPI |
| `usbcore.autosuspend=-1` | Disable USB autosuspend |
---
## Testing Sleep Modes
```bash
# Suspend to RAM
systemctl suspend
# Hibernate to disk
systemctl hibernate
# Suspend then hibernate
systemctl suspend-then-hibernate
# Freeze (CPUs idle, RAM on)
systemctl freeze
```
### Automated Stress Test
```bash
#!/bin/bash
for i in $(seq 1 10); do
echo "=== Cycle $i ==="
date
echo mem | sudo tee /sys/power/state 2>/dev/null || systemctl suspend
echo "Resume $i: SUCCESS"
sleep 5
done
```
---
## Quick Reference: Action Items
```bash
# 1. Enable NVIDIA suspend support
sudo systemctl enable nvidia-suspend.service
sudo systemctl enable nvidia-suspend-then-hibernate.service
# 2. Add NVIDIA power management module parameter
echo 'options nvidia NVreg_PreserveVideoMemoryAllocations=1' | sudo tee /etc/modprobe.d/nvidia-preserve.conf
# 3. Reboot
sudo reboot
# 4. Test suspend
systemctl suspend
# 5. After resume, check for errors
dmesg | tail -30
journalctl -b -0 | grep -iE 'error|fail|nvidia' | tail -20
```