Live data from Hacker News

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

nyanpasu64.gitlab.io

171–180 of 218 posts

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

#171
Why was dm->cached_state storing -12 instead of a pointer? Most likely this happened because earlier during suspend, dm_suspend() assigned dm.cached_state = drm_atomic_helper_suspend(adev_to_drm(adev)). The callee drm_atomic_helper_suspend() could return either a valid pointer, or ERR_PTR(err) which encoded errors as negative pointers. But the caller function assigned the return value directly to a pointer which gets dereferenced upon resume, instead of testing the return value for an error.

One more point for rust in the kernel. Just can't happen if you're required to handle a Result type.

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

#172

Earlier quoted context omitted.

Firefox preserves opened tabs on close/re-open, and so does Notepad++/Sublime (and for those, it works even for tabs you've never saved as files). And let's be honest, losing most of those browser is inconsequential. So while I get the "I just want sleep to work, dangit" attitude (it really should just work, to be honest) the fact is that it barely does work. Seriously, it took this long to realize that VRAM contents…

That won't restore my 3+ neovim instances, including loaded buffers, associated undo trees, tabs, and splits. Neither will it restore the various PDFs I have open, the file browser instances pointed at specific locations, nor the containing window and desktop layouts for all of that. It's pretty unbelievable when you think about it. The majority of mainstream progress on application state management has taken place i…

MacOS is pretty good at it as well.

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

#173
post #36

Earlier quoted context omitted.

Sleep & suspend doesn’t work on Windows either. Power control is the kind of stuff that benefits from very tight integration, and PCs just don’t have that. Firmware is seen by most vendors as a pure cost to minimize, so you get a fragmented market full of subcontractors delivering the bare minimum that is considered “working”. Manufacturers also know most people aren’t going to use a big part of the functions they’re…

> Sleep & suspend doesn’t work on Windows either. Or Macintosh. My $DAYJOB Macbook sleeps properly about about 2 out of 10 times, at best. Most of the time it fails to sleep and by the next morning when I open it up, the battery is dead. :-( For comparison, my System76 laptop running PopOS! sleeps perfectly, every time with no issues. shrug

> My $DAYJOB Macbook sleeps properly about about 2 out of 10 times, at best. Most of the time it fails to sleep and by the next morning when I open it up, the battery is dead. :-(

Important to remember that work laptops typically install all sorts of crap spyware and fleet management software that causes the system to misbehave. That’s not as much on Apple although not protecting their brand against such software is on them.

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

#174

Why was dm->cached_state storing -12 instead of a pointer? Most likely this happened because earlier during suspend, dm_suspend() assigned dm.cached_state = drm_atomic_helper_suspend(adev_to_drm(adev)). The callee drm_atomic_helper_suspend() could return either a valid pointer, or ERR_PTR(err) which encoded errors as negative pointers. But the caller function assigned the return value directly to a pointer which gets…

You can also get algebraic sum types in C with the C preprocessor: https://github.com/Hirrolot/datatype99

But of course defaults matter and the kernel’s rich history of not modernizing coding practices is going to work against improvements in C land. Ironically, it’s that same resistance that frustrates the Rust devs so much because their resistant to even cleaning up their own subsystems or putting down markers documenting how the subsystems are supposed to work.

Maybe https://github.com/llvm/llvm-project/issues/74205 would help once it trickles down into the kernel, but I suspect that people are still going to choose to do this manual overloading of the pointer instead of using types for safety.

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

#175
post #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…

sigh, I have been struggling with this issue for a while, but this did not seem to work either. I have documented it here: https://bbs.archlinux.org/viewtopic.php?id=302440 Any further insight you might have on these Aorus wakeup issues? In particular, it seems the wakeup in my case is coming from `.../devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:45/wakeup/wakeup6` which does not really mean anything to me.

It doesn't to me either, but following a tip from someone higher up the comments you could try

  ACTION=="offline", KERNELS=="0000:00:45.6", ATTR{power/wakeup}="disabled"
Maybe ACTION=="change" and / or KERNELS=="0000:00:45" or KERNELS=="0000:00:45.?"

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

#176
post #162
post #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…

Wow, thanks for this tip! I've been dealing with suspend issues with an X570 Aorus Master as well. Running `echo GPP0 >> /proc/acpi/wakeup` into a systemd unit at boot solved the issue for me... except the first sleep after a boot would always wake back up immediately. I applied your udev rule and that issue seems to be resolved as well!

This is more so for your future unit file use: did you use `Type=oneshot` and `RemainAfterExit=yes`?

I remember there being some strange interaction with the wakeup behaviour being toggled otherwise. But this could be due to me being on NixOS.

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

#177
post #167
post #54

Earlier quoted context omitted.

Did you try the general fix? And reload udev rules? You also have to make sure it applies after the default rules. You can check if the rule applies once you have everything set up by doing an `udevadm` attribute walk of your SSD device (not partition), and then following it up all the way up the device tree until you see your specific device port (target fix) or PCIe driver subsystem (general fix). Then check if "po…

Maybe I should have clarified more - I'm using a desktop PC, not a laptop The system seems to go into sleep state just fine, it just freezes when waking up again

Yes, my problem was with an Aorus ATX motherboard too.

> The system seems to go into sleep state just fine, it just freezes when waking up again

The behavior differs per device. Some sleep but freeze on wakeup, some immediately wakeup after sleeping, and some (like mine) will go to sleep 98% of the way, but the fans keep spinning. That was a dead giveaway for me that the bug was triggered. I suspect that on some systems, either the fans turn off and the system succeeded to getting to sleep 99% of the way, or the fans are so quiet that people do not notice them. And from that limbo state you can only recover with a hardware shutdown or interrupting power.

I'm fairly certain this issue is fixable for you as well, either with only this fix (and we just have to find the proper port(s), or with this fix and for whatever other device might be causing this issue.

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

#178
very nice and detailed writeup, so many interesting stuff in here really. reading about systemd (bugreport) always hurts my brain (bugreport) but all the low level interactions between OS and drivers /firmware regarding these states and what kind of issues can happen between them, how to find out whats happening better, verynice :). many thanks! for the year long hunt and the excellent writeup.

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

#179
post #57

Earlier quoted context omitted.

> Sleep & suspend doesn’t work on Windows either. What's strange is that it never used to be a problem. There are five Windows laptops floating around our house at various times (mixture of work and personal) and suspend works properly on none of them. Oddly, it works on my personal laptop with Debian Stable almost every time, failing maybe 1/25 times. Other distros are about the same as Windows.

Modern Standby. Windows wanted to do the Apple "power nap" stuff, but never realized how painful it'd be if you don't control all the hardware and have millions of different hardware permutations (with a lot of terrible drivers) instead of just a few. Not that it would've helped, half the time my machine is either overheating or off it seems to be wake timers doing windows updates (which yes, you can disable, but mos…

> Windows wanted to do the Apple "power nap" stuff

On Linux, you can run a systemd unit file that will trigger `rfkill` on sleep and a different `rfkill` invocation on wake and you effectively dodge all that crap because the laptop isn't connected to WiFi and thus will sit around realizing its spinning its wheels and wil shut down further down the s0 chain.

> I don't get why S3 sleep had to die for this, but it did.

Worse yet, the dirty little secret is that many laptops that offer both S0 and S3 will actually drain more energy in S3 than in S0 because the S3 mode has had poor QA.

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

#180
post #108
post #36

Earlier quoted context omitted.

Sleep & suspend doesn’t work on Windows either. Power control is the kind of stuff that benefits from very tight integration, and PCs just don’t have that. Firmware is seen by most vendors as a pure cost to minimize, so you get a fragmented market full of subcontractors delivering the bare minimum that is considered “working”. Manufacturers also know most people aren’t going to use a big part of the functions they’re…

Are there issues in Windows? Sure but if you give me 100 laptops, 80% will do this right without any issue. Maybe 30% of those laptops will work right on any Linux distro without major fucking around with bullshit trying to make it work. Yes those numbers are made up but I have been running versions of Linux since Slackware in the 90s. I still have a desktop with an amd cpu and nvidia gpu that I can’t get to sleep/su…

0% of new Windows laptops support proper S3 sleep mode since Microsoft gutted it in favor of "modern standby".
Post reply on HN