How to use AMD P-State in Linux

powerprofiles tries to create something like the energy settings on windows, where you can configure some system presets to switch manually or depending on the power supply method - it does not change anything related to EPP - might be that one can configure it somehow to do that but I am not familiar with it myself.

that’s just the 3 profiles that one can configure - apparently, they are configured to do the same on all 3 profiles.

check with the method that works:

leave it commented as epp only knows performance and powersave governor, and powersave is the default and the one you want to use.

3 Likes

well … I gave the task of writing the script to ChatGPT free model (chatGPT 3):

User
Write a Shell script that applies a configurable value, for example 'balance_power' to all threads of a system. The path is /sys/devices/system/cpu/cpufreq/policy6/energy_performance_preference



ChatGPT

Certainly! Here's a Shell script that applies a configurable value, such as 'balance_power', to all threads of a system by modifying the energy_performance_preference file for each CPU thread:

bash

#!/bin/bash

# Configurable value
CONFIG_VALUE="balance_power"

# Get the number of CPU threads
NUM_THREADS=$(grep -c ^processor /proc/cpuinfo)

# Loop through each CPU thread and apply the configurable value
for ((i=0; i<NUM_THREADS; i++))
do
    THREAD_PATH="/sys/devices/system/cpu/cpufreq/policy$i/energy_performance_preference"
    
    # Check if the energy_performance_preference file exists
    if [ -f "$THREAD_PATH" ]; then
        echo "$CONFIG_VALUE" > "$THREAD_PATH"
        echo "Applied $CONFIG_VALUE to $THREAD_PATH"
    else
        echo "Error: $THREAD_PATH does not exist"
    fi
done

Here's how the script works:

    The configurable value is set to "balance_power" in the CONFIG_VALUE variable.
    The script retrieves the number of CPU threads by counting the lines containing "processor" in the /proc/cpuinfo file.
    It then loops through each CPU thread from 0 to NUM_THREADS-1.
    For each thread, it constructs the path to the energy_performance_preference file using the thread number.
    The script checks if the energy_performance_preference file exists for the current thread.
    If the file exists, it writes the configurable value to the file using the echo command.
    Finally, it prints a success message if the value was applied, or an error message if the file doesn't exist.

Make sure to run this script with appropriate permissions (e.g., sudo) since modifying system files typically requires elevated privileges.


User
rewrite the script to be silent


ChatGPT

Certainly! Here's a modified version of the script that runs silently, without printing any messages:

bash

#!/bin/bash

# Configurable value
CONFIG_VALUE="balance_power"

# Get the number of CPU threads
NUM_THREADS=$(grep -c ^processor /proc/cpuinfo)

# Loop through each CPU thread and apply the configurable value
for ((i=0; i<NUM_THREADS; i++))
do
    THREAD_PATH="/sys/devices/system/cpu/cpufreq/policy$i/energy_performance_preference"
    
    # Check if the energy_performance_preference file exists
    if [ -f "$THREAD_PATH" ]; then
        echo "$CONFIG_VALUE" > "$THREAD_PATH" 2>/dev/null
    fi
done

In this version of the script, the echo command that writes the CONFIG_VALUE to the file is appended with 2>/dev/null. This redirects the standard error stream to /dev/null, discarding any error messages that may occur during the execution of the script.

With this modification, the script will run silently, without any output or error messages.

I am now executing that script with the systemd process that I set up above and it works

Edit:
Here is the silent script without having to scroll through the chat-log and minor modifications for race condition fixes.

#!/bin/bash

# Configurable value
CONFIG_VALUE='balance_power'
sleep 3
# Get the number of CPU threads
NUM_THREADS=$(grep -c ^processor /proc/cpuinfo)

# Loop through each CPU thread and apply the configurable value
for ((i=0; i<NUM_THREADS; i++))
do
    THREAD_PATH="/sys/devices/system/cpu/cpufreq/policy$i/energy_performance_preference"
    
    # Check if the energy_performance_preference file exists
    if [ -f "$THREAD_PATH" ]; then
        echo "$CONFIG_VALUE" > "$THREAD_PATH" 2>/dev/null
    fi
done
1 Like

Hey everyone, I dont generally hang around here anymore so ill make a repo for this on my gitlab so people can submit issues there for updates to the guide and i can see them. Ill post the repo soon

The up to date pstate guide i use myself is now here

Please submit any issues/changes needed i may have missed to the gitlab as a merge or issue

5 Likes

Does this work for 5700G? Edit: I see lit listed, but doesn’t activate if I follow the guide.

ls /usr/lib/modules/$(uname -r)/kernel/drivers/cpufreq/ output:
acpi-cpufreq.ko.zst  amd-pstate-ut.ko.zst  amd_freq_sensitivity.ko.zst  p4-clockmod.ko.zst  pcc-cpufreq.ko.zst  powernow-k8.ko.zst  speedstep-lib.ko.zst

@echoa : does epp v2 still works with kernel 6.3.3 ?
i have tested the guide , i cannot now have report of lists available performances with 6.3.3

I’m on the latest kernel 6.3.4-arch1-1 and i have no issues. I only have amd_pstate=active in the grub command line.

https://www.phoronix.com/news/AMD-P-State-Active-Default*
active mode epp is in last kernel stable ( 6.3.6 )

that change is not in 6.3.6. It is queued for 6.5
Active already got merged into 6.3 pre-RC time, see How to use AMD P-State in Linux - #316 by BS86

So, one thing I’ve wondered, does that mean w/ 6.5 we can remove the amd-pstate=whichever from teh kernel line in grub and when it detects a (compatible) AMD processor it’ll just USE amd-pstate active by default?

1 Like

that’s exactly what 6.5 will do - the only thing coming in between would be a kernel maintainer or Linus Torvalds in the last instance decides to not merge the pull request - but at this stage, that is rather unlikely.

2 Likes

EPP in kernel 6.5
https://www.phoronix.com/news/Linux-6.5-Power-Management

1 Like

for kernel 6.4.1 , 6.3.11 and 6.1.37 amd-pstate=active will work with EPP

Anyone testing the guided mode ?
6.4.1 is out now…

Yeah I have it enabled on a Ryzen 7 7700X. Works fine and is very responsive:

sudo cat /sys/devices/system/cpu/amd_pstate/status
guided

sudo cpupower frequency-info
analyzing CPU 6:
driver: amd-pstate
CPUs which run at the same hardware frequency: 6
CPUs which need to have their frequency coordinated by software: 6
maximum transition latency: 20.0 us
hardware limits: 400 MHz - 5.57 GHz
available cpufreq governors: conservative ondemand userspace powersave performance schedutil
current policy: frequency should be within 400 MHz and 5.57 GHz.
The governor “schedutil” may decide which speed to use
within this range.
current CPU frequency: Unable to call hardware
current CPU frequency: 5.29 GHz (asserted by call to kernel)
boost state support:
Supported: yes
Active: yes
AMD PSTATE Highest Performance: 166. Maximum Frequency: 5.57 GHz.
AMD PSTATE Nominal Performance: 134. Nominal Frequency: 4.50 GHz.
AMD PSTATE Lowest Non-linear Performance: 89. Lowest Non-linear Frequency: 2.99 GHz.
AMD PSTATE Lowest Performance: 12. Lowest Frequency: 400 MHz.

Clocks are scaling from 29XXMHz to 53XXMhz during normal usage using “schedutil” as the scaling governor.

Active mode also worked fine on kernel 6.3 with clocks scaling from 400MHz to 47XXMhz during normal usage using “powersave” as the scaling governor and “balance_performance” as the energy performance preference. Changing the energy performance preference to “performance” made it scale from 400MHz to 53XXMhz.

So far i prefer the guided mode over active in terms of performance / responsiveness on desktop.

1 Like

How is it set now for guided?

Edit: I am using active so i just change to guided?

Change your kernel cmdline from amd_pstate=active or amd_pstate=passive to amd_pstate=guided

https://docs.kernel.org/admin-guide/pm/amd-pstate.html

be very careful this is now amd-pstate no more amd_pstate …