Linux perf tools on ARM64
  • May 26, 2020 by Kai Wolf

For a current client project I need to get a thorough understanding of the performance bottlenecks for several target architectures, including ARM64. For this, I’ve already ordered an ODROID-C2 development board. This is currently the only ARM64 development board available that also supports Android as far as I am aware.

When doing a performance analysis (especially under Linux) I really like using perf as it supports a wide range of options such as hw/sw performance counters and has several useful subcommands. However, getting perf to run on a host system also requires the kernel sources as perf will emit a warning in any other case. Usually this can be achieved by simply fetching the sources for the current kernel by using a package manager such as apt:

$ apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`

In the case of ODROID-C2 things are a bit more complicated, which is the main motivation for this blog post. First of all, the kernel for this board is quite old (August 2014). Hence, we probably won’t find the kernel sources from within the package sources of our distribution, which turned out to be the case. In this case, we need to fetch the original sources provided by ODROID and also checkout the correct branch for the current version of this dev board:

git clone --depth 1 -b odroidc2-v3.16.y

If we change into the subdirectory of perf from within the kernel sources and try to compile the correct version ourselves, we receive another error though:

In file included from util/event.c:3:0:
util/event.h:95:17: error: ‘PERF_REGS_MAX’ undeclared here (not in a function); \
did you mean ‘PERF_REGS_MASK’?
  u64 cache_regs[PERF_REGS_MAX];
  CC       util/evsel.o

As already mentioned, this board is using a rather old kernel version. Thus, we need to fix this error ourselves by adding another define

// tools/perf/arch/arm64/include/perf_regs.h

Afterwards perf can be compiled with a simple make && make install and we should be good to go.

$ perf --version
perf version 3.16.82.g2ddf

I’m also available for software consultancy, training and mentoring. Please contact me, if you are interested in my services.