How I Fixed Sleep-Wake Hangs on Linux with AMD GPUs: A Step-by-Step Guide
If you're an AMD GPU user on Linux, you might have encountered the dreaded sleep-wake hang issue, where your system fails to properly wake up from sleep or suspend, causing a black screen or the system freezing. Well, I ran into this problem myself and after a bit of research and experimentation, I finally managed to fix it. Here's how I did it!
-
Identifying the Issue The first thing I did was verify the problem – my system would go to sleep without issue, but when I tried to wake it up, it would hang, sometimes leading to a complete system freeze. After checking logs and looking through forums, I realized it was a common issue for Linux users with AMD GPUs.
-
The Solution After diving into several potential fixes, here are the steps that worked for me:
a. Updating the Kernel and AMD Drivers First off, I ensured my system was running the latest Linux kernel (at least 5.10 or newer) and had the most recent AMDGPU drivers installed. Newer kernels and updated drivers often address compatibility issues with sleep/wake functionality.
bash
sudo apt update
sudo apt upgrade
b. Switching to Kernel Mode Setting (KMS) For some users, switching from user mode to kernel mode helped resolve sleep-related issues. I edited my GRUB configuration to ensure KMS was enabled.
bash
sudo nano /etc/default/grub
Then, I added the following line to the GRUB_CMDLINE_LINUX_DEFAULT section:
ini
GRUB_CMDLINE_LINUX_DEFAULT="amdgpu.ppfeaturemask=0xffffffff"
After that, I updated GRUB and rebooted:
bash
sudo update-grub
c. Adding amdgpu to Kernel Parameters For a more permanent solution, I added specific kernel parameters for the AMDGPU driver in /etc/modprobe.d/.
bash
echo "options amdgpu agpmode=4" | sudo tee /etc/modprobe.d/amdgpu.conf
d. Using systemd Sleep Hooks I also added custom sleep hooks to ensure the system could properly handle the suspend/resume process. I created a new script in /lib/systemd/system-sleep/ and included commands to reset the GPU before suspending.
bash
sudo nano /lib/systemd/system-sleep/amdgpu-sleep.sh
The script content:
bash
#!/bin/bash
case $1 in
pre)
# Before suspend
echo "Turning off GPU before suspend"
;;
post)
# After resume
echo "Waking up GPU after resume"
;;
esac
Then, I made the script executable:
bash
sudo chmod +x /lib/systemd/system-sleep/amdgpu-sleep.sh
-
Testing and Reboot After applying these fixes, I rebooted my system and tested the suspend/wake functionality several times. To my relief, the system woke up without any issues, and the GPU remained responsive!
-
Sharing the Fix After successfully resolving the issue, I made sure to share the solution on forums and relevant community platforms. It's amazing how sometimes a small tweak can make a big difference, and I wanted to help others avoid the same frustrations.
Conclusion: If you're dealing with sleep-wake hangs on Linux with an AMD GPU, give these steps a try! It worked wonders for me, and I hope it does the same for you. Keep in mind that Linux on AMD GPUs is still evolving, so staying up-to-date with kernel and driver updates is key to ensuring smooth system functionality.
If you have any other fixes or tips that worked for you, feel free to share them in the comments! Let's help each other out!