trulyspinach / SMCAMDProcessor

Power management, monitoring and VirtualSMC plugin for AMD processors
BSD 3-Clause "New" or "Revised" License
1.06k stars 90 forks source link

Power Tool - Incorrect behavior after waking from sleep #23

Closed robpneu closed 3 years ago

robpneu commented 4 years ago

After waking from sleep it seems that the Power Tool isn't reading all the cores properly. Here's a few gifs from some screen recordings I took.

After waking from sleep (notice how only the last bar moves): AMD-Power-Tool-After-Waking-up-from-Sleep-small

Another example after waking from sleep (after having rebooted to "reset it", see note below) AMD-Power-Tool-After-Waking-up-from-Sleep-2-small

After Reboot (expected/correct behavior): AMD-Power-Tool-After-Reboot-small

I wasn't able to get this part on video but it kind of looks all cores work for a split second and then the effective frequency freezes, where ever it is at that moment (except for the last core). This happens with or without speed adjustment enabled when the system is put/goes to sleep and is only resolved by rebooting the system. I am able to replicate this 100% of the time; it will works until I go to sleep, then it exhibits this odd behavior every subsequent time I wake from sleep (ie I can put it to sleep and wake it up a few minutes later and it's always stuck, only rebooting fixes it)

System: CPU: Ryzen 7 3700X Motherboard: Asus ROG X470 Crosshair VII (non-wifi) GPU: Radeon VII (not sure what else would be relevant, but I'd be happy to provide anything else)

trulyspinach commented 4 years ago

Hi @robpneu, thanks a lot for your feedback. I wasn’t realizing this issue as I haven’t setup my hackintosh to sleep yet. I am just wondering if AMD Power Gadget would continue to work correctly after wake up from sleep? Plus if you restart the application, will it start to working again?

EDIT: I have just checked your recording and seems like AMD Power Gadget is behaving as expected. And core frequency are also adjusted correctly. Can you confirm this?

robpneu commented 4 years ago

I believe Power Gadget is performing correctly before and after sleep (that is to say, it is displaying Frequency, Temperature, and Power, accurately I believe), but it is showing the issues that the Power Tool is causing.

I think the issue is with the effective frequency and demand graphs: if they get stuck the rest just reflects that being stuck. I haven't looked through your code but I suspect that the Automatic Speed Adjustment is depend on those to perform correctly. If you look at the first video (sorry for the terrible quality; GitHub has a 10 MB upload limit, and it had to be a gif) you can see that even under very little demand (I had purposefully killed almost everything else that was running), the frequency never goes below 3.71 GHz. In the second video, where there is a lot of demand (I purposefully tried to load the system in this test), it never goes above 2.46 GHz.

Quitting the whole program and reopening it does not fix the problem, only a reboot does. Power Gadget performs as normal but Power Tools remains stuck until after rebooting the whole system.

trulyspinach commented 4 years ago

Hi @robpneu. From this point I suspect this is caused by a reset in cpu topology defined by XNU after wake up from sleep. And the kext did not reconstruct its content with up to date changes. I can't get my Hackintosh sleep working so at this moment I am unable to reproduce this on my computer.

I will leave this open for now as I am current redoing the CPU configuration part in the kext as my plan. Hopefully this will be fixed automatically. For now I recommend you to not enabled auto adjustment to avoid issue with performance. It is still rather safe to use this only as a monitor 😄.

Plus, thanks you for your time writing this and making those Gifs!🤣

robpneu commented 4 years ago

Hi @robpneu. From this point I suspect this is caused by a reset in cpu topology defined by XNU after wake up from sleep. And the kext did not reconstruct its content with up to date changes. I can't get my Hackintosh sleep working so at this moment I am unable to reproduce this on my computer.

Seems logical to me. I've been through my share of issues with sleep (and mine still isn't perfect, but I'm mostly using it for now).

I will leave this open for now as I am current redoing the CPU configuration part in the kext as my plan. Hopefully this will be fixed automatically. For now I recommend you to not enabled auto adjustment to avoid issue with performance. It is still rather safe to use this only as a monitor 😄.

Will do! I was curious so I gave this a try; I have enough backup systems in place that even if it borked my system I'd be able to get it working again. Bugs like this are part of the process. I'm happy to do additional testing in the future.

Plus, thanks you for your time writing this and making those Gifs!🤣

I just wish Github didn't have as strict file size and type limitations. I have the full mov files if you'd like them uploaded to YouTube or just available online somewhere (google drive or something). I just got the gifs by trimming them to be smaller and throwing them into an online converter.

nvollmar commented 4 years ago

I've the same issue: last core is just staying at a high frequency after wakeup from sleep.

Workaround for me is just disabling and then enabling Automatic Speed Adjustment again, after that all cores are working properly again.

aluveitie commented 4 years ago

It took me about two months to get sleep working properly. For X570 mainboards there seems to be an issue with the XHC0 USB controller ending in a reboot when woken up. For me excluding that controller helped.

Interestingly, setting the Speed Step manually works after waking up. Just the automatic speed adjustment is not working anymore.

robpneu commented 4 years ago

It took me about two months to get sleep working properly. For X570 mainboards there seems to be an issue with the XHC0 USB controller ending in a reboot when woken up. For me excluding that controller helped.

I don’t think the issues with XHC0 controllers are limited to X570; my X470 Crosshair VII has similar issues. I can have the ports controlled by the XHC0 controller mapped but I can’t have anything plugged into any of those ports when the computer goes to sleep. My PTXH and AS43 controllers do not have that issue

trulyspinach commented 4 years ago

Though I still can't let my Hackintosh to sleep, please give the new release a try and see if this problem is fixed. Most functions related to frequency reading have been re-written so hopefully it don't have this issue anymore.

staking4ada commented 4 years ago

I tried the new release and indeed wake from sleep does not work correctly. 1 stuck core at 4.1GHz, all other cores reduce their speed. Average frequency reflects this (5 at min. speed, 1 at max). Switching off/on auto speed adjustment, or any other functions, including changing the values, does not solve it.

My system: Ryzen 5 3600, MSI B450M Mortar Max, High Sierra, Open Core, VirtualSMC, iStats

Thanks for an otherwise great powermgt solution!

aluveitie commented 4 years ago

Latest version behaves better, but still looks like a glitch in the read out:

Screenshot 2020-04-04 at 21 04 49

aluveitie commented 4 years ago

It must be a glitch reading out the frequency, waking up after 8 hours of sleep it has 21GHz on the first core :D

Screenshot 2020-04-09 at 20 42 59

aluveitie commented 4 years ago

@trulyspinach Do you have any hint where best to start looking into this?

trulyspinach commented 4 years ago

@aluveitie I cant get my Hackintosh to sleep so can not test any fixes. Some random guess for a potential fix: register to IOKit's power management event to get notified from sleeping and waking up. And re-init the some pm structures soon after wake up.

aluveitie commented 4 years ago

@trulyspinach Thanks, that sounds like a good idea. I'll try to look into it.

aluveitie commented 4 years ago

I have trouble including certain IOKit headers (file not found) even though they auto-complete and IOKit is added as required framework to the project.

Maybe you could have a quick look if you can spot the problem? https://github.com/aluveitie/SMCAMDProcessor/tree/wakeup-handling

trulyspinach commented 4 years ago

Auto complete doesn’t mean the header is provided. If you need any header it would be easier to just grab it from Apple’s open source repo and include it with “”

aluveitie commented 4 years ago

I was on the wrong path, that API is not available within the kernel. I've now the hook for entering/leaving sleep in place, but calling either pmRyzen_init or pmRyzen_PState_reset seems to actually make it worse. Then all cores are shown in a weird state... I guess I've to dive deeper into it.

Automata02 commented 4 years ago

Screenshot 2020-05-19 19 50 45 Screenshot 2020-05-19 19 46 15 I'm on the latest release (0.6.3), after resuming from sleep it seems like the tool can't enter low power state. Resetting options doesn't fix it, however I can still manually adjust the clock speed. It seems to boost to the maximum it can put out without any actual load.

aluveitie commented 4 years ago

I might have located the issue, just need to verify and test it.

staking4ada commented 4 years ago

The overall cosmetic feel with 0.6.3 is a lot better, however indeed after wake from sleep frequency graph in tool and gadget are off. manual freq change works, judging from temp and power.

cpu fan works great, including manual adjustment, however rpm not visible in imenu stats, but perhaps i need to look into this myself further.

aluveitie commented 4 years ago

@staking4ada A first fix for the sleep issue has been merged for the next version that should fix it in most cases.

LuHugo commented 4 years ago

Hi, while it's not quite appropriate to talk about other issues with hackintosh here, I really want to know how to get hackintosh to sleep and this issue has been bothering me for a month now. My hackintosh can't wake up after sleeping and can only restart it. This is the crash message

Sleep transition timed out after 180 seconds while calling power state change callbacks. suspected bundle: com.apple.iokit.IOUSBHostFamily. Thread 0x1a92.

Do I need to customize my own USB MAP?

My CPU is a ryzen 3900x and the motherboard is gigabyte x570 aorus pro wifi.

aluveitie commented 4 years ago

@LuHugo I'd be happy to help but opening a thread at https://forum.amd-osx.com would be a better place to start that discussion

LuHugo commented 4 years ago

@aluveitie Thanks. I'll check it out.

trulyspinach commented 4 years ago

@staking4ada Yes those fan infomations are currently only visible in the software as it is not registered to VirtualSMC.

So some feature still not work after wake up from sleep?

trulyspinach commented 3 years ago

I am, so excited to announce that😎: this issue that existed since the beginning of this project have finally resolved in the latest release! Please check it out

Feel free to open up a new issue if the still happen to you.