Add AMD/Intel pstate enablement to Advanced options

Would be nice to be able to enable intel_pstate and amd_pstate in TrueNAS SCALE without having to run a bunch of shell commands.

Would like to be able to Enable pstate, switch between active/passive/guided, and if active is enabled be able to switch between performance/balanace_performance/etc profiles.

In order to help bolster your cause I recommend you describe the tangable benefits of adding this feature and also you said besides using shell commands, what are the exact commands to enable the pstates in SCALE?

Looking forward to hearing your update. I may vote if I fully understand the benefit here. I understand acpi is the default.

Someone from the old forum did a little testing on the amd p-state driver on scale 23.10.
The problem with the default one was/is that the cpu will only clock down to 2.2Ghz at idle and changing it let the cpu idle at ~500Mhz, reducing power draw at idle. Here’s the link to the post on the old forum. @joeschmuck you even commented on it.
I also did some testing when i was using cobia, hoping i could reproduce the results the op in the old forum achieved, but when i changed to amd_pstate, my 3700x would clock down to 500Mhz, but would get stuck downclocked and would never increase clock speeds. Since then i’ve not tried it again.

1 Like

I’m using an AMD EPYC 7402P on a ASRock ROMED8-2T so I will talk about that. Intel_PSTATE is probably similar.

ACPI only allows my CPU to downlock to 1.5Ghz. AMD_PSTATE allows it to downclock to 400Mhz.

What is acpi cpufreq?

acpi cpufreq is a general driver that uses the Advanced Configuration and Power Interface (ACPI) to manage CPU performance states (P-states). It works with discrete P-states, making it compatible with both Intel and AMD processors. It’s often the default choice for systems without specialized drivers, providing basic frequency scaling for power management.

What is amd pstate?

amd pstate, on the other hand, is designed specifically for AMD processors, particularly those supporting the Collaborative Processor Performance Control (CPPC) interface. This driver allows for more dynamic and fine-grained control over CPU performance, potentially leading to improved energy efficiency and performance on supported hardware.

Key Differences

  • Specificity: acpi cpufreq is a general-purpose driver, while amd pstate is optimized for AMD’s architecture.
  • Performance Control: amd pstate uses CPPC for advanced management, whereas acpi cpufreq relies on standard ACPI P-state interfaces.
  • Hardware Requirements: amd pstate requires CPPC support, which may need specific BIOS settings, while acpi cpufreq is more universally compatible.

Here is a one liner to monitor CPU clock per core and list max freqency observed ever 1 seconds.

bash -c 'while true; do freqs=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); max=0; for f in $freqs; do [ $f -gt $max ] && max=$f; done; echo "Current (GHz): $(echo $freqs | tr " " "\n" | awk "{printf \"%.2f \", \$1/1000000}") | Max: $(echo $((max/1000)) | awk "{printf \"%.2f\", \$1/1000}") GHz"; sleep 1; done'

Looks like this…

Current (GHz): 0.40 3.00 2.31 2.29 3.01 2.24 3.09 3.22 2.38 0.40 0.40 0.40 2.31 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 2.26 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 2.30 0.40 0.40 0.40 0.40 2.46 0.40 0.40 1.77 3.20 3.35 2.30 2.28 3.35  | Max: 3.35 GHz
Current (GHz): 0.40 2.32 3.23 1.80 3.21 2.10 2.30 3.02 3.00 0.40 0.40 0.40 1.67 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 2.98 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 3.01 0.40 0.40 0.40 0.40 0.40 0.40 3.12 1.74 1.67 3.30 2.97 3.14 3.00  | Max: 3.30 GHz

You first need to make sure CPPC and EPP are enabled in the BIOS. Should be enabled by default but you never know.

In order to enable amd_pstate you need to run the following command

midclt call system.advanced.update '{ "kernel_extra_options": "amd_pstate=active" }'

If your CPU does not support EPP you will need to use guided instead. Guided does not have as granular control as I describe below.

midclt call system.advanced.update '{ "kernel_extra_options": "amd_pstate=guided" }'

What this does is call the function in the TrueNAS API that use to exsist under Advanced Settings > Kernel that no longer exsists for some reason.

You can confirm it is enabled by running…

cpupower frequency-info

Looks like this.

analyzing CPU 0:
  driver: amd-pstate-epp
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency:  Cannot determine or is not supported.
  hardware limits: 400 MHz - 3.35 GHz
  available cpufreq governors: performance powersave
  current policy: frequency should be within 400 MHz and 3.35 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency: Unable to call hardware
  current CPU frequency: 400 MHz (asserted by call to kernel)
  boost state support:
    Supported: yes
    Active: yes
    Boost States: 0
    Total States: 3
    Pstate-P0:  2800MHz
    Pstate-P1:  2400MHz
    Pstate-P2:  1500MHz

Then you can set the govenor between in this example ‘performance’ or ‘powersave’. ‘powersave’ allows you to set the energy_performance_preference

echo "powersave" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

energy_performance_preference allows the following options. In my testing all of these options allow for 400Mhz - 3.35 Ghz it just requires more or less cpu usage to get it to clock up to 3.35 Ghz.

  • performance: Max frequency, less power saving.
  • balance_performance: Slightly favors performance.
  • balance_power: Balanced (default in many cases).
  • power: Prioritizes power savings, lower frequencies.

Enable it by running…

echo "balance_power" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference

However setting the governor and EPP is not persistent with reboot. It will default to performance governor. However with my testing I don’t see a meaningful power consumtion reduction between ‘performance’ and ‘power’ (the most aggressive setting). So I didn’t test how to make it persistant through reboot.

I’m tired and need to sleep so hopefully this was coherent.

I see that, but that thread stopped after my minor comment about being interested in it.

I am running on ESXi 8 and my CPU drops to 175MHz during periods on non-use (watts drops significantly for the system). So it seems to be working on my ESXi system and I have no idea if that is just a feature of ESXi or if the CPU is throttling due to the VM, but I have no idea how it runs on bare metal.

My BIOS does not appear to have a CPPC setting, wish I knew for certain if it was enabled or not but the lack of the setting makes me think I’m using ACPI.

The command you provided did not work for me (No such file or directory), maybe due to me using ESXi or maybe my BIOS is limiting the function.

Either way, if this feature improves power performance, I’m all for it, even if I cannot use it. One day I will upgrade again so if it is there, Bonus!

1 Like

I did end up enabling balance_power on boot.

System > Advanced Settings > Init/Shutdown Scripts

Description: Set Power Mode
Type: Command
Command: echo "powersave" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; echo "balance_power" | tee /sys/devices/system/cpu/cpu*/cpufreq/energy_performance_preference
When: Post Init
:ballot_box_with_check: Enabled
Timeout: 10


Also I change the CPU clock monitoring one liner to inclue minimum clock.

bash -c 'while true; do freqs=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); max=0; min=999999999; for f in $freqs; do [ $f -gt $max ] && max=$f; [ $f -lt $min ] && min=$f; done; echo "Current (GHz): $(echo $freqs | tr " " "\n" | awk "{printf \"%.2f \", \$1/1000000}") | Max: $(echo $((max/1000)) | awk "{printf \"%.2f\", \$1/1000}") GHz | Min: $(echo $((min/1000)) | awk "{printf \"%.2f\", \$1/1000}") GHz"; sleep 1; done'
Current (GHz): 0.40 1.80 1.80 1.80 1.80 1.80 1.80 1.80 1.80 0.40 1.80 1.80 1.80 0.40 1.80 0.40 0.40 0.40 0.40 0.40 0.40 0.40 1.80 1.80 0.40 0.40 0.40 1.80 0.40 0.40 0.40 1.80 0.40 1.80 1.80 1.80 1.80 0.40 0.40 1.80 0.40 0.40 1.94 1.80 1.80 1.80 1.80 1.80  | Max: 1.94 GHz | Min: 0.40 GHz
Current (GHz): 0.40 1.80 1.80 1.80 1.80 1.80 1.80 1.80 1.80 0.40 0.40 0.40 1.80 1.80 0.40 0.40 2.40 0.40 0.40 0.40 0.40 1.80 1.80 1.80 0.40 0.40 1.80 0.40 0.40 0.40 0.40 0.40 0.40 0.40 1.80 0.40 0.40 0.40 0.40 0.40 0.40 0.40 0.40 1.80 1.80 1.80 1.80 1.80  | Max: 2.40 GHz | Min: 0.40 GHz

TLDR this entire thread:

Basically what I am asking for is for TrueNAS to have the same CPU power management as every Desktop Linux Distro and even Windows for that matter. Where it uses the platform specific PSTATE driver and provides the same Power Save / Balance / Max Performance CPU Power Profiles. TrueNAS already has HDD power profile options which should not be used 95% of the time but this is a power saving option that everyone could benefit from and it is almost as important as it is on Laptops to save battery because servers run 24/7 and the power savings add up over time.