syscl / XPS9350-macOS

macOS patches for Dell XPS 13 9350 (Skylake)
916 stars 74 forks source link

HWP + Sleep => KILLL #26

Open JackGlobetrotter opened 7 years ago

JackGlobetrotter commented 7 years ago

Hey, i used the patches etc.. i have used sleep once. After restart my partition died.. is that normal?

syscl commented 7 years ago

@JackGlobetrotter I've noticed this issue long time ago, there's nothing to do with HWP enable. More like sleep + nvme patch cause the issue.

Detail discussion can be found [here] (https://github.com/darkhandz/XPS15-9550-Sierra/commit/72f63339ff088dabe2bc9281b5f1a3dbe181ad31), the content is in Chinese.

In all, this problem

It's pretty tough for us to find the bug, because once data lost, how to see the log?

Suggestion till now:

syscl

x4080 commented 7 years ago

How about disabling write on hibernate?

syscl commented 7 years ago

@x4080 notice this piece of code in deploy.sh

_tidy_exec "sudo pmset hibernatemode ${gTarHibernateMode}" "Change hibernatemode from ${gOrgHibernateMode} to ${gTarHibernateMode}"

That disable hibernate write to disk, but I am not sure if this help prevent data corrupted.

syscl

x4080 commented 7 years ago

Ah I see, what I did was :

    sudo pmset -a hibernatemode 0
sudo rm /var/vm/sleepimage
sudo touch /var/vm/sleepimage
sudo chflags uchg /var/vm/sleepimage

I didn't have that sleep problem (but maybe I rarely do sleep)

syscl commented 7 years ago

@x4080 I rarely do sleep on XPS 13 9350 too. But it's a very convince function, especially when you open the lid then all the work pop on your screen.

I posted comment for Piker already, wish he could give us some light on this problem...

syscl

R1MnTnA commented 7 years ago

@syscl do you also have "sudo pmset -a disksleep 0" set in your script or would you recommend we do that? I believe this is the same thing as if you were to go to System Preferences>Energy Savings and uncheck the put hard disks to sleep, correct?

syscl commented 7 years ago

@R1MnTnA see the piece code in deploy.sh

 _tidy_exec "sudo pmset hibernatemode ${gTarHibernateMode}" "Change hibernatemode from ${gOrgHibernateMode} to ${gTarHibernateMode}"

Deploy.sh has already included what you want.

syscl

R1MnTnA commented 7 years ago

@syscl Yes I noticed that part, thank you, very smart to do that, but I was referring to- sudo pmset -a disksleep 0

syscl commented 7 years ago

@R1MnTnA What this mean? Disk never sleep?

syscl

R1MnTnA commented 7 years ago

@syscl, yes. it is to turn off/disable the sleep option for the ssd. Because if it goes to sleep it might cause data corruption and since it the ssd uses very little power, it doesn't need to sleep.

syscl commented 7 years ago

@R1MnTnA Thank you for your suggestion, I will try to add this command line in deploy.sh at this stage. Though the finally solution should be that we figure out what cause the data lose.

Thank you, syscl

R1MnTnA commented 7 years ago

@syscl Yes, that is why I think this is the problem. By not disabling disksleep you can start to have data corruption if the power is cut off to the ssd while it's trying to write

syscl commented 7 years ago

@R1MnTnA Actually we still have no clues if this will work or not. In theory, if disk sleep causes the problem, then our life will be much easier.

@R1MnTnA do you have evidence you never encounter data corrupt when you disable disk sleep? We need more information and corruption cases to figure out what's wrong.

syscl

R1MnTnA commented 7 years ago

@syscl okay. I will investigate and test it out further. I know that if power is cut off to the ssd abruptly or when the computer goes to sleep and doesn't finish writing to the ssd, then that's when you can have data corruption. Also just as a FYI: I read on the forums by @rehabman that if you have a dual boot system with Windows and have installed the Paragon HFS+ software then this will also cause data corruption in Mac OS.

syscl commented 7 years ago

@R1MnTnA I never use Paragon HFS+ which caused my data lose 7 years ago. It will also cause sleep issue as well. He just told you the stories he heard from others, but I just showed my disaster experience.

That's it, syscl

syscl commented 7 years ago

Though it will be possible to cause data lose. But from my observation, it's not that easy as you imagine. If NVMe halt abruptly, why the whole FS structure get corrupted? HFS+ has the journey to restore data in this cases. What I'm afraid is that there's bugs when macOS sleep XPS 13 such that macOS writes information in wrong block then corrupted metadata block. Because all the cases I've seen so far are quiet similar: their FS structure corrupted.

syscl

R1MnTnA commented 7 years ago

Oh, okay. Now I understand. That is crazy. I will try to help and test why or how this could happen. Also I'm wondering if possible if the TRIM in Mac os is Trimming/writing over the wrong blocks. This happened in a Linux kernel depending on the ssd. Thank you for all your work on it so far.

syscl commented 7 years ago

@R1MnTnA I want to test sleep frequently to see what's going on. But because I use XPS 13 as daily drive now, I need to test it later, because a lot of important information are now on this laptop.

syscl

R1MnTnA commented 7 years ago

@syscl also I remember we had do this on old versions of OS, but do we still need to do this command- "sudo TRIMforce enable" or is it not necessary?

svindled commented 7 years ago

@R1MnTnA I do believe if you're running what the OS thinks is a supported SSD you don't have to. I have a Samsung PM961 and TRIM is enabled by default for supported SSDs in macOS. I do believe that it's probably because of Clover's kext patching though. If you look in system profiler and go to either the SATA section if you have a regular SATA M.2 SSD or the NVM Express section if you have an NVMe M.2 SSD it'll say in there if TRIM is supported or not. If it says No in the TRIM Supported section then you'll have to run sudo TRIMForce enable

R1MnTnA commented 7 years ago

@squash- Ok, makes sense. Thank you. I have the Toshiba and it is TRIM supported in system profile.

bozma88 commented 7 years ago

I think to have discovered something. I think corruption is strictly related to hibernatemode 3 (active).

Background story: For one month I used my 9360 without HWP nor ssdtprgen. Pure vanilla ssdts. Power mamagement was working very well, verified with AppleIntelInfo logs. Hibernatemode set to 0. Slept the machine hundreds of times.

Then I played with HWP and I discovered that everytime you turn on/off HWP (by injecting/removing plugin-type on CPU-0) AND everytime you make changes to frequencyvectors or other plist Power management settings, hibernatemode is automatically reset to 3. Yesterday the PC slept for 12+ hours, HWP had just been disabled but I forgot to reset hibernatemode to 0. Sleep-wake continued to work good, but the first time I restarted the machine I got unrecoverable file system corruption and I had to recover from a TimeMachine backup.

What are your thoughts on this?

mircoianese commented 7 years ago

@bozma88 I was trying to get hibernation working on my 9350 too to test about data corruption. I did hundred of sleeps too and got no problem at all. Then I set hibernatemode to 25 to test pure hibernation. The result I got was Clover not recognising the bootable drive as "hibernated" (couldn't find sleepimage offset according to boot.log). I tried to hibernate many many times and sometimes I discovered some "data corruption". Office suite for example was not working anymore, Apps randomly crashing and Siri voice damaged. Well, strange things. Yesterday I checked with an Hex Editor the sleepimage code and found out that it was made only of zeroes. So I deleted it and put the laptop back to hibernation. At boot (clean boot as clover didn't recognised the sleepimage) I got the Hex Editor software (and the dmg file I've downloaded seconds before) both damaged. Sleepimage file was still made out of zeroes.

So, I think that for some reason while hibernating is not writing RAM things in correct sectors, and I think this is something related to NVMe drive. So, I think we can confirm sleep has no problem at all, I would like to find out how to fix this up.

bozma88 commented 7 years ago

I have no problem in keeping hibernation disabled. 9360 in pure sleep draws 1% of battery every 3-5 hours.

My main concern is that it seems that some actions (changing hwp or other system settings) reset hibernatemode to 3.

I did read a lot of reports, all of them say the very same things:

No-one told: "I got corruption after installing the OS, disabling hibernatemode and not doing any further patching or system update after that".

So, @syscl, I think the issue can be solved by proactively doing some checks, maybe writing hibernatemode 0 every time the mac prepares for sleep.

What do you guys think?

x4080 commented 7 years ago

@bozma88 , is 7th gen intel working ok with mac os?

syscl commented 7 years ago

Nice discover and now the switch SMBIOS may cause data corruption make sense!

Thank you @bozma88 @ZombieTheBest @R1MnTnA @squash- ! You all are awesome, I will keep updating ASAP. Till now my assignments and exams are going crazy... I am sorry for my late reply, but I appreciate to all your work! Will be back later!

Have a great day, syscl

mircoianese commented 7 years ago

@syscl As i reported in issue #49, adding pmset -a hibernatemode 0 in sleepwatcher script fixes the hibernatemode changes. Of course i don't know if this optimal solution, but at least it works and avoid data corruption while sleeping! Good luck with your exams!! đź‘Ť

syscl commented 7 years ago

@ZombieTheBest Yes, that's what I plan to do next :)

Hibernate 0 is a super fast and better sleep method IMO. But we need to confirm if the system read hibernate mode = 0 before we set it or after we set it to 0. Just like what @bozma88 worry about as well.

@bozma88 Does the hibernate mode very easy to be reset by system? I mean if I stick to MacBookPro13,2 with HWP, will hibernate mode be reset to 3 later?

Thank you, syscl

mircoianese commented 7 years ago

@syscl i tested it by setting hibernatemode to 25, then I put my laptop in stop. It didn't hibernate, it just goes to sleep, proving that (if i was not lucky) pmset -a hibernatemode 0 is triggered before that the OS reads the value. I don't know if this is it for 100% cases.

syscl commented 7 years ago

@ZombieTheBest Sorry I don't get it.

So, if sleep watcher + set hibernate mode = 25, then:

I mean if we need to confirm sleepwatcher + set hibernate = value works, we can try to set hibernate mode = 25 then put laptop sleep. Once we wake it up, it should do a fresh boot right? I don't know what will happen when set hibernate mode = 25.

Thank you, syscl

mircoianese commented 7 years ago

@syscl No, sorry i explained that bad. In Sleepwatcher script i wrote: pmset -a hibernatemode 0. I tried then to set in Terminal hibernatemode to 25, to see if hibernatemode 0 in sleep watcher was set BEFORE that the laptop reads my hibernatemode 25 value. The laptop went to sleep (and not hibernation), so this prove's that hibernatemode is set to zero by sleep watcher before that the OS reads it :)

Btw yes, hibernatemode 25 results in fresh boot as sleepimage gets corrupted. That's why script in sleep watcher is working: laptop did not hibernated, it went to sleep

syscl commented 7 years ago

@ZombieTheBest Nice!

Will try to merge it ASAP!! Because I really miss sleep function on XPS 13 93x0 :) LOL

Now, we can say, enjoy your sleep on XPS 13, LOL!

syscl

R1MnTnA commented 7 years ago

@syscl Found these instructions and info on the macrumors forum, not sure if they they might help or maybe you are already aware of this.-

  1. set hibernate mode to 0 sudo pmset -a hibernatemode 0 hibernationmode 0 is normal sleep, data kept in ram, nothing written to disk
  2. delete the unnecessary sleep file (since hibernate is disabled) to regain disk space equal to memory (saves the same amount of disk space as your RAM, eg. 8 GBs, valuable on an SSD), You can use the Go to folder menu to delete the file, found in the /var/vm/ folder, and named sleepimage. Reboot and simply delete that file,. Or use this: sudo rm /var/vm/sleepimage or sudo rm /private/var/vm/sleepimage The sleep image file is actually in /Private/var/vm/ but /var/vm/ is a symbolic link to that location. Optional: Create a blanked zero-byte file so the OS cannot rewrite the file: sudo touch /private/var/vm/sleepimage Make file immutable:
  3. sudo chflags uchg /private/var/vm/sleepimage or 2. sudo ln -s //dev/null/var/vm/sleepimage

If pmset -g shows: autopoweroff**1, disable this automatic hibernation mode (happens even if hibernation mode is set to 0 on the new Mac mini 2012 and iMac) sudo pmset -a autopoweroff 0

  1. set the safe sleep timer (standbydelay) to 20 hours, default is 4200 (1.67 hr) sudo pmset -a standbydelay 72000
  2. sudo pmset -a standby 0
R1MnTnA commented 7 years ago

As a side note to help tweak the NVMe/ssd, so it has less wear I use this script/launchdaemon I found on http://sysadmin.flakshack.com/post/9253439680/ssd-tweaks-for-mac-os-x

"Disable file access time tracking

Normally the Mac will keep track of the last time any file was accessed. This contributes to the wear on the SSD drive, so it is helpful to disable it."

sudo touch /Library/LaunchDaemons/com.noatime.root.plist

Edit the file and paste the following:

<?xml` version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
    <dict> 
        <key>Label</key> 
        <string>com.noatime.root</string> 
        <key>ProgramArguments</key> 
        <array> 
            <string>mount</string> 
            <string>-uwo</string> 
            <string>noatime</string> 
            <string>/</string> 
        </array> 
        <key>RunAtLoad</key> 
        <true/> 
    </dict> 
</plist>

Reboot and confirm the setting with:

mount | grep noatime

/dev/disk0s2 on / (hfs, local, journaled, noatime)

"Adjust Spotlight settings"

"Spotlight is the Mac’s indexer and search tool. While a lot of people just disable this service (sudo mdutil -a -i off), I need Spotlight because Outlook 2011 uses it for searching my Outlook data."

R1MnTnA: Personally I don't use Spotlight so I disable it using the above command.

To adjust this setting, go to System Preferences…Spotlight…Privacy. If you exclude directories that change frequently, you’ll save wear on your SSD. For example, I excluded:

/Library/Caches ~/Library/Caches /Library/Application Support/Riverbed/Steelhead Mobile/datastore ~/Downloads ~/Documents/Parallels (where I store my VMs)

mircoianese commented 7 years ago

@syscl That's right! And soon we will have SD Card support too! :D

bozma88 commented 7 years ago

@x4080, KBL works perfectly with CPU+GPU hw id spoof, as it's only a sidegrade (rebrand). @R1MnTnA, I think speed and over-provisioning of current-gen SSDs make this action not worth it. @syscl, I did encounter PM settings reset only when changing configs, so you should (?) be fine.

>> IDEA <<

If we could be able to decode the whole content of SleepPolicy plist var, we could craft a sleeppolicy where hibernatemode, autopoweroff and darkwake are 0 by default for the platform we are targeting in SMBIOS. This, combined with plist injection, would prevent hibernatemode (and potentially darkwake) taking wrong default values even in case of OS upgrades.


As a side note, I just discovered that our laptop has real, working hardware NVRAM, so emulation via EmuVariableUEFI driver shouldn't be needed. I am doing some research. EDIT: If I remove EmuVariableUEFI, WIFI+BT stop working after resume from sleep.

x4080 commented 7 years ago

@bozma88 Cool

We got another progress here

bozma88 commented 7 years ago

screen shot 2017-02-28 at 00 57 34

We have to investigate these values. In some cases, deleting them may disable them, in others the key absence may lead to a default value taking place (that's not what we want).

mircoianese commented 7 years ago

@syscl Tested hibernatemode fix. Working đź‘Ť

bozma88 commented 7 years ago

@syscl, there's more to do and to investigate.

Read here: https://en.wikipedia.org/wiki/Pmset

Autopoweroff (AC power) - Where supported, enabled per default as an implementation of Lot 6 to the European Energy-related Products Directive. After sleeping for autopoweroffdelay minutes, the system will write a hibernation image and go into a lower power chipset sleep. Wakeups from this state will take longer than wakeups from regular sleep. The system will not auto power off if any external devices are connected, if the system is on battery power, or if the system is bound to a network and wake for network access is enabled.

With autopoweroff enabled the machine will got into hibernate mode even if hibernatemode is 0.

My advice, also referring to commits de84079261a411a38235d28ab877dd17ed6d87c8 and 6de921c4b19a48d97bd0d4e4b2ef87a6b3a79e3e, is:

OR, better

bozma88 commented 7 years ago

@ all, please attach here sudo pmset -g log output. I am especially interested in log from a machine with HWP enabled and that shows initial signs of data corruption. I want to check whether system performed DarkWake cycles or other powerNap related operations during sleep. I still think it's a darkwake event with scrambled/corrupted memory that destroys data.

mircoianese commented 7 years ago

@bozma88 Laptop slept almost 10 hours this night. HWP enabled, had some signs of data corruption few days ago (before applying the autopoweroff patch). Here's my peset log.

pmset_log.txt

bozma88 commented 7 years ago

Gosh... just look at here (one of many instances):

Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :72 Dark Wake Count in this sleep cycle:71

2017-03-07 11:30:14 +0100 DarkWake DarkWake from Normal Sleep [CDN] due to /HID Activity: Using BATT (Charge:94%) 1 secs

My 9360 without HWP and without custom SSDT-pr has always 0 Darkwakes.

mircoianese commented 7 years ago

@bozma88 I usually have something like 2-3% battery drain during night sleep, so not so bad even with all those dark wakes. I think we should try without HWP, to see if it's even better

bozma88 commented 7 years ago

I am not questioning the power impact of these, but the eventuality that they are the cause of corruption. What we do know is that a system without darkwakes and autopoweroff (like mine) does not exhibit data corruption.

@ all, please post this log: pmset -g everything and list your sleep and PM configuration (HWP or not, autopoweroff 0 or 1). Thank you.

syscl commented 7 years ago

Thank you @bozma88 , awesome discovery, here's the log from my XPS 13 9350 pmlog.txt

Here's the dark wake cycle:

syscls-MacBook:~ syscl$ grep -i 'Dark Wake Count in this sleep cycle:' /Users/syscl/Desktop/pmlog.txt 
Sleep/Wakes since boot at 2017-02-21 09:51:15 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 10:58:57 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 11:24:22 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 13:01:36 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 13:06:38 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 13:14:57 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 13:21:08 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 14:27:23 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 14:52:36 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 14:54:54 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 15:09:22 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 15:27:29 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-21 17:44:54 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-22 00:04:41 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-22 00:23:11 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-22 00:35:20 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-22 10:39:14 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-22 21:30:57 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-22 21:33:25 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-22 21:34:47 -0600 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-02-22 21:34:47 -0600 :1   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-22 21:34:47 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-22 21:49:13 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-22 21:49:13 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-22 21:52:53 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-22 21:52:53 -0600 :1   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-23 23:29:23 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-25 15:04:33 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-27 10:03:43 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 09:05:30 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :1   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :2   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :3   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :4   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :6   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :0   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :7   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :8   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 10:01:54 -0600 :9   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 23:34:50 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-02-28 23:38:14 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-02 04:51:24 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-02 05:19:06 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-02 05:19:06 -0600 :1   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-02 05:19:06 -0600 :2   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-02 05:19:06 -0600 :4   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-03-02 05:19:06 -0600 :5   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-03 13:08:03 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-03 14:15:58 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-03 14:23:03 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 09:16:51 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 09:22:17 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 10:03:17 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 10:20:13 -0600 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-06 09:17:05 -0600 :0   Dark Wake Count in this sleep cycle:1
syscls-MacBook:~ syscl$ 

Due to @bozma88 and @ZombieTheBest , the data corruption seems more clear! In my case, there's at most a very small amount of sleep cycle, but after @ZombieTheBest 's little corruption, there's an abnormal value(71).

Here's @ZombieTheBest 's dark wake cycle:

syscls-MacBook:~ syscl$ grep -i 'Dark Wake Count in this sleep cycle:' ~/Downloads/pmset_log.txt 
Sleep/Wakes since boot at 2017-03-01 11:26:31 +0100 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-03-01 11:31:55 +0100 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-03-01 11:34:26 +0100 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-03-01 11:41:17 +0100 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-03-01 11:47:07 +0100 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-03-01 14:55:28 +0100 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-03-01 15:07:31 +0100 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :0   Dark Wake Count in this sleep cycle:0
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :1   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :72   Dark Wake Count in this sleep cycle:71
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :0   Dark Wake Count in this sleep cycle:71
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :73   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :75   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :77   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :78   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-01 17:29:58 +0100 :95   Dark Wake Count in this sleep cycle:17
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :0   Dark Wake Count in this sleep cycle:17
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :0   Dark Wake Count in this sleep cycle:17
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :3   Dark Wake Count in this sleep cycle:3
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :10   Dark Wake Count in this sleep cycle:7
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :11   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :12   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :14   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :16   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :18   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :19   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-02 19:48:14 +0100 :20   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-04 05:42:00 +0100 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-04 23:14:10 +0100 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-04 23:22:36 +0100 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-04 23:26:59 +0100 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 10:53:41 +0100 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 10:53:41 +0100 :1   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 10:53:41 +0100 :2   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 10:53:41 +0100 :3   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 19:48:56 +0100 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:12:05 +0100 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :0   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :1   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :8   Dark Wake Count in this sleep cycle:7
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :9   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :11   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :12   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :13   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :14   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :15   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :18   Dark Wake Count in this sleep cycle:3
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :19   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :21   Dark Wake Count in this sleep cycle:2
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :22   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :23   Dark Wake Count in this sleep cycle:1
Sleep/Wakes since boot at 2017-03-05 20:16:02 +0100 :25   Dark Wake Count in this sleep cycle:2

Once again, thank you @bozma88 for the discovery and thank you for the test data @ZombieTheBest !

syscl

bozma88 commented 7 years ago

Now we have to disable darkwake services, hibernation and autopoweroff in the above plist, to prevent the system from powering up in a darkstate (to hiberante, system has to wake up, sale RAM and power down.. and it does that in a darkwake session). My feeling is that there are some ACPI power states that get activated only during darkwakes that corrupt the RAM where open files are located. These files are then flushed to the HDD in a corrupted state.

syscl commented 7 years ago

@bozma88 Pay attention to kDarkWakeFlagIgnoreDiskIOAlways

static uint32_t  gDarkWakeFlags = kDarkWakeFlagHIDTickleNone | kDarkWakeFlagIgnoreDiskIOAlways;

enum {
    kDarkWakeFlagHIDTickleEarly      = 0x01, // hid tickle before gfx suppression
    kDarkWakeFlagHIDTickleLate      = 0x02, // hid tickle after gfx suppression
    kDarkWakeFlagHIDTickleNone      = 0x03, // hid tickle is not posted
    kDarkWakeFlagHIDTickleMask      = 0x03,
    kDarkWakeFlagIgnoreDiskIOInDark  = 0x04, // ignore disk idle in DW
    kDarkWakeFlagIgnoreDiskIOAlways  = 0x08, // always ignore disk idle
    kDarkWakeFlagIgnoreDiskIOMask    = 0x0C,
    kDarkWakeFlagAlarmIsDark        = 0x0100
};

There will be more interesting things to find. Thus, I think disable dark wake may not be necessary, only disable flag related Disk will be better from my point of view. Here's the flag we need to disable:

    kDarkWakeFlagIgnoreDiskIOInDark  = 0x04, // ignore disk idle in DW
    kDarkWakeFlagIgnoreDiskIOAlways  = 0x08, // always ignore disk idle
    kDarkWakeFlagIgnoreDiskIOMask    = 0x0C,

syscl

mircoianese commented 7 years ago

@syscl Hi. I'm not sure that the abnormal dark wake count is related to my little data corruption. I first discovered the data corruption on May 4/May 5 in my Google Drive folder. And not only the apps that I had opened were damaged, even "MaciASL", that I never opened in this hackintosh (so surely was not in ram). When I got the data corruption autopoweroff fix was not out. If you need I can send here a damaged app, so you can see if could be related to sleep đź‘Ť

Ps: before clean install I got Siri Italian Voice damaged and "Audio pop sound when changing volume", so the "files in RAM theory" seems quite good for me :)

bozma88 commented 7 years ago

Here's my sleep log for reference. I have no HWP, no SSDT-pr, so PM is not (fully) OS-managed.

sleep_log_incomplete_PM.txt

Look at this, for example:

Mine: 2017-03-02 09:14:27 +0100 Sleep Entering Sleep state due to 'Clamshell Sleep': Using Batt (Charge:79%) 11 secs

Yours: 2017-02-22 21:35:39 -0600 Sleep Entering Sleep state due to 'Clamshell Sleep':TCPKeepAlive=active Using Batt (Charge:38%) 3 secs