xref: /freebsd/lib/libpmc/pmc.3 (revision b293497146fea63d76a1c7492c3a21e4e5bf8f48)
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.\"
2482d6d46dSMitchell Horne.Dd June 23, 2023
25ebccf1e3SJoseph Koshy.Dt PMC 3
26aa12cea2SUlrich Spörlein.Os
27ebccf1e3SJoseph Koshy.Sh NAME
28c89d1cf5SJoseph Koshy.Nm pmc
29c89d1cf5SJoseph Koshy.Nd library for accessing hardware performance monitoring counters
30ebccf1e3SJoseph Koshy.Sh LIBRARY
31ebccf1e3SJoseph Koshy.Lb libpmc
32ebccf1e3SJoseph Koshy.Sh SYNOPSIS
33ebccf1e3SJoseph Koshy.In pmc.h
34ebccf1e3SJoseph Koshy.Sh DESCRIPTION
35ebccf1e3SJoseph KoshyThe
36c89d1cf5SJoseph Koshy.Lb libpmc
37c89d1cf5SJoseph Koshyprovides a programming interface that allows applications to use
38c89d1cf5SJoseph Koshyhardware performance counters to gather performance data about
39c89d1cf5SJoseph Koshyspecific processes or for the system as a whole.
40c89d1cf5SJoseph KoshyThe library is implemented using the lower-level facilities offered by
41c89d1cf5SJoseph Koshythe
42ebccf1e3SJoseph Koshy.Xr hwpmc 4
43c89d1cf5SJoseph Koshydriver.
44c89d1cf5SJoseph Koshy.Ss Key Concepts
45c89d1cf5SJoseph KoshyPerformance monitoring counters (PMCs) are represented by the library
46c89d1cf5SJoseph Koshyusing a software abstraction.
47c89d1cf5SJoseph KoshyThese
48c89d1cf5SJoseph Koshy.Dq abstract
49c2025a76SJoel DahlPMCs can have two scopes:
50c89d1cf5SJoseph Koshy.Bl -bullet
51c89d1cf5SJoseph Koshy.It
52c89d1cf5SJoseph KoshySystem scope.
53c89d1cf5SJoseph KoshyThese PMCs measure events in a whole-system manner, i.e., independent
54c89d1cf5SJoseph Koshyof the currently executing thread.
55c89d1cf5SJoseph KoshySystem scope PMCs are allocated on specific CPUs and do not
56c89d1cf5SJoseph Koshymigrate between CPUs.
57c89d1cf5SJoseph KoshyNon-privileged process are allowed to allocate system scope PMCs if the
58c89d1cf5SJoseph Koshy.Xr hwpmc 4
59c89d1cf5SJoseph Koshysysctl tunable:
60c89d1cf5SJoseph Koshy.Va security.bsd.unprivileged_syspmcs
61c89d1cf5SJoseph Koshyis non-zero.
62c89d1cf5SJoseph Koshy.It
63c89d1cf5SJoseph KoshyProcess scope.
64c89d1cf5SJoseph KoshyThese PMCs only measure hardware events when the processes they are
65c89d1cf5SJoseph Koshyattached to are executing on a CPU.
66c89d1cf5SJoseph KoshyIn an SMP system, process scope PMCs migrate between CPUs along with
67c89d1cf5SJoseph Koshytheir target processes.
68c89d1cf5SJoseph Koshy.El
69ebccf1e3SJoseph Koshy.Pp
70c89d1cf5SJoseph KoshyOrthogonal to PMC scope, PMCs may be allocated in one of two
71c89d1cf5SJoseph Koshyoperational modes:
72c89d1cf5SJoseph Koshy.Bl -bullet
73c89d1cf5SJoseph Koshy.It
74c89d1cf5SJoseph KoshyCounting PMCs measure events according to their scope
75c89d1cf5SJoseph Koshy(system or process).
76c89d1cf5SJoseph KoshyThe application needs to explicitly read these counters
77c89d1cf5SJoseph Koshyto retrieve their value.
78c89d1cf5SJoseph Koshy.It
79c89d1cf5SJoseph KoshySampling PMCs cause the CPU to be periodically interrupted
80c89d1cf5SJoseph Koshyand information about its state of execution to be collected.
81c89d1cf5SJoseph KoshySampling PMCs are used to profile specific processes and kernel
82c89d1cf5SJoseph Koshythreads or to profile the system as a whole.
83c89d1cf5SJoseph Koshy.El
84c89d1cf5SJoseph Koshy.Pp
85c89d1cf5SJoseph KoshyThe scope and operational mode for a software PMC are specified at
86c89d1cf5SJoseph KoshyPMC allocation time.
87c89d1cf5SJoseph KoshyAn application is allowed to allocate multiple PMCs subject
88c89d1cf5SJoseph Koshyto availability of hardware resources.
89c89d1cf5SJoseph Koshy.Pp
90c89d1cf5SJoseph KoshyThe library uses human-readable strings to name the event being
91c89d1cf5SJoseph Koshymeasured by hardware.
92c89d1cf5SJoseph KoshyThe syntax used for specifying a hardware event along with additional
93c89d1cf5SJoseph Koshyevent specific qualifiers (if any) is described in detail in section
94ebccf1e3SJoseph Koshy.Sx "EVENT SPECIFIERS"
95ebccf1e3SJoseph Koshybelow.
96ebccf1e3SJoseph Koshy.Pp
97c89d1cf5SJoseph KoshyPMCs are associated with the process that allocated them and
98c89d1cf5SJoseph Koshywill be automatically reclaimed by the system when the process exits.
99c89d1cf5SJoseph KoshyAdditionally, process-scope PMCs have to be attached to one or more
100c89d1cf5SJoseph Koshytarget processes before they can perform measurements.
101c89d1cf5SJoseph KoshyA process-scope PMC may be attached to those target processes
102c89d1cf5SJoseph Koshythat its owner process would otherwise be permitted to debug.
103c89d1cf5SJoseph KoshyAn owner process may attach PMCs to itself allowing
104c89d1cf5SJoseph Koshyit to measure its own behavior.
105c89d1cf5SJoseph KoshyAdditionally, on some machine architectures, such self-attached PMCs
106c89d1cf5SJoseph Koshymay be read cheaply using specialized instructions supported by the
107c89d1cf5SJoseph Koshyprocessor.
108ebccf1e3SJoseph Koshy.Pp
109c89d1cf5SJoseph KoshyCertain kinds of PMCs require that a log file be configured before
110c89d1cf5SJoseph Koshythey may be started.
111c89d1cf5SJoseph KoshyThese include:
1129ee2158bSJoel Dahl.Bl -bullet
113c89d1cf5SJoseph Koshy.It
114c89d1cf5SJoseph KoshySystem scope sampling PMCs.
115c89d1cf5SJoseph Koshy.It
116c89d1cf5SJoseph KoshyProcess scope sampling PMCs.
117c89d1cf5SJoseph Koshy.It
118c89d1cf5SJoseph KoshyProcess scope counting PMCs that have been configured to report PMC
119c89d1cf5SJoseph Koshyreadings on process context switches or process exits.
120c89d1cf5SJoseph Koshy.El
1219ee2158bSJoel Dahl.Pp
122c89d1cf5SJoseph KoshyUp to one log file may be configured per owner process.
123c89d1cf5SJoseph KoshyEvents logged to a log file may be subsequently analyzed using the
124c89d1cf5SJoseph Koshy.Xr pmclog 3
125c89d1cf5SJoseph Koshyfamily of functions.
126c89d1cf5SJoseph Koshy.Ss Supported CPUs
127c89d1cf5SJoseph KoshyThe CPUs known to the PMC library are named by the
128c89d1cf5SJoseph Koshy.Vt "enum pmc_cputype"
129c89d1cf5SJoseph Koshyenumeration.
130c89d1cf5SJoseph KoshySupported CPUs include:
1319ee2158bSJoel Dahl.Pp
1325faf9f4dSPau Amma.Bl -tag -width "Li PMC_CPU_ARMV7_CORTEX_A15" -compact
13380f30b73SJoseph Koshy.It Li PMC_CPU_AMD_K8
134c89d1cf5SJoseph Koshy.Tn "AMD Athlon64"
135c89d1cf5SJoseph KoshyCPUs.
1365faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A5
1375faf9f4dSPau Amma.Tn ARMv7
1385faf9f4dSPau Amma.Tn Cortex A5
1395faf9f4dSPau AmmaCPUs.
1405faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A7
1415faf9f4dSPau Amma.Tn ARMv7
1425faf9f4dSPau Amma.Tn Cortex A7
1435faf9f4dSPau AmmaCPUs.
1445faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A8
1455faf9f4dSPau Amma.Tn ARMv7
1465faf9f4dSPau Amma.Tn Cortex A8
1475faf9f4dSPau AmmaCPUs.
1485faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A9
1495faf9f4dSPau Amma.Tn ARMv7
1505faf9f4dSPau Amma.Tn Cortex A9
1515faf9f4dSPau AmmaCPUs.
1525faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A15
1535faf9f4dSPau Amma.Tn ARMv7 Cortex A15
1545faf9f4dSPau AmmaCPUs.
1555faf9f4dSPau Amma.It Li PMC_CPU_ARMV7_CORTEX_A17
1565faf9f4dSPau Amma.Tn ARMv7
1575faf9f4dSPau Amma.Tn Cortex A17
1585faf9f4dSPau AmmaCPUs.
1595faf9f4dSPau Amma.It Li PMC_CPU_ARMV8_CORTEX_A53
1605faf9f4dSPau AmmaARMv8
1615faf9f4dSPau Amma.Tn Cortex A53
1625faf9f4dSPau AmmaCPUs.
1635faf9f4dSPau Amma.It Li PMC_CPU_ARMV8_CORTEX_A57
1645faf9f4dSPau AmmaARMv8
1655faf9f4dSPau Amma.Tn Cortex A57
1665faf9f4dSPau AmmaCPUs.
1675faf9f4dSPau Amma.It Li PMC_CPU_ARMV8_CORTEX_A76
1685faf9f4dSPau AmmaARMv8
1695faf9f4dSPau Amma.Tn Cortex A76
1705faf9f4dSPau AmmaCPUs.
171f401d82eSJoseph Koshy.It Li GENERIC
172f401d82eSJoseph KoshyGeneric
173f401d82eSJoseph Koshy.It Li PMC_CPU_INTEL_ATOM
174f401d82eSJoseph Koshy.Tn Intel
175f401d82eSJoseph Koshy.Tn Atom
176f401d82eSJoseph KoshyCPUs and other CPUs conforming to version 3 of the
177f401d82eSJoseph Koshy.Tn Intel
178f401d82eSJoseph Koshyperformance measurement architecture.
179f401d82eSJoseph Koshy.It Li PMC_CPU_INTEL_CORE
180f401d82eSJoseph Koshy.Tn Intel
181f401d82eSJoseph Koshy.Tn Core Solo
182f401d82eSJoseph Koshyand
183f401d82eSJoseph Koshy.Tn Core Duo
184f401d82eSJoseph KoshyCPUs, and other CPUs conforming to version 1 of the
185f401d82eSJoseph Koshy.Tn Intel
186f401d82eSJoseph Koshyperformance measurement architecture.
187f401d82eSJoseph Koshy.It Li PMC_CPU_INTEL_CORE2
188f401d82eSJoseph Koshy.Tn Intel
189f401d82eSJoseph Koshy.Tn "Core2 Solo" ,
190f401d82eSJoseph Koshy.Tn "Core2 Duo"
191f401d82eSJoseph Koshyand
192f401d82eSJoseph Koshy.Tn "Core2 Extreme"
193f401d82eSJoseph KoshyCPUs, and other CPUs conforming to version 2 of the
194f401d82eSJoseph Koshy.Tn Intel
195f401d82eSJoseph Koshyperformance measurement architecture.
196f401d82eSJoseph Koshy.It Li PMC_CPU_PPC_7450
197f401d82eSJoseph Koshy.Tn PowerPC
198f401d82eSJoseph KoshyMPC7450 CPUs.
199f401d82eSJoseph Koshy.It Li PMC_CPU_PPC_970
200f401d82eSJoseph Koshy.Tn IBM
201f401d82eSJoseph Koshy.Tn PowerPC
202f401d82eSJoseph Koshy970 CPUs.
203f401d82eSJoseph Koshy.It Li PMC_CPU_PPC_E500
204f401d82eSJoseph Koshy.Tn PowerPC
205f401d82eSJoseph Koshye500 Core CPUs.
206f401d82eSJoseph Koshy.It Li PMC_CPU_PPC_POWER8
207f401d82eSJoseph Koshy.Tn IBM
208f401d82eSJoseph Koshy.Tn POWER8 and
209f401d82eSJoseph Koshy.Tn POWER9
210f401d82eSJoseph KoshyCPUs.
211c89d1cf5SJoseph Koshy.El
212c89d1cf5SJoseph Koshy.Ss Supported PMCs
2135faf9f4dSPau AmmaPMCs supported by this library are named by the
214c89d1cf5SJoseph Koshy.Vt enum pmc_class
215c89d1cf5SJoseph Koshyenumeration.
2165faf9f4dSPau AmmaSupported PMC classes include:
2179ee2158bSJoel Dahl.Pp
2185faf9f4dSPau Amma.Bl -tag -width "Li PMC_CLASS_POWER8" -compact
21972cf78b8SJoseph Koshy.It Li PMC_CLASS_IAF
220f20a61ffSJoseph KoshyFixed function hardware counters presents in CPUs conforming to the
22180f30b73SJoseph Koshy.Tn Intel
22280f30b73SJoseph Koshyperformance measurement architecture version 2 and later.
22372cf78b8SJoseph Koshy.It Li PMC_CLASS_IAP
22472cf78b8SJoseph KoshyProgrammable hardware counters present in CPUs conforming to the
22572cf78b8SJoseph Koshy.Tn Intel
22672cf78b8SJoseph Koshyperformance measurement architecture version 1 and later.
22780f30b73SJoseph Koshy.It Li PMC_CLASS_K8
228c89d1cf5SJoseph KoshyProgrammable hardware counters present in
229c89d1cf5SJoseph Koshy.Tn "AMD Athlon64"
230c89d1cf5SJoseph KoshyCPUs.
23180f30b73SJoseph Koshy.It Li PMC_CLASS_TSC
23224f2c3f3SJoseph KoshyThe timestamp counter on i386 and amd64 architecture CPUs.
2335faf9f4dSPau Amma.It Li PMC_CLASS_ARMV7
2345faf9f4dSPau Amma.Tn ARMv7
2355faf9f4dSPau Amma.It Li PMC_CLASS_ARMV8
2365faf9f4dSPau Amma.Tn ARMv8
2375faf9f4dSPau Amma.It Li PMC_CLASS_PPC970
2385faf9f4dSPau Amma.Tn IBM
2395faf9f4dSPau Amma.Tn PowerPC
2405faf9f4dSPau Amma970 class.
2415faf9f4dSPau Amma.It Li PMC_CLASS_POWER8
2425faf9f4dSPau Amma.Tn IBM
2435faf9f4dSPau Amma.Tn POWER8
2445faf9f4dSPau Ammaclass.
245f5f9340bSFabien Thomas.It Li PMC_CLASS_SOFT
246f5f9340bSFabien ThomasSoftware events.
247c89d1cf5SJoseph Koshy.El
248c89d1cf5SJoseph Koshy.Ss PMC Capabilities
249c89d1cf5SJoseph KoshyCapabilities of performance monitoring hardware are denoted using
250c89d1cf5SJoseph Koshythe
251c89d1cf5SJoseph Koshy.Vt "enum pmc_caps"
252c89d1cf5SJoseph Koshyenumeration.
253c89d1cf5SJoseph KoshySupported capabilities include:
2549ee2158bSJoel Dahl.Pp
25580f30b73SJoseph Koshy.Bl -tag -width "Li PMC_CAP_INTERRUPT" -compact
25680f30b73SJoseph Koshy.It Li PMC_CAP_CASCADE
25780f30b73SJoseph KoshyThe ability to cascade counters.
258b6e28991SAleksandr Rybalko.It Li PMC_CAP_DOMWIDE
259b6e28991SAleksandr RybalkoSeparate counters tied to each NUMA domain.
26080f30b73SJoseph Koshy.It Li PMC_CAP_EDGE
261c89d1cf5SJoseph KoshyThe ability to count negated to asserted transitions of the hardware
262c89d1cf5SJoseph Koshyconditions being probed for.
26380f30b73SJoseph Koshy.It Li PMC_CAP_INTERRUPT
264c89d1cf5SJoseph KoshyThe ability to interrupt the CPU.
26580f30b73SJoseph Koshy.It Li PMC_CAP_INVERT
266c89d1cf5SJoseph KoshyThe ability to invert the sense of the hardware conditions being
267c89d1cf5SJoseph Koshymeasured.
268624f6965SJoseph Koshy.It Li PMC_CAP_PRECISE
269624f6965SJoseph KoshyThe ability to perform precise sampling.
27080f30b73SJoseph Koshy.It Li PMC_CAP_QUALIFIER
271c89d1cf5SJoseph KoshyThe hardware allows monitored to be further qualified in some
272c89d1cf5SJoseph Koshysystem dependent way.
273624f6965SJoseph Koshy.It Li PMC_CAP_READ
274624f6965SJoseph KoshyThe ability to read from performance counters.
27580f30b73SJoseph Koshy.It Li PMC_CAP_SYSTEM
276c89d1cf5SJoseph KoshyThe ability to restrict counting of hardware events to when the CPU is
277c89d1cf5SJoseph Koshyrunning privileged code.
278b6e28991SAleksandr Rybalko.It Li PMC_CAP_SYSWIDE
279b6e28991SAleksandr RybalkoA single counter aggregating events for the whole system.
28080f30b73SJoseph Koshy.It Li PMC_CAP_THRESHOLD
281c89d1cf5SJoseph KoshyThe ability to ignore simultaneous hardware events below a
282c89d1cf5SJoseph Koshyprogrammable threshold.
28380f30b73SJoseph Koshy.It Li PMC_CAP_USER
284c89d1cf5SJoseph KoshyThe ability to restrict counting of hardware events to those when the
285c89d1cf5SJoseph KoshyCPU is running unprivileged code.
28680f30b73SJoseph Koshy.It Li PMC_CAP_WRITE
2870f3866faSJoseph KoshyThe ability to write to performance counters.
288c89d1cf5SJoseph Koshy.El
2896455febbSJoseph Koshy.Ss CPU Naming Conventions
290dd1259daSJoseph KoshyCPUs are named using small integers from zero up to, but
2916455febbSJoseph Koshyexcluding, the value returned by function
2926455febbSJoseph Koshy.Fn pmc_ncpu .
2936455febbSJoseph KoshyOn platforms supporting sparsely numbered CPUs not all the numbers in
2946455febbSJoseph Koshythis range will denote valid CPUs.
2956455febbSJoseph KoshyOperations on non-existent CPUs will return an error.
2966455febbSJoseph Koshy.Ss Functional Grouping of the API
297c89d1cf5SJoseph KoshyThis section contains a brief overview of the available functionality
298c89d1cf5SJoseph Koshyin the PMC library.
299c89d1cf5SJoseph KoshyEach function listed here is described further in its own manual page.
3009ee2158bSJoel Dahl.Bl -tag -width 2n
301c89d1cf5SJoseph Koshy.It Administration
3029ee2158bSJoel Dahl.Bl -tag -width 6n -compact
303c89d1cf5SJoseph Koshy.It Fn pmc_disable , Fn pmc_enable
304c89d1cf5SJoseph KoshyAdministratively disable (enable) specific performance monitoring
305c89d1cf5SJoseph Koshycounter hardware.
306c89d1cf5SJoseph KoshyCounters that are disabled will not be available to applications to
307c89d1cf5SJoseph Koshyuse.
308c89d1cf5SJoseph Koshy.El
309c89d1cf5SJoseph Koshy.It "Convenience Functions"
3109ee2158bSJoel Dahl.Bl -tag -width 6n -compact
311c89d1cf5SJoseph Koshy.It Fn pmc_event_names_of_class
312c89d1cf5SJoseph KoshyReturns a list of event names supported by a given PMC type.
313c89d1cf5SJoseph Koshy.It Fn pmc_name_of_capability
314c89d1cf5SJoseph KoshyConvert a
315c89d1cf5SJoseph Koshy.Dv PMC_CAP_*
316c89d1cf5SJoseph Koshyflag to a human-readable string.
317c89d1cf5SJoseph Koshy.It Fn pmc_name_of_class
318c89d1cf5SJoseph KoshyConvert a
319c89d1cf5SJoseph Koshy.Dv PMC_CLASS_*
320c89d1cf5SJoseph Koshyconstant to a human-readable string.
321c89d1cf5SJoseph Koshy.It Fn pmc_name_of_cputype
322c89d1cf5SJoseph KoshyReturn a human-readable name for a CPU type.
323c89d1cf5SJoseph Koshy.It Fn pmc_name_of_disposition
324c89d1cf5SJoseph KoshyReturn a human-readable string describing a PMC's disposition.
325c89d1cf5SJoseph Koshy.It Fn pmc_name_of_event
326c89d1cf5SJoseph KoshyConvert a numeric event code to a human-readable string.
327c89d1cf5SJoseph Koshy.It Fn pmc_name_of_mode
328c89d1cf5SJoseph KoshyConvert a
329c89d1cf5SJoseph Koshy.Dv PMC_MODE_*
330c89d1cf5SJoseph Koshyconstant to a human-readable name.
331c89d1cf5SJoseph Koshy.It Fn pmc_name_of_state
332c89d1cf5SJoseph KoshyReturn a human-readable string describing a PMC's current state.
333c89d1cf5SJoseph Koshy.El
334c89d1cf5SJoseph Koshy.It "Library Initialization"
3359ee2158bSJoel Dahl.Bl -tag -width 6n -compact
336c89d1cf5SJoseph Koshy.It Fn pmc_init
337c89d1cf5SJoseph KoshyInitialize the library.
338c89d1cf5SJoseph KoshyThis function must be called before any other library function.
339c89d1cf5SJoseph Koshy.El
340c89d1cf5SJoseph Koshy.It "Log File Handling"
3419ee2158bSJoel Dahl.Bl -tag -width 6n -compact
342c89d1cf5SJoseph Koshy.It Fn pmc_configure_logfile
343c89d1cf5SJoseph KoshyConfigure a log file for
344c89d1cf5SJoseph Koshy.Xr hwpmc 4
345c89d1cf5SJoseph Koshyto write logged events to.
346c89d1cf5SJoseph Koshy.It Fn pmc_flush_logfile
347c89d1cf5SJoseph KoshyFlush all pending log data in
348c89d1cf5SJoseph Koshy.Xr hwpmc 4 Ns Ap s
349c89d1cf5SJoseph Koshybuffers.
350dceed24aSFabien Thomas.It Fn pmc_close_logfile
351dceed24aSFabien ThomasFlush all pending log data and close
352dceed24aSFabien Thomas.Xr hwpmc 4 Ns Ap s
353dceed24aSFabien Thomasside of the stream.
354c89d1cf5SJoseph Koshy.It Fn pmc_writelog
355c89d1cf5SJoseph KoshyAppend arbitrary user data to the current log file.
356c89d1cf5SJoseph Koshy.El
357c89d1cf5SJoseph Koshy.It "PMC Management"
3589ee2158bSJoel Dahl.Bl -tag -width 6n -compact
359c89d1cf5SJoseph Koshy.It Fn pmc_allocate , Fn pmc_release
360c89d1cf5SJoseph KoshyAllocate (free) a PMC.
361c89d1cf5SJoseph Koshy.It Fn pmc_attach , Fn pmc_detach
362c89d1cf5SJoseph KoshyAttach (detach) a process scope PMC to a target.
363c89d1cf5SJoseph Koshy.It Fn pmc_read , Fn pmc_write , Fn pmc_rw
364c89d1cf5SJoseph KoshyRead (write) a value from (to) a PMC.
365c89d1cf5SJoseph Koshy.It Fn pmc_start , Fn pmc_stop
366c89d1cf5SJoseph KoshyStart (stop) a software PMC.
367c89d1cf5SJoseph Koshy.It Fn pmc_set
368c89d1cf5SJoseph KoshySet the reload value for a sampling PMC.
369c89d1cf5SJoseph Koshy.El
370c89d1cf5SJoseph Koshy.It "Queries"
3719ee2158bSJoel Dahl.Bl -tag -width 6n -compact
372c89d1cf5SJoseph Koshy.It Fn pmc_capabilities
373c89d1cf5SJoseph KoshyRetrieve the capabilities for a given PMC.
374c89d1cf5SJoseph Koshy.It Fn pmc_cpuinfo
375c89d1cf5SJoseph KoshyRetrieve information about the CPUs and PMC hardware present in the
376c89d1cf5SJoseph Koshysystem.
377c89d1cf5SJoseph Koshy.It Fn pmc_get_driver_stats
378c89d1cf5SJoseph KoshyRetrieve statistics maintained by
379c89d1cf5SJoseph Koshy.Xr hwpmc 4 .
380c89d1cf5SJoseph Koshy.It Fn pmc_ncpu
3816455febbSJoseph KoshyDetermine the greatest possible CPU number on the system.
382c89d1cf5SJoseph Koshy.It Fn pmc_npmc
383c89d1cf5SJoseph KoshyReturn the number of hardware PMCs present in a given CPU.
384c89d1cf5SJoseph Koshy.It Fn pmc_pmcinfo
385c89d1cf5SJoseph KoshyReturn information about the state of a given CPU's PMCs.
386c89d1cf5SJoseph Koshy.It Fn pmc_width
387c89d1cf5SJoseph KoshyDetermine the width of a hardware counter in bits.
388c89d1cf5SJoseph Koshy.El
389c89d1cf5SJoseph Koshy.It "x86 Architecture Specific API"
3909ee2158bSJoel Dahl.Bl -tag -width 6n -compact
391c89d1cf5SJoseph Koshy.It Fn pmc_get_msr
392c89d1cf5SJoseph KoshyReturns the processor model specific register number
393c89d1cf5SJoseph Koshyassociated with
394c5153e19SJoseph Koshy.Fa pmc .
395c89d1cf5SJoseph KoshyApplications may then use the x86
396c89d1cf5SJoseph Koshy.Ic RDPMC
397c89d1cf5SJoseph Koshyinstruction to directly read the contents of the PMC.
398c89d1cf5SJoseph Koshy.El
399c89d1cf5SJoseph Koshy.El
4009abe909bSRuslan Ermilov.Ss Signal Handling Requirements
401ebccf1e3SJoseph KoshyApplications using PMCs are required to handle the following signals:
402c89d1cf5SJoseph Koshy.Bl -tag -width ".Dv SIGBUS"
4039abe909bSRuslan Ermilov.It Dv SIGBUS
404ebccf1e3SJoseph KoshyWhen the
405ebccf1e3SJoseph Koshy.Xr hwpmc 4
406ebccf1e3SJoseph Koshymodule is unloaded using
407ebccf1e3SJoseph Koshy.Xr kldunload 8 ,
408ebccf1e3SJoseph Koshyprocesses that have PMCs allocated to them will be sent a
4099abe909bSRuslan Ermilov.Dv SIGBUS
4109abe909bSRuslan Ermilovsignal.
4119abe909bSRuslan Ermilov.It Dv SIGIO
412f263522aSJoseph KoshyThe
413f263522aSJoseph Koshy.Xr hwpmc 4
4149abe909bSRuslan Ermilovdriver will send a PMC owning process a
4159abe909bSRuslan Ermilov.Dv SIGIO
4169abe909bSRuslan Ermilovsignal if:
417f263522aSJoseph Koshy.Bl -bullet
418f263522aSJoseph Koshy.It
4195faf9f4dSPau Ammaany process-mode PMC allocated by it loses all its
420f263522aSJoseph Koshytarget processes.
421f263522aSJoseph Koshy.It
4225faf9f4dSPau Ammathe driver encounters an error when writing log data to a
423f263522aSJoseph Koshyconfigured log file.
424f263522aSJoseph KoshyThis error may be retrieved by a subsequent call to
425f263522aSJoseph Koshy.Fn pmc_flush_logfile .
426f263522aSJoseph Koshy.El
427ebccf1e3SJoseph Koshy.El
428c89d1cf5SJoseph Koshy.Ss Typical Program Flow
429c89d1cf5SJoseph Koshy.Bl -enum
430c89d1cf5SJoseph Koshy.It
431c89d1cf5SJoseph KoshyAn application would first invoke function
432c89d1cf5SJoseph Koshy.Fn pmc_init
433c89d1cf5SJoseph Koshyto allow the library to initialize itself.
434c89d1cf5SJoseph Koshy.It
435c89d1cf5SJoseph KoshySignal handling would then be set up.
436c89d1cf5SJoseph Koshy.It
437c89d1cf5SJoseph KoshyNext the application would allocate the PMCs it desires using function
438c89d1cf5SJoseph Koshy.Fn pmc_allocate .
439c89d1cf5SJoseph Koshy.It
440c89d1cf5SJoseph KoshyInitial values for PMCs may be set using function
441c89d1cf5SJoseph Koshy.Fn pmc_set .
442c89d1cf5SJoseph Koshy.It
443c89d1cf5SJoseph KoshyIf a log file is necessary for the PMCs to work, it would
444c89d1cf5SJoseph Koshybe configured using function
445c89d1cf5SJoseph Koshy.Fn pmc_configure_logfile .
446c89d1cf5SJoseph Koshy.It
447c89d1cf5SJoseph KoshyProcess scope PMCs would then be attached to their target processes
448c89d1cf5SJoseph Koshyusing function
449c89d1cf5SJoseph Koshy.Fn pmc_attach .
450c89d1cf5SJoseph Koshy.It
451c89d1cf5SJoseph KoshyThe PMCs would then be started using function
452c89d1cf5SJoseph Koshy.Fn pmc_start .
453c89d1cf5SJoseph Koshy.It
454c89d1cf5SJoseph KoshyOnce started, the values of counting PMCs may be read using function
455b53a052dSJoseph Koshy.Fn pmc_read .
456c89d1cf5SJoseph KoshyFor PMCs that write events to the log file, this logged data would be
457c89d1cf5SJoseph Koshyread and parsed using the
458c89d1cf5SJoseph Koshy.Xr pmclog 3
459c89d1cf5SJoseph Koshyfamily of functions.
460c89d1cf5SJoseph Koshy.It
461c89d1cf5SJoseph KoshyPMCs are stopped using function
462c89d1cf5SJoseph Koshy.Fn pmc_stop ,
463c89d1cf5SJoseph Koshyand process scope PMCs are detached from their targets using
464c89d1cf5SJoseph Koshyfunction
465c89d1cf5SJoseph Koshy.Fn pmc_detach .
466c89d1cf5SJoseph Koshy.It
4675faf9f4dSPau AmmaBefore the process exits, it may release its PMCs using function
468c89d1cf5SJoseph Koshy.Fn pmc_release .
469c89d1cf5SJoseph KoshyAny configured log file may be closed using function
470c89d1cf5SJoseph Koshy.Fn pmc_configure_logfile .
471c89d1cf5SJoseph Koshy.El
472ebccf1e3SJoseph Koshy.Sh EVENT SPECIFIERS
473ebccf1e3SJoseph KoshyEvent specifiers are strings comprising of an event name, followed by
474ebccf1e3SJoseph Koshyoptional parameters modifying the semantics of the hardware event
475ebccf1e3SJoseph Koshybeing probed.
4760b844226SJoseph KoshyEvent names are PMC architecture dependent, but the PMC library defines
4770b844226SJoseph Koshymachine independent aliases for commonly used events.
4780f7668cbSJoseph Koshy.Pp
4790f7668cbSJoseph KoshyEvent specifiers spellings are case-insensitive and space characters,
4800f7668cbSJoseph Koshyperiods, underscores and hyphens are considered equivalent to each other.
4810f7668cbSJoseph KoshyThus the event specifiers
4820f7668cbSJoseph Koshy.Qq "Example Event" ,
4830f7668cbSJoseph Koshy.Qq "example-event" ,
4840f7668cbSJoseph Koshyand
4850f7668cbSJoseph Koshy.Qq "EXAMPLE_EVENT"
4860f7668cbSJoseph Koshyare equivalent.
4870f7668cbSJoseph Koshy.Ss PMC Architecture Dependent Events
4880f7668cbSJoseph KoshyPMC architecture dependent event specifiers are described in the
4890f7668cbSJoseph Koshyfollowing manual pages:
4900f7668cbSJoseph Koshy.Bl -column " PMC_CLASS_TSC " "MANUAL PAGE "
4910f7668cbSJoseph Koshy.It Em "PMC Class"      Ta Em "Manual Page"
4920f7668cbSJoseph Koshy.It Li PMC_CLASS_IAF    Ta Xr pmc.iaf 3
4930f7668cbSJoseph Koshy.It Li PMC_CLASS_IAP    Ta Xr pmc.atom 3 , Xr pmc.core 3 , Xr pmc.core2 3
494*b2934971SMitchell Horne.It Li PMC_CLASS_K8     Ta Xr pmc.amd 3
4950f7668cbSJoseph Koshy.It Li PMC_CLASS_TSC    Ta Xr pmc.tsc 3
4960f7668cbSJoseph Koshy.El
497ebccf1e3SJoseph Koshy.Ss Event Name Aliases
49824f2c3f3SJoseph KoshyEvent name aliases are PMC-independent names for commonly used events.
499ebccf1e3SJoseph KoshyThe following aliases are known to this version of the
500110e1704SRuslan Ermilov.Nm pmc
501ebccf1e3SJoseph Koshylibrary:
502ebccf1e3SJoseph Koshy.Bl -tag -width indent
503ebccf1e3SJoseph Koshy.It Li branches
504ebccf1e3SJoseph KoshyMeasure the number of branches retired.
505ebccf1e3SJoseph Koshy.It Li branch-mispredicts
506ebccf1e3SJoseph KoshyMeasure the number of retired branches that were mispredicted.
507ebccf1e3SJoseph Koshy.It Li cycles
508ebccf1e3SJoseph KoshyMeasure processor cycles.
509ebccf1e3SJoseph KoshyThis event is implemented using the processor's Time Stamp Counter
510ebccf1e3SJoseph Koshyregister.
511ebccf1e3SJoseph Koshy.It Li dc-misses
512ebccf1e3SJoseph KoshyMeasure the number of data cache misses.
513ebccf1e3SJoseph Koshy.It Li ic-misses
514ebccf1e3SJoseph KoshyMeasure the number of instruction cache misses.
515ebccf1e3SJoseph Koshy.It Li instructions
516ebccf1e3SJoseph KoshyMeasure the number of instructions retired.
517ebccf1e3SJoseph Koshy.It Li interrupts
518ebccf1e3SJoseph KoshyMeasure the number of interrupts seen.
519177a2f22SJoseph Koshy.It Li unhalted-cycles
520177a2f22SJoseph KoshyMeasure the number of cycles the processor is not in a halted
521177a2f22SJoseph Koshyor sleep state.
522ebccf1e3SJoseph Koshy.El
5235138c36aSJoseph Koshy.Sh COMPATIBILITY
5245138c36aSJoseph KoshyThe interface between the
525110e1704SRuslan Ermilov.Nm pmc
5265138c36aSJoseph Koshylibrary and the
5275138c36aSJoseph Koshy.Xr hwpmc 4
5285138c36aSJoseph Koshydriver is intended to be private to the implementation and may
5295138c36aSJoseph Koshychange.
5305138c36aSJoseph KoshyIn order to ease forward compatibility with future versions of the
5315138c36aSJoseph Koshy.Xr hwpmc 4
5325138c36aSJoseph Koshydriver, applications are urged to dynamically link with the
533110e1704SRuslan Ermilov.Nm pmc
5345138c36aSJoseph Koshylibrary.
5353977781bSMitchell HorneDoing otherwise is unsupported.
536ebccf1e3SJoseph Koshy.Sh SEE ALSO
537*b2934971SMitchell Horne.Xr pmc.amd 3 ,
53872cf78b8SJoseph Koshy.Xr pmc.atom 3 ,
53972cf78b8SJoseph Koshy.Xr pmc.core 3 ,
54072cf78b8SJoseph Koshy.Xr pmc.core2 3 ,
54156e39702SGeorge V. Neville-Neil.Xr pmc.haswell 3 ,
54256e39702SGeorge V. Neville-Neil.Xr pmc.haswelluc 3 ,
543f1ec0939SRyan Stone.Xr pmc.haswellxeon 3 ,
54472cf78b8SJoseph Koshy.Xr pmc.iaf 3 ,
54556e39702SGeorge V. Neville-Neil.Xr pmc.ivybridge 3 ,
54656e39702SGeorge V. Neville-Neil.Xr pmc.ivybridgexeon 3 ,
54756e39702SGeorge V. Neville-Neil.Xr pmc.sandybridge 3 ,
54856e39702SGeorge V. Neville-Neil.Xr pmc.sandybridgeuc 3 ,
54956e39702SGeorge V. Neville-Neil.Xr pmc.sandybridgexeon 3 ,
550f5f9340bSFabien Thomas.Xr pmc.soft 3 ,
55124f2c3f3SJoseph Koshy.Xr pmc.tsc 3 ,
55256e39702SGeorge V. Neville-Neil.Xr pmc.westmere 3 ,
55356e39702SGeorge V. Neville-Neil.Xr pmc.westmereuc 3 ,
5547a40330bSEnji Cooper.Xr pmc_allocate 3 ,
5557a40330bSEnji Cooper.Xr pmc_attach 3 ,
5567a40330bSEnji Cooper.Xr pmc_capabilities 3 ,
5577a40330bSEnji Cooper.Xr pmc_configure_logfile 3 ,
5587a40330bSEnji Cooper.Xr pmc_disable 3 ,
5597a40330bSEnji Cooper.Xr pmc_event_names_of_class 3 ,
5607a40330bSEnji Cooper.Xr pmc_get_driver_stats 3 ,
5617a40330bSEnji Cooper.Xr pmc_get_msr 3 ,
5627a40330bSEnji Cooper.Xr pmc_init 3 ,
5637a40330bSEnji Cooper.Xr pmc_name_of_capability 3 ,
5647a40330bSEnji Cooper.Xr pmc_read 3 ,
5657a40330bSEnji Cooper.Xr pmc_set 3 ,
5667a40330bSEnji Cooper.Xr pmc_start 3 ,
567f263522aSJoseph Koshy.Xr pmclog 3 ,
568ebccf1e3SJoseph Koshy.Xr hwpmc 4 ,
569ebccf1e3SJoseph Koshy.Xr pmccontrol 8 ,
570ebccf1e3SJoseph Koshy.Xr pmcstat 8
5715138c36aSJoseph Koshy.Sh HISTORY
5725138c36aSJoseph KoshyThe
573110e1704SRuslan Ermilov.Nm pmc
5745138c36aSJoseph Koshylibrary first appeared in
5755138c36aSJoseph Koshy.Fx 6.0 .
576c89d1cf5SJoseph Koshy.Sh AUTHORS
577c89d1cf5SJoseph KoshyThe
578c89d1cf5SJoseph Koshy.Lb libpmc
579c89d1cf5SJoseph Koshylibrary was written by
5802b7af31cSBaptiste Daroussin.An Joseph Koshy Aq Mt jkoshy@FreeBSD.org .
581