Skip to content

Instantly share code, notes, and snippets.

@Mnkai
Last active April 13, 2024 14:11
Show Gist options
  • Star 78 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Mnkai/5a8edd34bd949199224b33bd90b8c3d4 to your computer and use it in GitHub Desktop.
Save Mnkai/5a8edd34bd949199224b33bd90b8c3d4 to your computer and use it in GitHub Desktop.
TDP and turbo parameter modification with MSR on non-overclockable Intel CPU (such as Intel i7-8550U)

TDP and turbo parameter modification with MSR on non-overclockable CPU

Disclaimer

  • MSR modification may void your CPU's (or system board's) warranty. Proceed with care. I'm not responsible for any destruction caused by this article.
  • MSR address (greatly) differs from CPU to CPU. Check your own CPU's MSR address using Intel's documentation.
  • Only tested on Intel i7-8550U (Kaby Lake R).
  • This article is translation of this article. If you can understand Korean, I recommend reading that article, not this.

Start

On Windows, Intel XTU can be used for modifying turbo-boost parameter and TDP related settings. But on other OSes, there are no specific (user friendly) tools available. In this article, I will directly modify MSR (Model-Specific Registers) to achieve similar effect.

Know about your CPU

There are many CPU models. We call them by their friendly names - such as 'Core i7' - but this is not enough in this article. In fact, some CPUs are very different even if they are named after same friendly name. Some CPUs are named different, but they are actually same varient of other CPU. In Intel, they distinguish between CPU using CPU family and model. For example,

$ cat /proc/cpuinfo | less
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 142
model name      : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping        : 10
...

Note that /proc/cpuinfo returns CPU family and model by decimal.

Some dependencies

In Linux, you will need msr-tools, and msr kernel module. You may want to insert kernel module automatically by adding appropriate configuration. (e.g., echo msr > /etc/modules-load.d/msr.conf in Arch Linux)

You can read from MSR with rdmsr 0x(address) and write to MSR with wrmsr 0x(address) 0x(value). When reading, you can specify bitmasks by -f 15:0 (from bit 0 to bit 15, in reverse).

Power/Energy/Time units

My CPU has MSR_RAPL_POWER_UNIT at address 606h.

606H MSR_RAPL_POWER_UNIT (RO)
    3:0 = Power unit (W) = 1/2^(decimal)W - def: 0.125W
    12:8 = Energy unit (J) = 1/2^(decimal)J - def: 0.00006103515625J
    19:16 = Time unit (sec) = 1/2^(decimal)sec - def: 0.0009765625sec

These units are needed to modify existing values.

Package power limits

Now the fun part begins, MSR_PKG_POWER_LIMIT has package power limit variables.

610H MSR_PKG_POWER_LIMIT (RW)
    14:0 = Pkg power limit = Powerunit * decimal
    15:15 = Pkg power enabled (bool)
    16:16 = Pkg clamping limit (bool)
    23:17 = Pkg power limit time window = 2^(21:17 bit) * (1.0 + (23:22 bit)/4.0 ) * Timeunit

    46:32 = Pkg power limit 2 = Powerunit * decimal
    47:47 = Pkg power 2 enabled (bool)
    48:48 = Pkg clamping limit 2 (bool)
    55:49 = Pkg power limit time window = 2^(53:49 bit) * (1.0 + (55:54 bit)/4.0 ) * Timeunit
    
    63:63 = MSR lock (bool)

If bit 63 is 0, those values can be changed by writing to 0x610 register. You may change package power limit to higher TDP, and prolong limit time window to increase your processor's performance (if you are not throttled by thermal throttling).

Turbo boost ratio limit

If MSR_PLATFORM_INFO[28] is 1, you can also change turbo boost limit variable.

CEH MSR_PLATFORM_INFO
    15:8 = Maximum non-turbo (RO) bool
    28 = Programmable ratio limit for turbo (RO) bool
    29 = Programmable TDP limit for turbo (RO) bool
    30 = Programmable TJ offset (RO) bool

1ADH MSR_TURBO_RATIO_LIMIT (RO if MSR_PLATFORM_INFO[28]=0, else RW)
    7:0 = Ratio 1C
    15:8 = Ratio 2C
    23:16 = Ratio 3C
    31:24 = Ratio 4C

Real life example, tune i7-8550U processor

Using above information, I could change MSR on my processor - i7-8550U.

Since this processor is limited to 37 boost ratio when all 4 cores are being used, I changed limitation to 40. Also, I changed 23W limit to 25W with longer (1073741824 seconds) boost duration.

From

610H
    42819800dd80b8h

    00000000 01000010 10000001 10011000
    00000000 11011101 10000000 10111000

    14:0 = Pkg power limit = 10111000b (184d, b8h) = 23
    15:15 = Pkg power enabled (bool) = 1b
    16:16 = Pkg clamping limit (bool) = 1b
    23:17 = Pkg power limit time window = 11b(3d) 01110b(14d) = 2^14*(1+3/4)*(1/2)^10=28

    46:32 = Pkg power limit 2 = 110011000b (408d, 198h) = 51
    47:47 = Pkg power 2 enabled (bool) = 1b
    48:48 = Pkg clamping limit 2 (bool) = 0b
    55:49 = Pkg power limit time window = 01b(1d) 00001b(1d) = 2^1*(1+1/4)*(1/2)^10=0.00244140625
    
    63:63 = MSR lock (bool) = 0b
    
1ADH
    25252828h
    
    7:0 = Ratio 1C = 40
    15:8 = Ratio 2C = 40
    23:16 = Ratio 3C = 37
    31:24 = Ratio 4C = 37

To

610H
    42819800FC80C8h

    00000000 01000010 10000001 10011000
    00000000 11111100 10000000 11001000

    14:0 = Pkg power limit = 11001000b (200d, c8h) = 25
    15:15 = Pkg power enabled (bool) = 1b
    16:16 = Pkg clamping limit (bool) = 0b
    23:17 = Pkg power limit time window = 11b(3d) 11110b(30d) = 2^30*(1+3/4)*(1/2)^10=1073741824

    46:32 = Pkg power limit 2 = 110011000b (408d, 198h) = 51
    47:47 = Pkg power 2 enabled (bool) = 1b
    48:48 = Pkg clamping limit 2 (bool) = 0b
    55:49 = Pkg power limit time window = 01b(1d) 00001b(1d) = 2^1*(1+1/4)*(1/2)^10=0.00244140625
    
    63:63 = MSR lock (bool) = 0b
    
1ADH
    28282828h
    
    7:0 = Ratio 1C = 40
    15:8 = Ratio 2C = 40
    23:16 = Ratio 3C = 40
    31:24 = Ratio 4C = 40

Result

turbostat reported updated TDP limit and duration, and changed turbo boost ratio. I could not test real life performance difference, since my processor is heavily throttled by thermal throttling even at 15W TDP.

#!/bin/bash
# This script is not intended for general usage.
# TDP
wrmsr 0x610 0x42819800FC80C8
/opt/devmem2 0xFED159A0 w 0x00DD80C8
# All core 40x boost
wrmsr 0x1AD 0x28282828
@xlz
Copy link

xlz commented Jul 30, 2020

Interested to know, how calculated 0xFED159A0. And what trying to do via devmem2, as 0x610 register value is already updated via wrmsr?

0xFED159A0 is 0xFED10000 + 0x59A0. 0xFED10000 is a common value for MCHBAR. The value of MCHBAR is located in the 48h of Host Bridge/DRAM Registers, which can be obtained with sudo setpci -s 0:0.0 48.l. 59A0h is Package Power Limit, see https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/10th-gen-core-families-datasheet-vol-2-datasheet.pdf. It is not documented until 10th Gen, but it works in older generations.

610h MSR_PKG_POWER_LIMIT is not synchronized with MCHBAR Package Power Limit for unknown reasons. If you set only one of the two the lower value seems to take effect.

Also, the command with wrmsr 0x610 can be replaced with native kernel interfaces in /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/ so msr module is not needed.

@fixapc
Copy link

fixapc commented Dec 7, 2021

So i was able to enable msr writing and reading on my system and installed the package. Also confirmed CPU frequency changes.

I have 2x E5-2687w v2 Cpus that have a base of 3.4 Ghz and a Turbo of 4Ghz. Iam trying to lock all cores at fixed turbo value for a real-time kernel to prevent frequency changes.

Can anyone give me a little more explaining, i understand the first value after wrmsr but i dont understand the 2nd long bit mask.... and have no clue how to convert what i want here.

I need 4Ghz for a total of 16 Cores.... and disable all Turbo power throttling if any...

@xrstokes
Copy link

xrstokes commented Dec 7, 2021

@fixapc Did you get it to go up in speed? I have 2x E5-2667's in a dell T620. I could only adjust clocks down and not up. I'll try again and see what happens.

@fixapc
Copy link

fixapc commented Dec 9, 2021

So i understand how it works and i know does work, but iam not sure how to calculate the last string value. The first string is what you want to modify. You can get these strings from the developers vol 4 guide on the intel site. If its not letting you get higher frequency you may have to increase the TDP or power watt limit first. As turbo boost works based on a power and thermal algorithm. Once you set those you can keep it locked at your designed frequency.

@xrstokes
Copy link

I now have a dell poweredge t620 with 2x e5-2667v2's. They can easy hold and sustain a 4gz clock. That's 16cores and 32 threads holding 4ghz on quite an old server. Thanks for the help everybody. I'm not sure what made it work in the end. I farted around for a day and gave up. a week later I checked my clocks and they were all 4ghz. Maybe it needed a restart??

@linus378
Copy link

linus378 commented Mar 4, 2024

I now have a dell poweredge t620 with 2x e5-2667v2's. They can easy hold and sustain a 4gz clock. That's 16cores and 32 threads holding 4ghz on quite an old server. Thanks for the help everybody. I'm not sure what made it work in the end. I farted around for a day and gave up. a week later I checked my clocks and they were all 4ghz. Maybe it needed a restart??

Can you replicate this results or did you suceed only one time? If you coupd help me that would he cool. Maybe write a guide. Thx in advance

@xrstokes
Copy link

xrstokes commented Mar 4, 2024

I now have a dell poweredge t620 with 2x e5-2667v2's. They can easy hold and sustain a 4gz clock. That's 16cores and 32 threads holding 4ghz on quite an old server. Thanks for the help everybody. I'm not sure what made it work in the end. I farted around for a day and gave up. a week later I checked my clocks and they were all 4ghz. Maybe it needed a restart??

Can you replicate this results or did you suceed only one time? If you coupd help me that would he cool. Maybe write a guide. Thx in advance

Sorry man. It's so long ago i can't remember what happened. I've got a t640 now. I love the storage that these servers deliver and the amount of vms the ram can take. but single core speeds are so depressing no matter what i do, I don't think i'll do another server after this one. especially now desktops can take so much more ram than before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment