LIBPFM(3)
πΈ LIBPFM(3) πΈ
okay bestie, listen up β this is a page from the Linux Programmer's Manual, and it's all about one very specific little function. no cap. let's get into it π
β¨ NAME β¨
pfm_get_event_attr_info β get event attribute information
β¨ SYNOPSIS β¨
#include <perfmon/pfmlib.h>
int pfm_get_event_attr_info(int idx, int attr, pfm_os_t os, pfm_event_attr_info_t *info);
β¨ DESCRIPTION β¨
so this function fills in info with the tea about the attribute that attr points to, for the event you named in idx, and for the os layer you picked in os. that's it, that's the whole vibe π¦
the pfm_os_t enumeration gives you these choices:
PFM_OS_NONEβ the info you get back is only about what the PMU hardware itself exports. no operating system attributes get taken into account at all. pure hardware, no notes πPFM_OS_PERF_EVENTβ the info you get back includes the actual PMU hardware plus the extra attributes exported by theperf_eventskernel interface. theperf_eventattributes pertain only to the PMU hardware. and ifperf_eventsisn't detected? boom, you get an error back. πPFM_OS_PERF_EVENT_EXTβ the info you get back includes everythingPFM_OS_PERF_EVENTalready gives you plus all the software attributes controlled byperf_events, like sampling period and precise sampling. the full package, fr fr β¨
π the pfm_event_attr_info_t structure π
it's defined like this, bestie:
typedef struct {
const char *name;
const char *desc;
const char *equiv;
size_t size;
uint64_t code;
pfm_attr_t type;
int idx;
pfm_attr_ctrl_t ctrl;
int reserved1;
struct {
int is_dfl:1;
int is_precise:1;
int is_speculative:2;
int support_hw_smpl:1;
int support_no_mods:1;
int reserved:26;
};
union {
uint64_t dfl_val64;
const char *dfl_str;
int dfl_bool;
int dfl_int;
};
} pfm_event_attr_info_t;
and now the field-by-field breakdown, because you deserve to know what every single one of these is doing π
π the fields π
nameβ this is the name of the attribute. it's a read-only string, don't even try it.descβ this is the description of the attribute. also a read-only string. it may contain multiple sentences, so like, a whole paragraph sometimes, she's chatty.equivβ okay so some attributes are literally just variations of other attributes for the same event. they're offered as handy shortcuts so you don't have to supply a long list of attributes. for those attributes, this field is notNULLand it holds the complete equivalent attribute string. that string, once you append it to the event name, may be used in library calls that require an event string. convenient queen πcodeβ this is the raw attribute code. forPFM_ATTR_UMASK, this is the unit mask code. for all other attributes, it's an opaque index. mysterious but valid.typeβ this is the type of the attribute. attributes represent either sub-events or extra filters you can apply to the event. filters (also called modifiers) may be tied to the event or to the PMU register the event is programmed into. the type of an attribute determines how you have to specify it. here are the types:PFM_ATTR_UMASKβ this is a unit mask, i.e., a sub-event. you specify it using its name. depending on the event, it may be possible to specify multiple unit masks. collect them all β¨PFM_ATTR_MOD_BOOLβ this is a boolean attribute. it has a value of0,1,yorn. the value goes after the equal sign, e.g.,foo=1. as a convenience, the equal sign and value may be omitted, in which case this is equivalent to=1. lazy-girl friendly, we love that.PFM_ATTR_MOD_INTEGERβ this is an integer attribute. it has a value which must be passed after the equal sign. the range of valid values depends on the attribute and is usually specified in its description. so read the description, bestie, it's there for a reason.
idxβ this is the attribute index. it's identical to the value ofattryou passed to the call, and it's provided for completeness. a little echo of your own choices, cute.sizeβ this field contains the size of the struct passed. it exists so the struct can be extended without breaking backward compatibility. the value should be set tosizeof(pfm_event_attr_info_t). if instead you specify a value of0, the library assumes the struct you passed is identical to the first ABI version, whose size isPFM_ATTR_INFO_ABI0. so if fields were added after that first ABI, they will not be set by the library. the library does check that bytes beyond what is implemented are zeroes. it's checking up on you πis_dflβ this field tells you whether or not this attribute is set by default. this applies mostly toPFM_ATTR_UMASK. if a unit mask is marked as default, and no unit mask is specified in the event string, then the library uses it by default. note that there may be multiple defaults per event depending on how unit masks are grouped. so many main characters.is_preciseβ this field tells you whether or not this umask supports precise sampling. precise sampling is a hardware mechanism that avoids instruction address skid when using interrupt-based sampling. on Intel X86 processors, this field indicates that the umask supports Precise Event-Based Sampling (PEBS). iconic behavior tbh.is_speculativeβ this bitfield tells you whether or not the attribute includes occurrences happening during speculative execution, for both wrong and correct paths. given that this kind of event information isn't always available from vendors, this field uses multiple bits. a value ofPFM_EVENT_INFO_SPEC_NAmeans speculation information is not available. a value ofPFM_EVENT_INFO_SPEC_TRUEmeans the attribute counts during speculative execution. a value ofPFM_EVENT_INFO_SPEC_FALSEmeans the attribute does not count during speculative execution. three moods, pick one πsupport_hw_smplβ this boolean field indicates that the attribute (in this case a umask) supports hardware sampling. that means the hardware can sample this event + umasks without involving the kernel at each sample. no kernel, no drama.support_no_modsβ this boolean field indicates that the attribute (in this case a umask) does not support any hardware or software modifiers, such as privilege level filters, sampling, precise sampling, and such. this is necessary when select umasks of an event have more restrictions than others, e.g., the event and most umasks support modifiers except a few umasks. some of them just want to be left alone.dfl_val64,dfl_str,dfl_bool,dfl_intβ this union contains the value of an attribute. forPFM_ATTR_UMASK, it's the unit mask code; for all other types, it's the actual value of the attribute.ctrlβ this field indicates which layer or source controls the attribute. here are the sources:PFM_ATTR_CTRL_UNKNOWNβ the source controlling the attribute is not known. mystery era π΅οΈPFM_ATTR_CTRL_PMUβ the attribute is controlled by the PMU hardware.PFM_ATTR_CTRL_PERF_EVENTβ the attribute is controlled by theperf_eventskernel interface.
reservedβ these fields must be set to zero. no negotiation. zero. π«Ά
β¨ RETURN β¨
if everything goes well, the function returns PFM_SUCCESS and hands you the attribute info in info. otherwise it returns an error code, and you deal with it. π
β¨ ERRORS β¨
PFMLIB_ERR_NOINITβ library has not been initialized properly. ma'am, please initialize.PFMLIB_ERR_INVALβ theidxorattrarguments are invalid, orinfoisNULL, orsizeis not zero.PFM_ERR_NOTSUPPβ the requested os layer has not been detected on the host system. it's not here, bestie, sorry.
β¨ AUTHOR β¨
Stephane Eranian <eranian@gmail.com> β legend behavior, we thank you for your service π
and that's the whole page, bestie π this manual page was dated December, 2009 and comes from LIBPFM(3) β the Linux Programmer's Manual. go forth and query your event attributes with confidence, periodt. β¨ππ¦
π¦ 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
- debian trixie: libpfm4-dev 4.13.0+git99-gc5587f9-1 Β· 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
- ubuntu questing: libpfm4-dev 4.13.0+git99-gc5587f9-1
- ubuntu resolute: libpfm4-dev 4.13.0+git106-g3e4031b-1 Β· MIT
- ubuntu resolute: libpfm4-dev 4.13.0+git106-g3e4031b-1ubuntu0.1 Β· MIT
- ubuntu stonking: libpfm4-dev 4.13.0+git106-g3e4031b-1ubuntu1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms