LIBPFM(3)
π 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 toPFM_PLM3. it's a boolean modifier β¨kβ measure at kernel level, which includes privilege level 0. this corresponds toPFM_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 theMEM_TRANS_RETIRED:LOAD_LATENCYevent. 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 is0π§intxcpβ do not count occurrences of the event when they're inside an aborted transactional memory region. boolean modifier, default value is0π«Άfe_thresβ this modifier is for theFRONTEND_RETIREDevent only. it defines the period in core cycles after which theIDQ_*_BUBBLESumask 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 theIDQ_*_BUBBLESumasks. 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 π¦π β¨
π¦ where this page comes from
- arch rolling: libpfm 4.14.1-1 Β· MIT
- centos-stream 10: libpfm-devel 4.14.1-1.el10 Β· MIT
- centos-stream 9: libpfm-devel 4.14.1-1.el9 Β· MIT
- centos-stream 9: libpfm-devel 4.14.1-1.el9 Β· MIT
- fedora 43: libpfm-devel 4.14.1-2.fc43 Β· MIT
- fedora 43: libpfm-devel 4.14.1-2.fc43 Β· MIT
- fedora 44: libpfm-devel 4.14.1-2.fc44 Β· MIT
- fedora 44: libpfm-devel 4.14.1-2.fc44 Β· MIT
- nixos 26.05: papi 7.2.0
- nixpkgs unstable: libpfm 4.14.1
- nixpkgs unstable: papi 7.2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms