Bug 210421 - MacBookAir5,2 doesn't wake from S3 by RTC alarm
Summary: MacBookAir5,2 doesn't wake from S3 by RTC alarm
Status: NEEDINFO
Alias: None
Product: Power Management
Classification: Unclassified
Component: Hibernation/Suspend (show other bugs)
Hardware: Intel Linux
: P1 normal
Assignee: Zhang Rui
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-30 06:40 UTC by Vadim Pisarev
Modified: 2021-07-03 23:44 UTC (History)
1 user (show)

See Also:
Kernel Version: 5.9.10-arch1-1
Subsystem:
Regression: No
Bisected commit-id:


Attachments
dmesg (74.47 KB, text/plain)
2020-11-30 06:40 UTC, Vadim Pisarev
Details
lspci (50.06 KB, text/plain)
2020-11-30 06:41 UTC, Vadim Pisarev
Details
lsusb (58.41 KB, text/plain)
2020-11-30 06:41 UTC, Vadim Pisarev
Details
acpi tables (14.88 KB, application/gzip)
2020-11-30 06:42 UTC, Vadim Pisarev
Details
/proc/acpi/wakeup (465 bytes, text/plain)
2020-11-30 06:43 UTC, Vadim Pisarev
Details
dmesg+interrupts (170.92 KB, application/gzip)
2021-03-22 18:05 UTC, Vadim Pisarev
Details
mem/freeze tests (132.18 KB, application/gzip)
2021-06-08 02:09 UTC, Vadim Pisarev
Details
dmesg (76.96 KB, text/plain)
2021-07-01 04:50 UTC, Vadim Pisarev
Details
debug patch to dump sci during suspend (7.62 KB, patch)
2021-07-02 03:07 UTC, Zhang Rui
Details | Diff
dmesg-freeze-ac.log (3.55 KB, text/plain)
2021-07-03 23:43 UTC, Vadim Pisarev
Details
dmesg-mem-ac.log (5.27 KB, text/plain)
2021-07-03 23:44 UTC, Vadim Pisarev
Details
dmesg-mem-bat.log (5.27 KB, text/plain)
2021-07-03 23:44 UTC, Vadim Pisarev
Details

Description Vadim Pisarev 2020-11-30 06:40:08 UTC
Overview:
MacBookAir5,2 doesn't wake from S3 by RTC alarm when lid is closed and power adapter is disconnected.

Steps to Reproduce:
Run 'rtcwake -m mem -s +15', wait for laptop to go to sleep then close the lid

Actual Results:
Nothing happens

Expected Results:
Laptop wakes up in ~15sec

Build Date & Hardware:
Linux air.plv.loc 5.9.10-arch1-1 #1 SMP PREEMPT Sun, 22 Nov 2020 14:16:59 +0000 x86_64 GNU/Linux
MacBookAir5,2

Additional Information:
Sleep/resume by lid close/open works fine without any tweaks. But the laptop would resume shortly if suspended with lid open and LID0 enabled in /proc/acpi/wakeup.
Anyway, the status of LID0 wakeup doesn't affect RTC wakeup.

Wakeup by RTC alarm works if either the lid is open or ADP1 is online.
Comment 1 Vadim Pisarev 2020-11-30 06:40:41 UTC
Created attachment 293869 [details]
dmesg
Comment 2 Vadim Pisarev 2020-11-30 06:41:04 UTC
Created attachment 293871 [details]
lspci
Comment 3 Vadim Pisarev 2020-11-30 06:41:43 UTC
Created attachment 293873 [details]
lsusb
Comment 4 Vadim Pisarev 2020-11-30 06:42:26 UTC
Created attachment 293875 [details]
acpi tables
Comment 5 Vadim Pisarev 2020-11-30 06:43:51 UTC
Created attachment 293877 [details]
/proc/acpi/wakeup
Comment 6 Zhang Rui 2021-01-03 12:17:20 UTC
what do you get by "cat  /sys/module/rtc_cmos/parameters/use_acpi_alarm"?
if it says N, can you please check if the problem still exists by setting it to Y?
Comment 7 Vadim Pisarev 2021-01-05 02:13:47 UTC
"use_acpi_alarm" was "N". Setting it to "Y" made no difference.

A couple of more observations (regardless of use_acpi_alarm setting): the laptop in S3 with RTC alarm set and everything in /proc/acpi/wakeup disabled will wake up by connecting a power supply or by opening the lid.
Comment 8 Zhang Rui 2021-03-21 15:49:12 UTC
(In reply to Vadim Pisarev from comment #7)
> "use_acpi_alarm" was "N". Setting it to "Y" made no difference.
> 
> A couple of more observations (regardless of use_acpi_alarm setting): the
> laptop in S3 with RTC alarm set and everything in /proc/acpi/wakeup disabled
> will wake up by connecting a power supply or by opening the lid.

what if RTC alarm is not set and everything in /proc/acpi/wakeup disabled, can the laptop wake up by connecting a power supply or by opening the lid?


(In reply to Vadim Pisarev from comment #0)
> Overview:
> MacBookAir5,2 doesn't wake from S3 by RTC alarm when lid is closed and power
> adapter is disconnected.

please attach the output of "grep . /sys/firmwire/acpi/interrupts/*" both before and after the s3 wake, and also the dmesg log.
Comment 9 Vadim Pisarev 2021-03-22 18:05:37 UTC
Created attachment 295999 [details]
dmesg+interrupts

Please see the attached archive. It has two directories inside:

case1 - regular sleep/resume via lid close/open
case2 - same as case1, but RTC alarm is set
Comment 10 Vadim Pisarev 2021-03-22 18:05:59 UTC
(In reply to Zhang Rui from comment #8)
> (In reply to Vadim Pisarev from comment #7)
> > "use_acpi_alarm" was "N". Setting it to "Y" made no difference.
> > 
> > A couple of more observations (regardless of use_acpi_alarm setting): the
> > laptop in S3 with RTC alarm set and everything in /proc/acpi/wakeup
> disabled
> > will wake up by connecting a power supply or by opening the lid.
> 
> what if RTC alarm is not set and everything in /proc/acpi/wakeup disabled,
> can the laptop wake up by connecting a power supply or by opening the lid?

No.
Comment 11 Zhang Rui 2021-06-02 07:53:12 UTC
(In reply to Vadim Pisarev from comment #9)
> Created attachment 295999 [details]
> dmesg+interrupts
> 
> Please see the attached archive. It has two directories inside:
> 
> case1 - regular sleep/resume via lid close/open
> case2 - same as case1, but RTC alarm is set

is case 2 done with Lid closed or opened?
Because I don't see the RTC wakeup event fired this time.

Please attach the dmesg+interrupts
1. regular suspend using rtcwake, with Lid always open
2. regular suspend using lid close/open
3. failure cause that suspend using rtcwake with Lid closed, and then open lid after like 30 seconds.

Plus, it would be good if you can do the same test for freeze mode as well, say rtcwake -m freeze -s 15 instead of rtcwake -m mem -s 15.
Comment 12 Vadim Pisarev 2021-06-08 02:08:42 UTC
(In reply to Zhang Rui from comment #11)
> (In reply to Vadim Pisarev from comment #9)
> > Created attachment 295999 [details]
> > dmesg+interrupts
> > 
> > Please see the attached archive. It has two directories inside:
> > 
> > case1 - regular sleep/resume via lid close/open
> > case2 - same as case1, but RTC alarm is set
> 
> is case 2 done with Lid closed or opened?
> Because I don't see the RTC wakeup event fired this time.

Lid closed.

> Please attach the dmesg+interrupts
> 1. regular suspend using rtcwake, with Lid always open
> 2. regular suspend using lid close/open
> 3. failure cause that suspend using rtcwake with Lid closed, and then open
> lid after like 30 seconds.
> 
> Plus, it would be good if you can do the same test for freeze mode as well,
> say rtcwake -m freeze -s 15 instead of rtcwake -m mem -s 15.

See the attached archive.
FYI, in freeze/case3 RTC woke up the laptop, but systemd immediately sent it back to freeze.

All in all, RTC alarm successfully wakes up the laptop from freeze.
Comment 13 Vadim Pisarev 2021-06-08 02:09:29 UTC
Created attachment 297221 [details]
mem/freeze tests
Comment 14 Zhang Rui 2021-07-01 03:34:18 UTC
from the dmesg, it seems that the system is doing a full suspend/resume. but I'm not sure if it is the RTC or the Lid that triggers the resume.
can you please redo the testcase 3 for mem, with "echo 1 > /sys/power/pm_debug_message" before suspend?
say,
1. echo 1 > /sys/power/pm_debug_message
2. echo mem > /sys/power/mem_sleep
3. rtcwake -m mem -t 30
4. open the lid after 60 seconds.

In the dmesg, we should see something like "Timekeeping suspended for xx seconds", and this suggests us it is the rtcwake or the lid open that triggers the system wakeup.
Comment 15 Vadim Pisarev 2021-07-01 04:50:26 UTC
My /sys/power/mem_sleep is "s2idle [deep]", so i skipped step #2.

The first sleep entry is at ~22 sec. AC adapter is NOT connected, RTC wakeup didn't work. Received the following ACPI events (why ac_adapter?):

    button/lid LID close
    processor LNXCPU:00 00000081 00000000
    button/lid LID open
    processor LNXCPU:01 00000081 00000000
    processor LNXCPU:02 00000081 00000000
    processor LNXCPU:03 00000081 00000000
    ac_adapter ACPI0003:00 00000002 00000000

The second sleep entry is at ~77 sec with AC adapter connected. ACPI events:

    button/lid LID close
    processor LNXCPU:00 00000081 00000000
    processor LNXCPU:01 00000081 00000000
    processor LNXCPU:02 00000081 00000000
    processor LNXCPU:03 00000081 00000000
    button/lid LID open

FYI, AC connect events are:

   ac_adapter ACPI0003:00 00000080 00000001
   processor LNXCPU:00 00000081 00000000
   processor LNXCPU:01 00000081 00000000
   processor LNXCPU:02 00000081 00000000
   processor LNXCPU:03 00000081 00000000

AC disconnect:

   ac_adapter ACPI0003:00 00000080 00000001
   processor LNXCPU:00 00000081 00000000
   processor LNXCPU:01 00000081 00000000
   processor LNXCPU:02 00000081 00000000
   processor LNXCPU:03 00000081 00000000
Comment 16 Vadim Pisarev 2021-07-01 04:50:48 UTC
Created attachment 297679 [details]
dmesg
Comment 17 Vadim Pisarev 2021-07-01 04:54:14 UTC
> AC disconnect:
> 
>    ac_adapter ACPI0003:00 00000080 00000001

My bad, this should be:

     ac_adapter ACPI0003:00 00000080 00000000
Comment 18 Zhang Rui 2021-07-01 05:51:30 UTC
[   23.000191] PM: Timekeeping suspended for 60.977 seconds
[   78.314604] PM: Timekeeping suspended for 29.050 seconds

In the first test, with AC unplugged, the RTC wake event is missing and it is the lid open that triggers the resume.
In the second test, with AC plugged, the RTC wake event is fired and triggered the resume.

I don't think the Linux kernel does anything special for the RTC fixed event. It is always enabled during the S3 suspend phase. So it is probably a firmware problem instead of Linux issue.

Let me think out a way to dump the SCI interrupts to confirm if the RTC fixed event is enabled during resume to confirm this.
Comment 19 Zhang Rui 2021-07-02 03:07:06 UTC
Created attachment 297687 [details]
debug patch to dump sci during suspend

please apply this patch on top of the latest upstream kernel, and make sure you're building the kernel with CONFIG_PM_SLEEP_DEBUG set, and then, with the new kernel, please
1. echo deep > /sys/power/mem_sleep
2. echo 1 > /sys/power/pm_debug_messages
3. with AC plugged, do "dmesg -C; rtcwake -m freeze -s 10; dmesg > dmesg-freeze-ac.log"
4. with AC plugged, do "dmesg -C; rtcwake -m mem -s 10; dmesg > dmesg-mem-ac.log"
5. with AC unplugged, do "dmesg -C; rtcwake -m mem -s 10; dmesg > dmesg-mem-bat.log"
and attach the three log files.
Comment 20 Vadim Pisarev 2021-07-03 23:43:26 UTC
Created attachment 297695 [details]
dmesg-freeze-ac.log
Comment 21 Vadim Pisarev 2021-07-03 23:44:02 UTC
Created attachment 297697 [details]
dmesg-mem-ac.log
Comment 22 Vadim Pisarev 2021-07-03 23:44:25 UTC
Created attachment 297699 [details]
dmesg-mem-bat.log

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