Giter Club home page Giter Club logo

amdgpu-clocks's Introduction

AMDGPU Clocks

Introduction

This is a simple script that can be used to set custom power states for recent AMD GPUs that are driven by amdgpu Linux kernel driver. The script is able to set custom clocks, voltages and some other power states, assuming that Radeon OverDrive is enabled in the driver. The OverDrive is not enabled by default as of Linux 5.x, it can be enabled by setting 14th bit (0x4000) of a ppfeaturemask amdgpu driver to 1. For example, setting amdgpu.ppfeaturemask=0xfffd7fff or amdgpu.ppfeaturemask=0xffffffff kernel boot option will do the trick. This would enable amdgpu driver sysfs API that allows fine grain control of GPU power states (GPU & VRAM clocks & voltages, depending on actual hardware). It should work on Polaris, Vega (unfortunately Vega found on AMD APUs does not expose this API) and Navi cards, and it can be used to easily manage multiple AMD graphics cards.

How does it work

By default, custom power states for a particular GPU are defined in /etc/default/amdgpu-custom-state.cardX file, which is expected to be created by user, and where X corresponds to a card in /sys/class/drm/cardX. The custom state file have same format as the actual /sys/class/drm/cardX/device/pp_od_clk_voltage, with option to add newlines, comments (lines starting with #) and few additional parameters, used to set extra power state parameters. These are FORCE_SCLK & FORCE_MCLK, that can be used to limit GPU and memory power states to a particular subset of states, FORCE_POWER_CAP that can be used to set desired power cap, and FORCE_PERF_LEVEL that can be used to force desired power_dpm_force_performance_level of a card (which can be auto, low, high, manual, etc).

Here is an example how custom power state file may look like for Polaris cards:

$ cat /etc/default/amdgpu-custom-states.card0
# Set custom GPU states 6 & 7:
OD_SCLK:
6:       1000MHz        860mV
7:       1050MHz        890mV
# Set custom memory states 1 & 2:
OD_MCLK:
1:        900MHz        800mV
2:       1600MHz        900mV
# Only allow SCLK states 5, 6 & 7:
FORCE_SCLK: 5 6 7
# Force fixed memory state:
FORCE_MCLK: 2
# Force power limit (in micro watts):
FORCE_POWER_CAP: 90000000
# In order to allow FORCE_SCLK & FORCE_MCLK:
FORCE_PERF_LEVEL: manual

Here is an example how custom power state file may look like for Navi cards:

# For Navi (and Radeon7) we can only set highest SCLK & MCLK, "state 1":
OD_SCLK:
1: 1550MHz
OD_MCLK:
1: 750MHz
# More fine-grain control of clocks and voltages are done with VDDC curve:
OD_VDDC_CURVE:
0: 800MHz @ 800mV
1: 1125MHz @ 820mV
2: 1550MHz @ 850mV
# Force power limit (in micro watts):
FORCE_POWER_CAP: 87000000
FORCE_PERF_LEVEL: manual

Installing and manually running the script

Simply place the script in /usr/local/bin/amdgpu-clocks:

sudo ln -s $(pwd)/amdgpu-clocks /usr/local/bin/amdgpu-clocks

and specify custom power states in /etc/default/amdgpu-custom-states.card0:

$ sudo amdgpu-clocks
Detecting the state values at /sys/class/drm/card0/device/pp_od_clk_voltage:
  SCLK state 0: 300MHz, 750mV
  SCLK state 1: 500MHz, 775mV
  SCLK state 2: 600MHz, 785mV
  SCLK state 3: 700MHz, 800mV
  SCLK state 4: 800MHz, 820mV
  SCLK state 5: 900MHz, 840mV
  SCLK state 6: 950MHz, 850mV
  SCLK state 7: 1000MHz, 860mV
  MCLK state 0: 300MHz, 750mV
  MCLK state 1: 1000MHz, 800mV
  MCLK state 2: 1750MHz, 900mV
  Maximum clocks & voltages:
    SCLK clock 2000MHz
    MCLK clock 2250MHz
    VDDC voltage 1150mV
  Curent power cap: 87W
Verifying user state values at amdgpu-custom-states.card0:
  SCLK state 6: 1000MHz, 860mV
  SCLK state 7: 1050MHz, 890mV
  MCLK state 2: 1600MHz, 900mV
  Force SCLK state to 5 6 7
  Force MCLK state to 2
  Force power cap to 90W
  Force performance level to manual
Committing custom states to /sys/class/drm/card0/device/pp_od_clk_voltage:
  Done

The script can also be invoked with specific custom state file prefix (can be a directory, case trailing slash is supplied), for example:

$ sudo USER_STATES_PATH=custom-states amdgpu-clocks

This will load and apply custom states from all custom-states.card* files in the current directory. Script can also be used with an additional 'restore' parameter that can be used to restore all states to the initial defaults (states before script was executed for the first time), with exception of pp_power_profile_mode which will be set to 0.

Making the custom power states persist

This can be achieved by placing provided systemd service file in /lib/systemd/system/ directory, and enable it:

$ sudo systemctl enable --now amdgpu-clocks

However, if your system goes to suspend state, the above service will not auto-restart (due to RemainAfterExit parameter). To fix that copy provided file into /usr/lib/systemd/system-sleep

$ cp amdgpu-clocks-resume /usr/lib/systemd/system-sleep/

Of course, one should not forget to place the actual custom power states in /etc/default/amdgpu-custom-state.cardX.

amdgpu-clocks's People

Contributors

sibradzic avatar j-m-hoffmann avatar terencode avatar adolfintel avatar naripok avatar chinf avatar nightbane112 avatar pavelis avatar erickgruis avatar marcinstobba avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.