LIBPFM(3)

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

πŸ’– LIBPFM(3) β€” nope wait, it's the libpfm_intel_gnr page bestie πŸ’–

okay so this is one of the pages from the LIBPFM(3) manual, straight out of the Linux Programmer's Manual, and it's all about the Intel GraniteRapids situation. strap in, it's lowkey iconic πŸ¦‹


✨ NAME ✨

libpfm_intel_gnr β€” support for Intel GraniteRapids core PMU πŸ’…


✨ SYNOPSIS ✨

#include <perfmon/pfmlib.h>
  • PMU name: gnr
  • PMU desc: Intel GraniteRapids

✨ DESCRIPTION ✨

so the library supports the Intel GraniteRapids core PMU. and ngl, one thing you HAVE to clock: this PMU model only covers each core's PMU, not the socket-level PMU. so don't come for the socket stuff here, it's not that girl πŸŽ€

on Intel GraniteRapids, the number of generic counters depends on the Hyperthreading (HT) mode. yes, it changes based on HT. periodt.

the pfm_get_pmu_info() function returns the maximum number of generic counters in num_cntrs. that's the number you want, bestie πŸ“Š


✨ MODIFIERS ✨

here's the roster of modifiers supported on Intel GraniteRapids processors. each one is a little lewk you can add:

  • 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. boolean modifier πŸ’œ
  • i β€” invert the meaning of the event. the counter will now count cycles in which the event is not occurring. 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. 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] πŸ’…
  • ldlat β€” pass a latency threshold to the MEM_TRANS_RETIRED:LOAD_LATENCY event. integer attribute that must be in the range [1:65535]. it is required for this event. also note that the event must be used with precise sampling (PEBS) β€” no PEBS, no vibes 😭
  • intx β€” monitor the event only when executing inside a transactional memory region (in tx). the event does not count otherwise. boolean modifier, default value is 0 🧚
  • intxcp β€” do not count occurrences of the event when they're inside an aborted transactional memory region. boolean modifier, default value is 0 🫢
  • fe_thres β€” this modifier is for the FRONTEND_RETIRED event only. it defines the period in core cycles after which the IDQ_*_BUBBLES umask counts. it acts as a threshold, i.e., at least a period of N core cycles where the frontend did not deliver X uops. it can only be used with the IDQ_*_BUBBLES umasks. if not specified, the default threshold value is 1 cycle. the valid values are in [1-4095] ⭐

🌈 OFFCORE_RESPONSE events 🌈

Intel GraniteRapids supports two encodings for offcore_response events. the library uses the generic OCR event name to match Intel's definitions. however β€” and this is the throwback β€” the old OFFCORE_RESPONSE_0 and OFFCORE_RESPONSE_1 names are still available for backward compatibility. also clock this: OCR is not an architected event, therefore it can change between processor generations. so don't get too attached πŸ’€

those events need special treatment in the performance monitoring infrastructure because each event uses an extra register to store some settings. so like, in case multiple OCR events are monitored simultaneously, the operating system needs to manage the sharing of that extra register. it's giving shared custody, fr fr 😭

the OCR events are exposed as normal events by the library. the extra settings are exposed as regular umasks. and the library takes care of encoding the events according to the underlying kernel interface. it handles all that, you just show up πŸ’…

on Intel GraniteRapids, the event is treated as a regular event with a flat set of umasks to choose from. it is not possible to combine the various requests, supplier, snoop bits anymore β€” that era is over bestie. therefore the library offers the list of validated combinations as per Intel's official event list. only the approved combos, no improvising πŸ‘‘


πŸ‘‘ Topdown via PERF_METRICS πŸ‘‘

Intel GraniteRapids supports the PERF_METRICS MSR which provides support for Topdown Level 1 and 2 via a single PMU counter. this special counter provides percentages of slots for each metric, which is honestly so main character of it ✨

this feature must be used in conjunction with fixed counter 3, which counts SLOTS, in order to work properly. they're a package deal, no separating them 🫢

the Linux kernel exposes PERF_METRICS metrics as individual pseudo events counting in slots unit; however, to operate correctly all events must be programmed together. the Linux kernel requires all PERF_METRICS events to be programmed as a single event group with the first event as SLOTS required. example:

{slots,topdown-retiring,topdown-bad-spec,topdown-fe-bound,topdown-be-bound,topdown-heavy-ops,topdown-br-mispredict,topdown-fetch-lat,topdown-mem-bound}

Libpfm4 provides access to the PERF_METRICS pseudo events via a dedicated event called TOPDOWN_M. this event uses the pseudo encodings assigned by the Linux kernel to PERF_METRICS pseudo events. using these encodings ensures the kernel detects them as targeting the PERF_METRICS MSR. note that libpfm4 only provides the encodings, and that it is up to the user on Linux to group them and order them properly for the perf_events interface. yeah. that part's on you bestie πŸ™ˆ

there exist generic counter encodings for most of the Topdown metrics and libpfm4 provides support for those via the TOPDOWN event. and note that all subevents of TOPDOWN_M use fixed counters which have, by definition, no actual event codes. the library uses the Linux pseudo event codes for them, even when compiled on non-Linux operating systems. the same holds true for any fixed counters pseudo event exported by libpfm4. same energy across the board 🌸


πŸŽ€ AUTHORS πŸŽ€

  • Stephane Eranian <eranian@gmail.com>

and that's the whole page!! πŸ’– it's dated June, 2024, it lives in the LIBPFM(3) slot of the Linux Programmer's Manual, and yeah β€” that's the version you just read. slay, go count some cycles, ily πŸ¦‹πŸ’…βœ¨