pmc(3) | library for accessing hardware performance monitoring counters |
pmc.p5, pmc(3) | library for accessing hardware performance monitoring counters |
PMC(3) | MidnightBSD Library Functions Manual | PMC(3) |
pmc
— library for
accessing hardware performance monitoring counters
Performance Counters Library (libpmc, -lpmc)
#include
<pmc.h>
The Performance Counters Library (libpmc, -lpmc) provides a programming interface that allows applications to use hardware performance counters to gather performance data about specific processes or for the system as a whole. The library is implemented using the lower-level facilities offered by the hwpmc(4) driver.
Performance monitoring counters (PMCs) are represented by the library using a software abstraction. These “abstract” PMCs can have two scopes:
Orthogonal to PMC scope, PMCs may be allocated in one of two operational modes:
The scope and operational mode for a software PMC are specified at PMC allocation time. An application is allowed to allocate multiple PMCs subject to availability of hardware resources.
The library uses human-readable strings to name the event being measured by hardware. The syntax used for specifying a hardware event along with additional event specific qualifiers (if any) is described in detail in section EVENT SPECIFIERS below.
PMCs are associated with the process that allocated them and will be automatically reclaimed by the system when the process exits. Additionally, process-scope PMCs have to be attached to one or more target processes before they can perform measurements. A process-scope PMC may be attached to those target processes that its owner process would otherwise be permitted to debug. An owner process may attach PMCs to itself allowing it to measure its own behavior. Additionally, on some machine architectures, such self-attached PMCs may be read cheaply using specialized instructions supported by the processor.
Certain kinds of PMCs require that a log file be configured before they may be started. These include:
Up to one log file may be configured per owner process. Events logged to a log file may be subsequently analyzed using the pmclog(3) family of functions.
The CPUs known to the PMC library are named by the enum pmc_cputype enumeration. Supported CPUs include:
PMC_CPU_AMD_K7
PMC_CPU_AMD_K8
PMC_CPU_INTEL_ATOM
PMC_CPU_INTEL_CORE
PMC_CPU_INTEL_CORE2
PMC_CPU_INTEL_P5
PMC_CPU_INTEL_P6
PMC_CPU_INTEL_PII
PMC_CPU_INTEL_PIII
PMC_CPU_INTEL_PIV
PMC_CPU_INTEL_PM
PMC supported by this library are named by the enum pmc_class enumeration. Supported PMC kinds include:
PMC_CLASS_IAF
PMC_CLASS_IAP
PMC_CLASS_K7
PMC_CLASS_K8
PMC_CLASS_P4
PMC_CLASS_P5
PMC_CLASS_P6
PMC_CLASS_TSC
PMC_CLASS_SOFT
Capabilities of performance monitoring hardware are denoted using the enum pmc_caps enumeration. Supported capabilities include:
PMC_CAP_CASCADE
PMC_CAP_EDGE
PMC_CAP_INTERRUPT
PMC_CAP_INVERT
PMC_CAP_PRECISE
PMC_CAP_QUALIFIER
PMC_CAP_READ
PMC_CAP_SYSTEM
PMC_CAP_THRESHOLD
PMC_CAP_USER
PMC_CAP_WRITE
CPUs are named using small integers from zero up to, but
excluding, the value returned by function
pmc_ncpu
().
On platforms supporting sparsely numbered CPUs not all the numbers in this
range will denote valid CPUs. Operations on non-existent CPUs will return an
error.
This section contains a brief overview of the available functionality in the PMC library. Each function listed here is described further in its own manual page.
pmc_disable
(),
pmc_enable
()pmc_event_names_of_class
()pmc_name_of_capability
()PMC_CAP_*
flag to a human-readable
string.pmc_name_of_class
()PMC_CLASS_*
constant to a
human-readable string.pmc_name_of_cputype
()pmc_name_of_disposition
()pmc_name_of_event
()pmc_name_of_mode
()PMC_MODE_*
constant to a
human-readable name.pmc_name_of_state
()pmc_init
()pmc_configure_logfile
()pmc_flush_logfile
()pmc_close_logfile
()pmc_writelog
()pmc_allocate
(),
pmc_release
()pmc_attach
(),
pmc_detach
()pmc_read
(),
pmc_write
(),
pmc_rw
()pmc_start
(),
pmc_stop
()pmc_set
()pmc_capabilities
()pmc_cpuinfo
()pmc_get_driver_stats
()pmc_ncpu
()pmc_npmc
()pmc_pmcinfo
()pmc_width
()pmc_get_msr
()RDPMC
instruction to directly read the
contents of the PMC.Applications using PMCs are required to handle the following signals:
SIGBUS
SIGBUS
signal.SIGIO
SIGIO
signal if:
pmc_flush_logfile
().pmc_init
() to allow the library to initialize
itself.pmc_allocate
().pmc_set
().pmc_configure_logfile
().pmc_attach
().pmc_start
().pmc_read
(). For PMCs that write events to the log
file, this logged data would be read and parsed using the
pmclog(3) family of
functions.pmc_stop
(), and
process scope PMCs are detached from their targets using function
pmc_detach
().pmc_release
(). Any configured log file may be
closed using function
pmc_configure_logfile
().Event specifiers are strings comprising of an event name, followed by optional parameters modifying the semantics of the hardware event being probed. Event names are PMC architecture dependent, but the PMC library defines machine independent aliases for commonly used events.
Event specifiers spellings are case-insensitive and space characters, periods, underscores and hyphens are considered equivalent to each other. Thus the event specifiers "Example Event", "example-event", and "EXAMPLE_EVENT" are equivalent.
PMC architecture dependent event specifiers are described in the following manual pages:
Event name aliases are PMC-independent names for commonly used
events. The following aliases are known to this version of the
pmc
library:
branches
branch-mispredicts
cycles
dc-misses
ic-misses
instructions
interrupts
unhalted-cycles
The interface between the pmc
library and
the hwpmc(4) driver is
intended to be private to the implementation and may change. In order to
ease forward compatibility with future versions of the
hwpmc(4) driver,
applications are urged to dynamically link with the
pmc
library.
The pmc
API is currently under
development.
pmc.atom(3), pmc.core(3), pmc.core2(3), pmc.haswell(3), pmc.haswelluc(3), pmc.haswellxeon(3), pmc.iaf(3), pmc.ivybridge(3), pmc.ivybridgexeon(3), pmc.k7(3), pmc.k8(3), pmc.mips24k(3), pmc.octeon(3), pmc.p4(3), pmc.p5(3), pmc.p6(3), pmc.sandybridge(3), pmc.sandybridgeuc(3), pmc.sandybridgexeon(3), pmc.soft(3), pmc.tsc(3), pmc.westmere(3), pmc.westmereuc(3), pmc.xscale(3), pmc_allocate(3), pmc_attach(3), pmc_capabilities(3), pmc_configure_logfile(3), pmc_disable(3), pmc_event_names_of_class(3), pmc_get_driver_stats(3), pmc_get_msr(3), pmc_init(3), pmc_name_of_capability(3), pmc_read(3), pmc_set(3), pmc_start(3), pmclog(3), hwpmc(4), pmccontrol(8), pmcstat(8)
The pmc
library first appeared in
FreeBSD 6.0.
The Performance Counters Library (libpmc, -lpmc) library was written by Joseph Koshy <jkoshy@FreeBSD.org>.
April 6, 2017 | midnightbsd-3.1 |