You are not logged in.

#1 2015-04-15 13:17:37

ttouch
Member
From: /dev/null
Registered: 2012-05-27
Posts: 130
Website

Instant resume after suspend

Hello,

I have a MacBook Pro 11,1 and when I try to suspend to ram through systemctl, it instantly resumes.
After a lot of debugging it's the xhci_hcd that does the bad job.
What can I do for that?

Do you need any logs?

Thanks.

Offline

#2 2015-04-16 02:32:50

hrod
Member
Registered: 2013-10-24
Posts: 57

Re: Instant resume after suspend

Hi.

Did you try the "disable usb wakeup ability" at the suspend section of the Arch Linux MacBookPro11,X wiki page?

If you make this file, the systemd-tmpfiles-setup service will disable XHC1 on startup (even though tmpfiles.d shouldn't really be used for /sys or /proc this seems to work fine for me):

echo "w /proc/acpi/wakeup - - - - XHC1" > /usr/lib/tmpfiles.d/disable-usb-wake.conf

(There is a thread for MacBookPro 11,x here btw.)

Last edited by hrod (2015-04-16 07:48:59)

Offline

#3 2015-04-16 12:16:40

ttouch
Member
From: /dev/null
Registered: 2012-05-27
Posts: 130
Website

Re: Instant resume after suspend

Nope, does not work... hmm

Offline

#4 2015-04-17 07:26:19

hrod
Member
Registered: 2013-10-24
Posts: 57

Re: Instant resume after suspend

Offline

#5 2015-04-17 12:02:18

ttouch
Member
From: /dev/null
Registered: 2012-05-27
Posts: 130
Website

Re: Instant resume after suspend

But I have an Early '14 MBP Retina.

Offline

#6 2015-04-18 03:44:48

hrod
Member
Registered: 2013-10-24
Posts: 57

Re: Instant resume after suspend

ttouch wrote:

But I have an Early '14 MBP Retina.

Well according to https://support.apple.com/en-au/HT201300 Late 2013 and Early 2014 are similar enough to have the same identifier (11.1). It seems to just be a CPU and RAM bump, so I doubt anything else changed, so try out any of the solutions listed for the early 2013 11.1 and see if they help you.

Last edited by hrod (2015-04-18 03:45:24)

Offline

#7 2015-04-18 15:13:41

ttouch
Member
From: /dev/null
Registered: 2012-05-27
Posts: 130
Website

Re: Instant resume after suspend

hrod wrote:
ttouch wrote:

But I have an Early '14 MBP Retina.

Well according to https://support.apple.com/en-au/HT201300 Late 2013 and Early 2014 are similar enough to have the same identifier (11.1). It seems to just be a CPU and RAM bump, so I doubt anything else changed, so try out any of the solutions listed for the early 2013 11.1 and see if they help you.

Still, 'echo "w /proc/acpi/wakeup - - - - XHC1" > /usr/lib/tmpfiles.d/disable-usb-wake.conf' does not work for me...

Offline

#8 2015-04-21 18:00:45

ttouch
Member
From: /dev/null
Registered: 2012-05-27
Posts: 130
Website

Re: Instant resume after suspend

Bump.
Any ideas?

Offline

#9 2015-05-19 20:11:26

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Instant resume after suspend

I have the same issue on MPB 9,2 (Mid 2012).
If I echo LID0 to /proc/acpi/wakeup which toggles respectively disables wakeup on LID-opening, suspendind via systemd or any similar method will work, but as it is probably obviously, sleeping via LID-closing does at least not work properly, especially the wakeup usually does not work.

So if you prefer to suspend via command line or even a graphical program, you might try this. Maybe you should first 'cat /proc/acpi/wakeup' to check if you have LID0 or similar listed.

Last edited by respiranto (2015-12-28 17:59:28)

Offline

#10 2015-06-30 20:30:24

rembo10
Member
Registered: 2011-10-11
Posts: 8

Re: Instant resume after suspend

Having the same issue on a 2013 MacbookAir6,1. If I disable XHC1 and LID0 I can get it to suspend, and I have to resume with the power button. Would love to get it working with the lid if anyone has any suggestions

Offline

#11 2015-07-01 16:13:53

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Instant resume after suspend

So suspend and resume from command line works?

Actually for me it started working since linux-4.0.{3|4} .
I had thought about writing a systemd unit that would disable LID0 (and if necessary XHC1) when suspending via command line and another one which would enable LID0 (and XHC1) after resume.
After resume you would have to check first, if these options are active, because as far as I know you can only toggle them.

Since I did not have that much time, I would have needed to learn enough about systemd-units, when I faced this problem, I have not succesfully completed the above approach.

If you don't know either how to write systemd-units, you might want to have a look at
- https://wiki.archlinux.org/index.php/Sy … unit_files
- https://wiki.archlinux.org/index.php/Po … leep_hooks
- some man-pages (e.g. systemd.unit(5) )

Here the small script I wrote - it should be self-explaining:

#!/bin/sh

if cat /proc/acpi/wakeup | grep -qE 'LID0.*enabled'
then
	test "$1" = "console-sleep" && echo LID0 > /proc/acpi/wakeup
else
	test "$1" = "resume" && echo LID0 > /proc/acpi/wakeup
fi

exit 0

You would have to call this from the systemd-unit files.

Offline

#12 2015-08-24 13:36:02

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Instant resume after suspend

The problem reappeared to me some days ago, so I worked around it today.
So just in case somebody else is still having this problem, as I presume, here is how:

---
IMPORTANT:
Check first, whether disabling LID0 does have any effect.

First, check the current status:

cat /proc/acpi/wakeup | grep LID0

Toggle if necessary (state should be disabled):

echo LID0 > /proc/acpi/wakeup

Now try to suspend.
---

/usr/local/bin/pre-suspend:

#!/bin/sh

if cat /proc/acpi/wakeup | grep -qE '^LID0.*enabled'
then
	grep -qE '^state: *open$' /proc/acpi/button/lid/LID0/state \
	&& echo LID0 > /proc/acpi/wakeup
else
	grep -qE '^state: *closed$' /proc/acpi/button/lid/LID0/state \
	&& echo LID0 > /proc/acpi/wakeup
fi

exit 0

/etc/systemd/system/root-suspend.service:

[Unit]
Description=Coordinate suspending via lid-close and systemctl
After=sleep.target

[Service]
Type=simple
ExecStart=/usr/local/bin/pre-suspend

[Install]
WantedBy=sleep.target

/etc/systemd/system/suspend@.service (only necessary if you want a non-root user to be able to suspend):

[Unit]
Description=Coordinate suspending via lid-close and systemctl
Before=sleep.target

[Service]
User=%I
Type=simple
ExecStart=/usr/bin/sudo /usr/local/bin/pre-suspend

[Install]
WantedBy=sleep.target

Give your user(s) (or alternatively a group your user(s) is/are member of) sudo rights for command pre-suspend in /etc/sudoers (not strictly necessary - see above):

<user>	ALL=(root) NOPASSWD: /usr/local/bin/pre-suspend

Finally enable the new services.

Obviously this will only work when suspending via systemd, but e.g. LID-close triggers suspend via systemd as does the xfce-exit-menu.
However echoing mem to /sys/power/state will not work.

If somebody uses this, please tell me if this works for you.
If requested, I can also package it and publish it to the AUR.

Edit:
Mixed up suspend and resume ...
Sorry, if this might have confused somebody.
It should have worked anyways.

Note:
It would probably be better to also have a resume service, so the default state is predictable.
For example, I have got the impression, that sometimes after lid-close and -open, resuming does not work properly.
This could probably be fixed by making LID0 enabled as default.
On the other hand, if one wants to be able to suspend via methods like echoing mem to /sys/power/state one could set LID0 disabled as default.

Last edited by respiranto (2015-12-28 17:58:43)

Offline

#13 2015-12-01 00:25:21

netw3rkd
Member
Registered: 2015-12-01
Posts: 1

Re: Instant resume after suspend

respiranto, what's the chances of getting you to package this up and put it in the AUR??   I'm very confused on getting this to work. 
  Thanks!

Offline

#14 2015-12-03 05:26:10

vamsi360
Member
Registered: 2015-12-03
Posts: 3

Re: Instant resume after suspend

@respiranto

Not working for me. MacbookPro 2015Mid

Offline

#15 2015-12-26 00:51:37

dalrympm
Member
Registered: 2015-12-26
Posts: 1

Re: Instant resume after suspend

@respiranto thanks for these instructions.  I'm running a MacBookPro 12,1 and this solved the problem for me.  The only clarifications I had were:

Make the script executable:

chmod a+x /usr/local/bin/pre-suspend

How to enable the service:

sudo systemctl enable root-suspend

Many thanks for making this work!

Offline

#16 2015-12-28 17:47:42

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Instant resume after suspend

netw3rkd wrote:

respiranto, what's the chances of getting you to package this up and put it in the AUR??   I'm very confused on getting this to work. 
  Thanks!

What exactly is confusing for you?

Actually, I don't think anymore, that it would be such a great idea to put this in the AUR because then it might be used
- without checking first whether it makes sense - Has `echo LID0 > /proc/acpi/wakeup' any effect?
- without checking what it does.

I do not want to encourage anybody to blindly use a random workaround he does not understand.
That does in my eyes not conform to the Arch way.

Furthermore it might happen one day, that this does not work anymore for a certain install (for example for mine) and then it is good to know, what this workaround does, how to disable it and how to modify it if necessary.

---

Nice to hear, dalrympm, that it worked for you.

Offline

#17 2016-03-28 15:10:24

sleeping
Member
Registered: 2016-01-09
Posts: 53

Re: Instant resume after suspend

Unfortunately it doesn't yet work for me.

I enabled the service, but journalctl nor systemctl show any indication that root-suspend.service was enabled.
Using a MacBook Pro 4,1 by the way.

Last edited by sleeping (2016-03-28 15:11:04)

Offline

#18 2016-03-28 15:29:45

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Instant resume after suspend

Did toggling the LID0 state have any effect?
Elsewise, this solution won't work for you, i.e. you should open a new thread (or search in the many others).

Offline

#19 2016-04-11 12:24:42

sleeping
Member
Registered: 2016-01-09
Posts: 53

Re: Instant resume after suspend

Yes it did. Actually, your solution works as I had no problems anymore after it.
The service just doesn't show...

Offline

#20 2016-04-12 16:47:15

respiranto
Member
Registered: 2015-05-15
Posts: 479
Website

Re: Instant resume after suspend

Glad to hear that my solution could help you.

What do you mean by a not showing service?
Upon starting it, there should be no output.

Does `systemctl status the_respective_name.service' show you an error?

Offline

#21 2020-11-22 21:07:20

plv
Member
Registered: 2020-11-22
Posts: 1

Re: Instant resume after suspend

I discovered another bug while playing with suspend/resume on Macbook. It doen't wake from suspend by RTC alarm if LID is disabled in acpi/wakeup. Which means hibernate part of suspend-then-hibernate won't work.

Anyway, here is my update for systemd-sleep.service. No sudo required.

First, the script, place it in /usr/local/bin/lid.sh and make it executable:

#!/bin/bash

# wakeup state
grep -qE '^LID0.*enabled' /proc/acpi/wakeup
WAKEUP=$?

# lid state
grep -qE '^state: *open$' /proc/acpi/button/lid/LID0/state
LID=$?

case $1 in
    "prepare")
        # if wakeup on and lid open OR wakeup off and lid closed
        [ $(( $WAKEUP ^ $LID )) -eq 0 ] && echo LID0 > /proc/acpi/wakeup
        ;;
    "restore")
        # if lid open and wakeup off
        [[ $WAKEUP -eq 1 && $LID -eq 0 ]] && echo LID0 > /proc/acpi/wakeup
        ;;
    *)
        exit 2
        ;;
esac

exit 0

Then create /etc/systemd/system/systemd-suspend.service.d/lid.conf:

[Service]
ExecStartPre=/usr/local/bin/lid.sh prepare
ExecStartPost=/usr/local/bin/lid.sh restore

and verify the result:

$ systemctl status systemd-suspend.service
● systemd-suspend.service - Suspend
     Loaded: loaded (/usr/lib/systemd/system/systemd-suspend.service; static)
    Drop-In: /etc/systemd/system/systemd-suspend.service.d
             └─lid.conf

Last edited by plv (2020-11-28 23:06:07)

Offline

#22 2024-02-19 22:55:52

florosus
Member
Registered: 2015-03-19
Posts: 25

Re: Instant resume after suspend

Can confirm the RTC issue. WIth the lid closed, my mid-2012 MacBook Pro won't wake on an RTC alarm, no matter whether LID0 is disabled in wakeup or not.
It's a shame this still hasn't been fixed. Thankfully, logind's hybrid-sleep seems to work out of the box.

Offline

Board footer

Powered by FluxBB