Amdgpu

amdgpu hwmon interface

Read thermal and other info provided by the amdgpu kernel driver.

1
/sys/class/drm/card0/device/hwmon/hwmon1/

Enable fan speed sensors

This is a prequisite for automatic management and fan1_target.

1
echo 1 > /sys/class/drm/card0/device/hwmon/hwmon1/fan1_enable

Systemd service to set amdgpu /sys options.

1
2
3
4
5
6
7
8
9
10
11
#/etc/systemd/system/amdgpu-settings.service
[Unit]
Description=Set amdgpu /sys options

[Service]
Type=oneshot

ExecStart=/home/user/bin/amdgpu-settings.sh

[Install]
WantedBy=multi-user.target

Same after sleep.

1
2
3
4
5
6
7
8
9
10
11
12
#/etc/systemd/system/amdgpu-settings-after-sleep.service
[Unit]
Description=Set amdgpu /sys options after sleep
After=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

[Service]
Type=oneshot

ExecStart=/home/user/bin/amdgpu-settings.sh

[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

Dynamic Power Management

Get vbios and card info

1
cat /sys/class/drm/card0/device/vbios_version

Feature mask to enable overdrive, prevent overheating

Older cards are by default clocked over safe limits by amdgpu.

Check frequencies / clocks.

1
2
/sys/class/drm/card0/device/pp_dpm_sclk # gpu
/sys/class/drm/card0/device/pp_dpm_mclk # memory

Enable overdrive to change frequencies.

1
cat /sys/module/amdgpu/parameters/ppfeaturemask
1
0xfff7bfff

Calculate the mask with the overdrive bit on.

1
printf '%#x' "$(( $(cat /sys/module/amdgpu/parameters/ppfeaturemask) | 0x4000 ))"
1
0xfff7ffff

Set the mask permanently.

Use custom clocks

After overdrive is enabled, custom frequencies can be used.

1
git clone https://github.com/sibradzic/amdgpu-clocks.git
1
2
3
4
5
6
cd amdgpu-clocks/
sudo cp amdgpu-clocks /usr/local/bin/
sudo cp amdgpu-clocks.service /etc/systemd/system/
sudo systemctl enable amdgpu-clocks.service
sudo cp amdgpu-clocks-resume /usr/lib/systemd/system-sleep/
sudo cp ~/.config/amdgpu-custom-state.card0 /etc/default/

Make sure to use your card manufacturer recommended settings first to make sure everything works.

1
2
3
4
5
6
7
8
#/etc/default/amdgpu-custom-state.card0
OD_VDDGFX_OFFSET:
-75mV
OD_SCLK:
0: 500MHz
1: 1980MHz
FORCE_PERF_LEVEL: manual
FORCE_POWER_CAP: 270

Kernel parameters

Allow recovering the device after a hang.

https://www.kernel.org/doc/html/v4.20/gpu/amdgpu.html

1
2
3
#/etc/modprobe.d/amdgpu.conf
# Enable recovery after hang. Enable overdrive, bit 14.
options amdgpu gpu_recovery=1 ppfeaturemask=0xfff7ffff
1
update-initramfs -uk all

Show kernel parameters of module.

1
systool -vm amdgpu

Display GPU statistics using mesa

List all names (help is one of the names).

1
GALLIUM_HUD=help glxgears

Use with Steam.

1
GALLIUM_HUD=shader-clock,memory-clock %command%

More examples

USB HID device polling rate

Show polling interval. Frequency (rate) in Hz (polls in a second). Interval = frequency / 1000 (for milliseconds, one thousandth of a second). To set 1000 Hz, the interval is 1000 / 1000 = 1.

1
systool -m usbhid -A jspoll

Get info about device using using lsusb.

Set polling interval for usbhid kernel driver. This uses kbpoll (keyboards), mousepoll, jspoll (game pads). If your device is not a Human Interface Device, other solutions may be necessary, like recompiling your driver.

1
2
#/etc/modprobe.d/usbhid.conf
options usbhid kbpoll=1 mousepoll=1