Skip to content

Commit

Permalink
Use MSR_IA32_MISC_ENABLE instead
Browse files Browse the repository at this point in the history
It turned out setting bit 32 of MSR_IA32_PERF_CTL didn't really have any
effect, at least on my system.

My concern about MSR_IA32_MISC_ENABLE disabling speed step was invalid
and so that approach was right after all.
  • Loading branch information
veloek committed Mar 23, 2020
1 parent 8d1af9a commit 492ba46
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 4 additions & 0 deletions DisableTurboBoost.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
INFOPLIST_FILE = DisableTurboBoost/Info.plist;
MARKETING_VERSION = 1.1;
MODULE_NAME = no.vtek.DisableTurboBoost;
MODULE_START = DisableTurboBoost_start;
MODULE_STOP = DisableTurboBoost_stop;
Expand All @@ -265,7 +267,9 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
INFOPLIST_FILE = DisableTurboBoost/Info.plist;
MARKETING_VERSION = 1.1;
MODULE_NAME = no.vtek.DisableTurboBoost;
MODULE_START = DisableTurboBoost_start;
MODULE_STOP = DisableTurboBoost_stop;
Expand Down
17 changes: 7 additions & 10 deletions DisableTurboBoost/DisableTurboBoost.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,28 @@ extern void mp_rendezvous_no_intrs(
void (*action_func)(void *),
void *arg);

const uint64_t disableTurboBoost = ((uint64_t)1) << 32;
const uint64_t disableTurboBoost = ((uint64_t)1) << 38;

void disable_tb(__unused void * param_not_used) {
wrmsr64(MSR_IA32_PERF_CTL, rdmsr64(MSR_IA32_PERF_CTL) | disableTurboBoost);
wrmsr64(MSR_IA32_MISC_ENABLE, rdmsr64(MSR_IA32_MISC_ENABLE) | disableTurboBoost);
}

void enable_tb(__unused void * param_not_used) {
wrmsr64(MSR_IA32_PERF_CTL, rdmsr64(MSR_IA32_PERF_CTL) & ~disableTurboBoost);
wrmsr64(MSR_IA32_MISC_ENABLE, rdmsr64(MSR_IA32_MISC_ENABLE) & ~disableTurboBoost);
}

kern_return_t DisableTurboBoost_start(kmod_info_t * ki, void *d);
kern_return_t DisableTurboBoost_stop(kmod_info_t *ki, void *d);

kern_return_t DisableTurboBoost_start(kmod_info_t * ki, void *d)
{
uint64_t prev = rdmsr64(MSR_IA32_PERF_CTL);
uint64_t prev = rdmsr64(MSR_IA32_MISC_ENABLE);
mp_rendezvous_no_intrs(disable_tb, NULL);
printf("Disabled Turbo Boost: %llx -> %llx\n", prev, rdmsr64(MSR_IA32_PERF_CTL));
printf("Disabled Turbo Boost: %llx -> %llx\n", prev, rdmsr64(MSR_IA32_MISC_ENABLE));
return KERN_SUCCESS;
}

kern_return_t DisableTurboBoost_stop(kmod_info_t *ki, void *d)
{
uint64_t prev = rdmsr64(MSR_IA32_PERF_CTL);
uint64_t prev = rdmsr64(MSR_IA32_MISC_ENABLE);
mp_rendezvous_no_intrs(enable_tb, NULL);
printf("Re-enabled Turbo Boost: %llx -> %llx\n", prev, rdmsr64(MSR_IA32_PERF_CTL));
printf("Re-enabled Turbo Boost: %llx -> %llx\n", prev, rdmsr64(MSR_IA32_MISC_ENABLE));
return KERN_SUCCESS;
}
4 changes: 2 additions & 2 deletions DisableTurboBoost/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 Vegard Løkken. All rights reserved.</string>
<key>OSBundleLibraries</key>
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DisableTurboBoost

A MacOS kernel extension (kext) for disabling CPU turbo boost to keep temperature (and fan noise) down.
A macOS kernel extension (kext) for disabling CPU turbo boost to keep temperature (and fan noise) down.

## Usage

Expand All @@ -18,11 +18,13 @@ sudo kextload DisableTurboBoost.kext

Run `kextstat |grep DisableTurboBoost` to verify that it's loaded.

Run `sudo kextunload -b no.vtek.DisableTurboBoost` to unload the kext.

## How it works

This small kernel extension will enable bit 32 of the MSR register `MSR_IA32_PERF_CTL`. This causes the CPU to disable turbo boost, while keeping speed step.
This small kernel extension will enable bit 38 of the MSR register `MSR_IA32_MISC_ENABLE` which causes the CPU to disable turbo boost.

Other similar extensions choose to enable bit 38 of `MSR_IA32_MISC_ENABLE`, but this also disables speed step causing the CPU to run at a higher frequency (and drain battery faster) than necessary.
There are some alternatives that enables bit 32 of `MSR_IA32_PERF_CTL`, but that didn't seem to have any impact on my system.

Take a look in the [manual](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html) for more info.

Expand All @@ -42,4 +44,4 @@ It will output something about invalid signatures, but the extension might still

## Credits

The code was written by Vegard Løkken with great inspiration from [nanoant/DisableTurboBoost.kext](https://github.com/nanoant/DisableTurboBoost.kext) and [pyrovski/powertools](https://github.com/pyrovski/powertools).
The code was based on an outdated repo [nanoant/DisableTurboBoost.kext](https://github.com/nanoant/DisableTurboBoost.kext).

0 comments on commit 492ba46

Please sign in to comment.