[Guide] FW13 Ryzen Power Management

Use B4

b4 am URL

You need both patches, this gets both and you can git am foo.mbox

I probably should explain what this does too.
It enables dynamic power gating which lets the VCN IP go to a lower power state ā€œbetweenā€ commands.

This should lower the overall power consumption of VCN during video playback.

That works for getting the patches, thanks.
But Iā€™m having a few problems, applying the patches. Multiple hunks are being rejected when patching. This is under NixOS nixpkgs-master and patching Kernel 6.9.8.

error: builder for '/nix/store/gabrk1ib12f88x5hl3ig4094zfmbvgl6-amdgpu-kernel-module-6.9.8.drv' failed with exit code 1;
       last 10 log lines:
       > Hunk #8 succeeded at 883 (offset -22 lines).
       > Hunk #9 succeeded at 906 (offset -22 lines).
       > Hunk #10 succeeded at 928 (offset -22 lines).
       > Hunk #11 succeeded at 950 (offset -22 lines).
       > 1 out of 11 hunks FAILED -- saving rejects to file drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c.rej
       > patching file drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
       > patching file drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
       > Hunk #1 succeeded at 386 (offset -26 lines).
       > Hunk #2 succeeded at 434 (offset -26 lines).
       > Hunk #3 succeeded at 462 (offset -26 lines).
       For full logs, run 'nix log /nix/store/gabrk1ib12f88x5hl3ig4094zfmbvgl6-amdgpu-kernel-module-6.9.8.drv'.
error: 1 dependencies of derivation '/nix/store/5ks31ir2n09ygkga55ydzl4mjhwgakb9-linux-6.9.8-modules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/vrcpnrpls0100l5yhj6m4dwfms3drsdv-nixos-system-framework-24.11.20240710.aa94615.drv' failed to build

Theyā€™re done against AMD staging DRM next (6.11 content), might need some contextual changes for older versions. Iā€™ll work out backports later on and post some links.

1 Like

Here you go. Hereā€™s 6.10-rc7 and 6.9 backports:

https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/log/?h=superm1/vcn-dpg-6.9
https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/log/?h=superm1/vcn-dpg-6.10

2 Likes

Tried it out for a few videos and overall saw a power consumption decrease.
Playing back a 2k video in Firefox with vp9 codec decreased power consumption by about 8-10W.
Playing back a 1080p video with AV1 codec in Firefox decreased power consumption by about 6-8W.
Playing back a 1080p x264 video with mpv saw only a small decrease of around 2-4W.
Playing back a 1080p x265 video with mpv saw a pretty big decrease of over 10W, total power draw during playback was around 17W, on idle I have about 10W power consumption.

The numbers are a pretty hefty decrease, they might have quite a bit of error margin, since I did no thorough tests.

This was tested with ppd set to balanced and only the iGPU on a framework 16.

5 Likes

Thatā€™s great to hear itā€™s working for you.

2 Likes

Phoronix article on what (I think?) is the patch set linked above:

1 Like

Thatā€™s an enormous decrease. Iā€™m tempted to learn how to compile my own kernel again (havenā€™t done it in a decade, and I think never on arch)

1 Like

I barely managed it, the results are pretty nice, especially for lower res.

1 Like

For anyone using NixOS, you can include these patches by adding this to your config:

boot = {
  kernelPackages = pkgs.linuxPackages_latest;
  kernelPatches = [
    # https://community.frame.work/t/guide-fw13-ryzen-power-management/42988/68
    {
      patch = pkgs.fetchpatch2 {
        name = "amdgpu-vcn-1.diff";
        url = "https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/rawdiff/?h=superm1/vcn-dpg-6.9&id=13b322789fae1d6a1fad2c09887fbd9c25ecddc4";
        hash = "sha256-Apf+jhlaLf9+AbLxJ1yWb2Ka5b3OfIV3gNIqnfnNwho=";
      };
    }
    {
      patch = pkgs.fetchpatch2 {
        name = "amdgpu-vcn-2.diff";
        url = "https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git/rawdiff/?h=superm1/vcn-dpg-6.9&id=c6b76db6ce46eab7d186b68b5ed4bea4d3800161";
        hash = "sha256-yZ9p/G/YMlreloF3Cq9dsshO1Oomj6+IVJkl/TH0/VE=";
      };
    }
  ];
};

This will recompile your kernel, so in case you have /tmp mounted as a tmpfs you have to make sure that you have enough room there (around 20GB in my case) or otherwise set your nix daemonā€™s tmp dir to something like /var/tmp/nix-daemon, with something like

systemd.services.nix-daemon.serviceConfig.environment.TMPDIR = "/var/tmp/nix-daemon";
4 Likes

If task ā€˜Aā€™ takes 30 seconds when split across 4 cores, then on 1 core, shouldnā€™t it take 120 seconds?

120 seconds / 4 cores = 30 seconds of processing per core, so across 2 cores, should it not be 120 / 2 = 60 seconds to complete task ā€˜Aā€™, thus 100% longer?

Or are other factors implied from context? I donā€™t understand the conclusion.

Think about it less in terms of time to complete and more in terms of energy consumed.

The relationship of energy consumption is not linear. It depends on the operating frequency.
There is actually a ceiling where if you have cores running below a certain frequency you consume more energy for a given workload.

Furthermore there is IP that is active whether itā€™s one core or 4 cores that consumes energy.

Is this related to V = IR (Ohmā€™s Law) and P = IV = I^2*R, thus a linear increase in voltage (and signal propagation speed) requires a square increase in current and thus power, so to 2x clock speed (knowing nothing else), we need 4x the power?

You canā€™t really simplify to that. What Iā€™m talking about energy (measured in joules). You can try to average this as power over a time period, but it wonā€™t really represent the situation effectively.

There are a number of counters (called PMUs) within the SoC that will let you tell how much energy a given IP has consumed. What you do is is look at the measurement at a given time, run your workload and then look at the counter after. This will tell you how much energy has been used.

When Iā€™m talking about efficiency Iā€™m talking about how much energy it takes for a task with one or more cores running at particular frequencies.

If you have 4 cores running below the lowest nonlinear frequency the task will take a longer time and you will probably consume more energy than if they were running at lowest nonlinear frequency.

You can read more about the processor architecture in the APM. Look specifically at the CPPC section.

https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/40332.pdf

Finally got around to giving it a try against 6.10. Iā€™m not an expert on benchmarking this kind of thing (my biggest learning is that YouTube on Firefox absolutely sucks battery even with the video paused, like 5W!!!). Eyeballing it though, it looks like itā€™s dropping power usage by 1-2W at least for me, which is pretty awesome!

1 Like

@Mario_Limonciello sorry for the maybe silly question, but to confirm: have these VCN changes made it into the merge window for 2.11? Or still being attempted but not approved? Not familiar with kernel dev :slight_smile:

Theyā€™re not part of the 6.11 merge window.

1 Like

Small correction, I think the TMP environment variable shouldnā€™t be under serviceConfig. This worked for me:

systemd.services.nix-daemon.environment.TMPDIR = "/nix/tmp";
Obviously you could use whatever tmpdir you want.