calasanmarko / TurboMac

Stops CPU throttling on Intel-based Macs
GNU General Public License v3.0
56 stars 7 forks source link

Doesn't look like working at all #5

Open axxonadmin opened 2 years ago

axxonadmin commented 2 years ago

High Sierra,

Several screens of errors after running [CatalinaAndBelowInstall.command] The script tries to run kmutil at the end, but there's no such utility in High Sierra. Of course it doesn't load any kext

calasanmarko commented 2 years ago

It shouldn't make a difference whether kmutil runs on older versions because kextutil runs anyway in the script. I will remove it for clarity though.

Try manually running sudo kextutil -v /Library/Extensions/TurboMac.kext, and post the output here. I assume it doesn't show up when you run sudo kextstat | grep TurboMac, but double-check just to be sure.

Telling me what hardware you're running will also help.

gzmarchenko commented 2 years ago

Macbook Pro 15" mid 2010 (macbook6,2) High Sierra 10.13.6

`MacBook-Pro-zgen:~ zgen$ sudo kextutil -v /Library/Extensions/TurboMac.kext Defaulting to kernel file '/System/Library/Kernels/kernel' Notice: /Library/Extensions/TurboMac.kext has debug properties set. Kext with invalid signatured (-67050) allowed: <OSKext 0x7fec6fe02360 [0x7fffa13aaaf0]> { URL = "file:///Library/Extensions/TurboMac.kext/", ID = "calasanmarko.TurboMac" } /Library/Extensions/TurboMac.kext - no compatible dependency found for com.apple.kpi.iokit. /Library/Extensions/TurboMac.kext - no compatible dependency found for com.apple.kpi.libkern. /Library/Extensions/TurboMac.kext - no compatible dependency found for com.apple.kpi.iokit. /Library/Extensions/TurboMac.kext - no compatible dependency found for com.apple.kpi.libkern. /Library/Extensions/TurboMac.kext - no compatible dependency found for com.apple.kpi.iokit. /Library/Extensions/TurboMac.kext - no compatible dependency found for com.apple.kpi.libkern. Code Signing Failure: code signature is invalid Warnings: Personality matches on IOResources but IOMatchCategory is missing or not equal to its IOClass; driver may be blocked from matching or may block others: TurboMac

Dependency Resolution Failures: Only incompatible kexts found for these libraries: com.apple.kpi.iokit com.apple.kpi.libkern

Diagnostics for /Library/Extensions/TurboMac.kext: Warnings: Personality matches on IOResources but IOMatchCategory is missing or not equal to its IOClass; driver may be blocked from matching or may block others: TurboMac

Dependency Resolution Failures: Only incompatible kexts found for these libraries: com.apple.kpi.iokit com.apple.kpi.libkern`

calasanmarko commented 2 years ago

I found the issue. I had developed this on Monterey, and as such had forgotten to fix the dependencies in Info.plist so that they are compatible with older versions of the OS, which is why you see all the dependency errors.

Bug is fixed as of https://github.com/calasanmarko/TurboMac/commit/d0c49db71e84462a1aa236db72b9a60196b6bd3a. It should work now on versions at least as old as Mountain Lion. If you have an even older version follow up and we'll see if we can get it working.

Please tell me if it works now so I can finalize it as a release.

gzmarchenko commented 2 years ago

MacBook-Pro-zgen:Build zgen$ sudo kextutil -v /Library/Extensions/TurboMac.kext Defaulting to kernel file '/System/Library/Kernels/kernel' Notice: /Library/Extensions/TurboMac.kext has debug properties set. Kext with invalid signatured (-67030) allowed: <OSKext 0x7fca04d1d510 [0x7fffa37fbaf0]> { URL = "file:///Library/Extensions/TurboMac.kext/", ID = "calasanmarko.TurboMac" } Code Signing Failure: code signature is invalid Warnings: Personality matches on IOResources but IOMatchCategory is missing or not equal to its IOClass; driver may be blocked from matching or may block others: TurboMac

Warnings: Personality matches on IOResources but IOMatchCategory is missing or not equal to its IOClass; driver may be blocked from matching or may block others: TurboMac

/Library/Extensions/TurboMac.kext appears to be loadable (not including linkage for on-disk libraries). Loading /Library/Extensions/TurboMac.kext. (kernel) kxld[calasanmarko.TurboMac]: The super class vtable 'ZTV9IOService' for vtable 'ZTV8TurboMac' is out of date. Make sure your kext has been built against the correct headers. (kernel) Can't load kext calasanmarko.TurboMac - link failed. (kernel) Failed to load executable for kext calasanmarko.TurboMac. (kernel) Kext calasanmarko.TurboMac failed to load (0xdc008016). (kernel) Failed to load kext calasanmarko.TurboMac (error 0xdc008016). Failed to load /Library/Extensions/TurboMac.kext - (libkern/kext) link error. Failed to load /Library/Extensions/TurboMac.kext - (libkern/kext) link error. Check library declarations for your kext with kextlibs(8).

calasanmarko commented 2 years ago

So apparently a rebuild was necessary. I rebuilt it using acidanthera's MacKernelSDK as of https://github.com/calasanmarko/TurboMac/commit/ca21193ffa14a0e7a26a656fbb87278c5185ff48. If it still doesn't work, then I'll have to download an older version of Xcode and use it to rebuild the kext.

I would try all of this myself but I only have Monterey running.

axxonadmin commented 2 years ago

This mac is accessible over IPv6 address. If you're able to connect using IPv6 I'd provide you with access to it directly. But you know, it's a little bit slow ;)

gzmarchenko commented 2 years ago

sudo kextutil -v /Library/Extensions/TurboMac.kext Defaulting to kernel file '/System/Library/Kernels/kernel' Notice: /Library/Extensions/TurboMac.kext has debug properties set. Kext with invalid signatured (-67050) allowed: <OSKext 0x7ffc89c41f20 [0x7fffa33bcaf0]> { URL = "file:///Library/Extensions/TurboMac.kext/", ID = "calasanmarko.TurboMac" } Code Signing Failure: code signature is invalid Warnings: Personality matches on IOResources but IOMatchCategory is missing or not equal to its IOClass; driver may be blocked from matching or may block others: TurboMac

Warnings: Personality matches on IOResources but IOMatchCategory is missing or not equal to its IOClass; driver may be blocked from matching or may block others: TurboMac

/Library/Extensions/TurboMac.kext appears to be loadable (not including linkage for on-disk libraries). Loading /Library/Extensions/TurboMac.kext. (kernel) kxld[calasanmarko.TurboMac]: The ZTV8TurboMac is unpatchable because its class declares the method 'ZN8TurboMac4freeEv' without providing an implementation. (kernel) Can't load kext calasanmarko.TurboMac - link failed. (kernel) Failed to load executable for kext calasanmarko.TurboMac. (kernel) Kext calasanmarko.TurboMac failed to load (0xdc008016). (kernel) Failed to load kext calasanmarko.TurboMac (error 0xdc008016). Failed to load /Library/Extensions/TurboMac.kext - (libkern/kext) link error. Failed to load /Library/Extensions/TurboMac.kext - (libkern/kext) link error. Check library declarations for your kext with kextlibs(8).

calasanmarko commented 2 years ago

The Monterey version of Xcode for some reason doesn't let me use an old SDK, so I guess I'll have to downgrade to an older OS, and try building it from there. No need for any remote access, thanks for the offer though.

I'll get back to you in a couple of hours. Sorry for the trouble!

calasanmarko commented 2 years ago

https://github.com/calasanmarko/TurboMac/commit/0170ed4a0f0f8b8baec731376bcf28dbad60df17 has been built using the 10.8 SDK. Tested working on both 10.13 (High Sierra) and 12.2 (Monterey) with no issues, so you should have no trouble now.

gzmarchenko commented 2 years ago

Thank you!

It loads just fine, but CPU freq stays 1.197.07 Mhz (Instead of 2.53Ghz i5) :(

gzmarchenko commented 2 years ago

checked using powermetrics

Processor usage

System Average frequency as fraction of nominal: 47.31% (1197.07 Mhz) Package 0 C-state residency: 0.00% (C2: 0.00% C3: 0.00% C6: 0.00% C7: 0.00% )

Core 0 C-state residency: 0.00% (C3: 0.00% C6: 0.00% C7: 0.00% )

CPU 0 duty cycles/s: active/idle [< 16 us: 173.67/257.01] [< 32 us: 99.92/108.32] [< 64 us: 141.09/87.13] [< 128 us: 153.68/60.15] [< 256 us: 143.89/86.13] [< 512 us: 89.13/71.95] [< 1024 us: 28.58/62.55] [< 2048 us: 76.34/94.13] [< 4096 us: 23.38/80.54] [< 8192 us: 9.99/32.78] [< 16384 us: 0.80/0.00] [< 32768 us: 0.20/0.00] CPU Average frequency as fraction of nominal: 47.31% (1197.07 Mhz)

CPU 1 duty cycles/s: active/idle [< 16 us: 213.84/38.97] [< 32 us: 54.76/51.36] [< 64 us: 60.95/54.96] [< 128 us: 37.77/40.57] [< 256 us: 43.97/61.35] [< 512 us: 33.57/29.58] [< 1024 us: 22.38/29.38] [< 2048 us: 14.19/42.77] [< 4096 us: 6.40/54.36] [< 8192 us: 3.20/76.14] [< 16384 us: 0.00/10.19] [< 32768 us: 0.00/1.40] CPU Average frequency as fraction of nominal: 47.31% (1197.07 Mhz)

Core 1 C-state residency: 0.00% (C3: 0.00% C6: 0.00% C7: 0.00% )

CPU 2 duty cycles/s: active/idle [< 16 us: 204.05/271.39] [< 32 us: 64.55/81.54] [< 64 us: 113.31/62.15] [< 128 us: 138.30/57.56] [< 256 us: 122.91/75.14] [< 512 us: 78.54/50.36] [< 1024 us: 26.98/50.56] [< 2048 us: 52.76/80.94] [< 4096 us: 23.58/73.94] [< 8192 us: 17.59/40.37] [< 16384 us: 1.20/0.00] [< 32768 us: 0.20/0.00] CPU Average frequency as fraction of nominal: 47.31% (1197.07 Mhz)

CPU 3 duty cycles/s: active/idle [< 16 us: 190.06/38.77] [< 32 us: 38.57/48.16] [< 64 us: 80.94/47.16] [< 128 us: 43.97/40.77] [< 256 us: 49.76/69.55] [< 512 us: 34.17/24.98] [< 1024 us: 21.78/26.18] [< 2048 us: 10.79/42.97] [< 4096 us: 6.20/50.56] [< 8192 us: 2.60/78.54] [< 16384 us: 0.00/10.19] [< 32768 us: 0.00/1.00] CPU Average frequency as fraction of nominal: 47.31% (1197.07 Mhz)

gzmarchenko commented 2 years ago

It seems I got it working building kernel module of CPUTune using old XCode

calasanmarko commented 2 years ago

Older CPUs seem to be sort of unreliable when it comes to writes to the IA32_PERF_CTL MSR to set the desired frequency on SpeedStep.

As of https://github.com/calasanmarko/TurboMac/commit/72c8c46f1dcef5d5c01d23632aa871b6171e99bb I have decided to make the kext disable SpeedStep entirely by writing to IA32_MISC_ENABLE, to avoid this issue in CPUs that don't support HWP (like yours). I have also added Nice to Info.plist to delay the kext loading, which may increase boot times slightly (although still much faster than they are now) but should make sure nothing reenables SpeedStep after it's loaded.

calasanmarko commented 2 years ago

It seems I got it working building kernel module of CPUTune using old XCode

Just saw this. Just so I know, what worked was disabling SpeedStep entirely, right? Either way glad you got it to work, if you could test out my latest commit I would appreciate it.

gzmarchenko commented 2 years ago

I believe it's about BD_PROCHOT since I don't have a battery at all.

I've tested your last commit, but it doesn't work just yet

jozsi commented 2 years ago

Hi @calasanmarko,

Following the instructions from README, I tried v1.1.0b, the extension is loaded, but the frequency is stuck at 0.80GHz. It's a Late 2013 MacBook Pro 15" with the topped out, 2.6 GHz CPU (I7-4960HQ). Running Big Sur 11.6.4.

How could I assist?

Thank you!

PS: the only warning message I saw is: com.apple.driver.KextExcludeList was not found!

jozsi commented 2 years ago

I did a fresh install of Catalina, tried v1.1.0b but it did not work. Swapped it out to v1.0.0b, same. I am going to download XCode and compile it myself. Then give CPUTune a try as well. I'll keep editing this post with my findings.

calasanmarko commented 2 years ago

The issue in a nutshell is that Intel CPUs before Skylake (released in 2015) have an entirely different way of doing power management because they don't support SpeedShift. I don't have any machine that old, so I can't test to see what the problem is.

Try running kextlog show | grep TurboMac and posting the results. This is so we can determine if the MSRs are written to at all.

If they are indeed written to, then it would be appreciated if you play around with CPUTune to see what particular settings, if any, work for you. It seems to be different for everyone! You can try disabling BD_PROCHOT for a start.

It would also help if you checked the values of the 0x1A0 and 0x199 MSRs (written to by TurboMac) through CPUTune, to see if maybe some other kext rewrites them after TurboMac is loaded.

jozsi commented 2 years ago

Installing Xcode will take some time. Meanwhile: (trimmed log)

CPU does not support SpeedShift.
Writing to IA32_MISC_ENABLE to disable SpeedStep...
TurboMac fully initialized

I'll get back with the MSR readings via CPUTune soon!

jozsi commented 2 years ago

Loading CPUTune alongside TurboMac worked instantly. By default, it disables BD_PROCHOT, which was the culprit, indeed!

I can't figure out how to read MSRs through CPUTune, did you mean voltageshift? In the logs, I can see 0x1a0 (MSR_IA32_MISC_ENABLE) toggle between 0x840089 and 0x4000840089, but no reference to 0x199

Thank you!

calasanmarko commented 2 years ago

Could you please try unloading TurboMac and see if it's still fast? Also yeah I confused it with voltageshift. 0x199 was referring to an earlier version of TurboMac, you're right.

jozsi commented 2 years ago

I removed TurboMac (rm'd the kext, ran kextcache and rebooted; did not run the uninstall script to avoid restoring the backup kexts). Confirmed with kextstat that it is not loaded. Intel Power Gadget still reports 2.6GHz instead of 0.8GHz.

calasanmarko commented 2 years ago

Alright, and with the backup kexts?

jozsi commented 2 years ago

Sorry, I've reset PRAM and SMC and stuck in a bootloop now (not sure if I restored the backup kexts before or after the reset). Actually, I was able to log on once but it shut off shortly.

calasanmarko commented 2 years ago

Wow, that's strange. Can you enter Recovery mode at least? Maybe delete the backup kexts again from the Recovery terminal?

jozsi commented 2 years ago

I can easily get into Safe Mode and all works well there. Also when CPUTune is NOT loading (SMC reset turns SIP back and prevents it). I lost track of all the possible combinations tried (I tend to beleive that toggling CPUTune options in safe mode - I beleive it modifies a .plist file - makes it work for a single restart).

Once I'll have a couple of hours free, I'm going to do a fresh install and use VoltageShift to play around exclusively with the PROCHOT MSR first, then in combination of removing the IOPlatformPluginFamily and AppleIntelCPUPowerManagement kexts, to see if they have any influence on my CPU.

I'll let you know about the outcome. If it is as simple as adding PROCHOT for my CPU (maybe in combination with disabled turbo boost, preventively), I think many would find it really useful. Having pre-built, official releases and out-of-the-box best-fit configurations, makes TurboMac stand tall.

calasanmarko commented 2 years ago

Sorry this has happened to you. Things like this are why I dislike Apple opaqueness, we have no way of knowing what does what so we have to brute force all combinations when something goes wrong. I can't help but feel that, in the case of battery death, this issue is intentional.

Having pre-built, official releases and out-of-the-box best-fit configurations, makes TurboMac stand tall.

Yeah, my idea was to get community feedback such that we can build an extension that automatically applies the proper MSR values and disables the appropriate kexts (from the so many combinations of these!) based on the Mac model it runs on. It's such a widespread issue that really deserves a simple solution. Thanks for the help.

jozsi commented 2 years ago

Hi @calasanmarko,

I made a fresh install of Catalina, reset NVRAM and SMC, disabled SIP, installed CPUTune and it worked out of the box, without any custom settings (defaults disable turbo boost and prochot), nor removal of IOPlatformPluginFamily/AppleIntelCPUPowerManagement. So I believe the late 2013 model (Haswell) is a more fortunate situation as it only depends on BD_PROCHOT.

I've donated the laptop but will have access to it once in a while. Looking forward to try out newer versions of TurboMac!