xref: /freebsd/share/man/man4/hwpmc.4 (revision 0afc94c17a8772df34294778904e816258542498)
16455febbSJoseph Koshy.\" Copyright (c) 2003-2008 Joseph Koshy
2a07d350cSJoseph Koshy.\" Copyright (c) 2007 The FreeBSD Foundation
3ebccf1e3SJoseph Koshy.\" All rights reserved.
4ebccf1e3SJoseph Koshy.\"
5a07d350cSJoseph Koshy.\" Portions of this software were developed by A. Joseph Koshy under
6a07d350cSJoseph Koshy.\" sponsorship from the FreeBSD Foundation and Google, Inc.
7a07d350cSJoseph Koshy.\"
8ebccf1e3SJoseph Koshy.\" Redistribution and use in source and binary forms, with or without
9ebccf1e3SJoseph Koshy.\" modification, are permitted provided that the following conditions
10ebccf1e3SJoseph Koshy.\" are met:
11ebccf1e3SJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright
12ebccf1e3SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer.
13ebccf1e3SJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright
14ebccf1e3SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer in the
15ebccf1e3SJoseph Koshy.\"    documentation and/or other materials provided with the distribution.
16ebccf1e3SJoseph Koshy.\"
17ebccf1e3SJoseph Koshy.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18ebccf1e3SJoseph Koshy.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19ebccf1e3SJoseph Koshy.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20ebccf1e3SJoseph Koshy.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21ebccf1e3SJoseph Koshy.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22ebccf1e3SJoseph Koshy.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23ebccf1e3SJoseph Koshy.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24ebccf1e3SJoseph Koshy.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25ebccf1e3SJoseph Koshy.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26ebccf1e3SJoseph Koshy.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27ebccf1e3SJoseph Koshy.\" SUCH DAMAGE.
28ebccf1e3SJoseph Koshy.\"
29ebccf1e3SJoseph Koshy.\" $FreeBSD$
30ebccf1e3SJoseph Koshy.\"
316455febbSJoseph Koshy.Dd September 22, 2008
32ebccf1e3SJoseph Koshy.Dt HWPMC 4
33ebccf1e3SJoseph Koshy.Os
34ebccf1e3SJoseph Koshy.Sh NAME
35ebccf1e3SJoseph Koshy.Nm hwpmc
36d9a5f346SJoseph Koshy.Nd "Hardware Performance Monitoring Counter support"
37ebccf1e3SJoseph Koshy.Sh SYNOPSIS
38d9a5f346SJoseph Koshy.Cd "options HWPMC_HOOKS"
39d9a5f346SJoseph Koshy.Cd "device hwpmc"
4079247772SJoseph Koshy.Pp
4179247772SJoseph KoshyAdditionally, for i386 systems:
4278ad5421SRuslan Ermilov.Cd "device apic"
43ebccf1e3SJoseph Koshy.Sh DESCRIPTION
44ebccf1e3SJoseph KoshyThe
45ebccf1e3SJoseph Koshy.Nm
46ebccf1e3SJoseph Koshydriver virtualizes the hardware performance monitoring facilities in
47ebccf1e3SJoseph Koshymodern CPUs and provides support for using these facilities from
48ebccf1e3SJoseph Koshyuser level processes.
49ebccf1e3SJoseph Koshy.Pp
50ebccf1e3SJoseph KoshyThe driver supports multi-processor systems.
51ebccf1e3SJoseph Koshy.Pp
52ebccf1e3SJoseph KoshyPMCs are allocated using the
53d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
54ebccf1e3SJoseph Koshyrequest.
55ebccf1e3SJoseph KoshyA successful
56d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
571a94fde8SJoseph Koshyrequest will return a handle to the requesting process.
58ebccf1e3SJoseph KoshySubsequent operations on the allocated PMC use this handle to denote
59ebccf1e3SJoseph Koshythe specific PMC.
60ebccf1e3SJoseph KoshyA process that has successfully allocated a PMC is termed an
61ebccf1e3SJoseph Koshy.Dq "owner process" .
62ebccf1e3SJoseph Koshy.Pp
631a94fde8SJoseph KoshyPMCs may be allocated with process or system scope.
641a94fde8SJoseph Koshy.Bl -tag -width ".Em Process-scope"
651a94fde8SJoseph Koshy.It Em "Process-scope"
661a94fde8SJoseph KoshyThe PMC is active only when a thread belonging
67ebccf1e3SJoseph Koshyto a process it is attached to is scheduled on a CPU.
681a94fde8SJoseph Koshy.It Em "System-scope"
691a94fde8SJoseph KoshyThe PMC operates independently of processes and
70ebccf1e3SJoseph Koshymeasures hardware events for the system as a whole.
71ebccf1e3SJoseph Koshy.El
72ebccf1e3SJoseph Koshy.Pp
731a94fde8SJoseph KoshyPMCs may be allocated for counting or for sampling:
74d9a5f346SJoseph Koshy.Bl -tag -width ".Em Counting"
756d6a103aSJoseph Koshy.It Em Counting
76ebccf1e3SJoseph KoshyIn counting modes, the PMCs count hardware events.
77ebccf1e3SJoseph KoshyThese counts are retrievable using the
78d9a5f346SJoseph Koshy.Dv PMC_OP_PMCREAD
794f00efe0SJoseph Koshysystem call on all architectures.
804f00efe0SJoseph KoshySome architectures offer faster methods of reading these counts.
81ebccf1e3SJoseph Koshy.It Em Sampling
824f00efe0SJoseph KoshyIn sampling modes, the PMCs are configured to sample the CPU
83a07d350cSJoseph Koshyinstruction pointer (and optionally to capture the call chain leading
84a07d350cSJoseph Koshyupto the sampled instruction pointer) after a configurable number of
85a07d350cSJoseph Koshyhardware events have been observed.
86a07d350cSJoseph KoshyInstruction pointer samples and call chain records are usually
87a07d350cSJoseph Koshydirected to a log file for subsequent analysis.
88ebccf1e3SJoseph Koshy.El
89ebccf1e3SJoseph Koshy.Pp
901a94fde8SJoseph KoshyScope and operational mode are orthogonal; a PMC may thus be
911a94fde8SJoseph Koshyconfigured to operate in one of the following four modes:
92ebccf1e3SJoseph Koshy.Bl -tag -width indent
931a94fde8SJoseph Koshy.It Process-scope, counting
94ebccf1e3SJoseph KoshyThese PMCs count hardware events whenever a thread in their attached process is
95ebccf1e3SJoseph Koshyscheduled on a CPU.
96ebccf1e3SJoseph KoshyThese PMCs normally count from zero, but the initial count may be
97ebccf1e3SJoseph Koshyset using the
98d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT
99ebccf1e3SJoseph Koshyoperation.
100ebccf1e3SJoseph KoshyApplications can read the value of the PMC anytime using the
101d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
102ebccf1e3SJoseph Koshyoperation.
1031a94fde8SJoseph Koshy.It Process-scope, sampling
104ebccf1e3SJoseph KoshyThese PMCs sample the target processes instruction pointer after they
105ebccf1e3SJoseph Koshyhave seen the configured number of hardware events.
106ebccf1e3SJoseph KoshyThe PMCs only count events when a thread belonging to their attached
107ebccf1e3SJoseph Koshyprocess is active.
108ebccf1e3SJoseph KoshyThe desired frequency of sampling is set using the
109d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT
110ebccf1e3SJoseph Koshyoperation prior to starting the PMC.
111ebccf1e3SJoseph KoshyLog files are configured using the
112d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG
113ebccf1e3SJoseph Koshyoperation.
1141a94fde8SJoseph Koshy.It System-scope, counting
115ebccf1e3SJoseph KoshyThese PMCs count hardware events seen by them independent of the
116ebccf1e3SJoseph Koshyprocesses that are executing.
117ebccf1e3SJoseph KoshyThe current count on these PMCs can be read using the
118d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
119ebccf1e3SJoseph Koshyrequest.
120ebccf1e3SJoseph KoshyThese PMCs normally count from zero, but the initial count may be
121ebccf1e3SJoseph Koshyset using the
122d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT
123ebccf1e3SJoseph Koshyoperation.
1241a94fde8SJoseph Koshy.It System-scope, sampling
125ebccf1e3SJoseph KoshyThese PMCs will periodically sample the instruction pointer of the CPU
126ebccf1e3SJoseph Koshythey are allocated on, and will write the sample to a log for further
127ebccf1e3SJoseph Koshyprocessing.
128ebccf1e3SJoseph KoshyThe desired frequency of sampling is set using the
129d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT
130ebccf1e3SJoseph Koshyoperation prior to starting the PMC.
131ebccf1e3SJoseph KoshyLog files are configured using the
132d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG
133ebccf1e3SJoseph Koshyoperation.
134ebccf1e3SJoseph Koshy.Pp
135ebccf1e3SJoseph KoshySystem-wide statistical sampling can only be enabled by a process with
136ebccf1e3SJoseph Koshysuper-user privileges.
137ebccf1e3SJoseph Koshy.El
138ebccf1e3SJoseph Koshy.Pp
1394f00efe0SJoseph KoshyProcesses are allowed to allocate as many PMCs as the hardware and
140ebccf1e3SJoseph Koshycurrent operating conditions permit.
141ebccf1e3SJoseph KoshyProcesses may mix allocations of system-wide and process-private
142ebccf1e3SJoseph KoshyPMCs.
14344caa872SJoseph KoshyMultiple processes may be using PMCs simultaneously.
144ebccf1e3SJoseph Koshy.Pp
145ebccf1e3SJoseph KoshyAllocated PMCs are started using the
146d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART
147ebccf1e3SJoseph Koshyoperation, and stopped using the
148d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTOP
149ebccf1e3SJoseph Koshyoperation.
150ebccf1e3SJoseph KoshyStopping and starting a PMC is permitted at any time the owner process
151ebccf1e3SJoseph Koshyhas a valid handle to the PMC.
152ebccf1e3SJoseph Koshy.Pp
153ebccf1e3SJoseph KoshyProcess-private PMCs need to be attached to a target process before
154ebccf1e3SJoseph Koshythey can be used.
155ebccf1e3SJoseph KoshyAttaching a process to a PMC is done using the
156d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
157ebccf1e3SJoseph Koshyoperation.
158ebccf1e3SJoseph KoshyAn already attached PMC may be detached from its target process
159ebccf1e3SJoseph Koshyusing the converse
160d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH
161ebccf1e3SJoseph Koshyoperation.
162d9a5f346SJoseph KoshyIssuing a
163d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART
164ebccf1e3SJoseph Koshyoperation on an as yet unattached PMC will cause it to be attached
165ebccf1e3SJoseph Koshyto its owner process.
166ebccf1e3SJoseph KoshyThe following rules determine whether a given process may attach
167ebccf1e3SJoseph Koshya PMC to another target process:
168ebccf1e3SJoseph Koshy.Bl -bullet -compact
169ebccf1e3SJoseph Koshy.It
170ebccf1e3SJoseph KoshyA non-jailed process with super-user privileges is allowed to attach
171ebccf1e3SJoseph Koshyto any other process in the system.
172ebccf1e3SJoseph Koshy.It
173ebccf1e3SJoseph KoshyOther processes are only allowed to attach to targets that they would
174ebccf1e3SJoseph Koshybe able to attach to for debugging (as determined by
175ebccf1e3SJoseph Koshy.Xr p_candebug 9 ) .
176ebccf1e3SJoseph Koshy.El
177ebccf1e3SJoseph Koshy.Pp
178ebccf1e3SJoseph KoshyPMCs are released using
179d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRELEASE .
180ebccf1e3SJoseph KoshyAfter a successful
181d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRELEASE
182ebccf1e3SJoseph Koshyoperation the handle to the PMC will become invalid.
183d9a5f346SJoseph Koshy.Ss Modifier Flags
184ebccf1e3SJoseph KoshyThe
185d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
186ebccf1e3SJoseph Koshyoperation supports the following flags that modify the behavior
187ebccf1e3SJoseph Koshyof an allocated PMC:
188d9a5f346SJoseph Koshy.Bl -tag -width indent
189a07d350cSJoseph Koshy.It Dv PMC_F_CALLCHAIN
190a07d350cSJoseph KoshyThis modifier informs sampling PMCs to record a callchain when
191a07d350cSJoseph Koshycapturing a sample.
192a07d350cSJoseph KoshyThe maximum depth to which call chains are recorded is specified
193a07d350cSJoseph Koshyby the
194a07d350cSJoseph Koshy.Va "kern.hwpmc.callchaindepth"
195a07d350cSJoseph Koshykernel tunable.
196ebccf1e3SJoseph Koshy.It Dv PMC_F_DESCENDANTS
197f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private
198ebccf1e3SJoseph Koshymode.
199ebccf1e3SJoseph KoshyIt signifies that the PMC will track hardware events for its
200ebccf1e3SJoseph Koshytarget process and the target's current and future descendants.
201f263522aSJoseph Koshy.It Dv PMC_F_KGMON
202f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in system-wide
203f263522aSJoseph Koshysampling mode.
204f263522aSJoseph KoshyIt signifies that the PMC's sampling interrupt is to be used to drive
205f263522aSJoseph Koshykernel profiling via
206f263522aSJoseph Koshy.Xr kgmon 8 .
207e805d32bSJoseph KoshyThis functionality is currently unimplemented.
208f263522aSJoseph Koshy.It Dv PMC_F_LOG_PROCCSW
209f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private
210f263522aSJoseph Koshymode.
2113bc6c674SJoseph KoshyWhen this modifier is present, at every context switch,
212f263522aSJoseph Koshy.Nm
2133bc6c674SJoseph Koshywill log a record containing the number of hardware events
2143bc6c674SJoseph Koshyseen by the target process when it was scheduled on the CPU.
215f263522aSJoseph Koshy.It Dv PMC_F_LOG_PROCEXIT
216f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private
217f263522aSJoseph Koshymode.
218f263522aSJoseph KoshyWith this modifier present,
219f263522aSJoseph Koshy.Nm
220f263522aSJoseph Koshywill maintain per-process counts for each target process attached to
221f263522aSJoseph Koshya PMC.
222d9a5f346SJoseph KoshyAt process exit time, a record containing the target process' PID and
223f263522aSJoseph Koshythe accumulated per-process count for that process will be written to the
224f263522aSJoseph Koshyconfigured log file.
225ebccf1e3SJoseph Koshy.El
226d9a5f346SJoseph Koshy.Pp
227f263522aSJoseph KoshyModifiers
228f263522aSJoseph Koshy.Dv PMC_F_LOG_PROCEXIT
229f263522aSJoseph Koshyand
230f263522aSJoseph Koshy.Dv PMC_F_LOG_PROCCSW
231f263522aSJoseph Koshymay be used in combination with modifier
232f263522aSJoseph Koshy.Dv PMC_F_DESCENDANTS
2334f00efe0SJoseph Koshyto track the behavior of complex pipelines of processes.
2343bc6c674SJoseph KoshyPMCs with modifiers
2353bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT
2363bc6c674SJoseph Koshyand
2373bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCCSW
2383bc6c674SJoseph Koshycannot be started until their owner process has configured a log file.
239d9a5f346SJoseph Koshy.Ss Signals
240ebccf1e3SJoseph KoshyThe
241ebccf1e3SJoseph Koshy.Nm
242ebccf1e3SJoseph Koshydriver may deliver signals to processes that have allocated PMCs:
243d9a5f346SJoseph Koshy.Bl -tag -width ".Dv SIGBUS"
244d9a5f346SJoseph Koshy.It Dv SIGIO
245ebccf1e3SJoseph KoshyA
246d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
247ebccf1e3SJoseph Koshyoperation was attempted on a process-private PMC that does not have
248ebccf1e3SJoseph Koshyattached target processes.
249d9a5f346SJoseph Koshy.It Dv SIGBUS
250ebccf1e3SJoseph KoshyThe
251ebccf1e3SJoseph Koshy.Nm
252ebccf1e3SJoseph Koshydriver is being unloaded from the kernel.
253ebccf1e3SJoseph Koshy.El
2541a94fde8SJoseph Koshy.Ss PMC ROW DISPOSITIONS
2551a94fde8SJoseph KoshyA PMC row is defined as the set of PMC resources at the same hardware
2561a94fde8SJoseph Koshyaddress in the CPUs in a system.
2571a94fde8SJoseph KoshySince process scope PMCs need to move between CPUs following their
2581a94fde8SJoseph Koshytarget threads, allocation of a process scope PMC reserves all PMCs in
2591a94fde8SJoseph Koshya PMC row for use only with process scope PMCs.
2601a94fde8SJoseph KoshyAccordingly a PMC row will be in one of the following dispositions:
2611a94fde8SJoseph Koshy.Bl -tag -width ".Dv PMC_DISP_STANDALONE" -compact
2621a94fde8SJoseph Koshy.It Dv PMC_DISP_FREE
2631a94fde8SJoseph KoshyHardware counters in this row are free and may be use to satisfy
2641a94fde8SJoseph Koshyeither of system scope or process scope allocation requests.
2651a94fde8SJoseph Koshy.It Dv PMC_DISP_THREAD
2661a94fde8SJoseph KoshyHardware counters in this row are in use by process scope PMCs
2671a94fde8SJoseph Koshyand are only available for process scope allocation requests.
2681a94fde8SJoseph Koshy.It Dv PMC_DISP_STANDALONE
2691a94fde8SJoseph KoshySome hardware counters in this row have been administratively
2701a94fde8SJoseph Koshydisabled or are in use by system scope PMCs.
2711a94fde8SJoseph KoshyNon-disabled hardware counters in such a row may be used
2721a94fde8SJoseph Koshyfor satisfying system scope allocation requests.
2731a94fde8SJoseph KoshyNo process scope PMCs will use hardware counters in this row.
2741a94fde8SJoseph Koshy.El
275ebccf1e3SJoseph Koshy.Sh PROGRAMMING API
276ebccf1e3SJoseph KoshyThe recommended way for application programs to use the facilities of
277ebccf1e3SJoseph Koshythe
278ebccf1e3SJoseph Koshy.Nm
279d9a5f346SJoseph Koshydriver is using the API provided by the
280d9a5f346SJoseph Koshy.Xr pmc 3
281d9a5f346SJoseph Koshylibrary.
282ebccf1e3SJoseph Koshy.Pp
283ebccf1e3SJoseph KoshyThe
284ebccf1e3SJoseph Koshy.Nm
285ebccf1e3SJoseph Koshydriver operates using a system call number that is dynamically
286ebccf1e3SJoseph Koshyallotted to it when it is loaded into the kernel.
287ebccf1e3SJoseph Koshy.Pp
288ebccf1e3SJoseph KoshyThe
289ebccf1e3SJoseph Koshy.Nm
290ebccf1e3SJoseph Koshydriver supports the following operations:
291ebccf1e3SJoseph Koshy.Bl -tag -width indent
292d9a5f346SJoseph Koshy.It Dv PMC_OP_CONFIGURELOG
293a5c506d2SJoseph KoshyConfigure a log file for PMCs that require a log file.
294a5c506d2SJoseph KoshyThe
295a5c506d2SJoseph Koshy.Nm
296a5c506d2SJoseph Koshydriver will write log data to this file asynchronously.
297a5c506d2SJoseph KoshyIf it encounters an error, logging will be stopped and the error code
298a5c506d2SJoseph Koshyencountered will be saved for subsequent retrieval by a
299a5c506d2SJoseph Koshy.Dv PMC_OP_FLUSHLOG
300a5c506d2SJoseph Koshyrequest.
301d9a5f346SJoseph Koshy.It Dv PMC_OP_FLUSHLOG
302f263522aSJoseph KoshyTransfer buffered log data inside
303f263522aSJoseph Koshy.Nm
304f263522aSJoseph Koshyto a configured output file.
305f263522aSJoseph KoshyThis operation returns to the caller after the write operation
306f263522aSJoseph Koshyhas returned.
307a5c506d2SJoseph KoshyThe returned error code reflects any pending error state inside
308a5c506d2SJoseph Koshy.Nm .
309d9a5f346SJoseph Koshy.It Dv PMC_OP_GETCPUINFO
3106455febbSJoseph KoshyRetrieve information about the highest possible CPU number for the system,
3116455febbSJoseph Koshyand the number of hardware performance monitoring counters available per CPU.
312d9a5f346SJoseph Koshy.It Dv PMC_OP_GETDRIVERSTATS
313ebccf1e3SJoseph KoshyRetrieve module statistics (for analyzing the behavior of
314ebccf1e3SJoseph Koshy.Nm
315ebccf1e3SJoseph Koshyitself).
316d9a5f346SJoseph Koshy.It Dv PMC_OP_GETMODULEVERSION
317ebccf1e3SJoseph KoshyRetrieve the version number of API.
318d9a5f346SJoseph Koshy.It Dv PMC_OP_GETPMCINFO
319ebccf1e3SJoseph KoshyRetrieve information about the current state of the PMCs on a
320ebccf1e3SJoseph Koshygiven CPU.
321d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCADMIN
322ebccf1e3SJoseph KoshySet the administrative state (i.e., whether enabled or disabled) for
323ebccf1e3SJoseph Koshythe hardware PMCs managed by the
324ebccf1e3SJoseph Koshy.Nm
325ebccf1e3SJoseph Koshydriver.
3261a94fde8SJoseph KoshyThe invoking process needs to possess the
3271a94fde8SJoseph Koshy.Dv PRIV_PMC_MANAGE
3281a94fde8SJoseph Koshyprivilege.
329d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCALLOCATE
330ebccf1e3SJoseph KoshyAllocate and configure a PMC.
331e805d32bSJoseph KoshyOn successful allocation, a handle to the PMC (a 32 bit value)
332ebccf1e3SJoseph Koshyis returned.
333d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCATTACH
334ebccf1e3SJoseph KoshyAttach a process mode PMC to a target process.
335ebccf1e3SJoseph KoshyThe PMC will be active whenever a thread in the target process is
336ebccf1e3SJoseph Koshyscheduled on a CPU.
337ebccf1e3SJoseph Koshy.Pp
338ebccf1e3SJoseph KoshyIf the
339ebccf1e3SJoseph Koshy.Dv PMC_F_DESCENDANTS
340ebccf1e3SJoseph Koshyflag had been specified at PMC allocation time, then the PMC is
341ebccf1e3SJoseph Koshyattached to all current and future descendants of the target process.
342d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCDETACH
343ebccf1e3SJoseph KoshyDetach a PMC from its target process.
344d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCRELEASE
345ebccf1e3SJoseph KoshyRelease a PMC.
346d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCRW
347ebccf1e3SJoseph KoshyRead and write a PMC.
348ebccf1e3SJoseph KoshyThis operation is valid only for PMCs configured in counting modes.
349d9a5f346SJoseph Koshy.It Dv PMC_OP_SETCOUNT
350ebccf1e3SJoseph KoshySet the initial count (for counting mode PMCs) or the desired sampling
351ebccf1e3SJoseph Koshyrate (for sampling mode PMCs).
352d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCSTART
353ebccf1e3SJoseph KoshyStart a PMC.
354d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCSTOP
355ebccf1e3SJoseph KoshyStop a PMC.
356d9a5f346SJoseph Koshy.It Dv PMC_OP_WRITELOG
357ebccf1e3SJoseph KoshyInsert a timestamped user record into the log file.
358ebccf1e3SJoseph Koshy.El
359d9a5f346SJoseph Koshy.Ss i386 Specific API
360ebccf1e3SJoseph KoshySome i386 family CPUs support the RDPMC instruction which allows a
361ebccf1e3SJoseph Koshyuser process to read a PMC value without needing to invoke a
362d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
363ebccf1e3SJoseph Koshyoperation.
364ebccf1e3SJoseph KoshyOn such CPUs, the machine address associated with an allocated PMC is
365ebccf1e3SJoseph Koshyretrievable using the
366d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR
367ebccf1e3SJoseph Koshysystem call.
368ebccf1e3SJoseph Koshy.Bl -tag -width indent
369d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCX86GETMSR
370ebccf1e3SJoseph KoshyRetrieve the MSR (machine specific register) number associated with
371ebccf1e3SJoseph Koshythe given PMC handle.
372ebccf1e3SJoseph Koshy.Pp
373c5153e19SJoseph KoshyThe PMC needs to be in process-private mode and allocated without the
374d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS
375c5153e19SJoseph Koshymodifier flag, and should be attached only to its owner process at the
376c5153e19SJoseph Koshytime of the call.
377ebccf1e3SJoseph Koshy.El
378d9a5f346SJoseph Koshy.Ss amd64 Specific API
379d9a5f346SJoseph KoshyAMD64 CPUs support the RDPMC instruction which allows a
380ebccf1e3SJoseph Koshyuser process to read a PMC value without needing to invoke a
381d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
382ebccf1e3SJoseph Koshyoperation.
383ebccf1e3SJoseph KoshyThe machine address associated with an allocated PMC is
384ebccf1e3SJoseph Koshyretrievable using the
385d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR
386ebccf1e3SJoseph Koshysystem call.
387ebccf1e3SJoseph Koshy.Bl -tag -width indent
388d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCX86GETMSR
389ebccf1e3SJoseph KoshyRetrieve the MSR (machine specific register) number associated with
390ebccf1e3SJoseph Koshythe given PMC handle.
391ebccf1e3SJoseph Koshy.Pp
392c5153e19SJoseph KoshyThe PMC needs to be in process-private mode and allocated without the
393d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS
394c5153e19SJoseph Koshymodifier flag, and should be attached only to its owner process at the
395c5153e19SJoseph Koshytime of the call.
396ebccf1e3SJoseph Koshy.El
39744cb3ab0SHiroki Sato.Sh SYSCTL VARIABLES AND LOADER TUNABLES
398ebccf1e3SJoseph KoshyThe behavior of
399ebccf1e3SJoseph Koshy.Nm
400ebccf1e3SJoseph Koshyis influenced by the following
401ebccf1e3SJoseph Koshy.Xr sysctl 8
402f263522aSJoseph Koshyand
403f263522aSJoseph Koshy.Xr loader 8
404ebccf1e3SJoseph Koshytunables:
405ebccf1e3SJoseph Koshy.Bl -tag -width indent
406a07d350cSJoseph Koshy.It Va kern.hwpmc.callchaindepth Pq integer, read-only
407a07d350cSJoseph KoshyThe maximum number of call chain records to capture per sample.
408a07d350cSJoseph KoshyThe default is 8.
409f263522aSJoseph Koshy.It Va kern.hwpmc.debugflags Pq string, read-write
410ebccf1e3SJoseph Koshy(Only available if the
411ebccf1e3SJoseph Koshy.Nm
412ebccf1e3SJoseph Koshydriver was compiled with
413d9a5f346SJoseph Koshy.Fl DDEBUG . )
414ebccf1e3SJoseph KoshyControl the verbosity of debug messages from the
415ebccf1e3SJoseph Koshy.Nm
416ebccf1e3SJoseph Koshydriver.
417f263522aSJoseph Koshy.It Va kern.hwpmc.hashsize Pq integer, read-only
418d9a5f346SJoseph KoshyThe number of rows in the hash tables used to keep track of owner and
419ebccf1e3SJoseph Koshytarget processes.
420f263522aSJoseph KoshyThe default is 16.
421f263522aSJoseph Koshy.It Va kern.hwpmc.logbuffersize Pq integer, read-only
422f263522aSJoseph KoshyThe size in kilobytes of each log buffer used by
423d9a5f346SJoseph Koshy.Nm Ns 's
424f263522aSJoseph Koshylogging function.
42524bae989SJoseph KoshyThe default buffer size is 4KB.
426f263522aSJoseph Koshy.It Va kern.hwpmc.mtxpoolsize Pq integer, read-only
427ebccf1e3SJoseph KoshyThe size of the spin mutex pool used by the PMC driver.
428f263522aSJoseph KoshyThe default is 32.
429f263522aSJoseph Koshy.It Va kern.hwpmc.nbuffers Pq integer, read-only
430f263522aSJoseph KoshyThe number of log buffers used by
431f263522aSJoseph Koshy.Nm
432f263522aSJoseph Koshyfor logging.
433f263522aSJoseph KoshyThe default is 16.
434f263522aSJoseph Koshy.It Va kern.hwpmc.nsamples Pq integer, read-only
435d9a5f346SJoseph KoshyThe number of entries in the per-CPU ring buffer used during sampling.
436f263522aSJoseph KoshyThe default is 16.
437f263522aSJoseph Koshy.It Va security.bsd.unprivileged_syspmcs Pq boolean, read-write
438ebccf1e3SJoseph KoshyIf set to non-zero, allow unprivileged processes to allocate system-wide
439ebccf1e3SJoseph KoshyPMCs.
440ebccf1e3SJoseph KoshyThe default value is 0.
441f263522aSJoseph Koshy.It Va security.bsd.unprivileged_proc_debug Pq boolean, read-write
442ebccf1e3SJoseph KoshyIf set to 0, the
443ebccf1e3SJoseph Koshy.Nm
444f263522aSJoseph Koshydriver will only allow privileged processes to attach PMCs to other
445ebccf1e3SJoseph Koshyprocesses.
446ebccf1e3SJoseph Koshy.El
447ebccf1e3SJoseph Koshy.Pp
448ebccf1e3SJoseph KoshyThese variables may be set in the kernel environment using
449ebccf1e3SJoseph Koshy.Xr kenv 1
450ebccf1e3SJoseph Koshybefore
451ebccf1e3SJoseph Koshy.Nm
452ebccf1e3SJoseph Koshyis loaded.
453ebccf1e3SJoseph Koshy.Sh IMPLEMENTATION NOTES
454f263522aSJoseph Koshy.Ss SMP Symmetry
455f263522aSJoseph KoshyThe kernel driver requires all physical CPUs in an SMP system to have
456f263522aSJoseph Koshyidentical performance monitoring counter hardware.
4576455febbSJoseph Koshy.Ss Sparse CPU Numbering
4586455febbSJoseph KoshyOn platforms that sparsely number CPUs and which support hot-plugging
4596455febbSJoseph Koshyof CPUs, requests that specify non-existent or disabled CPUs will fail
4606455febbSJoseph Koshywith an error.
4616455febbSJoseph KoshyApplications allocating system-scope PMCs need to be aware of
4626455febbSJoseph Koshythe possibility of such transient failures.
46379247772SJoseph Koshy.Ss x86 TSC Handling
464ebccf1e3SJoseph KoshyHistorically, on the x86 architecture,
465ebccf1e3SJoseph Koshy.Fx
466ebccf1e3SJoseph Koshyhas permitted user processes running at a processor CPL of 3 to
467ebccf1e3SJoseph Koshyread the TSC using the RDTSC instruction.
468ebccf1e3SJoseph KoshyThe
469ebccf1e3SJoseph Koshy.Nm
4704f00efe0SJoseph Koshydriver preserves this behavior.
471ebccf1e3SJoseph Koshy.Ss Intel P4/HTT Handling
472ebccf1e3SJoseph KoshyOn CPUs with HTT support, Intel P4 PMCs are capable of qualifying
473ebccf1e3SJoseph Koshyonly a subset of hardware events on a per-logical CPU basis.
474ebccf1e3SJoseph KoshyConsequently, if HTT is enabled on a system with Intel Pentium P4
475ebccf1e3SJoseph KoshyPMCs, then the
476ebccf1e3SJoseph Koshy.Nm
477ebccf1e3SJoseph Koshydriver will reject allocation requests for process-private PMCs that
478ebccf1e3SJoseph Koshyrequest counting of hardware events that cannot be counted separately
479ebccf1e3SJoseph Koshyfor each logical CPU.
480f263522aSJoseph Koshy.Ss Intel Pentium-Pro Handling
481d48fe4c5SJoseph KoshyWriting a value to the PMC MSRs found in Intel Pentium-Pro style PMCs
482f263522aSJoseph Koshy(found in
483f263522aSJoseph Koshy.Tn "Intel Pentium Pro" ,
484f263522aSJoseph Koshy.Tn "Pentium II" ,
485f263522aSJoseph Koshy.Tn "Pentium III" ,
486f263522aSJoseph Koshy.Tn "Pentium M"
487f263522aSJoseph Koshyand
488f263522aSJoseph Koshy.Tn "Celeron"
489f263522aSJoseph Koshyprocessors) will replicate bit 31 of the
490f263522aSJoseph Koshyvalue being written into the upper 8 bits of the MSR,
491f263522aSJoseph Koshybringing down the usable width of these PMCs to 31 bits.
492f263522aSJoseph KoshyFor process-virtual PMCs, the
493f263522aSJoseph Koshy.Nm
494f263522aSJoseph Koshydriver implements a workaround in software and makes the corrected 64
495f263522aSJoseph Koshybit count available via the
496d9a5f346SJoseph Koshy.Dv PMC_OP_RW
497f263522aSJoseph Koshyoperation.
498f263522aSJoseph KoshyProcesses that intend to use RDPMC instructions directly or
499f263522aSJoseph Koshythat intend to write values larger than 2^31 into these PMCs with
500d9a5f346SJoseph Koshy.Dv PMC_OP_RW
501f263522aSJoseph Koshyneed to be aware of this hardware limitation.
502f263522aSJoseph Koshy.Sh DIAGNOSTICS
503f263522aSJoseph Koshy.Bl -diag
504953adc17SJoseph Koshy.It "hwpmc: [class/npmc/capabilities]..."
505953adc17SJoseph KoshyAnnounce the presence of
506953adc17SJoseph Koshy.Va npmc
507953adc17SJoseph KoshyPMCs of class
508953adc17SJoseph Koshy.Va class ,
509953adc17SJoseph Koshywith capabilities described by bit string
510953adc17SJoseph Koshy.Va capabilities .
511953adc17SJoseph Koshy.It "hwpmc: kernel version (0x%x) does not match module version (0x%x)."
512953adc17SJoseph KoshyThe module loading process failed because a version mismatch was detected
513953adc17SJoseph Koshybetween the currently executing kernel and the module being loaded.
5143419317cSJoseph Koshy.It "hwpmc: this kernel has not been compiled with 'options HWPMC_HOOKS'."
5153419317cSJoseph KoshyThe module loading process failed because the currently executing kernel
5163419317cSJoseph Koshywas not configured with the required configuration option
51778ad5421SRuslan Ermilov.Dv HWPMC_HOOKS .
518d9a5f346SJoseph Koshy.It "hwpmc: tunable hashsize=%d must be greater than zero."
519f263522aSJoseph KoshyA negative value was supplied for tunable
520f263522aSJoseph Koshy.Va kern.hwpmc.hashsize .
521d9a5f346SJoseph Koshy.It "hwpmc: tunable logbuffersize=%d must be greater than zero."
522f263522aSJoseph KoshyA negative value was supplied for tunable
523f263522aSJoseph Koshy.Va kern.hwpmc.logbuffersize .
524d9a5f346SJoseph Koshy.It "hwpmc: tunable nlogbuffers=%d must be greater than zero."
525f263522aSJoseph KoshyA negative value was supplied for tunable
526f263522aSJoseph Koshy.Va kern.hwpmc.nlogbuffers .
527d9a5f346SJoseph Koshy.It "hwpmc: tunable nsamples=%d out of range."
528f263522aSJoseph KoshyThe value for tunable
529f263522aSJoseph Koshy.Va kern.hwpmc.nsamples
530f263522aSJoseph Koshywas negative or greater than 65535.
531f263522aSJoseph Koshy.El
5326d6a103aSJoseph Koshy.Sh COMPATIBILITY
5336d6a103aSJoseph KoshyThe
5346d6a103aSJoseph Koshy.Nm
5356d6a103aSJoseph Koshydriver is
5366d6a103aSJoseph Koshy.Ud
5376d6a103aSJoseph KoshyThe API and ABI documented in this manual page may change in
5386d6a103aSJoseph Koshythe future.
5396d6a103aSJoseph KoshyThe recommended method of accessing this driver is using the
5406d6a103aSJoseph Koshy.Xr pmc 3
5416d6a103aSJoseph KoshyAPI.
542ebccf1e3SJoseph Koshy.Sh ERRORS
543d9a5f346SJoseph KoshyA command issued to the
544ebccf1e3SJoseph Koshy.Nm
545ebccf1e3SJoseph Koshydriver may fail with the following errors:
546ebccf1e3SJoseph Koshy.Bl -tag -width Er
547a5c506d2SJoseph Koshy.It Bq Er EAGAIN
548a5c506d2SJoseph KoshyHelper process creation failed for a
549a5c506d2SJoseph Koshy.Dv PMC_OP_CONFIGURELOG
550a5c506d2SJoseph Koshyrequest due to a temporary resource shortage in the kernel.
551ebccf1e3SJoseph Koshy.It Bq Er EBUSY
552d9a5f346SJoseph KoshyA
553d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG
554ebccf1e3SJoseph Koshyoperation was requested while an existing log was active.
555ebccf1e3SJoseph Koshy.It Bq Er EBUSY
556d9a5f346SJoseph KoshyA DISABLE operation was requested using the
557d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
558ebccf1e3SJoseph Koshyrequest for a set of hardware resources currently in use for
559ebccf1e3SJoseph Koshyprocess-private PMCs.
560ebccf1e3SJoseph Koshy.It Bq Er EBUSY
561ebccf1e3SJoseph KoshyA
562d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
563ebccf1e3SJoseph Koshyoperation was requested on an active system mode PMC.
564ebccf1e3SJoseph Koshy.It Bq Er EBUSY
565ebccf1e3SJoseph KoshyA
566d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
567ebccf1e3SJoseph Koshyoperation was requested for a target process that already had another
568ebccf1e3SJoseph KoshyPMC using the same hardware resources attached to it.
569ebccf1e3SJoseph Koshy.It Bq Er EBUSY
570d9a5f346SJoseph KoshyA
571d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
572ebccf1e3SJoseph Koshyrequest writing a new value was issued on a PMC that was active.
573953adc17SJoseph Koshy.It Bq Er EBUSY
574953adc17SJoseph KoshyA
575953adc17SJoseph Koshy.Dv PMC_OP_PMCSETCOUNT
576953adc17SJoseph Koshyrequest was issued on a PMC that was active.
5773bc6c674SJoseph Koshy.It Bq Er EDOOFUS
5783bc6c674SJoseph KoshyA
579d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART
5803bc6c674SJoseph Koshyoperation was requested without a log file being configured for a
5813bc6c674SJoseph KoshyPMC allocated with
5823bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCCSW
5833bc6c674SJoseph Koshyand
5843bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT
5853bc6c674SJoseph Koshymodifiers.
5861e999888SJoseph Koshy.It Bq Er EDOOFUS
5871e999888SJoseph KoshyA
5881e999888SJoseph Koshy.Dv PMC_OP_PMCSTART
5891e999888SJoseph Koshyoperation was requested on a system-wide sampling PMC without a log
5901e999888SJoseph Koshyfile being configured.
591ebccf1e3SJoseph Koshy.It Bq Er EEXIST
592ebccf1e3SJoseph KoshyA
593d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
594ebccf1e3SJoseph Koshyrequest was reissued for a target process that already is the target
595ebccf1e3SJoseph Koshyof this PMC.
596ebccf1e3SJoseph Koshy.It Bq Er EFAULT
597ebccf1e3SJoseph KoshyA bad address was passed in to the driver.
598ebccf1e3SJoseph Koshy.It Bq Er EINVAL
599e805d32bSJoseph KoshyAn invalid PMC handle was specified.
600ebccf1e3SJoseph Koshy.It Bq Er EINVAL
601d9a5f346SJoseph KoshyAn invalid CPU number was passed in for a
602d9a5f346SJoseph Koshy.Dv PMC_OP_GETPMCINFO
603ebccf1e3SJoseph Koshyoperation.
604ebccf1e3SJoseph Koshy.It Bq Er EINVAL
605a5c506d2SJoseph KoshyA
606a5c506d2SJoseph Koshy.Dv PMC_OP_CONFIGURELOG
607a5c506d2SJoseph Koshyrequest to de-configure a log file was issued without a log file
608a5c506d2SJoseph Koshybeing configured.
609a5c506d2SJoseph Koshy.It Bq Er EINVAL
610a5c506d2SJoseph KoshyA
611a5c506d2SJoseph Koshy.Dv PMC_OP_FLUSHLOG
612a5c506d2SJoseph Koshyrequest was issued without a log file being configured.
613a5c506d2SJoseph Koshy.It Bq Er EINVAL
614d9a5f346SJoseph KoshyAn invalid CPU number was passed in for a
615d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
616ebccf1e3SJoseph Koshyoperation.
617ebccf1e3SJoseph Koshy.It Bq Er EINVAL
618d9a5f346SJoseph KoshyAn invalid operation request was passed in for a
619d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
620ebccf1e3SJoseph Koshyoperation.
621ebccf1e3SJoseph Koshy.It Bq Er EINVAL
622d9a5f346SJoseph KoshyAn invalid PMC ID was passed in for a
623d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
624ebccf1e3SJoseph Koshyoperation.
625ebccf1e3SJoseph Koshy.It Bq Er EINVAL
626ebccf1e3SJoseph KoshyA suitable PMC matching the parameters passed in to a
627d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
628ebccf1e3SJoseph Koshyrequest could not be allocated.
629ebccf1e3SJoseph Koshy.It Bq Er EINVAL
630ebccf1e3SJoseph KoshyAn invalid PMC mode was requested during a
631d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
632ebccf1e3SJoseph Koshyrequest.
633ebccf1e3SJoseph Koshy.It Bq Er EINVAL
634ebccf1e3SJoseph KoshyAn invalid CPU number was specified during a
635d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
636ebccf1e3SJoseph Koshyrequest.
637ebccf1e3SJoseph Koshy.It Bq Er EINVAL
638d9a5f346SJoseph KoshyA CPU other than
639d9a5f346SJoseph Koshy.Dv PMC_CPU_ANY
640ebccf1e3SJoseph Koshywas specified in a
641a5c506d2SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
642ebccf1e3SJoseph Koshyrequest for a process-private PMC.
643ebccf1e3SJoseph Koshy.It Bq Er EINVAL
644d9a5f346SJoseph KoshyA CPU number of
645d9a5f346SJoseph Koshy.Dv PMC_CPU_ANY
646ebccf1e3SJoseph Koshywas specified in a
647a5c506d2SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
648ebccf1e3SJoseph Koshyrequest for a system-wide PMC.
649ebccf1e3SJoseph Koshy.It Bq Er EINVAL
650ebccf1e3SJoseph KoshyThe
651ebccf1e3SJoseph Koshy.Ar pm_flags
652ebccf1e3SJoseph Koshyargument to an
653d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
654ebccf1e3SJoseph Koshyrequest contained unknown flags.
655ebccf1e3SJoseph Koshy.It Bq Er EINVAL
656a5c506d2SJoseph Koshy(On Intel Pentium 4 CPUs with HTT support)
657a5c506d2SJoseph KoshyA
658a5c506d2SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
659a5c506d2SJoseph Koshyrequest for a process-private PMC was issued for an event that does
660a5c506d2SJoseph Koshynot support counting on a per-logical CPU basis.
661a5c506d2SJoseph Koshy.It Bq Er EINVAL
662ebccf1e3SJoseph KoshyA PMC allocated for system-wide operation was specified with a
663d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
664a5c506d2SJoseph Koshyor
665a5c506d2SJoseph Koshy.Dv PMC_OP_PMCDETACH
666ebccf1e3SJoseph Koshyrequest.
667ebccf1e3SJoseph Koshy.It Bq Er EINVAL
668ebccf1e3SJoseph KoshyThe
669ebccf1e3SJoseph Koshy.Ar pm_pid
670ebccf1e3SJoseph Koshyargument to a
671d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
672a5c506d2SJoseph Koshyor
673a5c506d2SJoseph Koshy.Dv PMC_OP_PMCDETACH
674d9a5f346SJoseph Koshyrequest specified an illegal process ID.
675ebccf1e3SJoseph Koshy.It Bq Er EINVAL
676ebccf1e3SJoseph KoshyA
677d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH
678ebccf1e3SJoseph Koshyrequest was issued for a PMC not attached to the target process.
679ebccf1e3SJoseph Koshy.It Bq Er EINVAL
680ebccf1e3SJoseph KoshyArgument
681ebccf1e3SJoseph Koshy.Ar pm_flags
682ebccf1e3SJoseph Koshyto a
683d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
684ebccf1e3SJoseph Koshyrequest contained illegal flags.
685ebccf1e3SJoseph Koshy.It Bq Er EINVAL
686ebccf1e3SJoseph KoshyA
687d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR
688c5153e19SJoseph Koshyoperation was requested for a PMC not in process-virtual mode, or
689c5153e19SJoseph Koshyfor a PMC that is not solely attached to its owner process, or for
690c5153e19SJoseph Koshya PMC that was allocated with flag
691d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS .
692ebccf1e3SJoseph Koshy.It Bq Er EINVAL
693a5c506d2SJoseph KoshyA
694a5c506d2SJoseph Koshy.Dv PMC_OP_WRITELOG
695a5c506d2SJoseph Koshyrequest was issued for an owner process without a log file
696a5c506d2SJoseph Koshyconfigured.
697ebccf1e3SJoseph Koshy.It Bq Er ENOMEM
698ebccf1e3SJoseph KoshyThe system was not able to allocate kernel memory.
699ebccf1e3SJoseph Koshy.It Bq Er ENOSYS
700a5c506d2SJoseph Koshy(On i386 and amd64 architectures)
701d9a5f346SJoseph KoshyA
702d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR
703ebccf1e3SJoseph Koshyoperation was requested for hardware that does not support reading
704ebccf1e3SJoseph KoshyPMCs directly with the RDPMC instruction.
705ebccf1e3SJoseph Koshy.It Bq Er ENXIO
706d9a5f346SJoseph KoshyA
707d9a5f346SJoseph Koshy.Dv PMC_OP_GETPMCINFO
7086455febbSJoseph Koshyoperation was requested for an absent or disabled CPU.
709ebccf1e3SJoseph Koshy.It Bq Er ENXIO
7106455febbSJoseph KoshyA
7116455febbSJoseph Koshy.Dv PMC_OP_PMCALLOCATE
7126455febbSJoseph Koshyoperation specified allocation of a system-wide PMC on an absent or
7136455febbSJoseph Koshydisabled CPU.
714ebccf1e3SJoseph Koshy.It Bq Er ENXIO
715ebccf1e3SJoseph KoshyA
716d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART
717ebccf1e3SJoseph Koshyor
718d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTOP
7196455febbSJoseph Koshyrequest was issued for a system-wide PMC that was allocated on a CPU
7206455febbSJoseph Koshythat is currently absent or disabled.
721953adc17SJoseph Koshy.It Bq Er EOPNOTSUPP
722953adc17SJoseph KoshyA
723953adc17SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
724953adc17SJoseph Koshyrequest was issued for PMC capabilities not supported
725953adc17SJoseph Koshyby the specified PMC class.
726fe5ca00aSJoseph Koshy.It Bq Er EOPNOTSUPP
727fe5ca00aSJoseph Koshy(i386 architectures)
728fe5ca00aSJoseph KoshyA sampling mode PMC was requested on a CPU lacking an APIC.
729ebccf1e3SJoseph Koshy.It Bq Er EPERM
730d9a5f346SJoseph KoshyA
731d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
732ebccf1e3SJoseph Koshyrequest was issued by a process without super-user
733ebccf1e3SJoseph Koshyprivilege or by a jailed super-user process.
734ebccf1e3SJoseph Koshy.It Bq Er EPERM
735d9a5f346SJoseph KoshyA
736d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
737ebccf1e3SJoseph Koshyoperation was issued for a target process that the current process
738ebccf1e3SJoseph Koshydoes not have permission to attach to.
739c5153e19SJoseph Koshy.It Bq Er EPERM
740d9a5f346SJoseph Koshy(i386 and amd64 architectures)
741d9a5f346SJoseph KoshyA
742d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
743c5153e19SJoseph Koshyoperation was issued on a PMC whose MSR has been retrieved using
744d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR .
745ebccf1e3SJoseph Koshy.It Bq Er ESRCH
746f263522aSJoseph KoshyA process issued a PMC operation request without having allocated any
747f263522aSJoseph KoshyPMCs.
748f263522aSJoseph Koshy.It Bq Er ESRCH
749f263522aSJoseph KoshyA process issued a PMC operation request after the PMC was detached
750f263522aSJoseph Koshyfrom all of its target processes.
751ebccf1e3SJoseph Koshy.It Bq Er ESRCH
752ebccf1e3SJoseph KoshyA
753d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
754a5c506d2SJoseph Koshyor
755a5c506d2SJoseph Koshy.Dv PMC_OP_PMCDETACH
756d9a5f346SJoseph Koshyrequest specified a non-existent process ID.
757ebccf1e3SJoseph Koshy.It Bq Er ESRCH
758ebccf1e3SJoseph KoshyThe target process for a
759d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH
760a5c506d2SJoseph Koshyoperation is not being monitored by
761a5c506d2SJoseph Koshy.Nm .
762ebccf1e3SJoseph Koshy.El
763ebccf1e3SJoseph Koshy.Sh SEE ALSO
764ebccf1e3SJoseph Koshy.Xr kenv 1 ,
765ebccf1e3SJoseph Koshy.Xr pmc 3 ,
7666d6a103aSJoseph Koshy.Xr pmclog 3 ,
767f263522aSJoseph Koshy.Xr kgmon 8 ,
768ebccf1e3SJoseph Koshy.Xr kldload 8 ,
769ebccf1e3SJoseph Koshy.Xr pmccontrol 8 ,
770ebccf1e3SJoseph Koshy.Xr pmcstat 8 ,
771ebccf1e3SJoseph Koshy.Xr sysctl 8 ,
772a5c506d2SJoseph Koshy.Xr kproc_create 9 ,
773ebccf1e3SJoseph Koshy.Xr p_candebug 9
7746d6a103aSJoseph Koshy.Sh HISTORY
7756d6a103aSJoseph KoshyThe
7766d6a103aSJoseph Koshy.Nm
7776d6a103aSJoseph Koshydriver first appeared in
7786d6a103aSJoseph Koshy.Fx 6.0 .
779e805d32bSJoseph Koshy.Sh AUTHORS
780e805d32bSJoseph KoshyThe
781e805d32bSJoseph Koshy.Nm
782e805d32bSJoseph Koshydriver was written by
783e805d32bSJoseph Koshy.An "Joseph Koshy"
784e805d32bSJoseph Koshy.Aq jkoshy@FreeBSD.org .
785d9a5f346SJoseph Koshy.Sh BUGS
786d9a5f346SJoseph KoshyThe driver samples the state of the kernel's logical processor support
787d9a5f346SJoseph Koshyat the time of initialization (i.e., at module load time).
788d9a5f346SJoseph KoshyOn CPUs supporting logical processors, the driver could misbehave if
789d9a5f346SJoseph Koshylogical processors are subsequently enabled or disabled while the
790d9a5f346SJoseph Koshydriver is active.
791953adc17SJoseph Koshy.Pp
79279247772SJoseph KoshyOn the i386 architecture, the driver requires that the local APIC on the
793953adc17SJoseph KoshyCPU be enabled for sampling mode to be supported.
794953adc17SJoseph KoshyMany single-processor motherboards keep the APIC disabled in BIOS; on
795953adc17SJoseph Koshysuch systems
796953adc17SJoseph Koshy.Nm
797953adc17SJoseph Koshywill not support sampling PMCs.
798*0afc94c1SUlrich Spörlein.Sh SECURITY CONSIDERATIONS
799*0afc94c1SUlrich SpörleinPMCs may be used to monitor the actual behavior of the system on hardware.
800*0afc94c1SUlrich SpörleinIn situations where this constitutes an undesirable information leak,
801*0afc94c1SUlrich Spörleinthe following options are available:
802*0afc94c1SUlrich Spörlein.Bl -enum
803*0afc94c1SUlrich Spörlein.It
804*0afc94c1SUlrich SpörleinSet the
805*0afc94c1SUlrich Spörlein.Xr sysctl 8
806*0afc94c1SUlrich Spörleintunable
807*0afc94c1SUlrich Spörlein.Va security.bsd.unprivileged_syspmcs
808*0afc94c1SUlrich Spörleinto 0.
809*0afc94c1SUlrich SpörleinThis ensures that unprivileged processes cannot allocate system-wide
810*0afc94c1SUlrich SpörleinPMCs and thus cannot observe the hardware behavior of the system
811*0afc94c1SUlrich Spörleinas a whole.
812*0afc94c1SUlrich SpörleinThis tunable may also be set at boot time using
813*0afc94c1SUlrich Spörlein.Xr loader 8 ,
814*0afc94c1SUlrich Spörleinor with
815*0afc94c1SUlrich Spörlein.Xr kenv 1
816*0afc94c1SUlrich Spörleinprior to loading the
817*0afc94c1SUlrich Spörlein.Nm
818*0afc94c1SUlrich Spörleindriver into the kernel.
819*0afc94c1SUlrich Spörlein.It
820*0afc94c1SUlrich SpörleinSet the
821*0afc94c1SUlrich Spörlein.Xr sysctl 8
822*0afc94c1SUlrich Spörleintunable
823*0afc94c1SUlrich Spörlein.Va security.bsd.unprivileged_proc_debug
824*0afc94c1SUlrich Spörleinto 0.
825*0afc94c1SUlrich SpörleinThis will ensure that an unprivileged process cannot attach a PMC
826*0afc94c1SUlrich Spörleinto any process other than itself and thus cannot observe the hardware
827*0afc94c1SUlrich Spörleinbehavior of other processes with the same credentials.
828*0afc94c1SUlrich Spörlein.El
829*0afc94c1SUlrich Spörlein.Pp
830*0afc94c1SUlrich SpörleinSystem administrators should note that on IA-32 platforms
831*0afc94c1SUlrich Spörlein.Fx
832*0afc94c1SUlrich Spörleinmakes the content of the IA-32 TSC counter available to all processes
833*0afc94c1SUlrich Spörleinvia the RDTSC instruction.
834