Linux kernel amd ryzen

Maximising AMD Ryzen CPU performance in Linux

If you haven’t «Ryzen» with a state of P, you should.

Table of contents

As of Linux Kernel 5.18, P-state for CPUs is now supported and depending on your CPU and your distribution of linux, it may or may not be automatically enabled. But what does this mean for you, especially, if you own a Ryzen CPU? Or rather, what is P-state? Consider P-states as different power profiles for your CPU which the OS can trigger to either run the CPU at higher clock speeds for demanding workloads or just scale down and run at lower clock speeds to save power (which is especially important for laptops to conserve battery life). If you want the finer details you can read more here.

So let’s get back to the focus of this piece. ***How do you use the new kernel features to maximise the performance of your Ryzen based system? ***

Hinweis / Notice: * I’m using Fedora 37 Workstation with the 6.1.6
kernel. If your distro is yet to provide this kernel version, you may want to wait or take the risks of kernel patching (i.e. Ubuntu and derivatives, kernel patching can break your system if anything goes wrong. For others, such as Fedora, Arch based distros, OpenSUSE it should be fine). *

Preliminaries: BIOS settings

Before you begin, make sure to check that these settings in your BIOS are **enabled. (**Some motherboards tend to disable some or all of the below and if it is in your case, just enable it.). You can find them inside Advanced CPU configuration or AMD CBS Menu.

And yes, if you’re not overclocking your CPU, do definitely enable PBO(Precision Boost Overdrive).

Inside Linux

Install kernel-tools

Use the package manager of your distro to install the kernel-tools package (or however they named it for your distro).

Check if P-state is already enabled

sudo cpupower frequency-info | grep driver 

If the output does not show the following then you don’t have P-state automatically enabled.

Check CPU capabilities

There are two ways the new kernel handles the CPU P-state, with full MSR support or via Shared Memory Model. You’ve to find out first which one your CPU supports.

If you don’t see any output, then your CPU supports the shared memory model.

Update GRUB

In this case you’ve to add a modifier flag to GRUB, the bootloader. Open the grub config to edit it:

There, have the GRUB_CMDLINE_LINUX, which looks like this on my system:

GRUB_CMDLINE_LINUX="rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 initcall_blacklist=simpledrm_platform_driver_init rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 initcall_blacklist=simpledrm_platform_driver_init" 

What you have to do here is that at the end of the string (still inside the “”) add the following:

amd_pstate.shared_mem=1 amd_pstate=passive 

Now the variable should look like this:

GRUB_CMDLINE_LINUX="rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 initcall_blacklist=simpledrm_platform_driver_init rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 initcall_blacklist=simpledrm_platform_driver_init amd_pstate.shared_mem=1 amd_pstate=passive" 

Once done, update grub according to the instructions of your distro and reboot your computer. For Fedora, you can find the instructions here.

Читайте также:  Где находятся файлы service linux

Verify if P-state is enabled

Once your computer boots back into linux, run the following command to see if all the changes have taken effect.

sudo cpupower frequency-info | grep driver 

The expected output should be:

Check frequency scaling policy

The frequency scaling policy determines which power profile will be used for your CPU.

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 

In many distros, the default is to use schedutil . However if you’re on a desktop as me, and conserving batter isn’t a concern, you can switch this to performance .

sudo cpupower frequency-set -g performance 

cpupower frequency info

Once done, check how the scaling will be done for your cpu

sudo cpupower frequency-info 

On my system (Ryzen 9 3950X) it shows the following:

analyzing CPU 0: driver: amd-pstate CPUs which run at the same hardware frequency: 0 CPUs which need to have their frequency coordinated by software: 0 maximum transition latency: 131 us hardware limits: 550 MHz - 4.76 GHz available cpufreq governors: conservative ondemand userspace powersave performance schedutil current policy: frequency should be within 550 MHz and 4.76 GHz. The governor "performance" may decide which speed to use within this range. current CPU frequency: Unable to call hardware current CPU frequency: 4.40 GHz (asserted by call to kernel) boost state support: Supported: yes Active: yes AMD PSTATE Highest Performance: 166. Maximum Frequency: 4.76 GHz. AMD PSTATE Nominal Performance: 122. Nominal Frequency: 3.50 GHz. AMD PSTATE Lowest Non-linear Performance: 61. Lowest Non-linear Frequency: 1.75 GHz. AMD PSTATE Lowest Performance: 20. Lowest Frequency: 550 MHz. 

One minor issue though .

What I’ve found is that cpupower reverts back to default on each boot. Which means you’ve to run the command manually. I find that kind of inefficient. So an easy solution would be to enable the cpupower systemd-service and modify it.

sudo systemctl enable cpupower.service sudo systemctl start cpupower.service --now 

Now add the slight edit in the service file

sudo nano /lib/systemd/system/cpupower.service 

Inside, change the ExecStart variable to the following.

ExecStart=/usr/bin/cpupower frequency-set -g performance 

Once done, save the edits, and reload all daemons.

sudo systemctl daemon-reload 

That’s it

The frequency scaling via cpupower can also be done through GNOME power settings as well. However it also depends on your distro if they’ve integrated all the features. So that’s it. You can now get the most out of your Ryzen CPU with proper OS controlled boosting.

Источник

Ryzen

Install the amd-ucode package to enable microcode updates and enable it with the help of the Microcode page. These updates provide bug fixes that can be critical to the stability of your system. It is highly recommended to use it despite it being proprietary.

Tweaking Ryzen

Voltage, power and temperature monitoring

lm_sensors should be able to monitor temperatures out of the box. However, for more detailed information such as power consumption and voltage, zenpower3-dkms AUR is needed. For GUI based monitoring tools, use zenmonitor AUR or zenmonitor3-git AUR for Zen 3 CPUs.

Читайте также:  Github desktop linux mint

Power management, undervolting and overclocking

  • RyzenAdj — RyzenAdj is a command-line tool that can adjust power management settings for Ryzen mobile processors.
  • Ryzen Controller — Ryzen Controller is a GUI for RyzenAdj.
  • amdctl — amdctl is a command-line tool for under/over clocking/volting AMD CPUs, currently supporting AMD CPU families 10h, 11h, 12h, 15h, 16h, 17h and 19h.
  • ZenStates-Linux — ZenStates is a command-line tool to adjust the clock speed and voltage. A detailed setup example is given in Level1Techs forum.

Compiling a kernel

See Gentoo:Ryzen#Kernel on enabling Ryzen support. The officially supported kernels have the required configuration by default.

Troubleshooting

Random reboots

With Ryzen 5000 series, particularly the higher-end models of 5950X and 5900X there seem to be some slight instability issues under Linux, related possibly to the 5.11+ kernel, as shown by this kernel bug. After investigating and reading reports on the Internet, It seems that out of the box, Windows seems to run the CPUs at higher voltage and lower peak frequencies, compared to the stock linux kernel, which depending on your draw from the silicon lottery could cause a host of random application crashes or hardware errors that lead to reboots. You will recognise those by dmesg logs that look like:

kernel: mce: [Hardware Error]: Machine check events logged kernel: mce: [Hardware Error]: CPU 22: Machine Check: 0 Bank 1: bc800800060c0859 kernel: mce: [Hardware Error]: TSC 0 ADDR 7ea8f5b00 MISC d012000000000000 IPID 100b000000000 kernel: mce: [Hardware Error]: PROCESSOR 2:a20f10 TIME 1636645367 SOCKET 0 APIC d microcode a201016

The CPU ID and the Processor number may vary. To solve this problem you need to supply higher voltage to your CPU so that it is stable when running at peak frequencies. The easiest way to achieve this is to use the AMD curve optimiser which is accessible via your motherboard’s bios. Access it and put a positive offset of 4 points, which will increase the voltage your CPU is getting at higher loads. It will limit overclocking potential due to higher heat dissipation requirements, but it will run stable. For more details check this forum post. When I did this for my 5950X, my processor stabilised and the frequency and voltage ranges were more similar to those observed under windows.

Screen-tearing (APU)

If you are using Xorg and are experiencing screen-tearing, see AMDGPU#Tear free rendering.

Soft lock freezing

This bug is well known and is being discussed on bugzilla and launchpad. While the solution is not the same in all cases, this one helped some users. Add the output of this command echo rcu_nocbs=0-$(($(nproc)-1)) as a kernel parameter where the command nproc just prints your CPU’s threads. For this option to be applied, you need a compiled kernel with option CONFIG_RCU_NOCB_CPU (like linux ).

A different cause for the freezes is the power saving management indicated by c-states. The maximum power saving state c6 can cause problems. Adding the kernel parameter processor.max_cstate=5 helped in some cases but other users reported that the option is not applied and the c6 state is still entered. For them, this package disable-c6-systemd AUR helped. Before using it, modprobe msr needs to be run in order to activate that kernel module.

Читайте также:  Move linux to another drive

Some laptops with Ryzen CPUs such as the HP Envy x360 15-bq100na may experience CPU soft locks which result in a frozen system. These can be avoided with the kernel parameter idle=nomwait added.

In some cases, kernel parameter pci=nomsi fixes the issue.

In some other cases, the issue is simply bad hardware, and warranty claiming the CPU for a new one may just solve your issues.

Freeze on shutdown, reboot and suspend

This seems to be related to the C6 c-state, that does not seem to be well supported (if at all) in Linux.

To fix this issue, go into UEFI Setup and search for an option labelled something like this: «Power idle control». Change its value to «Typical current idle». Note that these names are dependent on what the motherboard manufacturer calls them, so they may be a little different in your particular case.

Other less ideal solutions include disabling c-states in the UEFI Setup or adding processor.max_cstate=1 to your kernel command line arguments.

Источник

Linux kernel amd ryzen

I recently switched to a ryzen processor (for the first time) and I noticed that in the linux-zen kernel that i use on all my desktop systems, the CONFIG_MZEN flag is not set.

$ zcat /proc/config.gz | grep ZEN CONFIG_ZEN_INTERACTIVE=y # CONFIG_MZEN is not set

I found this gentoo wiki page , with instructions on compiling the kernel for Zen arch CPUs.

I did not want to start from a blank slate, and I also did not want to use any kernel-git packages, prefer a stable kernel release for a daily use system.

I finally found that the linux-ck package is still on AUR (the kernel I used to use before linux-zen ), and the PKGBUILD for this also allows you to set the -march easily and can nconfig Kernel options easily as well 🙂

After a little bit, I also found that the Unofficial repo-ck has a pre-compiled package for zen: linux-ck-zen ; this is pretty great 🙂

  • Other ryzen users, What kernel do you use? Are there any AMD specific config to help system performance?
  • How can I find what CFLAGS are used to compile the linux-ck packages?
  • Is it compiled with -O3 ? Is this not advisable for compiling the kernel?
  • Can I add custom CFLAGS or modify the CFLAGS being used by the linux-ck (or any other kernel) package?

Also, does anyone know if this linux-ryzen-git is worth looking into?

  • I am using the Ryzen 2700X CPU.
  • I do have the amd-ucode package installed and applied on boot
  • I know that the linux-zen kernel has nothing to do with the AMD Zen CPU Architecture.

I want to iterate that the linux and linux-zen kernels work without any issues on my CPU (and I guess on all other Zen arch CPUs as well), I am just trying to leverage any available Zen CPU optimizations on the kernel 🙂

Источник

Оцените статью
Adblock
detector