How to set specific cpu frequency when using intel_pstate
Asked Answered
P

3

9

When I am using intel_pstate, I found that I can not change the cpu frequency with command:

sudo cpupower frequency-set -f SomeValue

I know the reason is that intel_pstate's governors (powersave and performance) don't support changing frequency manually. Also I tried to write frequency value directly to the file /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq. But it says I'm changing a readonly file.

So is there a way to change a core's frequency when using intel_pstate driver?

Prehensile answered 18/4, 2020 at 9:14 Comment(0)
G
14

The intel_pstate driver running in one of the active modes doesn't allow you to set a particular frequency directly (cpupower frequency-set -f), but you can change the maximum and minimum frequencies the driver is allowed to set as follows:

With cpupower you can use:

cpupower frequency-set -u 3000mhz

… to set the maximum frequency for all cores. To set minimum frequency you can use

cpupower frequency-set -d 3000mhz

These commands require root privileges (executed with sudo).

In this example, the desired frequency 3000 MHz is applied to all cores. The actual frequency would be the closest supported frequency that is larger than (if possible) to the desired frequency. The actual active range of frequencies and current core frequency can determined from cpupower frequency-info.

Some processors support per-core frequency domains. You can specify a particular core or a set of cores with the -c option for which you want to change the frequency range.

Giorgione answered 19/11, 2020 at 17:12 Comment(2)
I lose the setting when I reboot. How to make these settings persistent?Nellie
This seems to work great, but it somehow doesnt increase CPU pkg wattage at all when I check turbostat. If I do the same thing on Windows (set to high performance) my cpu power will go from 10 watts to 30 watts. How is this possible?Hollyhock
A
2

I've had success by setting maximum and minimum frequency percentage in this way:

echo "50" | sudo tee /sys/devices/system/cpu/intel_pstate/min_perf_pct
echo "50" | sudo tee /sys/devices/system/cpu/intel_pstate/max_perf_pct
Atrocity answered 16/8, 2023 at 10:44 Comment(0)
T
1

Yes, there is. Before setting the frequency, first set intel_pstate to passive. That enables setting the governor to userspace. Then set the governor to userspace. My script for this purpose:

    #!/bin/bash  
    # Rig4TopSpeed.sh
    UPPER=4200MHz
    LOWER=4200MHz
    echo passive | sudo tee /sys/devices/system/cpu/intel_pstate/status
    sudo cpupower idle-set -E
    sudo cpupower frequency-set -g userspace
    sudo cpupower frequency-set -u $UPPER
    sudo cpupower frequency-set -d $UPPER
    sudo cpupower frequency-set -f $UPPER
    sudo cpupower frequency-info
    echo
    sudo turbostat --num_iterations 1  --interval 2  2>/dev/shm/turbostat.stderr 
    echo 
    grep  -i "cpufreq" /dev/shm/turbostat.stderr
    echo 
    grep -i "frequency" /dev/shm/turbostat.stderr
    echo
    grep -i "max turbo" /dev/shm/turbostat.stderr
    echo
    inxi -C|cat
    echo
    grep "cpu MHz" /proc/cpuinfo 
    sleep 3

The sleep at the bottom gives me time to look at the results before the console window self-closes when run from a GUI menu.

Note that if your CPU has HWP and it is active, then the CPU takes your settings as advice. Idle and hot CPU's will have other clock rates.

Advice: Never set the fixed value to higher than what turbostat reports the CPU can do with all cores active.

Tremaine answered 30/8, 2022 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.