Live data from Hacker News

I helped fix sleep-wake hangs on Linux with AMD GPUs

nyanpasu64.gitlab.io

1–10 of 218 posts

Re: I helped fix sleep-wake hangs on Linux with AMD GPUs

#3
> Through some digging, I found that when a desktop enters S3 sleep, the system cuts power to PCIe GPUs

I am not sure how correct this assumption is. S3 is supposed to cut power to everything but RAM, but for example Gigabyte Aorus motherboards are notorious for an NVMe SSD sleep bug that randomly prevents the system from properly sleeping or waking.

This is fixed by adding the following udev rule:

  # Generic PCIe fix for sleep bugs by preventing wakeup from any PCIe port
  ACTION=="offline", SUBSYSTEM=="pci", DRIVER=="pcieport",     ATTR{power/wakeup}="disabled"
   
or more targeted:

  # Gigabyte sleep fix by preventing wakeup from problematic PCIe port, depends on motherboard model
  ACTION=="offline",  SUBSYSTEM=="pci", ATTR{vendor}=="0x8086", ATTR{device}=="0x43bc", ATTR{power/wakeup}="disabled"
   
You can find any glitched PCIe wakeup device with:

  1. cat /proc/acpi/wakeup (you'll have to trial and error your way through the wakeup devices if it isn't immediately clear)
  2. cat /sys/class/pci_bus/*/*/yourWakeupDevicePci/uevent | grep PCI_ID
  3. prepend "0x"
You also have the option of:

  udevadm info --attribute-walk /dev/whatever
  
but for that you need to know some basic identifier of your glitchy device.

Or if you want to shellscript it (less reliable than letting udev do it for you and needs to be done via systemd service file or another automation):

  # Gigabyte sleep fix, port depends on mobo model
  /bin/bash -c 'if grep 'RP05' /proc/acpi/wakeup | grep -q 'enabled'; then echo 'RP05' > /proc/acpi/wakeup; fi'";

Yes I really hate this (and other) Linux sleep issues.

Re: I helped fix sleep-wake hangs on Linux with AMD GPUs

#5
post #2

Fantastic news. AMD's linux graphics drivers have mostly worked great for me but this has been the one exception that I've hit multiple times.

Same great experience, but I experience similar issues when I disconnect thunderbolt with monitors when my machine is asleep. Laptop though, so very different driver set, no GPU via pci

Re: I helped fix sleep-wake hangs on Linux with AMD GPUs

#7
I have an Nvidia GPU and a sporadic crash (black screen) with no logs on Linux. I suspect it's a driver issue too. Going to try some of these tips to enable the debug shell, but I'm not sure if they'll be effective.

Anyone have other tips for this type of thing? I did try upgrading drivers/kernels already

Re: I helped fix sleep-wake hangs on Linux with AMD GPUs

#8
I notice I am confused how the code needed for the GPU to sleep was implemented. It was failing when simply saving/copying gigabytes of flat memory, but on the other hand it was able to recover successfully the previous complex hw and sw state and data structures?! I guess it probably makes sense if after waking up that data is actually dropped and the gpu and ui is reinitialized and redrawn.

Re: I helped fix sleep-wake hangs on Linux with AMD GPUs

#10
post #5
post #2

Fantastic news. AMD's linux graphics drivers have mostly worked great for me but this has been the one exception that I've hit multiple times.

Same great experience, but I experience similar issues when I disconnect thunderbolt with monitors when my machine is asleep. Laptop though, so very different driver set, no GPU via pci

You can probably write a udev rule for the Thunderbolt / USB-C port with either ACTION=="offline", "remove" or "online".

"offline" is for when your system turns off or suspends, "online" vice versa, and "remove" is self-explanatory.

If you go with "offline", I'd look into hard disconnecting the monitors. This might cause monitor rearrangement (= you'll need to manually assign) or blinking on laptop bootup. Might also stop any charging. But that could be mitigated by checking the "subsystems" attribute.

If you go with "online", you probably need run some sort of clean-up / refresh script or rule

If you go with "remove", you'll need the same clean-up / refresh script.

It'll take some trial-and-error, but it'll be satisfying once it works. Also highly recommended to check the NixOS repositories and official wiki and Arch wiki to see if your laptop or monitors have workarounds for their quirks.

Post reply on HN