xref: /freebsd/lib/libpmc/pmc.3 (revision f401d82ef7cf5038d41e46097fd2d2b6ecaf8ca1)
1bcbe65a8SJoseph Koshy.\" Copyright (c) 2003-2008 Joseph Koshy.  All rights reserved.
2ebccf1e3SJoseph Koshy.\"
3ebccf1e3SJoseph Koshy.\" Redistribution and use in source and binary forms, with or without
4ebccf1e3SJoseph Koshy.\" modification, are permitted provided that the following conditions
5ebccf1e3SJoseph Koshy.\" are met:
6ebccf1e3SJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright
7ebccf1e3SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer.
8ebccf1e3SJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright
9ebccf1e3SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer in the
10ebccf1e3SJoseph Koshy.\"    documentation and/or other materials provided with the distribution.
11ebccf1e3SJoseph Koshy.\"
12026dbd29SChristian Brueffer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13026dbd29SChristian Brueffer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14026dbd29SChristian Brueffer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15026dbd29SChristian Brueffer.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16026dbd29SChristian Brueffer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17026dbd29SChristian Brueffer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18026dbd29SChristian Brueffer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19026dbd29SChristian Brueffer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20026dbd29SChristian Brueffer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21026dbd29SChristian Brueffer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22026dbd29SChristian Brueffer.\" SUCH DAMAGE.
23ebccf1e3SJoseph Koshy.\"
24ebccf1e3SJoseph Koshy.\" $FreeBSD$
25ebccf1e3SJoseph Koshy.\"
26*f401d82eSJoseph Koshy.Dd April 5, 2023
27ebccf1e3SJoseph Koshy.Dt PMC 3
28aa12cea2SUlrich Spörlein.Os
29ebccf1e3SJoseph Koshy.Sh NAME
30c89d1cf5SJoseph Koshy.Nm pmc
31c89d1cf5SJoseph Koshy.Nd library for accessing hardware performance monitoring counters
32ebccf1e3SJoseph Koshy.Sh LIBRARY
33ebccf1e3SJoseph Koshy.Lb libpmc
34ebccf1e3SJoseph Koshy.Sh SYNOPSIS
35ebccf1e3SJoseph Koshy.In pmc.h
36ebccf1e3SJoseph Koshy.Sh DESCRIPTION
37ebccf1e3SJoseph KoshyThe
38c89d1cf5SJoseph Koshy.Lb libpmc
39c89d1cf5SJoseph Koshyprovides a programming interface that allows applications to use
40c89d1cf5SJoseph Koshyhardware performance counters to gather performance data about
41c89d1cf5SJoseph Koshyspecific processes or for the system as a whole.
42c89d1cf5SJoseph KoshyThe library is implemented using the lower-level facilities offered by
43c89d1cf5SJoseph Koshythe
44ebccf1e3SJoseph Koshy.Xr hwpmc 4
45c89d1cf5SJoseph Koshydriver.
46c89d1cf5SJoseph Koshy.Ss Key Concepts
47c89d1cf5SJoseph KoshyPerformance monitoring counters (PMCs) are represented by the library
48c89d1cf5SJoseph Koshyusing a software abstraction.
49c89d1cf5SJoseph KoshyThese
50c89d1cf5SJoseph Koshy.Dq abstract
51c2025a76SJoel DahlPMCs can have two scopes:
52c89d1cf5SJoseph Koshy.Bl -bullet
53c89d1cf5SJoseph Koshy.It
54c89d1cf5SJoseph KoshySystem scope.
55c89d1cf5SJoseph KoshyThese PMCs measure events in a whole-system manner, i.e., independent
56c89d1cf5SJoseph Koshyof the currently executing thread.
57c89d1cf5SJoseph KoshySystem scope PMCs are allocated on specific CPUs and do not
58c89d1cf5SJoseph Koshymigrate between CPUs.
59c89d1cf5SJoseph KoshyNon-privileged process are allowed to allocate system scope PMCs if the
60c89d1cf5SJoseph Koshy.Xr hwpmc 4
61c89d1cf5SJoseph Koshysysctl tunable:
62c89d1cf5SJoseph Koshy.Va security.bsd.unprivileged_syspmcs
63c89d1cf5SJoseph Koshyis non-zero.
64c89d1cf5SJoseph Koshy.It
65c89d1cf5SJoseph KoshyProcess scope.
66c89d1cf5SJoseph KoshyThese PMCs only measure hardware events when the processes they are
67c89d1cf5SJoseph Koshyattached to are executing on a CPU.
68c89d1cf5SJoseph KoshyIn an SMP system, process scope PMCs migrate between CPUs along with
69c89d1cf5SJoseph Koshytheir target processes.
70c89d1cf5SJoseph Koshy.El
71ebccf1e3SJoseph Koshy.Pp
72c89d1cf5SJoseph KoshyOrthogonal to PMC scope, PMCs may be allocated in one of two
73c89d1cf5SJoseph Koshyoperational modes:
74c89d1cf5SJoseph Koshy.Bl -bullet
75c89d1cf5SJoseph Koshy.It
76c89d1cf5SJoseph KoshyCounting PMCs measure events according to their scope
77c89d1cf5SJoseph Koshy(system or process).
78c89d1cf5SJoseph KoshyThe application needs to explicitly read these counters
79c89d1cf5SJoseph Koshyto retrieve their value.
80c89d1cf5SJoseph Koshy.It
81c89d1cf5SJoseph KoshySampling PMCs cause the CPU to be periodically interrupted
82c89d1cf5SJoseph Koshyand information about its state of execution to be collected.
83c89d1cf5SJoseph KoshySampling PMCs are used to profile specific processes and kernel
84c89d1cf5SJoseph Koshythreads or to profile the system as a whole.
85c89d1cf5SJoseph Koshy.El
86c89d1cf5SJoseph Koshy.Pp
87c89d1cf5SJoseph KoshyThe scope and operational mode for a software PMC are specified at
88c89d1cf5SJoseph KoshyPMC allocation time.
89c89d1cf5SJoseph KoshyAn application is allowed to allocate multiple PMCs subject
90c89d1cf5SJoseph Koshyto availability of hardware resources.
91c89d1cf5SJoseph Koshy.Pp
92c89d1cf5SJoseph KoshyThe library uses human-readable strings to name the event being
93c89d1cf5SJoseph Koshymeasured by hardware.
94c89d1cf5SJoseph KoshyThe syntax used for specifying a hardware event along with additional
95c89d1cf5SJoseph Koshyevent specific qualifiers (if any) is described in detail in section
96ebccf1e3SJoseph Koshy.Sx "EVENT SPECIFIERS"
97ebccf1e3SJoseph Koshybelow.
98ebccf1e3SJoseph Koshy.Pp
99c89d1cf5SJoseph KoshyPMCs are associated with the process that allocated them and
100c89d1cf5SJoseph Koshywill be automatically reclaimed by the system when the process exits.
101c89d1cf5SJoseph KoshyAdditionally, process-scope PMCs have to be attached to one or more
102c89d1cf5SJoseph Koshytarget processes before they can perform measurements.
103c89d1cf5SJoseph KoshyA process-scope PMC may be attached to those target processes
104c89d1cf5SJoseph Koshythat its owner process would otherwise be permitted to debug.
105c89d1cf5SJoseph KoshyAn owner process may attach PMCs to itself allowing
106c89d1cf5SJoseph Koshyit to measure its own behavior.
107c89d1cf5SJoseph KoshyAdditionally, on some machine architectures, such self-attached PMCs
108c89d1cf5SJoseph Koshymay be read cheaply using specialized instructions supported by the
109c89d1cf5SJoseph Koshyprocessor.
110ebccf1e3SJoseph Koshy.Pp
111c89d1cf5SJoseph KoshyCertain kinds of PMCs require that a log file be configured before
112c89d1cf5SJoseph Koshythey may be started.
113c89d1cf5SJoseph KoshyThese include:
1149ee2158bSJoel Dahl.Bl -bullet
115c89d1cf5SJoseph Koshy.It
116c89d1cf5SJoseph KoshySystem scope sampling PMCs.
117c89d1cf5SJoseph Koshy.It
118c89d1cf5SJoseph KoshyProcess scope sampling PMCs.
119c89d1cf5SJoseph Koshy.It
120c89d1cf5SJoseph KoshyProcess scope counting PMCs that have been configured to report PMC
121c89d1cf5SJoseph Koshyreadings on process context switches or process exits.
122c89d1cf5SJoseph Koshy.El
1239ee2158bSJoel Dahl.Pp
124c89d1cf5SJoseph KoshyUp to one log file may be configured per owner process.
125c89d1cf5SJoseph KoshyEvents logged to a log file may be subsequently analyzed using the
126c89d1cf5SJoseph Koshy.Xr pmclog 3
127c89d1cf5SJoseph Koshyfamily of functions.
128c89d1cf5SJoseph Koshy.Ss Supported CPUs
129c89d1cf5SJoseph KoshyThe CPUs known to the PMC library are named by the
130c89d1cf5SJoseph Koshy.Vt "enum pmc_cputype"
131c89d1cf5SJoseph Koshyenumeration.
132c89d1cf5SJoseph KoshySupported CPUs include:
1339ee2158bSJoel Dahl.Pp
1345faf9f4dSPau Amma.Bl -tag -width "Li PMC_CPU_ARMV7_CORTEX_A15" -compact
13580f30b73SJoseph Koshy.It Li PMC_CPU_AMD_K7
136c89d1cf5SJoseph Koshy.Tn "AMD Athlon"
137c89d1cf5SJoseph KoshyCPUs.
13880f30b73SJoseph Koshy.It Li PMC_CPU_AMD_K8
139c89d1cf5SJoseph Koshy.Tn "AMD Athlon64"
140c89d1cf5SJoseph KoshyCPUs.
1415faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A5
1425faf9f4dSPau Amma.Tn ARMv7
1435faf9f4dSPau Amma.Tn Cortex A5
1445faf9f4dSPau AmmaCPUs.
1455faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A7
1465faf9f4dSPau Amma.Tn ARMv7
1475faf9f4dSPau Amma.Tn Cortex A7
1485faf9f4dSPau AmmaCPUs.
1495faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A8
1505faf9f4dSPau Amma.Tn ARMv7
1515faf9f4dSPau Amma.Tn Cortex A8
1525faf9f4dSPau AmmaCPUs.
1535faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A9
1545faf9f4dSPau Amma.Tn ARMv7
1555faf9f4dSPau Amma.Tn Cortex A9
1565faf9f4dSPau AmmaCPUs.
1575faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A15
1585faf9f4dSPau Amma.Tn ARMv7 Cortex A15
1595faf9f4dSPau AmmaCPUs.
1605faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A17
1615faf9f4dSPau Amma.Tn ARMv7
1625faf9f4dSPau Amma.Tn Cortex A17
1635faf9f4dSPau AmmaCPUs.
1645faf9f4dSPau Amma.It Li PMC_CPU_ARMV8_CORTEX_A53
1655faf9f4dSPau AmmaARMv8
1665faf9f4dSPau Amma.Tn Cortex A53
1675faf9f4dSPau AmmaCPUs.
1685faf9f4dSPau Amma.It Li PMC_CPU_ARMV8_CORTEX_A57
1695faf9f4dSPau AmmaARMv8
1705faf9f4dSPau Amma.Tn Cortex A57
1715faf9f4dSPau AmmaCPUs.
1725faf9f4dSPau Amma.It Li PMC_CPU_ARMV8_CORTEX_A76
1735faf9f4dSPau AmmaARMv8
1745faf9f4dSPau Amma.Tn Cortex A76
1755faf9f4dSPau AmmaCPUs.
176*f401d82eSJoseph Koshy.It Li GENERIC
177*f401d82eSJoseph KoshyGeneric
178*f401d82eSJoseph Koshy.It Li PMC_CPU_INTEL_ATOM
179*f401d82eSJoseph Koshy.Tn Intel
180*f401d82eSJoseph Koshy.Tn Atom
181*f401d82eSJoseph KoshyCPUs and other CPUs conforming to version 3 of the
182*f401d82eSJoseph Koshy.Tn Intel
183*f401d82eSJoseph Koshyperformance measurement architecture.
184*f401d82eSJoseph Koshy.It Li PMC_CPU_INTEL_CORE
185*f401d82eSJoseph Koshy.Tn Intel
186*f401d82eSJoseph Koshy.Tn Core Solo
187*f401d82eSJoseph Koshyand
188*f401d82eSJoseph Koshy.Tn Core Duo
189*f401d82eSJoseph KoshyCPUs, and other CPUs conforming to version 1 of the
190*f401d82eSJoseph Koshy.Tn Intel
191*f401d82eSJoseph Koshyperformance measurement architecture.
192*f401d82eSJoseph Koshy.It Li PMC_CPU_INTEL_CORE2
193*f401d82eSJoseph Koshy.Tn Intel
194*f401d82eSJoseph Koshy.Tn "Core2 Solo" ,
195*f401d82eSJoseph Koshy.Tn "Core2 Duo"
196*f401d82eSJoseph Koshyand
197*f401d82eSJoseph Koshy.Tn "Core2 Extreme"
198*f401d82eSJoseph KoshyCPUs, and other CPUs conforming to version 2 of the
199*f401d82eSJoseph Koshy.Tn Intel
200*f401d82eSJoseph Koshyperformance measurement architecture.
201*f401d82eSJoseph Koshy.It Li PMC_CPU_PPC_7450
202*f401d82eSJoseph Koshy.Tn PowerPC
203*f401d82eSJoseph KoshyMPC7450 CPUs.
204*f401d82eSJoseph Koshy.It Li PMC_CPU_PPC_970
205*f401d82eSJoseph Koshy.Tn IBM
206*f401d82eSJoseph Koshy.Tn PowerPC
207*f401d82eSJoseph Koshy970 CPUs.
208*f401d82eSJoseph Koshy.It Li PMC_CPU_PPC_E500
209*f401d82eSJoseph Koshy.Tn PowerPC
210*f401d82eSJoseph Koshye500 Core CPUs.
211*f401d82eSJoseph Koshy.It Li PMC_CPU_PPC_POWER8
212*f401d82eSJoseph Koshy.Tn IBM
213*f401d82eSJoseph Koshy.Tn POWER8 and
214*f401d82eSJoseph Koshy.Tn POWER9
215*f401d82eSJoseph KoshyCPUs.
216c89d1cf5SJoseph Koshy.El
217c89d1cf5SJoseph Koshy.Ss Supported PMCs
2185faf9f4dSPau AmmaPMCs supported by this library are named by the
219c89d1cf5SJoseph Koshy.Vt enum pmc_class
220c89d1cf5SJoseph Koshyenumeration.
2215faf9f4dSPau AmmaSupported PMC classes include:
2229ee2158bSJoel Dahl.Pp
2235faf9f4dSPau Amma.Bl -tag -width "Li PMC_CLASS_POWER8" -compact
22472cf78b8SJoseph Koshy.It Li PMC_CLASS_IAF
225f20a61ffSJoseph KoshyFixed function hardware counters presents in CPUs conforming to the
22680f30b73SJoseph Koshy.Tn Intel
22780f30b73SJoseph Koshyperformance measurement architecture version 2 and later.
22872cf78b8SJoseph Koshy.It Li PMC_CLASS_IAP
22972cf78b8SJoseph KoshyProgrammable hardware counters present in CPUs conforming to the
23072cf78b8SJoseph Koshy.Tn Intel
23172cf78b8SJoseph Koshyperformance measurement architecture version 1 and later.
23280f30b73SJoseph Koshy.It Li PMC_CLASS_K7
233c89d1cf5SJoseph KoshyProgrammable hardware counters present in
234c89d1cf5SJoseph Koshy.Tn "AMD Athlon"
235c89d1cf5SJoseph KoshyCPUs.
23680f30b73SJoseph Koshy.It Li PMC_CLASS_K8
237c89d1cf5SJoseph KoshyProgrammable hardware counters present in
238c89d1cf5SJoseph Koshy.Tn "AMD Athlon64"
239c89d1cf5SJoseph KoshyCPUs.
24080f30b73SJoseph Koshy.It Li PMC_CLASS_TSC
24124f2c3f3SJoseph KoshyThe timestamp counter on i386 and amd64 architecture CPUs.
2425faf9f4dSPau Amma.It Li PMC_CLASS_ARMV7
2435faf9f4dSPau Amma.Tn ARMv7
2445faf9f4dSPau Amma.It Li PMC_CLASS_ARMV8
2455faf9f4dSPau Amma.Tn ARMv8
2465faf9f4dSPau Amma.It Li PMC_CLASS_PPC970
2475faf9f4dSPau Amma.Tn IBM
2485faf9f4dSPau Amma.Tn PowerPC
2495faf9f4dSPau Amma970 class.
2505faf9f4dSPau Amma.It Li PMC_CLASS_POWER8
2515faf9f4dSPau Amma.Tn IBM
2525faf9f4dSPau Amma.Tn POWER8
2535faf9f4dSPau Ammaclass.
254f5f9340bSFabien Thomas.It Li PMC_CLASS_SOFT
255f5f9340bSFabien ThomasSoftware events.
256c89d1cf5SJoseph Koshy.El
257c89d1cf5SJoseph Koshy.Ss PMC Capabilities
258c89d1cf5SJoseph KoshyCapabilities of performance monitoring hardware are denoted using
259c89d1cf5SJoseph Koshythe
260c89d1cf5SJoseph Koshy.Vt "enum pmc_caps"
261c89d1cf5SJoseph Koshyenumeration.
262c89d1cf5SJoseph KoshySupported capabilities include:
2639ee2158bSJoel Dahl.Pp
26480f30b73SJoseph Koshy.Bl -tag -width "Li PMC_CAP_INTERRUPT" -compact
26580f30b73SJoseph Koshy.It Li PMC_CAP_CASCADE
26680f30b73SJoseph KoshyThe ability to cascade counters.
267b6e28991SAleksandr Rybalko.It Li PMC_CAP_DOMWIDE
268b6e28991SAleksandr RybalkoSeparate counters tied to each NUMA domain.
26980f30b73SJoseph Koshy.It Li PMC_CAP_EDGE
270c89d1cf5SJoseph KoshyThe ability to count negated to asserted transitions of the hardware
271c89d1cf5SJoseph Koshyconditions being probed for.
27280f30b73SJoseph Koshy.It Li PMC_CAP_INTERRUPT
273c89d1cf5SJoseph KoshyThe ability to interrupt the CPU.
27480f30b73SJoseph Koshy.It Li PMC_CAP_INVERT
275c89d1cf5SJoseph KoshyThe ability to invert the sense of the hardware conditions being
276c89d1cf5SJoseph Koshymeasured.
277624f6965SJoseph Koshy.It Li PMC_CAP_PRECISE
278624f6965SJoseph KoshyThe ability to perform precise sampling.
27980f30b73SJoseph Koshy.It Li PMC_CAP_QUALIFIER
280c89d1cf5SJoseph KoshyThe hardware allows monitored to be further qualified in some
281c89d1cf5SJoseph Koshysystem dependent way.
282624f6965SJoseph Koshy.It Li PMC_CAP_READ
283624f6965SJoseph KoshyThe ability to read from performance counters.
28480f30b73SJoseph Koshy.It Li PMC_CAP_SYSTEM
285c89d1cf5SJoseph KoshyThe ability to restrict counting of hardware events to when the CPU is
286c89d1cf5SJoseph Koshyrunning privileged code.
287b6e28991SAleksandr Rybalko.It Li PMC_CAP_SYSWIDE
288b6e28991SAleksandr RybalkoA single counter aggregating events for the whole system.
28980f30b73SJoseph Koshy.It Li PMC_CAP_THRESHOLD
290c89d1cf5SJoseph KoshyThe ability to ignore simultaneous hardware events below a
291c89d1cf5SJoseph Koshyprogrammable threshold.
29280f30b73SJoseph Koshy.It Li PMC_CAP_USER
293c89d1cf5SJoseph KoshyThe ability to restrict counting of hardware events to those when the
294c89d1cf5SJoseph KoshyCPU is running unprivileged code.
29580f30b73SJoseph Koshy.It Li PMC_CAP_WRITE
2960f3866faSJoseph KoshyThe ability to write to performance counters.
297c89d1cf5SJoseph Koshy.El
2986455febbSJoseph Koshy.Ss CPU Naming Conventions
299dd1259daSJoseph KoshyCPUs are named using small integers from zero up to, but
3006455febbSJoseph Koshyexcluding, the value returned by function
3016455febbSJoseph Koshy.Fn pmc_ncpu .
3026455febbSJoseph KoshyOn platforms supporting sparsely numbered CPUs not all the numbers in
3036455febbSJoseph Koshythis range will denote valid CPUs.
3046455febbSJoseph KoshyOperations on non-existent CPUs will return an error.
3056455febbSJoseph Koshy.Ss Functional Grouping of the API
306c89d1cf5SJoseph KoshyThis section contains a brief overview of the available functionality
307c89d1cf5SJoseph Koshyin the PMC library.
308c89d1cf5SJoseph KoshyEach function listed here is described further in its own manual page.
3099ee2158bSJoel Dahl.Bl -tag -width 2n
310c89d1cf5SJoseph Koshy.It Administration
3119ee2158bSJoel Dahl.Bl -tag -width 6n -compact
312c89d1cf5SJoseph Koshy.It Fn pmc_disable , Fn pmc_enable
313c89d1cf5SJoseph KoshyAdministratively disable (enable) specific performance monitoring
314c89d1cf5SJoseph Koshycounter hardware.
315c89d1cf5SJoseph KoshyCounters that are disabled will not be available to applications to
316c89d1cf5SJoseph Koshyuse.
317c89d1cf5SJoseph Koshy.El
318c89d1cf5SJoseph Koshy.It "Convenience Functions"
3199ee2158bSJoel Dahl.Bl -tag -width 6n -compact
320c89d1cf5SJoseph Koshy.It Fn pmc_event_names_of_class
321c89d1cf5SJoseph KoshyReturns a list of event names supported by a given PMC type.
322c89d1cf5SJoseph Koshy.It Fn pmc_name_of_capability
323c89d1cf5SJoseph KoshyConvert a
324c89d1cf5SJoseph Koshy.Dv PMC_CAP_*
325c89d1cf5SJoseph Koshyflag to a human-readable string.
326c89d1cf5SJoseph Koshy.It Fn pmc_name_of_class
327c89d1cf5SJoseph KoshyConvert a
328c89d1cf5SJoseph Koshy.Dv PMC_CLASS_*
329c89d1cf5SJoseph Koshyconstant to a human-readable string.
330c89d1cf5SJoseph Koshy.It Fn pmc_name_of_cputype
331c89d1cf5SJoseph KoshyReturn a human-readable name for a CPU type.
332c89d1cf5SJoseph Koshy.It Fn pmc_name_of_disposition
333c89d1cf5SJoseph KoshyReturn a human-readable string describing a PMC's disposition.
334c89d1cf5SJoseph Koshy.It Fn pmc_name_of_event
335c89d1cf5SJoseph KoshyConvert a numeric event code to a human-readable string.
336c89d1cf5SJoseph Koshy.It Fn pmc_name_of_mode
337c89d1cf5SJoseph KoshyConvert a
338c89d1cf5SJoseph Koshy.Dv PMC_MODE_*
339c89d1cf5SJoseph Koshyconstant to a human-readable name.
340c89d1cf5SJoseph Koshy.It Fn pmc_name_of_state
341c89d1cf5SJoseph KoshyReturn a human-readable string describing a PMC's current state.
342c89d1cf5SJoseph Koshy.El
343c89d1cf5SJoseph Koshy.It "Library Initialization"
3449ee2158bSJoel Dahl.Bl -tag -width 6n -compact
345c89d1cf5SJoseph Koshy.It Fn pmc_init
346c89d1cf5SJoseph KoshyInitialize the library.
347c89d1cf5SJoseph KoshyThis function must be called before any other library function.
348c89d1cf5SJoseph Koshy.El
349c89d1cf5SJoseph Koshy.It "Log File Handling"
3509ee2158bSJoel Dahl.Bl -tag -width 6n -compact
351c89d1cf5SJoseph Koshy.It Fn pmc_configure_logfile
352c89d1cf5SJoseph KoshyConfigure a log file for
353c89d1cf5SJoseph Koshy.Xr hwpmc 4
354c89d1cf5SJoseph Koshyto write logged events to.
355c89d1cf5SJoseph Koshy.It Fn pmc_flush_logfile
356c89d1cf5SJoseph KoshyFlush all pending log data in
357c89d1cf5SJoseph Koshy.Xr hwpmc 4 Ns Ap s
358c89d1cf5SJoseph Koshybuffers.
359dceed24aSFabien Thomas.It Fn pmc_close_logfile
360dceed24aSFabien ThomasFlush all pending log data and close
361dceed24aSFabien Thomas.Xr hwpmc 4 Ns Ap s
362dceed24aSFabien Thomasside of the stream.
363c89d1cf5SJoseph Koshy.It Fn pmc_writelog
364c89d1cf5SJoseph KoshyAppend arbitrary user data to the current log file.
365c89d1cf5SJoseph Koshy.El
366c89d1cf5SJoseph Koshy.It "PMC Management"
3679ee2158bSJoel Dahl.Bl -tag -width 6n -compact
368c89d1cf5SJoseph Koshy.It Fn pmc_allocate , Fn pmc_release
369c89d1cf5SJoseph KoshyAllocate (free) a PMC.
370c89d1cf5SJoseph Koshy.It Fn pmc_attach , Fn pmc_detach
371c89d1cf5SJoseph KoshyAttach (detach) a process scope PMC to a target.
372c89d1cf5SJoseph Koshy.It Fn pmc_read , Fn pmc_write , Fn pmc_rw
373c89d1cf5SJoseph KoshyRead (write) a value from (to) a PMC.
374c89d1cf5SJoseph Koshy.It Fn pmc_start , Fn pmc_stop
375c89d1cf5SJoseph KoshyStart (stop) a software PMC.
376c89d1cf5SJoseph Koshy.It Fn pmc_set
377c89d1cf5SJoseph KoshySet the reload value for a sampling PMC.
378c89d1cf5SJoseph Koshy.El
379c89d1cf5SJoseph Koshy.It "Queries"
3809ee2158bSJoel Dahl.Bl -tag -width 6n -compact
381c89d1cf5SJoseph Koshy.It Fn pmc_capabilities
382c89d1cf5SJoseph KoshyRetrieve the capabilities for a given PMC.
383c89d1cf5SJoseph Koshy.It Fn pmc_cpuinfo
384c89d1cf5SJoseph KoshyRetrieve information about the CPUs and PMC hardware present in the
385c89d1cf5SJoseph Koshysystem.
386c89d1cf5SJoseph Koshy.It Fn pmc_get_driver_stats
387c89d1cf5SJoseph KoshyRetrieve statistics maintained by
388c89d1cf5SJoseph Koshy.Xr hwpmc 4 .
389c89d1cf5SJoseph Koshy.It Fn pmc_ncpu
3906455febbSJoseph KoshyDetermine the greatest possible CPU number on the system.
391c89d1cf5SJoseph Koshy.It Fn pmc_npmc
392c89d1cf5SJoseph KoshyReturn the number of hardware PMCs present in a given CPU.
393c89d1cf5SJoseph Koshy.It Fn pmc_pmcinfo
394c89d1cf5SJoseph KoshyReturn information about the state of a given CPU's PMCs.
395c89d1cf5SJoseph Koshy.It Fn pmc_width
396c89d1cf5SJoseph KoshyDetermine the width of a hardware counter in bits.
397c89d1cf5SJoseph Koshy.El
398c89d1cf5SJoseph Koshy.It "x86 Architecture Specific API"
3999ee2158bSJoel Dahl.Bl -tag -width 6n -compact
400c89d1cf5SJoseph Koshy.It Fn pmc_get_msr
401c89d1cf5SJoseph KoshyReturns the processor model specific register number
402c89d1cf5SJoseph Koshyassociated with
403c5153e19SJoseph Koshy.Fa pmc .
404c89d1cf5SJoseph KoshyApplications may then use the x86
405c89d1cf5SJoseph Koshy.Ic RDPMC
406c89d1cf5SJoseph Koshyinstruction to directly read the contents of the PMC.
407c89d1cf5SJoseph Koshy.El
408c89d1cf5SJoseph Koshy.El
4099abe909bSRuslan Ermilov.Ss Signal Handling Requirements
410ebccf1e3SJoseph KoshyApplications using PMCs are required to handle the following signals:
411c89d1cf5SJoseph Koshy.Bl -tag -width ".Dv SIGBUS"
4129abe909bSRuslan Ermilov.It Dv SIGBUS
413ebccf1e3SJoseph KoshyWhen the
414ebccf1e3SJoseph Koshy.Xr hwpmc 4
415ebccf1e3SJoseph Koshymodule is unloaded using
416ebccf1e3SJoseph Koshy.Xr kldunload 8 ,
417ebccf1e3SJoseph Koshyprocesses that have PMCs allocated to them will be sent a
4189abe909bSRuslan Ermilov.Dv SIGBUS
4199abe909bSRuslan Ermilovsignal.
4209abe909bSRuslan Ermilov.It Dv SIGIO
421f263522aSJoseph KoshyThe
422f263522aSJoseph Koshy.Xr hwpmc 4
4239abe909bSRuslan Ermilovdriver will send a PMC owning process a
4249abe909bSRuslan Ermilov.Dv SIGIO
4259abe909bSRuslan Ermilovsignal if:
426f263522aSJoseph Koshy.Bl -bullet
427f263522aSJoseph Koshy.It
4285faf9f4dSPau Ammaany process-mode PMC allocated by it loses all its
429f263522aSJoseph Koshytarget processes.
430f263522aSJoseph Koshy.It
4315faf9f4dSPau Ammathe driver encounters an error when writing log data to a
432f263522aSJoseph Koshyconfigured log file.
433f263522aSJoseph KoshyThis error may be retrieved by a subsequent call to
434f263522aSJoseph Koshy.Fn pmc_flush_logfile .
435f263522aSJoseph Koshy.El
436ebccf1e3SJoseph Koshy.El
437c89d1cf5SJoseph Koshy.Ss Typical Program Flow
438c89d1cf5SJoseph Koshy.Bl -enum
439c89d1cf5SJoseph Koshy.It
440c89d1cf5SJoseph KoshyAn application would first invoke function
441c89d1cf5SJoseph Koshy.Fn pmc_init
442c89d1cf5SJoseph Koshyto allow the library to initialize itself.
443c89d1cf5SJoseph Koshy.It
444c89d1cf5SJoseph KoshySignal handling would then be set up.
445c89d1cf5SJoseph Koshy.It
446c89d1cf5SJoseph KoshyNext the application would allocate the PMCs it desires using function
447c89d1cf5SJoseph Koshy.Fn pmc_allocate .
448c89d1cf5SJoseph Koshy.It
449c89d1cf5SJoseph KoshyInitial values for PMCs may be set using function
450c89d1cf5SJoseph Koshy.Fn pmc_set .
451c89d1cf5SJoseph Koshy.It
452c89d1cf5SJoseph KoshyIf a log file is necessary for the PMCs to work, it would
453c89d1cf5SJoseph Koshybe configured using function
454c89d1cf5SJoseph Koshy.Fn pmc_configure_logfile .
455c89d1cf5SJoseph Koshy.It
456c89d1cf5SJoseph KoshyProcess scope PMCs would then be attached to their target processes
457c89d1cf5SJoseph Koshyusing function
458c89d1cf5SJoseph Koshy.Fn pmc_attach .
459c89d1cf5SJoseph Koshy.It
460c89d1cf5SJoseph KoshyThe PMCs would then be started using function
461c89d1cf5SJoseph Koshy.Fn pmc_start .
462c89d1cf5SJoseph Koshy.It
463c89d1cf5SJoseph KoshyOnce started, the values of counting PMCs may be read using function
464b53a052dSJoseph Koshy.Fn pmc_read .
465c89d1cf5SJoseph KoshyFor PMCs that write events to the log file, this logged data would be
466c89d1cf5SJoseph Koshyread and parsed using the
467c89d1cf5SJoseph Koshy.Xr pmclog 3
468c89d1cf5SJoseph Koshyfamily of functions.
469c89d1cf5SJoseph Koshy.It
470c89d1cf5SJoseph KoshyPMCs are stopped using function
471c89d1cf5SJoseph Koshy.Fn pmc_stop ,
472c89d1cf5SJoseph Koshyand process scope PMCs are detached from their targets using
473c89d1cf5SJoseph Koshyfunction
474c89d1cf5SJoseph Koshy.Fn pmc_detach .
475c89d1cf5SJoseph Koshy.It
4765faf9f4dSPau AmmaBefore the process exits, it may release its PMCs using function
477c89d1cf5SJoseph Koshy.Fn pmc_release .
478c89d1cf5SJoseph KoshyAny configured log file may be closed using function
479c89d1cf5SJoseph Koshy.Fn pmc_configure_logfile .
480c89d1cf5SJoseph Koshy.El
481ebccf1e3SJoseph Koshy.Sh EVENT SPECIFIERS
482ebccf1e3SJoseph KoshyEvent specifiers are strings comprising of an event name, followed by
483ebccf1e3SJoseph Koshyoptional parameters modifying the semantics of the hardware event
484ebccf1e3SJoseph Koshybeing probed.
4850b844226SJoseph KoshyEvent names are PMC architecture dependent, but the PMC library defines
4860b844226SJoseph Koshymachine independent aliases for commonly used events.
4870f7668cbSJoseph Koshy.Pp
4880f7668cbSJoseph KoshyEvent specifiers spellings are case-insensitive and space characters,
4890f7668cbSJoseph Koshyperiods, underscores and hyphens are considered equivalent to each other.
4900f7668cbSJoseph KoshyThus the event specifiers
4910f7668cbSJoseph Koshy.Qq "Example Event" ,
4920f7668cbSJoseph Koshy.Qq "example-event" ,
4930f7668cbSJoseph Koshyand
4940f7668cbSJoseph Koshy.Qq "EXAMPLE_EVENT"
4950f7668cbSJoseph Koshyare equivalent.
4960f7668cbSJoseph Koshy.Ss PMC Architecture Dependent Events
4970f7668cbSJoseph KoshyPMC architecture dependent event specifiers are described in the
4980f7668cbSJoseph Koshyfollowing manual pages:
4990f7668cbSJoseph Koshy.Bl -column " PMC_CLASS_TSC " "MANUAL PAGE "
5000f7668cbSJoseph Koshy.It Em "PMC Class"      Ta Em "Manual Page"
5010f7668cbSJoseph Koshy.It Li PMC_CLASS_IAF    Ta Xr pmc.iaf 3
5020f7668cbSJoseph Koshy.It Li PMC_CLASS_IAP    Ta Xr pmc.atom 3 , Xr pmc.core 3 , Xr pmc.core2 3
5030f7668cbSJoseph Koshy.It Li PMC_CLASS_K7     Ta Xr pmc.k7 3
5040f7668cbSJoseph Koshy.It Li PMC_CLASS_K8     Ta Xr pmc.k8 3
5050f7668cbSJoseph Koshy.It Li PMC_CLASS_TSC    Ta Xr pmc.tsc 3
5060f7668cbSJoseph Koshy.El
507ebccf1e3SJoseph Koshy.Ss Event Name Aliases
50824f2c3f3SJoseph KoshyEvent name aliases are PMC-independent names for commonly used events.
509ebccf1e3SJoseph KoshyThe following aliases are known to this version of the
510110e1704SRuslan Ermilov.Nm pmc
511ebccf1e3SJoseph Koshylibrary:
512ebccf1e3SJoseph Koshy.Bl -tag -width indent
513ebccf1e3SJoseph Koshy.It Li branches
514ebccf1e3SJoseph KoshyMeasure the number of branches retired.
515ebccf1e3SJoseph Koshy.It Li branch-mispredicts
516ebccf1e3SJoseph KoshyMeasure the number of retired branches that were mispredicted.
517ebccf1e3SJoseph Koshy.It Li cycles
518ebccf1e3SJoseph KoshyMeasure processor cycles.
519ebccf1e3SJoseph KoshyThis event is implemented using the processor's Time Stamp Counter
520ebccf1e3SJoseph Koshyregister.
521ebccf1e3SJoseph Koshy.It Li dc-misses
522ebccf1e3SJoseph KoshyMeasure the number of data cache misses.
523ebccf1e3SJoseph Koshy.It Li ic-misses
524ebccf1e3SJoseph KoshyMeasure the number of instruction cache misses.
525ebccf1e3SJoseph Koshy.It Li instructions
526ebccf1e3SJoseph KoshyMeasure the number of instructions retired.
527ebccf1e3SJoseph Koshy.It Li interrupts
528ebccf1e3SJoseph KoshyMeasure the number of interrupts seen.
529177a2f22SJoseph Koshy.It Li unhalted-cycles
530177a2f22SJoseph KoshyMeasure the number of cycles the processor is not in a halted
531177a2f22SJoseph Koshyor sleep state.
532ebccf1e3SJoseph Koshy.El
5335138c36aSJoseph Koshy.Sh COMPATIBILITY
5345138c36aSJoseph KoshyThe interface between the
535110e1704SRuslan Ermilov.Nm pmc
5365138c36aSJoseph Koshylibrary and the
5375138c36aSJoseph Koshy.Xr hwpmc 4
5385138c36aSJoseph Koshydriver is intended to be private to the implementation and may
5395138c36aSJoseph Koshychange.
5405138c36aSJoseph KoshyIn order to ease forward compatibility with future versions of the
5415138c36aSJoseph Koshy.Xr hwpmc 4
5425138c36aSJoseph Koshydriver, applications are urged to dynamically link with the
543110e1704SRuslan Ermilov.Nm pmc
5445138c36aSJoseph Koshylibrary.
5455138c36aSJoseph Koshy.Pp
5465138c36aSJoseph KoshyThe
547110e1704SRuslan Ermilov.Nm pmc
5485138c36aSJoseph KoshyAPI is
5495138c36aSJoseph Koshy.Ud
550ebccf1e3SJoseph Koshy.Sh SEE ALSO
55172cf78b8SJoseph Koshy.Xr pmc.atom 3 ,
55272cf78b8SJoseph Koshy.Xr pmc.core 3 ,
55372cf78b8SJoseph Koshy.Xr pmc.core2 3 ,
55456e39702SGeorge V. Neville-Neil.Xr pmc.haswell 3 ,
55556e39702SGeorge V. Neville-Neil.Xr pmc.haswelluc 3 ,
556f1ec0939SRyan Stone.Xr pmc.haswellxeon 3 ,
55772cf78b8SJoseph Koshy.Xr pmc.iaf 3 ,
55856e39702SGeorge V. Neville-Neil.Xr pmc.ivybridge 3 ,
55956e39702SGeorge V. Neville-Neil.Xr pmc.ivybridgexeon 3 ,
56024f2c3f3SJoseph Koshy.Xr pmc.k7 3 ,
56124f2c3f3SJoseph Koshy.Xr pmc.k8 3 ,
56256e39702SGeorge V. Neville-Neil.Xr pmc.sandybridge 3 ,
56356e39702SGeorge V. Neville-Neil.Xr pmc.sandybridgeuc 3 ,
56456e39702SGeorge V. Neville-Neil.Xr pmc.sandybridgexeon 3 ,
565f5f9340bSFabien Thomas.Xr pmc.soft 3 ,
56624f2c3f3SJoseph Koshy.Xr pmc.tsc 3 ,
56756e39702SGeorge V. Neville-Neil.Xr pmc.westmere 3 ,
56856e39702SGeorge V. Neville-Neil.Xr pmc.westmereuc 3 ,
5697a40330bSEnji Cooper.Xr pmc_allocate 3 ,
5707a40330bSEnji Cooper.Xr pmc_attach 3 ,
5717a40330bSEnji Cooper.Xr pmc_capabilities 3 ,
5727a40330bSEnji Cooper.Xr pmc_configure_logfile 3 ,
5737a40330bSEnji Cooper.Xr pmc_disable 3 ,
5747a40330bSEnji Cooper.Xr pmc_event_names_of_class 3 ,
5757a40330bSEnji Cooper.Xr pmc_get_driver_stats 3 ,
5767a40330bSEnji Cooper.Xr pmc_get_msr 3 ,
5777a40330bSEnji Cooper.Xr pmc_init 3 ,
5787a40330bSEnji Cooper.Xr pmc_name_of_capability 3 ,
5797a40330bSEnji Cooper.Xr pmc_read 3 ,
5807a40330bSEnji Cooper.Xr pmc_set 3 ,
5817a40330bSEnji Cooper.Xr pmc_start 3 ,
582f263522aSJoseph Koshy.Xr pmclog 3 ,
583ebccf1e3SJoseph Koshy.Xr hwpmc 4 ,
584ebccf1e3SJoseph Koshy.Xr pmccontrol 8 ,
585ebccf1e3SJoseph Koshy.Xr pmcstat 8
5865138c36aSJoseph Koshy.Sh HISTORY
5875138c36aSJoseph KoshyThe
588110e1704SRuslan Ermilov.Nm pmc
5895138c36aSJoseph Koshylibrary first appeared in
5905138c36aSJoseph Koshy.Fx 6.0 .
591c89d1cf5SJoseph Koshy.Sh AUTHORS
592c89d1cf5SJoseph KoshyThe
593c89d1cf5SJoseph Koshy.Lb libpmc
594c89d1cf5SJoseph Koshylibrary was written by
5952b7af31cSBaptiste Daroussin.An Joseph Koshy Aq Mt jkoshy@FreeBSD.org .
596