LIBPFM(3)

πŸ’… LIBPFM β€” the MIPS 74k era

okay bestie, so this is a page out of the Linux Programmer's Manual, section 3, and it's all about the libpfm side of things. it's literally called LIBPFM(3) and it's the whole glow-up guide for one very specific little processor family. let's get into it 🫢


✨ NAME ✨

libpfm_mips_74k β€” support for MIPS 74k processors

like, that's it. that's the whole job. it's giving "i have one hyper-specific niche and i am OBSESSED with it" πŸ’–


🌸 SYNOPSIS 🌸

#include <perfmon/pfmlib.h>

also, for the record:

  • PMU name: mips_74k
  • PMU desc: MIPS 74k

πŸ¦‹ DESCRIPTION πŸ¦‹

so the library supports MIPS 74k processors, and it does it in big or little endian modes β€” either way, it's got you, no cap. πŸŽ€


πŸ”₯ ENCODINGS πŸ”₯

okay this is the part where you gotta pay attention, bestie, because it's lowkey the whole plot twist.

on this processor, what is measured by an event depends on the event code AND on the counter it is programmed on. not just one β€” both. the way that the meaning of the event code changes between odd and even indexed counters is honestly iconic in a chaotic way. πŸ’€

for instance, event code 0x2 means 'PREDICTED_JR31' when it's programmed on even-indexed counters, and it means 'JR_31_MISPREDICTIONS' when it's on odd-indexed counters. same code, different personality depending on where it lands. main character behavior fr fr.

so to correctly measure an event, you need both the event encoding and a list of possible counters. both. don't skip one. πŸ™ˆ

now, when pfm_get_os_event_encoding() is used with PFM_OS_NONE to return the raw PMU encoding, the library hands you back two values:

  • the event encoding, as per the architecture manual
  • a bitmask of valid counters to program it on

for example, for 'JR_31_MISPREDICTIONS', the library returns codes[0] = 0x4a, codes[1]= 0xa (supported on counter 1, 3). slay. ✨

and just so you know: the encoding for a specific kernel interface may vary, and that whole situation is handled internally by the library. so you don't gotta stress about it β€” it's taken care of. πŸ’…

πŸ’– MODIFIERS πŸ’–

the following modifiers are supported on MIPS 74k:

  • u β€” Measure at user level. this corresponds to PFM_PLM3. it's a boolean modifier. βœ…
  • k β€” Measure at kernel level. this corresponds to PFM_PLM0. boolean modifier. βœ…
  • e β€” Measure at exception level. this corresponds to PFM_PLM2. boolean modifier. βœ…
  • s β€” Measure at supervisor level. this corresponds to PFM_PLM1. boolean modifier. βœ…
⚠️ okay real talk: it should be noted that those modifiers are available for encoding as raw mode with PFM_OS_NONE, but they may not all be present with specific kernel interfaces. so like, don't assume the whole set shows up everywhere β€” vibe check your kernel interface first. 😭

πŸ‘‘ AUTHORS πŸ‘‘

Stephane Eranian <eranian@gmail.com>


and that's the whole page, bestie!! 🌈 the source/version is LIBPFM(3), and it's dated September, 2011 β€” a vintage queen, honestly. mwah. πŸŽ€πŸ’‹