PERFMON(4)
β¨ PERFMON(4) β¨
okay bestie, this is a page from the i386 Kernel Interfaces Manual β yes, the i386 one, we're going vintage today π
β and it's all about perfmon, the CPU performance-monitoring interface. buckle up π
πΈ NAME πΈ
perfmon β the CPU performance-monitoring interface, i.e. the little door into your CPU's built-in "how hard am I working tho" hardware π«Ά
β¨ SYNOPSIS β¨
cpu I586_CPU
cpu I686_CPU
options PERFMON
like, you gotta have one of those CPUs and you gotta turn on that option. no option, no vibes. periodt.
π DESCRIPTION π
so the perfmon driver hands you the keys to the internal performance-monitoring capabilities of the Intel Pentium and Pentium Pro CPUs. these processors are lowkey flexing 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, bestie, we're counting in cycles), plus there's a cycle counter that just counts clock cycles. and perfmon gives you a device-style interface to all of that. iconic. π₯
every single bit of access to the performance-monitoring counters goes through the special device file /dev/perfmon. this device supports a bunch of ioctl(2) requests, which are defined in <machine/perfmon.h> β and that header is also where the definitions of the various counters live, for both Pentium and Pentium Pro processors. π¦
NOTA BENE: the set of available events differs from processor to processor. it is the responsibility of the programmer to make sure the event numbers used are the correct ones for the CPU type being measured. no cap, this one matters. β οΈ
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 instruct pmc:int pmc_numβ the number of the counter in question; must be less thanNPMC(currently2).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 modePMCF_OSβ count events in kernel modePMCF_Eβ count number of events rather than their durationPMCF_INVβ invert the sense of the counter mask comparison
PMIOGETβ (struct pmc) returns the current configuration of the specified counter. like a lil vibe check on your counter's settings πPMIOSTARTPMIOSTOPβ (int) starts (stops) the specified counter. and here's the tea π΅: 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). so like, it's on you, bestie πPMIORESETβ (int) reset the specified counter to zero. the counter should be stopped withPMIOSTOPbefore it is reset. all counters are automatically reset byPMIOSETUP. π§PMIOREADβ (struct pmc_data) get the current value of the counter. thepmc_datastructure defines two fields:int pmcd_numβ the number of the counter to readquad_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. β¨
PMIOTSTAMPβ (struct pmc_tstamp) read the time stamp counter. thepmc_tstampstructure defines two fields:int pmct_rateβ the approximate rate of the counter, in MHzquad_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. so don't trust it with your life, she's just guessing π
π 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 theioctl()commands
π¦ SEE ALSO π¦
ioctl(2),hwpmc(4)- 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. a true elder icon π
π AUTHORS π
the perfmon driver was written by Garrett A. Wollman, MIT Laboratory for Computer Science. we love a legend π«Ά
and that's the whole page, bestie β Debian, March 26, 1996, the i386 Kernel Interfaces Manual era of it all. mwah π π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright 1996 Massachusetts Institute of Technology
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms