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