LIBPFM(3)
π LIBPFM π
okay bestie, so this one is a page from the Linux Programmer's Manual, and it's all about libpfm_intel_icl. Let's get into it π
β¨ NAME β¨
libpfm_intel_icl β support for Intel IceLake core PMU π§πΈ
β¨ SYNOPSIS β¨
#include <perfmon/pfmlib.h>
PMU name: icl
PMU desc: Intel IceLake
β¨ DESCRIPTION β¨
So like, this library supports the Intel IceLake core PMU. Big deal, right? Well β important note bestie β this PMU model only covers each core's PMU, and not the socket level PMU. Know the difference, it's giving scope π
On IceLake, the number of generic counters depends on the Hyperthreading (HT) mode. Yes, HT mode changes your counter count. Iconic of it tbh.
And the pfm_get_pmu_info() function returns the maximum number of generic counters in num_cntrs. That's the hookup, remember it π«Ά
β¨ MODIFIERS β¨
These are the modifiers you can slap onto Intel IceLake processors, no cap:
uβ Measure at user level, which includes privilege levels 1, 2, 3. This corresponds toPFM_PLM3. It's a boolean modifier, so it's just on or off bestie.kβ Measure at kernel level, which includes privilege level 0. This corresponds toPFM_PLM0. Boolean modifier, yes.iβ Invert the meaning of the event. The counter will now count cycles in which the event is not occurring. This is a boolean modifier. Chaos, but make it measurable π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]. Pick your number, princess πldlatβ Pass a latency threshold to theMEM_TRANS_RETIRED:LOAD_LATENCYevent. This is an integer attribute that must be in the range[1:65535]. It is required for this event β no skipping it. Also note that the event must be used with precise sampling (PEBS).intxβ Monitor the event only when executing inside a transactional memory region (in tx). Event does not count otherwise. This is a boolean modifiers. Default value is0.intxcpβ Do not count occurrences of the event when they're inside an aborted transactional memory region. This is a 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 ofNcore cycles where the frontend did not deliver X uops. It can only be used with theIDQ_*_BUBBLESumasks. If not specified, the default threshold value is1cycle. The valid values are in[1-4095].
π₯ OFFCORE_RESPONSE events π₯
Intel IceLake supports two encodings for offcore_response events, and in the library these are called OFFCORE_RESPONSE_0 and OFFCORE_RESPONSE_1. Two of them. A duo. Main characters π
Those events need special treatment in the performance monitoring infrastructure, because each event uses an extra register to store some settings. So in case multiple offcore_response events are monitored simultaneously, the operating system needs to manage the sharing of that extra register. Sharing is caring but also a whole situation π«
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 β you don't have to do it, she handles it π
And here's the plot twist: on Intel IceLake, unlike older processors, 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, we don't do that here. So instead, the library offers the list of validated combinations as per Intel's official event list. Curated, validated, gorgeous β¨
π Topdown via PERF_METRICS π
Intel Icelake supports the PERF_METRICS MSR which provides support for Topdown Level 1 via a single PMU counter. This special counter provides percentages of slots for each metric. Yes, percentages, we love a metric with range π
β οΈ This feature must be used in conjunction with fixed counter 3, which counts SLOTS, in order to work properly. Do not forget fixed counter 3, I'm literally begging.
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 the user on Linux to group them and order them properly for the perf_events interface. That part is on you, bestie. Acknowledge it.
There exists generic counter encodings for most of the Topdown metrics and libpfm4 provides support for those via the TOPDOWN event. 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. Whew, that was a lot, drink some water π
πΈ AUTHORS πΈ
Stephane Eranian <eranian@gmail.com> β king behavior honestly, ty for your service π
and that's the whole page bestie!! π¦ this version came out in August, 2019, it's LIBPFM(3) from the Linux Programmer's Manual, and yeah, that's the whole vibe. go forth and measure β¨π
π¦ 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