Skip to content

TutorialLikwidPerf

TomTheBear edited this page Aug 3, 2018 · 5 revisions

How to use LIKWID and perf

Running LIKWID with perf backend

Since LIKWID 4.3 it is possible to use Linux kernel's perf_event interface to measure the events and still benefit from the features of LIKWID (Performance groups, derived metrics and the MarkerAPI).

To configure LIKWID, set ACCESSMODE=perf_event before compiling. Afterwards, just do a make && make install. No root permissions required for installation if the install destination is writable or the user.

Currently, perf_event does not support thermal readings, thus this does not work with the perf_event backend. There might also be some other drawbacks when access to a MSR is required (likwid-features, likwid-setFrequencies, ...)

Why the execpid, perfflags and perfpid options?

When running LIKWID with perf_event, you can limit the measurements to some PID. Commonly, likwid-perfctr is used as a wrapper for the real application. If you want to limit the counting to the application, you can use the --execpid option.

If you want to measure some other application (not wrapped by likwid-perfctr), you can use the --perfpid <PID> option.

With --perfflags <FLAGS> you can specific additional flags handed over to the perf_event backend (see flags field for perf_event_open syscall).

Feature limitations

LIKWID does more than reading just the performance counter registers. There are other registers that contain useful information like the CPU turbo frequency limits, the state of prefetchers, Uncore frequency (Intel only), ...

Here is a list of features that don't work:

LIKWID specifies counter names so you can address in which counter the event should be measured. Perf_event doesn't allow to specify the counter as it schedules the events more freely and decides itself where to count the event (at least I havn't found a way). Although you cannot specify more counters that are available on your system as LIKWID limits it, perf_event might schedule them differently as you think, e.g. the instructions event of perf_event does not always use the fixed-purpose counter that counts only instructions but uses a general-purpose counter for that. If you have specified additional events that have to use the general-purpose counters, perf_event might multiplex the events on the general-purpose counters (commonly no problem but in rare cases the counts might be off a little).

Using LIKWID's information with perf

The great commandline tool for perf_event is perf. It provides a set of pre- defined events but it is also possible to add raw events. If you want to measure a specific event known by LIKWID, you can use the event data to add it as a raw event to perf.

When running likwid-perfctr -e or likwid-perfctr -E <searchstr> you get a list like this:

UOPS_RETIRED_ALL, 0xC2, 0x1, PMC
UOPS_RETIRED_CORE_ALL, 0xC2, 0x1, PMC
UOPS_RETIRED_RETIRE_SLOTS, 0xC2, 0x2, PMC

The first is the event name, followed by the event identifier and the umask. The final entry in a line defines the counter (group) that can be used for the event.

For events in the PMC group, you can use r<umask><eventid> as input to perf, so if we want to add UOPS_RETIRED_ALL, it looks like this: perf -e r01C2 a.out

You can probably add event options as well but you have to get the bit index from sysfs. The data resides in /sys/devices/cpu/format/. LIKWID option names and perf option names are not similar, but not difficult:

  • EDGEDETECT -> edge
  • THRESHOLD -> cmask
  • INVERT -> invert
  • ANYTHREAD -> any

I didn't find any documentation how to add Uncore raw events.

Clone this wiki locally