Skip to content
Robert Bragg edited this page Nov 11, 2015 · 19 revisions

We should be able to improve on this, but here's something of a brain dump of how to build the drivers needed by GPU Top (these are still in development) and some other dependencies.

I've tried to avoid assuming much prior experience with building the kernel or even Linux packages so of course if you know what you're doing feel free to diverge however suits you.

Prep

For the different userspace components the instructions assume everything will be installed to a common prefix in your home directory. I'll assume the directory is ~/local. To ensure that the configuration scripts for building can find dependencies create a ~/local/bashrc file to setup some environment variables like PATH, PKG_CONFIG_PATH like LD_LIBRARY_PATH:

export PATH=~/local/bin:$PATH
export PKG_CONFIG_PATH=~/local/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=~/local/lib:$LD_LIBRARY_PATH
export LLVM=~/local/bin

The instructions below assume that the above file has been evaluated in your current shell e.g. with:

source ~/local/bashrc

Or

. ~/local/bashrc

Building The Driver:

There are two modes in which GPU Top access Gen performance metrics.

  1. System Wide Metrics

In this mode GPU Top collects metrics directly from the kernel via an 'i915 perf' interface. The git repo for this is here: https://github.com/rib/linux

  1. Single Context Metrics

In this mode GPU Top collects metrics via Mesa, OpenGL using an extension called GL_INTEL_performance_query. Internally Mesa gets metrics through the same 'i915 perf' interface as for system wide metrics. The repo for the mesa driver is here: https://github.com/rib/mesa/. Mesa depends on libdrm as a library that wraps the kernel graphics interfaces, and a branch of libdrm is maintained here: https://github.com/rib/drm

Currently my latest work is under branches named 'wip/rib/i915-perf-properties'. Soon these will be pushed to 'wip/rib/oa-next' once they have had a bit more testing (I still need to test them on Broadwell+)

Kernel:

git clone https://github.com/rib/linux
git checkout -b wip/rib/i915-perf-properties origin/wip/rib/i915-perf-properties

Configure the build to only build what's currently needed by your running machine, to minimize what needs to be built:

make localmodconfig

(Say yes to any questions)

Give the kernel a version suffix to distinguish it from your distro kernel:

make menuconfig

Navigate as follows:

->General setup
'Local version - append to kernel release'

And set the Local version to "-drm-intel"

Make sure to uncheck 'Automatically append version information to the version string' if currently set.

Now build the kernel:

make

(Make a cup of tea)

Personally I then have a ./install.sh script for moving the kernel to /boot, generating an initrd and ensuring it will be listed by Grub. For major distros like Ubuntu and Fedora such a script can simply be:

#!/bin/sh
sudo make modules_install
sudo make install

If you use ArchLinux (I do) then you can use something like:

#!/bin/bash
set +x

VERSION=`cat include/config/kernel.release`

sudo make modules_install
sudo mkinitcpio -k $VERSION -g /boot/initramfs-drm-intel.img
sudo cp -v arch/x86/boot/bzImage /boot/vmlinuz-drm-intel
sudo cp System.map /boot/System.map-drm-intel

With the kernel built, then install it:

chmod +x ./install.sh
./install.sh

Later if fetching newer version of the driver it should typically only be necessary to run:

make
./install.sh

libdrm

git clone https://github.com/rib/drm
cd drm
git checkout -b wip/rib/i915-perf-properties origin/wip/rib/i915-perf-properties
./autogen.sh
./configure --prefix=~/local

mesa

For a more minimal build, I configure Mesa something like:

git clone https://github.com/rib/mesa
cd mesa
git checkout -b wip/rib/i915-perf-properties origin/wip/rib/i915-perf-properties
./autogen.sh
./configure --prefix=~/local --with-dri-drivers=i965 --enable-gles2 --with-egl-platforms=drm,x11 --with-gallium-drivers=
make
make install

Web UI Dependencies (optional)

To be able to support the remote GPU Top UI, we're using Emscripten to handle counter normalization in the browser which depends on a special branch of llvm that needs to be built...

LLVM 'Fastcomp' backend

Note: this takes quite a while to build, though you should only need to do it once.

git clone https://github.com/kripken/emscripten-fastcomp
git clone https://github.com/kripken/emscripten-fastcomp-clang emscripten-fastcomp/tools/clang
mkdir emscripten-fastcomp/build
cd emscripten-fastcomp/build
cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/prefix -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;JSBackend" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_TESTS=OFF
make -j4
make install

After building llvm-fastcomp, fetch emscripten itself:

Emscripten

git clone https://github.com/kripken/emscripten.git

Edit ~/local/bashrc to add the path to the emscripten source repo to the PATH environment variable. E.g.:

export PATH=~/local/bin:~/src/emscripten:$PATH

Check the Emscripten compiler runs with:

emcc -v

libprotobuf

At least on Ubuntu 14.04 it's currently necessary to build libprotobuf from source for a more recent version:

git clone https://github.com/google/protobuf
./autogen.sh
./configure --prefix=~/local
make
make install

Building GPU Top

git clone https://github.com/rib/gputop
git checkout -b wip/rib/i915-perf-properties origin/wip/rib/i915-perf-properties
./autogen.sh
./configure --prefix=~/local

See the message at the end of running ./configure and make sure it shows "GL Intercept: yes" and if you want to test the remote UI, check for "Web UI: yes".

make install

Running GPU Top

For the text based, terminal interface showing system-wide metrics run:

gputop

For the text based, terminal interface showing application specific GL metrics:

gputop glxgears

For the web ui pass --remote as an argument to gputop and then navigate to http://localhost:7890

For reference the 'gputop' program is only a launcher program that sets certain environment variables before running a given program. If you need to use a debugger with gputop it is sometimes better to avoid running the gputop tool and instead set the environment variables manually.

If you run gputop --help it shows what environment variables are set.

To run without the 'gputop' tool, for example:

GPUTOP_MODE=remote GPUTOP_GL_LIBRARY=~/local/lib/libGL.so

LD_LIBRARY_PATH=~/local/lib/wrappers:$LD_LIBRARY_PATH glxgears

Clone this wiki locally