Introduction

It should be no news to people who have been closely following the open source driver development that it was a hit and miss trying to enable radeon drivers. This tutorial might be useful to those users who have been unaware of how to enable dynamic gpu switching at runtime. Thanks to reddit user JackDostoevsky, who wrote the necessary steps to set it up, this tutorial was possible. This tutorial is just the re-iteration of that post. Read this post, if you want to follow the discussion. I have taken a more conservative approach of installation in this tutorial. If you want to checkout git versions, follow above discussion. In case of ubuntu, I am using 13.04 (linux 3.8) with xorg-edgers ppa. Performance wise in a game under wine, this setup was garbage. While in arch, I got better FPS compared to using just the Intel graphics card. Though the performance of native games were largely improved. Therefore in this case, newer versions of the driver and kernel packages are always better.

Step 1: Installation

Ubuntu

If you are using Ubuntu 13.04, and using catalyst driver uninstall it (Reset Everything). Also, if you have disabled AMD graphics card using vgaswitcheroo in (/etc/rc.loal), remove that line. Enable xorg-edgers ppa and update using following commands.

sudo add-apt-repository ppa:xorg-edgers/ppa sudo apt-get update sudo apt-get dist-upgrade

Note: If you have been using intel graphics installer make sure to remove it, because it might interfere with vgaswitcheroo. Also, if you are on ubuntu 13.10 and above (see comments section), you don’t need to enable this ppa to get the basic functionality that was added in linux 3.11 to enable switching. However, as I said above since development regarding radeon drivers and kernel (with amd driver features) is happening at a rapid rate, therefore if you want to experience the improvements as they happen, it is probably a good idea to enable this ppa for the graphics drivers.

Arch

If you have been using catalyst driver, remove it. Also make sure systemd-vgaswitcheroo-units service is disabled (systemctl disable vgaswitcheroo.service), if you had installed it to disable dgpu at boot. Update your installation (sudo pacman -Syu) and make sure ati-dri, xf86-video-ati, lib32-mesa, lib32-mesa-libgl, mesa-libgl, mesa-demos, libtxc_dxtn, lib32-libtxc_dxtn and lib32-ati-dri packages are installed in addition to the standard graphics packages.

On linux 3.11 and above, you can enable radeon.dpm=1 kernel parameter to enable dynamic power management. Also JackDostoevsky notes that “DPM/power management process works significantly better in 3.12 than 3.11 — in 3.12 I get power management on par with Windows”. Therefore, definitely try out 3.12 to get better performance.

Edit: For newer kernels (kernel released in 2015), you no longer need to enable radeon.dpm using kernel parameter (at least in my test in Arch Linux). Since laptops have become quieter without the manual setup of vgaswitcheroo you can perform all the following steps without modifying your system. Just make sure ati drivers are installed, and you have composting enabled (as explained in the next section).

Step 2: Compositing

Make sure the window manager and desktop environment that you use have composting enabled. Standard gnome/cinnamon/unity has it enabled. If you are in xfce you can enable it from settings menu. If you are in LXDE, you can install a package called xcompmgr and enable it in ~/.config/lxsession/LXDE/autostart by adding following line.

@xcompmgr

Default location for LXDE autostart happens to be (/etc/xdg/lxsession/LXDE/autostart), but it did not work for me. Restart your computer (or display manager by properly logging out) for this to take effect.

Step 3: List both GPU providers

Make sure, both graphics cards are enabled. Login as root (sudo su) and read the contents of /sys/kernel/debug/vgaswitcheroo/switch file.

# cat /sys/kernel/debug/vgaswitcheroo/switch 0:IGD:+: Pwr:0000:00:02.0 1:DIS: : Pwr:0000:01:00.0

Run following command and note the id’s of both providers. You could also just note the names of both providers (radeon and Intel in this case).

$ xrandr --listproviders Providers: number : 2 Provider 0: id: 0x79 cap: 0xb, Source Output, Sink Output, Sink Offload crtcs: 2 outputs: 4 associated providers: 0 name:Intel Provider 1: id: 0x53 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 0 associated providers: 0 name:radeon

If it shows only one provider something is wrong. In ubuntu, I found if I boot with AMD graphics card disabled and try to enable it afterwards, above command sometimes did not list both providers. Therefore, make sure you don’t disable amd graphics card using some scripts, or settings. Sometimes just not installing proper packages is the problem. If above command lists both provides then it is all good.

Step 4: Enable prime/optimus dynamic switching.

Run following command (with id’s or names noted above) to enable the switching. Above command listed 0x79 and 0x53 as id’s.

$ xrandr --setprovideroffloadsink 0x53 0x79 or $ xrandr --setprovideroffloadsink radeon Intel

I think the second option is better, because re-installation of the OS resets the ids. After this step, if you prepend DRI_PRIME=1 environment variable command while running your application you force the graphical processing to AMD graphics card and the final composting to happen in intel graphics card. If you don’t use this variable, your application runs on default intel graphics card as it used to.

$ DRI_PRIME=1 yourapplicationname

E.g

$ DRI_PRIME=1 glxinfo | grep"OpenGL renderer" $ DRI_PRIME=1 glxgears -info $ DRI_PRIME=1 wine somegame.exe $ env DRI_PRIME=1 steam steam://rungameid/570

To make the process seamless, you can put the setprovideroffloadsink (above) command in the startup file like .bashrc (or create a .desktop file in ~/.config/autostart/ directory). You can learn about creating a .desktop file in my other post. To run an application create a script that prepends DRI_PRIME=1. E.g. (rungame.sh)

#!/bin/bash DRI_PRIME=1 glxinfo | grep"OpenGL renderer" DRI_PRIME=1 $1

After making above script executable (chmod +x rungame.sh) and adding it to PATH environment variable you can run your game by using the script.

$ rungame.sh "game-name"

As I said above, FPS in one of the games under wine was crap in ubuntu. For xonotic in ultra settings, I got 15 FPS in intel hd 3000, and it maintained 30+ FPS in AMD graphics card. One problem I had on Arch was that the computer turned off without any warnings (most probably overheating). Therefore watch closely the overheating issue. As the development progresses, some of the heating issues should be solved.

Also, one reason for overheating (because of the compact build of laptops) might be because of lack of space between the laptop and the vent (in addition to dust build up). If there is no space between the fan and the other blocking surface (e.g., bottom surface) (from where air flows in), as you progress in the game the gpu heats up, and there is no sufficient cool air to flow in. This in fact, heats up the whole environment to the side of the laptop from which air flows out. Result is, temperature gets above the max (85 degrees) pretty quickly reaches the critical point (100 degrees). At this point, the game is no more playable and computer is almost unusable (even turns off).

You can fix this issue by putting your laptop above a book or something that does not cover up the input vent. In my 2-3 hours gaming test temperature never went above 80 degrees and maintained a fairly playable FPS. When I exited the game, it came to 50 degrees just within 1 minute. You can also use external laptop fan while using heavy applications.

One strange but good thing I have with arch is I don’t have to enable AMD graphics card at boot (radeon.dpm=1). In newer versions, I don’t even install vgaswitcheroo service. The /sys/kernel/debug/vgaswitcheroo/switch shows the discrete (amd) card as DynOff and when it is used it shows ad DynOn as opposed to Pwr and Off as before. After boot I can just run the setprovideroffloadsink and run an application using DRI_PRIME=1.

If this is true (please test this).

This tutorial listed steps necessary for ubuntu and arch. In ubuntu installing ia32-libs installs all the 32-bit libraries necessary for radeon driver to work on 32-bit applications (In newer versions of ubuntu ia32-libs meta package does not exist, therefore you have to install the 32-bit libraries separately as explained in my catalyst driver installation posts for ubuntu). With this information, it should not be hard to set it up on other distributions too. Also, there is lot of development happening in newer kernels regarding dynamic power management and runtime GPU management. Look forward to those releases.

Tell me your experience, and Good Luck 🙂 !!