Bug 474468 - Power Management auto suspend freezes laptop, but not Application Launcher Sleep button
Summary: Power Management auto suspend freezes laptop, but not Application Launcher Sl...
Status: RESOLVED UPSTREAM
Alias: None
Product: Powerdevil
Classification: Plasma
Component: general (show other bugs)
Version: 5.27.7
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Natalie Clarius
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-13 03:15 UTC by gavsiu
Modified: 2023-09-20 01:39 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gavsiu 2023-09-13 03:15:24 UTC
SUMMARY
I can suspend using `systemctl suspend` and the Sleep button in the Plasma 5 Application Launcher, but I cannot have the Power Management Energy Saving auto Sleep after an amount of time. The screen goes black except for the mouse cursor. This also means hybrid-sleep does the same thing. I have to hold the power button to shut down and restart.

This is the same when setting the laptop lid to Sleep. I cannot test the power button because it doesn't register when I press it. This may be another issue I have to investigate.

I don't have this issue with hibernation using all 3 methods. I have also tested setting the auto option to Shut down, Lock screen and they also work.

I tried looking thru the Powerdevil source code but can't figure out how it's suspending my laptop and why is it acting different. Anyone know where to look what the exact command is?


STEPS TO REPRODUCE
1. System Settings > Power Management > Energy Saving > Enable Suspend session
2. Set to automatically Sleep after 5 min
3. Wait 5 min

or

1. System Settings > Power Management > Energy Saving > Button events handling
2. Set laptop lid closed to Sleep
3. Close lid

OBSERVED RESULT
Black screen with cursor visible. Keyboard light stays on.

EXPECTED RESULT
Suspend properly like when using `systemctl suspend` in terminal or pressing the sleep button in the Application Launcher.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 6.5.2-arch1-1 (64-bit)
KDE Plasma Version: 5.27.7
KDE Frameworks Version: 5.110.0
Qt Version: 5.15.10
Comment 1 Natalie Clarius 2023-09-13 15:15:28 UTC
Up until now energy saving settings (auto suspend after an amount of time, lid close and power button) uses a different code path than the buttons in the app launcher, so that explains why it can act differently in principle, although of course it shouldn't. This will be changed in Plasma 6 so that the automatic suspend uses the same thing that the button in the app launcher does, which should hopefully resolve the issue for you, but I'll see if I can figure out why it doesn't work in Plasma 5.27.5.

As for 

> I cannot test the power button because it doesn't register when I press it. This may be another issue I have to investigate.

Can you please file a separate bug report for this? Thank you!
Comment 2 gavsiu 2023-09-14 16:04:28 UTC
(In reply to Natalie Clarius from comment #1)
> Up until now energy saving settings (auto suspend after an amount of time,
> lid close and power button) uses a different code path than the buttons in
> the app launcher, so that explains why it can act differently in principle,
> although of course it shouldn't. This will be changed in Plasma 6 so that
> the automatic suspend uses the same thing that the button in the app
> launcher does, which should hopefully resolve the issue for you, but I'll
> see if I can figure out why it doesn't work in Plasma 5.27.5.
> 
> As for 
> 
> > I cannot test the power button because it doesn't register when I press it. This may be another issue I have to investigate.
> 
> Can you please file a separate bug report for this? Thank you!

I did some research and I don't think it's a KDE issue, unless you do, then I'll file it. Apparently the button does work, but needs to be held for 2 seconds. I also found this https://unix.stackexchange.com/questions/351726/getting-rid-of-power-button-delay
Comment 3 Natalie Clarius 2023-09-14 16:25:31 UTC
Ok. And does sleep work if you set it to the power button and hold it pressed for long enough?
Comment 4 gavsiu 2023-09-14 16:29:32 UTC
(In reply to Natalie Clarius from comment #3)
> Ok. And does sleep work if you set it to the power button and hold it
> pressed for long enough?

I figured out the power button worked cause I still had it set to Sleep and it froze my laptop like the auto timer and lid close. I was wondering why the button worked in console with showkey but not in xev until I held it longer.
Comment 5 Natalie Clarius 2023-09-15 02:04:12 UTC
Ah, of course.  

So it is consistently the triggers in energy saving settings which don't work. 

Could you please run

> killall org_kde_powerdevil; QT_LOGGING_RULES="org.kde.powerdevil=true" /usr/lib/org_kde_powerdevil 

then try to put it to sleep, and paste the terminal output here?
Comment 6 gavsiu 2023-09-15 15:09:55 UTC
(In reply to Natalie Clarius from comment #5)
> Ah, of course.  
> 
> So it is consistently the triggers in energy saving settings which don't
> work. 
> 
> Could you please run
> 
> > killall org_kde_powerdevil; QT_LOGGING_RULES="org.kde.powerdevil=true" /usr/lib/org_kde_powerdevil 
> 
> then try to put it to sleep, and paste the terminal output here?

Is it supposed to save the output to a file? All I see is this when I run the command. The screen goes blank and freezes with a cursor when I trigger the sleep. I can't see the terminal when that happens.

````
org.kde.powerdevil: Backend loaded, loading core
org.kde.powerdevil: Core loaded, initializing backend
org.kde.powerdevil: Trying Backlight Helper first...
org.kde.powerdevil: org.kde.powerdevil.chargethresholdhelper.getthreshold failed "Charge thresholds are not supported by the kernel for this hardware"
org.kde.powerdevil: current screen brightness value:  476
org.kde.powerdevil: Backend ready, KDE Power Management system initialized
org.kde.powerdevil: Battery with UDI "/org/freedesktop/UPower/devices/battery_BAT1" was detected
org.kde.powerdevil: Session path: "/org/freedesktop/login1/session/_32"
org.kde.powerdevil: ACTIVE SESSION PATH: "/org/freedesktop/login1/session/_32"
org.kde.powerdevil: Current session is now active
org.kde.powerdevil: fd passing available: true
org.kde.powerdevil: systemd powersave events handling inhibited, descriptor: 21
org.kde.powerdevil: Checking logind inhibitions
org.kde.powerdevil: systemd support initialized
org.kde.powerdevil: Kbd backlight brightness value:  0
org.kde.powerdevil: Core is ready, registering various services on the bus...
org.kde.powerdevil: Can't contact ck
org.kde.powerdevil: Currently using activity  "842b8d74-6db6-4373-ba16-8e8abe1f67c0"
org.kde.powerdevil: Activities with settings: () ()
org.kde.powerdevil: Settings for loaded activity: "842b8d74-6db6-4373-ba16-8e8abe1f67c0" () ()
org.kde.powerdevil: Loading profile for plugged AC
org.kde.powerdevil: Activity is not forcing a profile
org.kde.powerdevil: Handle button events action could not check for screen configuration
org.kde.powerdevil: 
org.kde.powerdevil: Loading timeouts with  900000
org.kde.powerdevil: Can't contact ck
org.kde.powerdevil: org.kde.powerdevil.chargethresholdhelper.getthreshold failed "Charge thresholds are not supported by the kernel for this hardware"
````
Comment 7 Natalie Clarius 2023-09-16 23:41:10 UTC
Right, that was not very thoroughly thought through by me :) Sorry.

You can turn on logs persistently (without having to restart powerdevil) with

> echo "org.kde.powerdevil=true" >> ~/.config/QtProject/qtlogging.ini

And then get the output even after rebooting using

> journalctl --user-unit plasma-powerdevil --since="5 min ago"
Comment 8 Natalie Clarius 2023-09-16 23:42:14 UTC
Another thing you could try is temporarily moving your

> ~/.config/powermanagementprofilesrc

to somewhere else to see if maybe something blew up your energy saving settings.
Comment 9 Natalie Clarius 2023-09-16 23:53:17 UTC
> You can turn on logs persistently (without having to restart powerdevil) with

What I meant was, it won't take effect immediately, but an ordinary system restart without having to kill and restart powerdevil on the command line will do.
Comment 10 gavsiu 2023-09-18 15:26:52 UTC
This is after running killall:

````
Sep 18 08:21:00 Laptop systemd[882]: Stopping Powerdevil...
Sep 18 08:21:00 Laptop systemd[882]: Stopped Powerdevil.
-- Boot --
Sep 18 08:21:45 Laptop systemd[933]: Starting Powerdevil...
Sep 18 08:21:45 Laptop libddcutil[1209]: Initializing.  ddcutil version 1.4.1
Sep 18 08:21:45 Laptop libddcutil[1209]: Library initialization complete.
Sep 18 08:21:46 Laptop org_kde_powerdevil[1209]: org.kde.powerdevil: org.kde.powerdevil.chargethresholdhelper.getthreshold failed "Charge thresholds are not supported by the kernel for this hardware"
Sep 18 08:21:46 Laptop systemd[933]: Started Powerdevil.
Sep 18 08:21:46 Laptop org_kde_powerdevil[1209]: org.kde.powerdevil: Handle button events action could not check for screen configuration
Sep 18 08:21:46 Laptop org_kde_powerdevil[1209]: org.kde.powerdevil: org.kde.powerdevil.chargethresholdhelper.getthreshold failed "Charge thresholds are not supported by the kernel for this hardware"
Sep 18 08:22:43 Laptop org_kde_powerdevil[1209]: org.kde.powerdevil: org.kde.powerdevil.chargethresholdhelper.getthreshold failed "Charge thresholds are not supported by the kernel for this hardware"
-- Boot --
Sep 18 08:23:55 Laptop systemd[889]: Starting Powerdevil...
Sep 18 08:23:56 Laptop libddcutil[1185]: Initializing.  ddcutil version 1.4.1
Sep 18 08:23:56 Laptop libddcutil[1185]: Library initialization complete.
Sep 18 08:23:56 Laptop org_kde_powerdevil[1185]: org.kde.powerdevil: org.kde.powerdevil.chargethresholdhelper.getthreshold failed "Charge thresholds are not supported by the kernel for this hardware"
Sep 18 08:23:56 Laptop systemd[889]: Started Powerdevil.
Sep 18 08:23:56 Laptop org_kde_powerdevil[1185]: org.kde.powerdevil: Handle button events action could not check for screen configuration
Sep 18 08:23:56 Laptop org_kde_powerdevil[1185]: org.kde.powerdevil: org.kde.powerdevil.chargethresholdhelper.getthreshold failed "Charge thresholds are not supported by the kernel for this hardware"
````
Comment 11 gavsiu 2023-09-18 15:38:24 UTC
I found the culprit to be the setting "While asleep, hibernate after a period of inactivity." Is there a way to enable suspend-to-hibernate?
Comment 12 Natalie Clarius 2023-09-18 16:23:17 UTC
Good find! Did I understand it correctly that if you have the "hibernate after a period inactivity" (aka "suspend-then-hibernate") enabled, the freezing happens, but if you disable it, it does not?  

Does the freeze also happen when invoking it with 

qdbus --system org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.SuspendThenHibernate

?

What does

qdbus --system org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.CanSuspendThenHibernat

say?
Comment 13 gavsiu 2023-09-18 18:17:12 UTC
````
% qdbus --system org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.SuspendThenHibernate
Error: org.freedesktop.DBus.Error.InvalidArgs
Invalid arguments '' to call org.freedesktop.login1.Manager.SuspendThenHibernate(), expecting 'b'.

~
2 % qdbus --system org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.CanSuspendThenHibernat
Error: org.freedesktop.DBus.Error.AccessDenied
Rejected send message, 2 matched rules; type="method_call", sender=":1.123" (uid=1000 pid=4035 comm="qdbus --system org.freedesktop.login1 /org/freedes") interface="org.freedesktop.login1.Manager" member="CanSuspendThenHibernat" error name="(unset)" requested_reply="0" destination="org.freedesktop.login1" (uid=0 pid=613 comm="/usr/lib/systemd/systemd-logind")
````

`systemctl suspend-then-hibernate` also freezes. Maybe it isn't a KDE issue. I'm still looking around. I didn't have this problem before I reformatted and installed Plasma 5. Before reformatting, I was using no display manager, no DE, just bspwm, but it became tiring fixing things because of updates. I'm on Arch Linux if it matters.
Comment 14 gavsiu 2023-09-18 18:27:15 UTC
Forgot to mention, yes, disabling suspend-then-hibernate in Powerdevil does not freeze the laptop.
Comment 15 Natalie Clarius 2023-09-18 19:12:31 UTC
What the "hibernate after inactivity" setting does is effectively replace ordinary sleep (= systemctl suspend) by suspend-then-hibernate, and that for some reason isn't working on your machine. If before Plasma you were using some other DE where you were likely invoking odinary suspend, that would explain why you didn't run into this issue before. So whatever the reason is that it causes a total freeze for you, if suspend-then-hibernate is not supported on your machine then energy settings shouldn't let you enable it. And on my own setup, that command which gives you an access denied reports for me that it is not supported, but I am being shown that option in energy saving settings anyway. So that's a bug that we should fix, and let's hope that this resolves the issue for you too.
Comment 16 gavsiu 2023-09-18 19:27:19 UTC
No, I remember for sure I had it working before. The laptop would wake up after a while to hibernate. It looks like an issue with systemd and closed source Nvidia drivers that was introduced last year. https://github.com/systemd/systemd/issues/27559#issuecomment-1620100554

While trying to see if it would work if I ran `envycontrol -s integrated`, I kinda broke my install and it won't boot. Even when I set it back to hybrid using chroot. Soooo... gonna see what I can do.
Comment 17 Natalie Clarius 2023-09-20 01:37:18 UTC
Good work finding this, and good luck recovering your install.

If systemd's issues with Nvidia drivers is the cause for the freeze with suspend-then-hibernate, then there is no bug in KDE software involved here, so I'm closing this as an upstream issue.
Comment 18 gavsiu 2023-09-20 01:39:39 UTC
Thanks, it was easy. Just `envycontrol --reset`. Sorry for the trouble.