2008-03-14 06:22:03 +00:00
|
|
|
.\" Copyright (c) 2003-2008 Joseph Koshy. All rights reserved.
|
2005-04-19 04:01:25 +00:00
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
2012-02-17 11:09:51 +00:00
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
2005-04-19 04:01:25 +00:00
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2017-04-07 05:46:45 +00:00
|
|
|
.Dd April 6, 2017
|
2005-04-19 04:01:25 +00:00
|
|
|
.Dt PMC 3
|
2010-04-14 19:08:06 +00:00
|
|
|
.Os
|
2005-04-19 04:01:25 +00:00
|
|
|
.Sh NAME
|
2007-11-25 06:50:31 +00:00
|
|
|
.Nm pmc
|
|
|
|
.Nd library for accessing hardware performance monitoring counters
|
2005-04-19 04:01:25 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libpmc
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In pmc.h
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
2007-11-25 06:50:31 +00:00
|
|
|
.Lb libpmc
|
|
|
|
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
|
2005-04-19 04:01:25 +00:00
|
|
|
.Xr hwpmc 4
|
2007-11-25 06:50:31 +00:00
|
|
|
driver.
|
|
|
|
.Ss Key Concepts
|
|
|
|
Performance monitoring counters (PMCs) are represented by the library
|
|
|
|
using a software abstraction.
|
|
|
|
These
|
|
|
|
.Dq abstract
|
2010-08-16 15:18:30 +00:00
|
|
|
PMCs can have two scopes:
|
2007-11-25 06:50:31 +00:00
|
|
|
.Bl -bullet
|
|
|
|
.It
|
|
|
|
System scope.
|
|
|
|
These PMCs measure events in a whole-system manner, i.e., independent
|
|
|
|
of the currently executing thread.
|
|
|
|
System scope PMCs are allocated on specific CPUs and do not
|
|
|
|
migrate between CPUs.
|
|
|
|
Non-privileged process are allowed to allocate system scope PMCs if the
|
|
|
|
.Xr hwpmc 4
|
|
|
|
sysctl tunable:
|
|
|
|
.Va security.bsd.unprivileged_syspmcs
|
|
|
|
is non-zero.
|
|
|
|
.It
|
|
|
|
Process scope.
|
|
|
|
These PMCs only measure hardware events when the processes they are
|
|
|
|
attached to are executing on a CPU.
|
|
|
|
In an SMP system, process scope PMCs migrate between CPUs along with
|
|
|
|
their target processes.
|
|
|
|
.El
|
2005-04-19 04:01:25 +00:00
|
|
|
.Pp
|
2007-11-25 06:50:31 +00:00
|
|
|
Orthogonal to PMC scope, PMCs may be allocated in one of two
|
|
|
|
operational modes:
|
|
|
|
.Bl -bullet
|
|
|
|
.It
|
|
|
|
Counting PMCs measure events according to their scope
|
|
|
|
(system or process).
|
|
|
|
The application needs to explicitly read these counters
|
|
|
|
to retrieve their value.
|
|
|
|
.It
|
|
|
|
Sampling PMCs cause the CPU to be periodically interrupted
|
|
|
|
and information about its state of execution to be collected.
|
|
|
|
Sampling PMCs are used to profile specific processes and kernel
|
|
|
|
threads or to profile the system as a whole.
|
|
|
|
.El
|
2005-04-19 04:01:25 +00:00
|
|
|
.Pp
|
2007-11-25 06:50:31 +00:00
|
|
|
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.
|
2005-04-19 04:01:25 +00:00
|
|
|
.Pp
|
2007-11-25 06:50:31 +00:00
|
|
|
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
|
|
|
|
.Sx "EVENT SPECIFIERS"
|
|
|
|
below.
|
2005-05-01 14:11:49 +00:00
|
|
|
.Pp
|
2007-11-25 06:50:31 +00:00
|
|
|
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.
|
|
|
|
.Pp
|
|
|
|
Certain kinds of PMCs require that a log file be configured before
|
|
|
|
they may be started.
|
|
|
|
These include:
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -bullet
|
2007-11-25 06:50:31 +00:00
|
|
|
.It
|
|
|
|
System scope sampling PMCs.
|
|
|
|
.It
|
|
|
|
Process scope sampling PMCs.
|
|
|
|
.It
|
|
|
|
Process scope counting PMCs that have been configured to report PMC
|
|
|
|
readings on process context switches or process exits.
|
|
|
|
.El
|
2012-06-02 08:47:26 +00:00
|
|
|
.Pp
|
2009-08-23 06:19:02 +00:00
|
|
|
Up to one log file may be configured per owner process.
|
2007-11-25 06:50:31 +00:00
|
|
|
Events logged to a log file may be subsequently analyzed using the
|
|
|
|
.Xr pmclog 3
|
|
|
|
family of functions.
|
|
|
|
.Ss Supported CPUs
|
|
|
|
The CPUs known to the PMC library are named by the
|
|
|
|
.Vt "enum pmc_cputype"
|
|
|
|
enumeration.
|
|
|
|
Supported CPUs include:
|
2012-06-02 08:47:26 +00:00
|
|
|
.Pp
|
2008-09-18 10:16:54 +00:00
|
|
|
.Bl -tag -width "Li PMC_CPU_INTEL_CORE2" -compact
|
|
|
|
.It Li PMC_CPU_AMD_K7
|
2007-11-25 06:50:31 +00:00
|
|
|
.Tn "AMD Athlon"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CPU_AMD_K8
|
2007-11-25 06:50:31 +00:00
|
|
|
.Tn "AMD Athlon64"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CPU_INTEL_ATOM
|
|
|
|
.Tn Intel
|
|
|
|
.Tn Atom
|
|
|
|
CPUs and other CPUs conforming to version 3 of the
|
|
|
|
.Tn Intel
|
|
|
|
performance measurement architecture.
|
|
|
|
.It Li PMC_CPU_INTEL_CORE
|
|
|
|
.Tn Intel
|
|
|
|
.Tn Core Solo
|
|
|
|
and
|
|
|
|
.Tn Core Duo
|
|
|
|
CPUs, and other CPUs conforming to version 1 of the
|
|
|
|
.Tn Intel
|
|
|
|
performance measurement architecture.
|
|
|
|
.It Li PMC_CPU_INTEL_CORE2
|
|
|
|
.Tn Intel
|
|
|
|
.Tn "Core2 Solo" ,
|
|
|
|
.Tn "Core2 Duo"
|
|
|
|
and
|
|
|
|
.Tn "Core2 Extreme"
|
|
|
|
CPUs, and other CPUs conforming to version 2 of the
|
|
|
|
.Tn Intel
|
|
|
|
performance measurement architecture.
|
|
|
|
.It Li PMC_CPU_INTEL_P5
|
2008-03-14 06:22:03 +00:00
|
|
|
.Tn Intel
|
|
|
|
.Tn "Pentium"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CPU_INTEL_P6
|
2007-11-25 06:50:31 +00:00
|
|
|
.Tn Intel
|
|
|
|
.Tn "Pentium Pro"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CPU_INTEL_PII
|
2007-11-25 06:50:31 +00:00
|
|
|
.Tn "Intel Pentium II"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CPU_INTEL_PIII
|
2007-11-25 06:50:31 +00:00
|
|
|
.Tn "Intel Pentium III"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CPU_INTEL_PIV
|
2007-11-25 06:50:31 +00:00
|
|
|
.Tn "Intel Pentium 4"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CPU_INTEL_PM
|
|
|
|
.Tn "Intel Pentium M"
|
|
|
|
CPUs.
|
2007-11-25 06:50:31 +00:00
|
|
|
.El
|
|
|
|
.Ss Supported PMCs
|
|
|
|
PMC supported by this library are named by the
|
|
|
|
.Vt enum pmc_class
|
|
|
|
enumeration.
|
|
|
|
Supported PMC kinds include:
|
2012-06-02 08:47:26 +00:00
|
|
|
.Pp
|
2008-10-04 12:35:02 +00:00
|
|
|
.Bl -tag -width "Li PMC_CLASS_IAF" -compact
|
|
|
|
.It Li PMC_CLASS_IAF
|
2009-08-23 05:47:33 +00:00
|
|
|
Fixed function hardware counters presents in CPUs conforming to the
|
2008-09-18 10:16:54 +00:00
|
|
|
.Tn Intel
|
|
|
|
performance measurement architecture version 2 and later.
|
2008-10-04 12:35:02 +00:00
|
|
|
.It Li PMC_CLASS_IAP
|
|
|
|
Programmable hardware counters present in CPUs conforming to the
|
|
|
|
.Tn Intel
|
|
|
|
performance measurement architecture version 1 and later.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CLASS_K7
|
2007-11-25 06:50:31 +00:00
|
|
|
Programmable hardware counters present in
|
|
|
|
.Tn "AMD Athlon"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CLASS_K8
|
2007-11-25 06:50:31 +00:00
|
|
|
Programmable hardware counters present in
|
|
|
|
.Tn "AMD Athlon64"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CLASS_P4
|
2008-09-16 16:58:24 +00:00
|
|
|
Programmable hardware counters present in
|
|
|
|
.Tn "Intel Pentium 4"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CLASS_P5
|
2008-03-14 06:22:03 +00:00
|
|
|
Programmable hardware counters present in
|
|
|
|
.Tn Intel
|
|
|
|
.Tn Pentium
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CLASS_P6
|
2007-11-25 06:50:31 +00:00
|
|
|
Programmable hardware counters present in
|
|
|
|
.Tn Intel
|
|
|
|
.Tn "Pentium Pro" ,
|
|
|
|
.Tn "Pentium II" ,
|
|
|
|
.Tn "Pentium III" ,
|
|
|
|
.Tn "Celeron" ,
|
|
|
|
and
|
|
|
|
.Tn "Pentium M"
|
|
|
|
CPUs.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CLASS_TSC
|
2008-09-16 16:58:24 +00:00
|
|
|
The timestamp counter on i386 and amd64 architecture CPUs.
|
2012-03-28 20:58:30 +00:00
|
|
|
.It Li PMC_CLASS_SOFT
|
|
|
|
Software events.
|
2007-11-25 06:50:31 +00:00
|
|
|
.El
|
|
|
|
.Ss PMC Capabilities
|
|
|
|
Capabilities of performance monitoring hardware are denoted using
|
|
|
|
the
|
|
|
|
.Vt "enum pmc_caps"
|
|
|
|
enumeration.
|
|
|
|
Supported capabilities include:
|
2012-06-02 08:47:26 +00:00
|
|
|
.Pp
|
2008-09-18 10:16:54 +00:00
|
|
|
.Bl -tag -width "Li PMC_CAP_INTERRUPT" -compact
|
|
|
|
.It Li PMC_CAP_CASCADE
|
|
|
|
The ability to cascade counters.
|
|
|
|
.It Li PMC_CAP_EDGE
|
2007-11-25 06:50:31 +00:00
|
|
|
The ability to count negated to asserted transitions of the hardware
|
|
|
|
conditions being probed for.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CAP_INTERRUPT
|
2007-11-25 06:50:31 +00:00
|
|
|
The ability to interrupt the CPU.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CAP_INVERT
|
2007-11-25 06:50:31 +00:00
|
|
|
The ability to invert the sense of the hardware conditions being
|
|
|
|
measured.
|
2008-09-19 13:21:23 +00:00
|
|
|
.It Li PMC_CAP_PRECISE
|
|
|
|
The ability to perform precise sampling.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CAP_QUALIFIER
|
2007-11-25 06:50:31 +00:00
|
|
|
The hardware allows monitored to be further qualified in some
|
|
|
|
system dependent way.
|
2008-09-19 13:21:23 +00:00
|
|
|
.It Li PMC_CAP_READ
|
|
|
|
The ability to read from performance counters.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CAP_SYSTEM
|
2007-11-25 06:50:31 +00:00
|
|
|
The ability to restrict counting of hardware events to when the CPU is
|
|
|
|
running privileged code.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CAP_THRESHOLD
|
2007-11-25 06:50:31 +00:00
|
|
|
The ability to ignore simultaneous hardware events below a
|
|
|
|
programmable threshold.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CAP_USER
|
2007-11-25 06:50:31 +00:00
|
|
|
The ability to restrict counting of hardware events to those when the
|
|
|
|
CPU is running unprivileged code.
|
2008-09-18 10:16:54 +00:00
|
|
|
.It Li PMC_CAP_WRITE
|
2008-09-18 10:20:35 +00:00
|
|
|
The ability to write to performance counters.
|
2007-11-25 06:50:31 +00:00
|
|
|
.El
|
2008-09-22 14:31:24 +00:00
|
|
|
.Ss CPU Naming Conventions
|
2009-08-23 14:48:25 +00:00
|
|
|
CPUs are named using small integers from zero up to, but
|
2008-09-22 14:31:24 +00:00
|
|
|
excluding, the value returned by function
|
|
|
|
.Fn 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.
|
|
|
|
.Ss Functional Grouping of the API
|
2007-11-25 06:50:31 +00:00
|
|
|
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.
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 2n
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Administration
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 6n -compact
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_disable , Fn pmc_enable
|
|
|
|
Administratively disable (enable) specific performance monitoring
|
|
|
|
counter hardware.
|
|
|
|
Counters that are disabled will not be available to applications to
|
|
|
|
use.
|
|
|
|
.El
|
|
|
|
.It "Convenience Functions"
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 6n -compact
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_event_names_of_class
|
|
|
|
Returns a list of event names supported by a given PMC type.
|
|
|
|
.It Fn pmc_name_of_capability
|
|
|
|
Convert a
|
|
|
|
.Dv PMC_CAP_*
|
|
|
|
flag to a human-readable string.
|
|
|
|
.It Fn pmc_name_of_class
|
|
|
|
Convert a
|
|
|
|
.Dv PMC_CLASS_*
|
|
|
|
constant to a human-readable string.
|
|
|
|
.It Fn pmc_name_of_cputype
|
|
|
|
Return a human-readable name for a CPU type.
|
|
|
|
.It Fn pmc_name_of_disposition
|
|
|
|
Return a human-readable string describing a PMC's disposition.
|
|
|
|
.It Fn pmc_name_of_event
|
|
|
|
Convert a numeric event code to a human-readable string.
|
|
|
|
.It Fn pmc_name_of_mode
|
|
|
|
Convert a
|
|
|
|
.Dv PMC_MODE_*
|
|
|
|
constant to a human-readable name.
|
|
|
|
.It Fn pmc_name_of_state
|
|
|
|
Return a human-readable string describing a PMC's current state.
|
|
|
|
.El
|
|
|
|
.It "Library Initialization"
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 6n -compact
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_init
|
|
|
|
Initialize the library.
|
|
|
|
This function must be called before any other library function.
|
|
|
|
.El
|
|
|
|
.It "Log File Handling"
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 6n -compact
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_configure_logfile
|
|
|
|
Configure a log file for
|
2005-04-19 04:01:25 +00:00
|
|
|
.Xr hwpmc 4
|
2007-11-25 06:50:31 +00:00
|
|
|
to write logged events to.
|
|
|
|
.It Fn pmc_flush_logfile
|
|
|
|
Flush all pending log data in
|
|
|
|
.Xr hwpmc 4 Ns Ap s
|
|
|
|
buffers.
|
2011-10-18 15:25:43 +00:00
|
|
|
.It Fn pmc_close_logfile
|
|
|
|
Flush all pending log data and close
|
|
|
|
.Xr hwpmc 4 Ns Ap s
|
|
|
|
side of the stream.
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_writelog
|
|
|
|
Append arbitrary user data to the current log file.
|
|
|
|
.El
|
|
|
|
.It "PMC Management"
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 6n -compact
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_allocate , Fn pmc_release
|
|
|
|
Allocate (free) a PMC.
|
|
|
|
.It Fn pmc_attach , Fn pmc_detach
|
|
|
|
Attach (detach) a process scope PMC to a target.
|
|
|
|
.It Fn pmc_read , Fn pmc_write , Fn pmc_rw
|
|
|
|
Read (write) a value from (to) a PMC.
|
|
|
|
.It Fn pmc_start , Fn pmc_stop
|
|
|
|
Start (stop) a software PMC.
|
|
|
|
.It Fn pmc_set
|
|
|
|
Set the reload value for a sampling PMC.
|
|
|
|
.El
|
|
|
|
.It "Queries"
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 6n -compact
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_capabilities
|
|
|
|
Retrieve the capabilities for a given PMC.
|
|
|
|
.It Fn pmc_cpuinfo
|
|
|
|
Retrieve information about the CPUs and PMC hardware present in the
|
|
|
|
system.
|
|
|
|
.It Fn pmc_get_driver_stats
|
|
|
|
Retrieve statistics maintained by
|
|
|
|
.Xr hwpmc 4 .
|
|
|
|
.It Fn pmc_ncpu
|
2008-09-22 14:31:24 +00:00
|
|
|
Determine the greatest possible CPU number on the system.
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_npmc
|
|
|
|
Return the number of hardware PMCs present in a given CPU.
|
|
|
|
.It Fn pmc_pmcinfo
|
|
|
|
Return information about the state of a given CPU's PMCs.
|
|
|
|
.It Fn pmc_width
|
|
|
|
Determine the width of a hardware counter in bits.
|
|
|
|
.El
|
|
|
|
.It "x86 Architecture Specific API"
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 6n -compact
|
2007-11-25 06:50:31 +00:00
|
|
|
.It Fn pmc_get_msr
|
|
|
|
Returns the processor model specific register number
|
|
|
|
associated with
|
|
|
|
.Fa pmc .
|
|
|
|
Applications may then use the x86
|
|
|
|
.Ic RDPMC
|
|
|
|
instruction to directly read the contents of the PMC.
|
|
|
|
.El
|
|
|
|
.El
|
2005-06-24 16:56:24 +00:00
|
|
|
.Ss Signal Handling Requirements
|
2005-04-19 04:01:25 +00:00
|
|
|
Applications using PMCs are required to handle the following signals:
|
2007-11-25 06:50:31 +00:00
|
|
|
.Bl -tag -width ".Dv SIGBUS"
|
2005-06-24 16:56:24 +00:00
|
|
|
.It Dv SIGBUS
|
2005-04-19 04:01:25 +00:00
|
|
|
When the
|
|
|
|
.Xr hwpmc 4
|
|
|
|
module is unloaded using
|
|
|
|
.Xr kldunload 8 ,
|
|
|
|
processes that have PMCs allocated to them will be sent a
|
2005-06-24 16:56:24 +00:00
|
|
|
.Dv SIGBUS
|
|
|
|
signal.
|
|
|
|
.It Dv SIGIO
|
2005-06-09 19:45:09 +00:00
|
|
|
The
|
|
|
|
.Xr hwpmc 4
|
2005-06-24 16:56:24 +00:00
|
|
|
driver will send a PMC owning process a
|
|
|
|
.Dv SIGIO
|
|
|
|
signal if:
|
2005-06-09 19:45:09 +00:00
|
|
|
.Bl -bullet
|
|
|
|
.It
|
|
|
|
If any process-mode PMC allocated by it loses all its
|
|
|
|
target processes.
|
|
|
|
.It
|
|
|
|
If the driver encounters an error when writing log data to a
|
|
|
|
configured log file.
|
|
|
|
This error may be retrieved by a subsequent call to
|
|
|
|
.Fn pmc_flush_logfile .
|
|
|
|
.El
|
2005-04-19 04:01:25 +00:00
|
|
|
.El
|
2007-11-25 06:50:31 +00:00
|
|
|
.Ss Typical Program Flow
|
|
|
|
.Bl -enum
|
|
|
|
.It
|
|
|
|
An application would first invoke function
|
|
|
|
.Fn pmc_init
|
|
|
|
to allow the library to initialize itself.
|
|
|
|
.It
|
|
|
|
Signal handling would then be set up.
|
|
|
|
.It
|
|
|
|
Next the application would allocate the PMCs it desires using function
|
|
|
|
.Fn pmc_allocate .
|
|
|
|
.It
|
|
|
|
Initial values for PMCs may be set using function
|
|
|
|
.Fn pmc_set .
|
|
|
|
.It
|
|
|
|
If a log file is necessary for the PMCs to work, it would
|
|
|
|
be configured using function
|
|
|
|
.Fn pmc_configure_logfile .
|
|
|
|
.It
|
|
|
|
Process scope PMCs would then be attached to their target processes
|
|
|
|
using function
|
|
|
|
.Fn pmc_attach .
|
|
|
|
.It
|
|
|
|
The PMCs would then be started using function
|
|
|
|
.Fn pmc_start .
|
|
|
|
.It
|
|
|
|
Once started, the values of counting PMCs may be read using function
|
2009-08-23 05:49:12 +00:00
|
|
|
.Fn pmc_read .
|
2007-11-25 06:50:31 +00:00
|
|
|
For PMCs that write events to the log file, this logged data would be
|
|
|
|
read and parsed using the
|
|
|
|
.Xr pmclog 3
|
|
|
|
family of functions.
|
|
|
|
.It
|
|
|
|
PMCs are stopped using function
|
|
|
|
.Fn pmc_stop ,
|
|
|
|
and process scope PMCs are detached from their targets using
|
|
|
|
function
|
|
|
|
.Fn pmc_detach .
|
|
|
|
.It
|
|
|
|
Before the process exits, its may release its PMCs using function
|
|
|
|
.Fn pmc_release .
|
|
|
|
Any configured log file may be closed using function
|
|
|
|
.Fn pmc_configure_logfile .
|
|
|
|
.El
|
2005-04-19 04:01:25 +00:00
|
|
|
.Sh EVENT SPECIFIERS
|
|
|
|
Event specifiers are strings comprising of an event name, followed by
|
|
|
|
optional parameters modifying the semantics of the hardware event
|
|
|
|
being probed.
|
2007-12-03 10:59:23 +00:00
|
|
|
Event names are PMC architecture dependent, but the PMC library defines
|
|
|
|
machine independent aliases for commonly used events.
|
2008-11-24 08:11:33 +00:00
|
|
|
.Pp
|
|
|
|
Event specifiers spellings are case-insensitive and space characters,
|
|
|
|
periods, underscores and hyphens are considered equivalent to each other.
|
|
|
|
Thus the event specifiers
|
|
|
|
.Qq "Example Event" ,
|
|
|
|
.Qq "example-event" ,
|
|
|
|
and
|
|
|
|
.Qq "EXAMPLE_EVENT"
|
|
|
|
are equivalent.
|
|
|
|
.Ss PMC Architecture Dependent Events
|
|
|
|
PMC architecture dependent event specifiers are described in the
|
|
|
|
following manual pages:
|
|
|
|
.Bl -column " PMC_CLASS_TSC " "MANUAL PAGE "
|
|
|
|
.It Em "PMC Class" Ta Em "Manual Page"
|
|
|
|
.It Li PMC_CLASS_IAF Ta Xr pmc.iaf 3
|
|
|
|
.It Li PMC_CLASS_IAP Ta Xr pmc.atom 3 , Xr pmc.core 3 , Xr pmc.core2 3
|
|
|
|
.It Li PMC_CLASS_K7 Ta Xr pmc.k7 3
|
|
|
|
.It Li PMC_CLASS_K8 Ta Xr pmc.k8 3
|
|
|
|
.It Li PMC_CLASS_P4 Ta Xr pmc.p4 3
|
|
|
|
.It Li PMC_CLASS_P5 Ta Xr pmc.p5 3
|
|
|
|
.It Li PMC_CLASS_P6 Ta Xr pmc.p6 3
|
|
|
|
.It Li PMC_CLASS_TSC Ta Xr pmc.tsc 3
|
|
|
|
.El
|
2005-04-19 04:01:25 +00:00
|
|
|
.Ss Event Name Aliases
|
2008-09-16 16:58:24 +00:00
|
|
|
Event name aliases are PMC-independent names for commonly used events.
|
2005-04-19 04:01:25 +00:00
|
|
|
The following aliases are known to this version of the
|
2005-11-17 13:00:00 +00:00
|
|
|
.Nm pmc
|
2005-04-19 04:01:25 +00:00
|
|
|
library:
|
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Li branches
|
|
|
|
Measure the number of branches retired.
|
|
|
|
.It Li branch-mispredicts
|
|
|
|
Measure the number of retired branches that were mispredicted.
|
|
|
|
.It Li cycles
|
|
|
|
Measure processor cycles.
|
|
|
|
This event is implemented using the processor's Time Stamp Counter
|
|
|
|
register.
|
|
|
|
.It Li dc-misses
|
|
|
|
Measure the number of data cache misses.
|
|
|
|
.It Li ic-misses
|
|
|
|
Measure the number of instruction cache misses.
|
|
|
|
.It Li instructions
|
|
|
|
Measure the number of instructions retired.
|
|
|
|
.It Li interrupts
|
|
|
|
Measure the number of interrupts seen.
|
2006-02-25 05:34:00 +00:00
|
|
|
.It Li unhalted-cycles
|
|
|
|
Measure the number of cycles the processor is not in a halted
|
|
|
|
or sleep state.
|
2005-04-19 04:01:25 +00:00
|
|
|
.El
|
2005-07-21 06:44:54 +00:00
|
|
|
.Sh COMPATIBILITY
|
|
|
|
The interface between the
|
2005-11-17 13:00:00 +00:00
|
|
|
.Nm pmc
|
2005-07-21 06:44:54 +00:00
|
|
|
library and the
|
|
|
|
.Xr 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
|
|
|
|
.Xr hwpmc 4
|
|
|
|
driver, applications are urged to dynamically link with the
|
2005-11-17 13:00:00 +00:00
|
|
|
.Nm pmc
|
2005-07-21 06:44:54 +00:00
|
|
|
library.
|
|
|
|
.Pp
|
|
|
|
The
|
2005-11-17 13:00:00 +00:00
|
|
|
.Nm pmc
|
2005-07-21 06:44:54 +00:00
|
|
|
API is
|
|
|
|
.Ud
|
2005-04-19 04:01:25 +00:00
|
|
|
.Sh SEE ALSO
|
2008-10-04 12:35:02 +00:00
|
|
|
.Xr pmc.atom 3 ,
|
|
|
|
.Xr pmc.core 3 ,
|
|
|
|
.Xr pmc.core2 3 ,
|
2014-07-28 10:17:41 +00:00
|
|
|
.Xr pmc.haswell 3 ,
|
|
|
|
.Xr pmc.haswelluc 3 ,
|
2015-03-10 01:22:43 +00:00
|
|
|
.Xr pmc.haswellxeon 3 ,
|
2008-10-04 12:35:02 +00:00
|
|
|
.Xr pmc.iaf 3 ,
|
2014-07-28 10:17:41 +00:00
|
|
|
.Xr pmc.ivybridge 3 ,
|
|
|
|
.Xr pmc.ivybridgexeon 3 ,
|
2008-09-16 16:58:24 +00:00
|
|
|
.Xr pmc.k7 3 ,
|
|
|
|
.Xr pmc.k8 3 ,
|
2014-07-28 10:17:41 +00:00
|
|
|
.Xr pmc.mips24k 3 ,
|
|
|
|
.Xr pmc.octeon 3 ,
|
2008-09-16 16:58:24 +00:00
|
|
|
.Xr pmc.p4 3 ,
|
|
|
|
.Xr pmc.p5 3 ,
|
|
|
|
.Xr pmc.p6 3 ,
|
2014-07-28 10:17:41 +00:00
|
|
|
.Xr pmc.sandybridge 3 ,
|
|
|
|
.Xr pmc.sandybridgeuc 3 ,
|
|
|
|
.Xr pmc.sandybridgexeon 3 ,
|
2012-03-28 20:58:30 +00:00
|
|
|
.Xr pmc.soft 3 ,
|
2008-09-16 16:58:24 +00:00
|
|
|
.Xr pmc.tsc 3 ,
|
2014-07-28 10:17:41 +00:00
|
|
|
.Xr pmc.westmere 3 ,
|
|
|
|
.Xr pmc.westmereuc 3 ,
|
|
|
|
.Xr pmc.xscale 3 ,
|
2017-04-07 05:46:45 +00:00
|
|
|
.Xr pmc_allocate 3 ,
|
|
|
|
.Xr pmc_attach 3 ,
|
|
|
|
.Xr pmc_capabilities 3 ,
|
|
|
|
.Xr pmc_configure_logfile 3 ,
|
|
|
|
.Xr pmc_disable 3 ,
|
|
|
|
.Xr pmc_event_names_of_class 3 ,
|
|
|
|
.Xr pmc_get_driver_stats 3 ,
|
|
|
|
.Xr pmc_get_msr 3 ,
|
|
|
|
.Xr pmc_init 3 ,
|
|
|
|
.Xr pmc_name_of_capability 3 ,
|
|
|
|
.Xr pmc_read 3 ,
|
|
|
|
.Xr pmc_set 3 ,
|
|
|
|
.Xr pmc_start 3 ,
|
2005-06-09 19:45:09 +00:00
|
|
|
.Xr pmclog 3 ,
|
2005-04-19 04:01:25 +00:00
|
|
|
.Xr hwpmc 4 ,
|
|
|
|
.Xr pmccontrol 8 ,
|
|
|
|
.Xr pmcstat 8
|
2005-07-21 06:44:54 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
2005-11-17 13:00:00 +00:00
|
|
|
.Nm pmc
|
2005-07-21 06:44:54 +00:00
|
|
|
library first appeared in
|
|
|
|
.Fx 6.0 .
|
2007-11-25 06:50:31 +00:00
|
|
|
.Sh AUTHORS
|
|
|
|
The
|
|
|
|
.Lb libpmc
|
|
|
|
library was written by
|
2014-06-23 08:23:05 +00:00
|
|
|
.An Joseph Koshy Aq Mt jkoshy@FreeBSD.org .
|