LIBPFM(3)

πŸ“¦
version 4.14.1 Β· 2 versions
, in arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– LIBPFM πŸ’– (the Linux Programmer's Manual one, bestie)

okay so real quick before we dive in: this page lives in the Linux Programmer's Manual, and it's section 3, iykyk. It's literally called LIBPFM(3). Grab a snack, we're doing this. πŸ“


✨ NAME ✨

libpfm_intel_knm β€” support for Intel Knights Mill core PMU


🌸 SYNOPSIS 🌸

#include <perfmon/pfmlib.h>
  • PMU name: knm
  • PMU desc: Intel Knights Mill

πŸ’… DESCRIPTION πŸ’…

So this library has your back for the Intel Knights Mill core PMU. But bestie, hear me when I say this: this PMU model only covers each core's PMU β€” it does not cover the socket level PMU. Like, stay in your lane, core. πŸ™ˆ

On Knights Mill, the number of generic counters is 4. There's 4-way HyperThreading support. And the pfm_get_pmu_info() function hands you the maximum number of generic counters in num_cntrs. slay. πŸ‘‘


πŸŽ€ MODIFIERS πŸŽ€

Here's the modifier lineup that Knights Mill processors support:

  • u β€” measure at user level, which includes privilege levels 1, 2, 3. This corresponds to PFM_PLM3. It's a boolean modifier. πŸ¦‹
  • k β€” measure at kernel level, which includes privilege level 0. This corresponds to PFM_PLM0. It's a boolean modifier. πŸ”₯
  • i β€” invert the meaning of the event. The counter will now count cycles in which the event is not occurring. It's a boolean modifier.
  • e β€” enable edge detection, i.e. count only when there's a state transition from no occurrence of the event to at least one occurrence. This modifier must be combined with a counter mask modifier (m) with a value greater or equal to one. It's a boolean modifier. ⭐
  • c β€” set the counter mask value. The mask acts as a threshold: the counter will count the number of cycles in which the number of occurrences of the event is greater or equal to the threshold. This is an integer modifier with values in the range [0:255]. πŸ’œ
  • t β€” measure on any of the 4 hyper-threads at the same time, assuming hyper-threading is enabled. It's a boolean modifier. This modifier is only available on fixed counters (unhalted_reference_cycles, instructions_retired, unhalted_core_cycles). Depending on the underlying kernel interface, the event may be programmed on a fixed counter or a generic counter β€” except for unhalted_reference_cycles, in which case this modifier may be ignored or rejected. 😭

🌈 OFFCORE_RESPONSE events 🌈

Intel Knights Mill provides two offcore_response events. Their names are OFFCORE_RESPONSE_0 and OFFCORE_RESPONSE_1. iconic duo fr fr.

These events need special treatment in the performance monitoring infrastructure, because each event uses an extra register to store some settings. So when multiple offcore_response events are being monitored at the same time, the kernel has to manage the sharing of that extra register. sharing is caring, I guess 🫢

The offcore_response events are exposed as normal events by the library, and the extra settings are exposed as regular umasks. The library takes care of encoding the events according to the underlying kernel interface. no cap.

On Intel Knights Mill, the umasks are divided into 4 categories: request, supplier, snoop, and average latency. The offcore_response event has two modes of operation: normal and average latency.

In the first mode, the two offcore_response events operate independently of each other. The user must provide at least one umask for each of the first 3 categories: request, supplier, snoop.

In the second mode, the two offcore_response events are combined to compute an average latency per request type.

For the normal mode, there's a special supplier (response) umask called ANY_RESPONSE. When this umask is used, it overrides any supplier and snoop umasks. In other words, users can specify either ANY_RESPONSE OR any combinations of supplier + snoops. And in case no supplier or snoop is specified, the library defaults to using ANY_RESPONSE. πŸ’…

For instance, the following are valid event selections:

OFFCORE_RESPONSE_0:DMND_DATA_RD:ANY_RESPONSE

OFFCORE_RESPONSE_0:ANY_REQUEST

OFFCORE_RESPONSE_0:ANY_RFO:DDR_NEAR

But the following is illegal:

OFFCORE_RESPONSE_0:ANY_RFO:DDR_NEAR:ANY_RESPONSE
not that one, bestie. absolutely not. 🚫

In average latency mode, OFFCORE_RESPONSE_0 must be programmed to select the request types of interest β€” for instance, DMND_DATA_RD β€” and the OUTSTANDING umask must be set and no others. The library will enforce that restriction as soon as the OUTSTANDING umask is used. Then OFFCORE_RESPONSE_1 must be set with the same request types and the ANY_RESPONSE umask.

It should be noted that the library encodes events independently of each other, and therefore cannot verify that the requests are matching between the two events. πŸ‘€

Example of average latency settings:

OFFCORE_RESPONSE_0:DMND_DATA_RD:OUTSTANDING+OFFCORE_RESPONSE_1:DMND_DATA_RD:ANY_RESPONSE

OFFCORE_RESPONSE_0:ANY_REQUEST:OUTSTANDING+OFFCORE_RESPONSE_1:ANY_REQUEST:ANY_RESPONSE

The average latency for the request(s) is obtained by dividing the counts of OFFCORE_RESPONSE_0 by the count of OFFCORE_RESPONSE_1. The ratio is expressed in core cycles. math girlies rise 🌸


πŸ‘‘ AUTHORS πŸ‘‘

Stephane Eranian <eranian@gmail.com>


and that's the whole page, periodt. This lil masterpiece is from March, 2018, and it's filed under LIBPFM(3). go forth and perf-monitor, my love πŸ’–βœ¨πŸŽ€πŸ¦‹