Objective

Monitor system temperatures and voltage on an AMD Ryzen system running Linux.

Distributions

All distributions running kernel 4.11 or higher

Requirements

A working Linux install with kernel 4.11 or greater and root privileges.

Difficulty

Medium

Conventions

  • # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - requires given linux commands to be executed as a regular non-privileged user

Introduction

AMD's Ryzen CPUs have been out for several months now, but AMD still hasn't released any specifications or code to get temperature monitoring support for CPU sensors in Linux. Thankfully, there are fairly accurate sensors on Ryzen motherboards, and they are accessible through Linux. You can only take full advantage of them by using the latest kernel modules, and in some cases, lm_sensors itself.

Install The Build Dependencies

First, you're going to need to get the build dependencies in line to compile the latest versions of the sensor modules from Git. Assuming you're using a Debian-based distro, install the following.
$ sudo apt install build-essential bison flex linux-headers
$ sudo apt build-dep linux
$ sudo apt build-dep lm-sensors

Determine Your Module

There are two modules that you'll encounter on Ryzen boards. They are it87 and nct6775. Just about every board has one or the other. it87 is more common.

There are a couple of ways to check which one your board has. It might be easiest to do a search online. That might not turn anything up, so you'll have to use modprobe

If you compiled your own kernel, make sure that you built both modules. Distribution kernels should have them available. Then, try to load each of the modules. If you receive an error stating that you don't have that hardware, that's the one you don't have. Try the other one. Whichever one is successful is the one you need to build.


Get And Build

This next section is going to refer to the it87 module, but the process is exactly the same for both. Just substitute in nct6775, if that's the one you have.

Go to the directory you want to build in, and clone the repository from Git.
$ cd Downloads
$ git clone https://github.com/groeck/it87.git
Remember: Substitute nct6775 here too.

Now, change into the cloned directory.
$ cd it87
Depending on your distribution, you might need to modify the Makefile. It needs to point at the actual location of your kernel's source or headers. If you get an error saying that make can't find your kernel headers, you need to modify the file.

Open up the Makefile and look for the following line.
KERNEL_BUILD   := /usr/src/linux-headers-$(TARGET)
Change it to point at the actual location of your headers or source. The example below works for Gentoo.
KERNEL_BUILD    := /usr/src/linux
Once that's settled, you can actually build your module.
$ make -j5
There's not a lot of source, so the build won't take long. Before you install, make sure that your /boot partition is mounted. The install needs your System.map file.
$ sudo mount /dev/sda1 /boot
$ sudo make install

Build lm_sensors

You may or may not need to do this part, but it can't really hurt. So, if you're unsure, do it. cd back up one level and grab the latest sources with Git.
$ cd ..
$ git clone https://github.com/groeck/lm-sensors.git
Change into the new folder and build it.
$ cd lm-sensors
$ make -j5 all
Don't worry if you see some errors. Make sure that the compile actually completes, though. When it's done, install.
$ sudo make install


Test It

You can load the modules now. Use modprobe to do that.
$ sudo modprobe it87
You might need to force an id for the module.
$ sudo modprobe it87 force_id=0x8622 
Some common force id's for it87 are 0x8622, 0x8628, 0x8728, 0x8732. For nct6775, try 0xd120 or 0xd352. Start up your lm_sensors daemon(if it isn't already), and try to detect your sensors.
$ sudo systemctl start lm_sensors
$ sudo sensors-detect
Here's where it might get weird. It might not detect anything in the scan. Don't take it at face value. Run the plain sensors command to see for sure. In many cases, you'll see output from your motherboard sensors.

Some people might not be so lucky. Ryzen's release has been extremely erratic. Minor differences here and there have had a huge impact. If it didn't work for you, check back for updates regularly, and keep your BIOS updated. Eventually,you should see support.

Make It Permanent

Congratulations! You've made it this far. It's time to save your progress, so your computer uses it every time it boots.

Create the following files.
$ sudo touch /etc/modules-load.d/it87.conf
$ sudo touch /etc/modprobe.d/it87.conf
In /etc/modules-load.d/it87.conf, place the line below.
it87
Then, put this line in /etc/modprobe.d/it87.conf.
options it87 force_id=0x8622
Obviously, make sure to use the actual module and force id that got your sensors working.

Closing Thoughts

Ryzen's release has been messy, especially on Linux. That doesn't mean that it's a bad platform. Actually, Ryzen is a great option for a multi-threaded Linux workstation. Just be aware of the potential problems.

In this case, these kernel modules will get your temperature sensors working as needed. Eventually, the need to do this will disappear, as support is merged into the kernel.
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions