Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to fix Hibernation #48

Open
5T33Z0 opened this issue Dec 4, 2023 · 9 comments
Open

Trying to fix Hibernation #48

5T33Z0 opened this issue Dec 4, 2023 · 9 comments
Labels
help wanted Extra attention is needed

Comments

@5T33Z0
Copy link
Owner

5T33Z0 commented Dec 4, 2023

@5T33Z0 After spending a lot of time trying to find guides or any info on hibernation in modern hackintosh (OpenCore). I managed to fix hibernation, before these fixes I was only getting a black screen or a restart when trying to wake from hibernation hibernatemode=25 the main problem was some RTC memory regions getting overwritten when starting the machine again, there were other small issues too. I tested with Catalina and Sonoma and its been reliable so far

To fix hibernation you will the kexts HibernationFixup and RTCMemoryFixup

  • Add rtcfx_exclude=80-AB to boot-args
  • Set HibernateMode to NVRAM in Misc/Boot
  • Set RebuildAppleMemoryMap to False in Booter/Quirks
  • Use the following ReservedMemory entry
    Screenshot 2023-12-02 at 8 22 21 PM
    ReservedMemory.plist.zip
  • Optionally set HibernateSkipsPicker in Misc/Boot to true for a more seamless hibernation wake

To fix a black screen that happens after hibernating and waking once and then try to hibernate again

  • Enable the DiscardHibernateMap Booter quirk
  • Reset NVRAM

Originally posted by @jozews321 in #43 (comment)

@5T33Z0 5T33Z0 added the help wanted Extra attention is needed label Dec 4, 2023
@5T33Z0
Copy link
Owner Author

5T33Z0 commented Dec 4, 2023

Added the settings and kext and changed Hibernatemode to 25 in Sonoma. Now, if I send the system to sleep, I can no longer wake it via the Fn key. I guess this is because the keyboard is powered down in Hibernation. If I press the power button, the system comes back right to where I left it. Is this the correct behavior?

Or do I have to change delays o anything else here?:

5t33z0@5T33Z0s-MacBook-Pro ~ % pmset -g
System-wide power settings:
Currently in use:
 standbydelaylow      4200
 standby              1
 womp                 1
 halfdim              1
 hibernatefile        /var/vm/sleepimage
 powernap             1
 networkoversleep     0
 disksleep            10
 standbydelayhigh     4200
 sleep                0
 autopoweroffdelay    259200
 hibernatemode        25
 autopoweroff         1
 ttyskeepawake        1
 displaysleep         10
 highstandbythreshold 50
 lidwake              1

I don't know how to system to force into hibernating but it damn sure fixed idle sleep.

On the RTCMemoryFixup repo I read:

Offsets from 0x80 to 0xAB are used to store some hibernation information (IOHibernateRTCVariables). If any offset in this range causes a conflict, **you can exclude it, but hibernation won't work.

So, if I understand this correctly, with the boot-arg you added, hibernation shouldn't work.

Originally posted by @5T33Z0 in #43 (comment)

@5T33Z0
Copy link
Owner Author

5T33Z0 commented Dec 4, 2023

@5T33Z0 If I understand correctly with rtcfx_exclude=80-AB you are disabling the hibernation using the RTC memory that just causes a lot of trouble

And with HibernateMode set to NVRAM you are only using NVRAM to do the hibernation, that is way more stable than the old RTC stuff.

Yes I saw that when hibernating the only way to wake the laptop is with the power button, but also the lid sensor wakes it up, so maybe some ACPI fixes can fix that. The delays only apply when using hibernatemode=3 I think, you can also do some fine tunning with the boot args of HibernationFixup to set when and in what conditions the laptop goes to hibernate. And with hibernatemode=25 it always goes to hibernate Also I forgot to tell that the bios mode needs to be set to UEFI only, CSM disabled for hibernation to work

Originally posted by @jozews321 in #43 (comment)

@5T33Z0
Copy link
Owner Author

5T33Z0 commented Dec 4, 2023

@jozews321

If you say so.
[…]
After further testing in Big Sur and Sonoma, it seems that I don't need RTCMemoryFixup. Switching HibernateMode to NVRAM for Hibernation, adding the Reserved Memory region and adding DiscardHibernateMap solved idle sleep so the machine now enters hibernation on its own.

Originally posted by @5T33Z0 in #43 (comment)

@5T33Z0
Copy link
Owner Author

5T33Z0 commented Dec 4, 2023

@jozews321

If you say so.

In the OC Post-Install guide it says that you can also use the "RTC Blacklist" in NVRAM to enter the memory regions to exclude. But you have te enter every single region from 80 (128) to AB (170 manualy (43 regions). So: 8081828……A9AAAB. Not going to do that :D

After further testing in Big Sur and Sonoma, it seems that I don't need RTCMemoryFixup. Switching HibernateMode to NVRAM for Hibernation, adding the Reserved Memory region and adding DiscardHibernateMap solved idle sleep so the machine now enters hibernation on its own.

Yes I can confirm the RTC fixes are not necessary for me either. But now I had the issue that not matter what time I was setting in standbydelayhigh and standbydelaylow and using hibernatemode= 3, I wasn't getting the laptop to auto hibernate.

Turn out the fault was the Disable RTC wake scheduling kernel patch that was preventing the RTC to wake the laptop in the scheduled time, I enabled the patch a long time ago on my t430 because I was getting random wakes and I just figured that those random wakes were the stock values of standbydelayhigh and standbydelaylow and hibernatemode=3 that are set by default on a mbp SMBIOS trying to hibernate but unable to do it. So you should disable that kernel patch too, i see that you have that kernel patch enabled in your config too.

Now talking about other things, have you seen something like this when waking from sleep or booting macOS just before the login screen

PHOTO-2023-12-03-16-48-21 PHOTO-2023-12-03-16-48-20

The temporal solution is to go to sleep again and wake or use Shift + Control + eject(Insert) to turn the display on and off or closing the lid and opening it again. I've seen online people with T420, T430, X230, and more second and third gen Thinkpads but I haven't been able to find info on how to solve it, do you have any idea?

Originally posted by @jozews321 in #43 (comment)

@5T33Z0
Copy link
Owner Author

5T33Z0 commented Dec 4, 2023

I have never seen anything like this, sorry.

Yes, I've added the RTC Wake Scheduling patch in April as well because RTC/HID activity was waking the system all the time. But my concern is that the wake issue returns if I disable the patch.

@jozews321

I did some more testing today. Here are my results so far:

  • After changing Hibernatemode to NVRAM, idle sleep is working now
  • I don't meed the Reserved Memory region for the screen to wake
  • If I disable the "RTC Wake Schduling" patch, the system wakes when attempting to enter Hibernatemode 3 after the timer delay (standbydelayhigh, since the Laptop is connected to AC) has run out.
  • I've added hbfx-dump-nvram for HibernationFixup to save NVRAM to a file nvram.plist before hibernation and after kernel panic (with panic info) but it doesn't change anything.
  • I also set autopoweroff real short for testing (120 seconds), but it just stays in sleep instead of shutitng off

@jozews321
Copy link

@5T33Z0
No idea how setting HibernateMode to NVRAM fixed idle sleep for you, maybe it was because you had it on Auto, before fixing hibernation I had it on None and idle sleep worked fine

Try to make varios hibernations in a row that's when freezing after wake issues started to happen without the ReservedMemory region in my end.

In hibernationmode=3 it's normal that that the laptop darkwakes up when the time in standbydelayhigh elapses, in this moment it does the logic if it should enter hibernation or not, the main requirement to make a hibernation in this darkwake is to have the boot-arg hbfx-ahbm set to at least 1 if it's not set it's never going into hibernation and the laptop will just sleep again.
I have personally set hbfx-ahbm to 5 and both standbydelay to 10800 so it wakes up after 3 hours and only enters hibernation when it's disconnected from AC as doing many hibernations can cause excessive wear on the SSD and I mainly use my laptop docked and always connected

I've tried the NVRAM dump but it doesn't work for me either, maybe it needs the Debug version of the kext

As for autopoweroff this issue thread goes into detail in some of the things that HibernationFixup can't access acidanthera/bugtracker#2057 (comment)

@5T33Z0
Copy link
Owner Author

5T33Z0 commented Dec 4, 2023

Yes, I had Hibernatemodeset to Auto before.

hbfx-ahbm is set to 1

If I understand hibernation correctly, it should write the current system state to disk and turn it off after the autopoweroffdelay timer has elapsed. So my expectations were:

If I do nothing, the system enters sleep after x seconds, and after x more seconds of standbydelayhigh have passed is enters hibernation and after x more seconds for autopoeroff it then turns the system off.

Or am I missing something here in terms of dependencies? I think need to create a flowchart/organigram to fully understand it.

@jozews321
Copy link

jozews321 commented Dec 4, 2023

The flow goes like this:
With hbfx-ahbm to 1 for basic auto hibernation without logic and hibernatemode set to 3 and a standbydelayhigh and standbydelaylow of x (they need to be set to the same number), ignore autopoweroffdelay as it doesn't seem to do anything

  1. The laptop goes to sleep in x time if it was just idling without user intervention
  2. After x standbydelaylow/high time passes the laptop darkwakes by the RTC
  3. In the darkwake the laptop does the hibernation logic, in this case as hbfx-ahbm is set to 1, it will just start the process of hibernation and after it's done the laptop is essentially shut down not using any power (just the EC is running), but that is the case even if it's powered down without anything.
  4. You press the power button to turn on the laptop and restore the hibernation image

So this is what happens when using hbfx-ahbm=1 and hibernatemode 3, if using different hbfx-ahbm values it will hibernate or not hibernate depending on the values used, but that logic is always done in step 3.
If the conditions to hibernate are not met it will just sleep again at the end of step 3 and the process repeats from step 2 to 3 to 2 to 3 again until the hibernation conditions are met

@5T33Z0
Copy link
Owner Author

5T33Z0 commented Dec 4, 2023

Thanks for the explanations.

I think this flag might be helpful as well:

DisableStimulusDarkWakeActivityTickle = 128: Disable power event kStimulusDarkWakeActivityTickle in kernel, so this event cannot trigger a switching from dark wake to full wake

EDIT: So I disabled the RTC Wake Scheduler Kernel Patch and changed hbfx-ahbm to 129. Now the system no longer wakes involuntarily as it did before without the patch enabled.

Repository owner deleted a comment from flo-at-work Jun 27, 2024
Repository owner deleted a comment from flo-at-work Jun 27, 2024
Repository owner deleted a comment from flo-at-work Jun 27, 2024
Repository owner deleted a comment from flo-at-work Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants