PERFMON(4)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… PERFMON(4) πŸ’…

okay so real talk, this is from the i386 Kernel Interfaces Manual and it's giving very specific vintage CPU energy, but bestie, the details are all here, periodt.


✨ NAME ✨

perfmon β€” the CPU performance-monitoring interface πŸŽ€


✨ SYNOPSIS ✨

cpu I586_CPU
cpu I686_CPU
options PERFMON

✨ DESCRIPTION ✨

The perfmon driver is literally your VIP pass to the internal performance-monitoring capabilities of the Intel Pentium and Pentium Pro CPUs. 🌸

These processors have two internal counters that you can configure to measure a whole bunch of events β€” either as a count or as a duration (in CPU cycles) β€” plus a cycle counter that counts clock cycles. The perfmon driver gives you a device-style interface to all of that. Slay. ✨

All access to the performance-monitoring counters happens through the special device file /dev/perfmon. This device supports a bunch of ioctl(2) requests, all defined in <machine/perfmon.h> β€” and that same header also holds the definitions of the various counters for both Pentium and Pentium Pro processors. iykyk.

NOTA BENE: 🚨 the set of available events is not the same from processor to processor. It is the responsibility of the programmer to make sure the event numbers they're using are the correct ones for the CPU type being measured. No cap, check your CPU first.

The following ioctl(2) requests are defined:

  • PMIOSETUP (struct pmc) β€” set up a counter with the parameters and flags defined in the structure. The following fields are defined in struct pmc:
    • int pmc_num β€” the number of the counter in question; must be less than NPMC (currently 2).
    • u_char pmc_event β€” the particular event number to be monitored, as defined in <machine/perfmon.h>.
    • u_char pmc_unit β€” the unit mask value, specific to the event type (see the Intel documentation).
    • u_char pmc_flags β€” flags modifying the operation of the counter (see below).
    • u_char pmc_mask β€” the counter mask value; essentially this is a threshold used to restrict the count to events lasting more (or less) than the specified number of clocks.

The following pmc_flags values are defined:

  • PMCF_USR β€” count events in user mode
  • PMCF_OS β€” count events in kernel mode
  • PMCF_E β€” count the number of events rather than their duration
  • PMCF_INV β€” invert the sense of the counter mask comparison
  • PMIOGET (struct pmc) β€” returns the current configuration of the specified counter.
  • PMIOSTART / PMIOSTOP (int) β€” starts (stops) the specified counter. 🫢 but lowkey due to hardware deficiencies, counters must be started and stopped in numerical order. (That is to say, counter 0 can never be stopped without first stopping counter 1.) The driver will not enforce this restriction (since it may not be present in future CPUs). πŸ’€
  • PMIORESET (int) β€” reset the specified counter to zero. The counter should be stopped with PMIOSTOP before it is reset. All counters are automatically reset by PMIOSETUP.
  • PMIOREAD (struct pmc_data) β€” get the current value of the counter. The pmc_data structure defines two fields:
    • int pmcd_num β€” the number of the counter to read
    • quad_t pmcd_value β€” the resulting value as a 64-bit signed integer

In the future, it may be possible to use the RDPMC instruction on Pentium Pro processors to read the counters directly. ✨ manifesting ✨

  • PMIOTSTAMP (struct pmc_tstamp) β€” read the time stamp counter. The pmc_tstamp structure defines two fields:
    • int pmct_rate β€” the approximate rate of the counter, in MHz
    • quad_t pmct_value β€” the current value of the counter as a 64-bit integer

It is important to note that the counter rate, as provided in the pmct_rate field, is often incorrect because of calibration difficulties and non-integral clock rates. This field should be considered more of a hint or sanity-check than an actual representation of the rate of clock ticks. 😭 fr fr don't trust it.


✨ FILES ✨

  • /dev/perfmon β€” character device interface to counters
  • /usr/include/machine/perfmon.h β€” include file with definitions of structures and event types
  • /usr/share/examples/perfmon β€” sample source code demonstrating use of all the ioctl() commands

✨ SEE ALSO ✨

Intel Corporation, Pentium Pro Family Developer's Manual, vol. 3, January 1996, Operating System Writer's Manual. πŸ“š


✨ HISTORY ✨

The perfmon device first appeared in FreeBSD 2.2. πŸ¦‹


✨ AUTHORS ✨

The perfmon driver was written by Garrett A. Wollman, MIT Laboratory for Computer Science. πŸ‘‘


πŸ’– okay that's the whole page bestie! this one's from Debian, dated March 26, 1996, and the page is PERFMON(4) β€” go forth and monitor those CPU events, you icon. πŸ’…βœ¨
πŸ“¦ where this page comes from