5T33Z0 / Lenovo-T530-Hackintosh-OpenCore

OpenCore folder for running macOS High Sierra up to Sequoia on the Lenovo ThinkPad T530 Laptop.
BSD 3-Clause "New" or "Revised" License
93 stars 12 forks source link

Trying to fix Hibernation #48

Open 5T33Z0 opened 11 months ago

5T33Z0 commented 11 months ago

@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

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

Originally posted by @jozews321 in https://github.com/5T33Z0/Lenovo-T530-Hackintosh-OpenCore/issues/43#issuecomment-1837315676

5T33Z0 commented 11 months ago

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 https://github.com/5T33Z0/Lenovo-T530-Hackintosh-OpenCore/issues/43#issuecomment-1837418515

5T33Z0 commented 11 months ago

@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 https://github.com/5T33Z0/Lenovo-T530-Hackintosh-OpenCore/issues/43#issuecomment-1837486765

5T33Z0 commented 11 months ago

@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 https://github.com/5T33Z0/Lenovo-T530-Hackintosh-OpenCore/issues/43#issuecomment-1837504555

5T33Z0 commented 11 months ago

@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 https://github.com/5T33Z0/Lenovo-T530-Hackintosh-OpenCore/issues/43#issuecomment-1837627898

5T33Z0 commented 11 months ago

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:

jozews321 commented 11 months ago

@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 https://github.com/acidanthera/bugtracker/issues/2057#issuecomment-1201318837

5T33Z0 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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.