RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1081093 - Laptop doesn't suspend on lid close after external monitor unplugged
Summary: Laptop doesn't suspend on lid close after external monitor unplugged
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: gnome-settings-daemon
Version: 7.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: rc
: ---
Assignee: Rui Matos
QA Contact: Desktop QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-03-26 15:46 UTC by Michal Domonkos
Modified: 2017-07-03 15:04 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-06-13 12:07:52 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
g-s-d debug (110.86 KB, text/plain)
2014-04-15 16:03 UTC, Michal Domonkos
no flags Details
xrandr -q --prop (1.85 KB, text/plain)
2014-04-15 16:04 UTC, Michal Domonkos
no flags Details
g-s-d debug - no suspend after 30s (116.29 KB, text/plain)
2014-04-24 10:28 UTC, Michal Domonkos
no flags Details
g-s-d debug (build bz1090555) - undock with lid already closed (78.77 KB, text/plain)
2014-04-25 09:56 UTC, Michal Domonkos
no flags Details

Description Michal Domonkos 2014-03-26 15:46:07 UTC
Description of problem:
Lid close event does not trigger suspend any more after a monitor has been connected and then disconnected.

There's a common use case when a user undocks his laptop and closes the lid to carry the laptop with them.

Version-Release number of selected component (if applicable):
systemd-208-9.el7.x86_64
kernel-3.10.0-114.el7.x86_64

How reproducible:
always

Steps to Reproduce:
1. Plug an external monitor
2. Unplug it
3. Close the lid

Actual results:
Laptop doesn't suspend.

Expected results:
Laptop suspends.

Comment 1 Michal Domonkos 2014-03-26 16:14:10 UTC
The above is based on the assumption that the laptop shouldn't suspend when an external monitor (or docking station) is used.  This is a change from RHEL6 where it suspends even in this case but I suppose it is a deliberate change (please correct me if I'm wrong).

Comment 2 RHEL Program Management 2014-04-03 05:47:38 UTC
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.

Comment 4 Lukáš Nykrýn 2014-04-14 08:13:45 UTC
Can you please switch systemd loging to debug "kill -56 1" or add "debug" to kernel cmdline, reproduce the issue and post here output of journalctl -b.

Comment 5 Michal Sekletar 2014-04-14 08:40:19 UTC
Also please switch on debug for systemd-logind. Add drop-in configuration file debug.conf with following content : 

[Service]
Environment="SYSTEMD_LOG_LEVEL=debug"

under /etc/systemd/system/systemd-logind.service.d/ and reload systemd and restart logind.

Comment 6 Lukáš Nykrýn 2014-04-14 08:55:54 UTC
gnome-settings-deamon is creating an handle-lid-switch inhibitor when multiple monitors are attached, but it is not releasing it after the laptop is taken out of the dock.

     Who: lnykryn (UID 1000/lnykryn, PID 1604/gnome-settings-)
    What: handle-lid-switch
     Why: Multiple displays attached
    Mode: block

Comment 7 Bastien Nocera 2014-04-15 15:11:29 UTC
Can you please run:
/usr/libexec/gnome-settings-daemon --replace --debug
reproduce the problem and send the output?

Also, what's the output of "xrandr -q --props" after unplugging the dock?

Comment 8 Michal Domonkos 2014-04-15 16:03:59 UTC
Created attachment 886544 [details]
g-s-d debug

Comment 9 Michal Domonkos 2014-04-15 16:04:24 UTC
Created attachment 886545 [details]
xrandr -q --prop

Comment 10 Michal Domonkos 2014-04-15 16:05:24 UTC
Attached are the requested logs.

What I did:
1. Placed my laptop in the dock, disabled the integrated display and enabled an external one
2. Replaced the g-s-d instance by running:
/usr/libexec/gnome-settings-daemon --replace --debug
3. Unplugged the laptop
4. Closed the lid

Comment 11 Bastien Nocera 2014-04-22 18:07:43 UTC
How long did you wait for the laptop to suspend. Near the end, we can see that you closed the lid, which starts a timeout.

The log:
(gnome-settings-daemon:3742): power-plugin-DEBUG: up changed: lid is now closed
(gnome-settings-daemon:3742): power-plugin-DEBUG: restarting lid close safety timer
(gnome-settings-daemon:3742): power-plugin-DEBUG: setting up lid close safety timer

The code:
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-manager.c?h=gnome-3-8#n2177

30 seconds later, after the timeout, you'll get either "no external monitors for a while; uninhibiting lid close" or "external monitor still there; trying again later":
https://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-manager.c?h=gnome-3-8#n2151

Instead, I see:
(gnome-settings-daemon:3742): power-plugin-DEBUG: up changed: lid is now open

Which means that you opened the lid before the 30 seconds were up. The 30 seconds are there for you to be able to open the lid without the laptop having suspended. It's actually a feature.

Am I correct in thinking that you didn't wait 30 seconds?

Comment 12 Matthias Clasen 2014-04-23 19:23:23 UTC
Michal, is this something you're just seeing with a single laptop/dock combination or specific to a single test machine ? (assuming it is not simple a case of 'didn't wait long enough')

Comment 13 Michal Domonkos 2014-04-24 10:13:50 UTC
Bastien, Matthias, you're right.  I didn't wait for 30 seconds; I repeated the process today and found out that it really *suspends* after 30 seconds.  While I agree with this feature being useful, it's not something that one would expect.  From an ordinary user's point of view, if I closed the lid and the laptop didn't suspend right away (let's say +- 10 seconds) I would simply assume that it's not going to (and would just reopen the lid and suspend the machine manually if I was in a hurry.)

However, to make it a little more complicated:  If I close the lid in rapid succession after undocking (i.e. before g-s-d has a chance to get notified about the layout change, which is noticeable as a desktop refresh) it won't suspend at all, not even after the 30 secs.  This may be just a nature of the whole process and not a bug, though.

Do you think the latter deserves a separate bug report?

Comment 14 Michal Domonkos 2014-04-24 10:19:58 UTC
Just to add:  Any subsequent lid close (after that first one since undocking) makes the computer suspend without the delay.

Comment 15 Michal Domonkos 2014-04-24 10:28:54 UTC
Created attachment 889230 [details]
g-s-d debug - no suspend after 30s

Attaching the g-s-d output after reproducing the case when it never suspends (well, I waited for 2 minutes :) ), see Comment 13 for details.

Comment 16 Bastien Nocera 2014-04-24 12:40:21 UTC
(In reply to Michal Domonkos from comment #13)
> Bastien, Matthias, you're right.  I didn't wait for 30 seconds; I repeated
> the process today and found out that it really *suspends* after 30 seconds. 
> While I agree with this feature being useful, it's not something that one
> would expect.  From an ordinary user's point of view, if I closed the lid
> and the laptop didn't suspend right away (let's say +- 10 seconds) I would
> simply assume that it's not going to (and would just reopen the lid and
> suspend the machine manually if I was in a hurry.)
> 
> However, to make it a little more complicated:  If I close the lid in rapid
> succession after undocking (i.e. before g-s-d has a chance to get notified
> about the layout change, which is noticeable as a desktop refresh) it won't
> suspend at all, not even after the 30 secs.  This may be just a nature of
> the whole process and not a bug, though.
> 
> Do you think the latter deserves a separate bug report?

It's 30 seconds after the last one of lid opening/closing and the screen configuration changing. See the repeated "setting up lid close safety timer" messages. As I mentioned, we should see either the:
no external monitors for a while; uninhibiting lid close
message, or this one:
external monitor still there; trying again later

We don't see either, which leads me to believe that you didn't wait long enough.

Comment 17 Michal Domonkos 2014-04-24 13:46:36 UTC
I'm not arguing about the 30s delay :)  I already confirmed your suspicion that I didn't wait for 30s originally.  As I said I tried to reproduce today but waited for 30s this time and it really did suspend then.  I even checked the log and saw the "no external monitors for a while; uninhibiting lid close" message.

What I'm not sure about now is whether it is expected that the machine doesn't suspend after those 30s in case you close the lid too soon after unplugging external monitors (i.e. within ~3 seconds)?

Comment 18 Bastien Nocera 2014-04-24 14:33:36 UTC
(In reply to Michal Domonkos from comment #17)
> What I'm not sure about now is whether it is expected that the machine
> doesn't suspend after those 30s in case you close the lid too soon after
> unplugging external monitors (i.e. within ~3 seconds)?

It's supposed to suspend, and I was asking about whether you waited long enough for *that* use. When you unplug monitors, and close the lid in quick succession, two things could occur:
- The monitor being unplugged is detected first, we'll set up a timeout, and inhibit_lid_switch_timer_cb() will be triggered 30 seconds later (giving one of those 2 messages I was mentioning)
- The lid being closed will be triggered first, showing the "up changed: lid is now ..." message, a timeout will be setup, again to check for the status of the machine in 30 seconds.

But, I can see a lot of "Screen configuration changed" messages at the bottom of your logs, meaning that the timer will be restarted (again) for each of those events:
(gnome-settings-daemon:7098): wacom-plugin-DEBUG: Screen configuration changed
(gnome-settings-daemon:7098): power-plugin-DEBUG: restarting lid close safety timer
(gnome-settings-daemon:7098): power-plugin-DEBUG: setting up lid close safety timer
<bis repetita>

So, did you wait long enough in your latest test?

Comment 19 Michal Domonkos 2014-04-24 16:37:48 UTC
But the point is that it doesn't suspend in the said case :)

What do you mean by "long enough"?  I was waiting even 3 minutes (measured with a stopwatch in my phone) without the laptop going to sleep.

To sum it up, this is the failing scenario I was talking about:

1. Have the laptop docked, lid open
2. Undock the laptop
3. Close the lid right away
4. Wait for suspend

Result:  After 30 seconds the laptop doesn't suspend.  Like I said above, I'm actually waiting for 3 minutes in total and the laptop is still running (as indicated by a LED on the top of the lid).

While playing with this I've found another failing scenario:

1. Have the laptop docked, lid *closed*
2. Undock the laptop
4. Wait for suspend

Result:  Same as the previous one, no suspend after 30 seconds or more.

-------------

Success scenario:

1. Have the laptop docked, lid open
2. Undock the laptop
3. Wait for a few seconds until the monitor config change is detected (screen refreshes).  Usually takes around 3 to 4 seconds
4. Close the lid
5. Wait for suspend

Result:  After 30 seconds the laptop suspends.

-------------

According to what you are saying about the events in the log, it seems like something is triggering the "Screen configuration changed" events but I have no idea what that might be since I'm not doing anything with the laptop once undocked and lid closed.

Comment 20 Michal Domonkos 2014-04-24 16:40:50 UTC
To make sure it's not something HW or installation specific I'll test a different laptop tomorrow or so and will report here the findings.

Comment 21 Vladimir Benes 2014-04-25 07:22:39 UTC
(In reply to Michal Domonkos from comment #19)
<snip> 

> 1. Have the laptop docked, lid *closed*
> 2. Undock the laptop
> 4. Wait for suspend

<snip>

this works for me for X230 ivy bridge laptop. I have to wait 30 seconds but it finally gets to sleep.

Comment 22 Bastien Nocera 2014-04-25 07:46:36 UTC
Can you please test with this build?
https://brewweb.devel.redhat.com/taskinfo?taskID=7385368

Also make sure to capture the debug output again.

Comment 23 Michal Domonkos 2014-04-25 09:51:20 UTC
Ugh, this build actually segfaults for me as soon as I undock, here's the backtrace:

#0  0x00007ffff73b2a53 in diff_outputs_and_emit_signals (old=0x728ee0, new=0xaf24d0, new=0xaf24d0) at gnome-rr.c:554
#1  screen_update (screen=0x7dd2e0, force_callback=force_callback@entry=1, needs_reprobe=needs_reprobe@entry=0, error=error@entry=0x0) at gnome-rr.c:622
#2  0x00007ffff73b2c95 in screen_on_event (xevent=<optimized out>, event=<optimized out>, data=<optimized out>) at gnome-rr.c:654
#3  0x00007ffff6a81ea1 in gdk_event_apply_filters (xevent=xevent@entry=0x7fffffffdd60, event=event@entry=0x88c4c0, window=window@entry=0x65b050) at gdkeventsource.c:81
#4  0x00007ffff6a82153 in gdk_event_source_translate_event (xevent=0x7fffffffdd60, event_source=0x653210) at gdkeventsource.c:202
#5  _gdk_x11_display_queue_events (display=0x652020) at gdkeventsource.c:338
#6  0x00007ffff6a56188 in gdk_display_get_event (display=display@entry=0x652020) at gdkdisplay.c:313
#7  0x00007ffff6a81f22 in gdk_event_source_dispatch (source=source@entry=0x653210, callback=<optimized out>, user_data=<optimized out>) at gdkeventsource.c:360
#8  0x00007ffff53e0ac6 in g_main_dispatch (context=0x6405b0) at gmain.c:3058
#9  g_main_context_dispatch (context=context@entry=0x6405b0) at gmain.c:3634
#10 0x00007ffff53e0e48 in g_main_context_iterate (context=0x6405b0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3705
#11 0x00007ffff53e125a in g_main_loop_run (loop=0x729b50) at gmain.c:3899
#12 0x00007ffff6e4f0ed in gtk_main () at gtkmain.c:1156
#13 0x0000000000403847 in main (argc=1, argv=0x7fffffffe0e8) at main.c:479

Comment 24 Michal Domonkos 2014-04-25 09:56:02 UTC
Created attachment 889628 [details]
g-s-d debug (build bz1090555) - undock with lid already closed

Probably irrelevant due to the segfault but attaching it anyway.

Comment 25 Michal Domonkos 2014-04-25 13:21:56 UTC
Summary of my testing to date:

1. Undock with lid open, then close (within ~3 seconds)
    * X230 and HP EliteBook both suspend after 30s
    * T520 keeps running even after 30s
2. Undock with lid open, then close (with at least ~3 seconds in between)
    * all laptops suspend after 30s
3. Undock with lid closed
    * X230 suspends after 30s
    * T520 and HP EliteBook both keep running even after 30s

Comment 26 Rui Matos 2014-04-28 20:24:08 UTC
Please test this build:

https://brewweb.devel.redhat.com/taskinfo?taskID=7393974

It fixes the problem here on a T520.

Comment 27 Michal Domonkos 2014-04-29 10:55:21 UTC
(In reply to Rui Matos from comment #26)
> Please test this build:
> 
> https://brewweb.devel.redhat.com/taskinfo?taskID=7393974
> 
> It fixes the problem here on a T520.

OK, this is the situation with the new build tested on my T520:

1. Undock with lid open, then close (within ~3 seconds)
    * suspends after 30s
2. Undock with lid open, then close (with at least ~3 seconds in between)
    * suspends after 30s
3. Undock with lid closed
    * suspends after 30s

However, case 3 will only pass when the following conditions are met:
* Current g-s-d instance was launched while the lid was open
* It's the first suspend with the current g-s-d instance, i.e. any repeated suspend will fail again until you re-launch the g-s-d or open (and then close again) the lid.

IOW, there really is an improvement (as case 3 never passed with the older build) but it's still not 100%.

Comment 28 Rui Matos 2014-04-29 20:11:44 UTC
(In reply to Michal Domonkos from comment #27)
> OK, this is the situation with the new build tested on my T520:
> 
> 1. Undock with lid open, then close (within ~3 seconds)
>     * suspends after 30s
> 2. Undock with lid open, then close (with at least ~3 seconds in between)
>     * suspends after 30s
> 3. Undock with lid closed
>     * suspends after 30s

Thanks for testing. The patch used in that build is a pretty simple fix to g-s-d's output detection:

diff --git a/plugins/power/gpm-common.c b/plugins/power/gpm-common.c
index b1ce32a..70e4591 100644
--- a/plugins/power/gpm-common.c
+++ b/plugins/power/gpm-common.c
@@ -1694,6 +1694,8 @@ randr_output_is_on (GnomeRROutput *output)
 {
         GnomeRRCrtc *crtc;
 
+        if (!gnome_rr_output_is_connected (output))
+                return FALSE;
         crtc = gnome_rr_output_get_crtc (output);
         if (!crtc)
                 return FALSE;


Note that this bug also exists in g-s-d's most recent branches. I don't think this check ever worked correctly before.

> However, case 3 will only pass when the following conditions are met:
> * Current g-s-d instance was launched while the lid was open
> * It's the first suspend with the current g-s-d instance, i.e. any repeated
> suspend will fail again until you re-launch the g-s-d or open (and then
> close again) the lid.

I investigated this and to me it seems like a systemd-logind bug:

g-s-d does not issue the suspend call directly, it simply lets logind suspend when the lid is closed by releasing logind's lid inhibitor. What happens on this case is that logind only polls the lid button state after it has seen one lid open event[1].

If the laptop resumes from suspend while the lid is closed, g-s-d takes the inhibitor as usual. If it sees the external monitor it holds the inhibitor and prevents suspension. Then, when it gets undocked, g-s-d releases the inhibitor, but logind isn't checking the lid state because there never was a lid open event and thus it doesn't suspend.

This should probably be evaluated by a systemd developer.

[1] http://cgit.freedesktop.org/systemd/systemd/tree/src/login/logind-button.c?id=1434ae6fd49f8377b0ddbd4c675736e0d3226ea6#n158 - this is the v208 of the code, i.e. what's shipped in rhel7

Comment 29 Michal Domonkos 2014-04-30 08:32:01 UTC
Thanks for looking into that, Rui, now it pretty much makes sense.  I've just filed it against systemd as bug 1092905.

Comment 33 Ludek Smid 2014-06-13 12:07:52 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.


Note You need to log in before you can comment on or make changes to this bug.