xref: /freebsd/share/man/man4/hwpmc.4 (revision 44caa8729351f59192918379bea23b034ef6df2b)
1ebccf1e3SJoseph Koshy.\" Copyright (c) 2003-2005 Joseph Koshy
2ebccf1e3SJoseph Koshy.\" All rights reserved.
3ebccf1e3SJoseph Koshy.\"
4ebccf1e3SJoseph Koshy.\" Redistribution and use in source and binary forms, with or without
5ebccf1e3SJoseph Koshy.\" modification, are permitted provided that the following conditions
6ebccf1e3SJoseph Koshy.\" are met:
7ebccf1e3SJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright
8ebccf1e3SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer.
9ebccf1e3SJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright
10ebccf1e3SJoseph Koshy.\"    notice, this list of conditions and the following disclaimer in the
11ebccf1e3SJoseph Koshy.\"    documentation and/or other materials provided with the distribution.
12ebccf1e3SJoseph Koshy.\"
13ebccf1e3SJoseph Koshy.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14ebccf1e3SJoseph Koshy.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15ebccf1e3SJoseph Koshy.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16ebccf1e3SJoseph Koshy.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17ebccf1e3SJoseph Koshy.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18ebccf1e3SJoseph Koshy.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19ebccf1e3SJoseph Koshy.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20ebccf1e3SJoseph Koshy.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21ebccf1e3SJoseph Koshy.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22ebccf1e3SJoseph Koshy.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23ebccf1e3SJoseph Koshy.\" SUCH DAMAGE.
24ebccf1e3SJoseph Koshy.\"
25ebccf1e3SJoseph Koshy.\" $FreeBSD$
26ebccf1e3SJoseph Koshy.\"
2779247772SJoseph Koshy.Dd September 28, 2005
28ebccf1e3SJoseph Koshy.Dt HWPMC 4
29ebccf1e3SJoseph Koshy.Os
30ebccf1e3SJoseph Koshy.Sh NAME
31ebccf1e3SJoseph Koshy.Nm hwpmc
32d9a5f346SJoseph Koshy.Nd "Hardware Performance Monitoring Counter support"
33ebccf1e3SJoseph Koshy.Sh SYNOPSIS
34d9a5f346SJoseph Koshy.Cd "options HWPMC_HOOKS"
35d9a5f346SJoseph Koshy.Cd "device hwpmc"
3679247772SJoseph Koshy.Pp
3779247772SJoseph KoshyAdditionally, for i386 systems:
3878ad5421SRuslan Ermilov.Cd "device apic"
39ebccf1e3SJoseph Koshy.Sh DESCRIPTION
40ebccf1e3SJoseph KoshyThe
41ebccf1e3SJoseph Koshy.Nm
42ebccf1e3SJoseph Koshydriver virtualizes the hardware performance monitoring facilities in
43ebccf1e3SJoseph Koshymodern CPUs and provides support for using these facilities from
44ebccf1e3SJoseph Koshyuser level processes.
45ebccf1e3SJoseph Koshy.Pp
46ebccf1e3SJoseph KoshyThe driver supports multi-processor systems.
47ebccf1e3SJoseph Koshy.Pp
48ebccf1e3SJoseph KoshyPMCs are allocated using the
49d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
50ebccf1e3SJoseph Koshyrequest.
51ebccf1e3SJoseph KoshyA successful
52d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
534f00efe0SJoseph Koshyrequest will return an integer handle to the requesting process.
54ebccf1e3SJoseph KoshySubsequent operations on the allocated PMC use this handle to denote
55ebccf1e3SJoseph Koshythe specific PMC.
56ebccf1e3SJoseph KoshyA process that has successfully allocated a PMC is termed an
57ebccf1e3SJoseph Koshy.Dq "owner process" .
58ebccf1e3SJoseph Koshy.Pp
59ebccf1e3SJoseph KoshyPMCs may be allocated to operate in process-private or in system-wide
60ebccf1e3SJoseph Koshymodes.
61d9a5f346SJoseph Koshy.Bl -tag -width ".Em Process-private"
62ebccf1e3SJoseph Koshy.It Em Process-private
63ebccf1e3SJoseph KoshyIn process-private mode, a PMC is active only when a thread belonging
64ebccf1e3SJoseph Koshyto a process it is attached to is scheduled on a CPU.
65ebccf1e3SJoseph Koshy.It Em System-wide
66d9a5f346SJoseph KoshyIn system-wide mode, a PMC operates independently of processes and
67ebccf1e3SJoseph Koshymeasures hardware events for the system as a whole.
68ebccf1e3SJoseph Koshy.El
69ebccf1e3SJoseph Koshy.Pp
70ebccf1e3SJoseph KoshyThe
71ebccf1e3SJoseph Koshy.Nm
72ebccf1e3SJoseph Koshydriver supports the use of hardware PMCs for counting or for
73ebccf1e3SJoseph Koshysampling:
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
83ebccf1e3SJoseph Koshyinstruction pointer after a configurable number of hardware events
84ebccf1e3SJoseph Koshyhave been observed.
854f00efe0SJoseph KoshyThese instruction pointer samples are usually directed to a log file
864f00efe0SJoseph Koshyfor subsequent analysis.
87ebccf1e3SJoseph Koshy.El
88ebccf1e3SJoseph Koshy.Pp
89ebccf1e3SJoseph KoshyThese modes of operation are orthogonal; a PMC may be configured to
90ebccf1e3SJoseph Koshyoperate in one of four modes:
91ebccf1e3SJoseph Koshy.Bl -tag -width indent
92ebccf1e3SJoseph Koshy.It Process-private, counting
93ebccf1e3SJoseph KoshyThese PMCs count hardware events whenever a thread in their attached process is
94ebccf1e3SJoseph Koshyscheduled on a CPU.
95ebccf1e3SJoseph KoshyThese PMCs normally count from zero, but the initial count may be
96ebccf1e3SJoseph Koshyset using the
97d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT
98ebccf1e3SJoseph Koshyoperation.
99ebccf1e3SJoseph KoshyApplications can read the value of the PMC anytime using the
100d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
101ebccf1e3SJoseph Koshyoperation.
102ebccf1e3SJoseph Koshy.It Process-private, sampling
103ebccf1e3SJoseph KoshyThese PMCs sample the target processes instruction pointer after they
104ebccf1e3SJoseph Koshyhave seen the configured number of hardware events.
105ebccf1e3SJoseph KoshyThe PMCs only count events when a thread belonging to their attached
106ebccf1e3SJoseph Koshyprocess is active.
107ebccf1e3SJoseph KoshyThe desired frequency of sampling is set using the
108d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT
109ebccf1e3SJoseph Koshyoperation prior to starting the PMC.
110ebccf1e3SJoseph KoshyLog files are configured using the
111d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG
112ebccf1e3SJoseph Koshyoperation.
113ebccf1e3SJoseph Koshy.It System-wide, counting
114ebccf1e3SJoseph KoshyThese PMCs count hardware events seen by them independent of the
115ebccf1e3SJoseph Koshyprocesses that are executing.
116ebccf1e3SJoseph KoshyThe current count on these PMCs can be read using the
117d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
118ebccf1e3SJoseph Koshyrequest.
119ebccf1e3SJoseph KoshyThese PMCs normally count from zero, but the initial count may be
120ebccf1e3SJoseph Koshyset using the
121d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT
122ebccf1e3SJoseph Koshyoperation.
123ebccf1e3SJoseph Koshy.It System-wide, sampling
124ebccf1e3SJoseph KoshyThese PMCs will periodically sample the instruction pointer of the CPU
125ebccf1e3SJoseph Koshythey are allocated on, and will write the sample to a log for further
126ebccf1e3SJoseph Koshyprocessing.
127ebccf1e3SJoseph KoshyThe desired frequency of sampling is set using the
128d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT
129ebccf1e3SJoseph Koshyoperation prior to starting the PMC.
130ebccf1e3SJoseph KoshyLog files are configured using the
131d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG
132ebccf1e3SJoseph Koshyoperation.
133ebccf1e3SJoseph Koshy.Pp
134ebccf1e3SJoseph KoshySystem-wide statistical sampling can only be enabled by a process with
135ebccf1e3SJoseph Koshysuper-user privileges.
136ebccf1e3SJoseph Koshy.El
137ebccf1e3SJoseph Koshy.Pp
1384f00efe0SJoseph KoshyProcesses are allowed to allocate as many PMCs as the hardware and
139ebccf1e3SJoseph Koshycurrent operating conditions permit.
140ebccf1e3SJoseph KoshyProcesses may mix allocations of system-wide and process-private
141ebccf1e3SJoseph KoshyPMCs.
14244caa872SJoseph KoshyMultiple processes may be using PMCs simultaneously.
143ebccf1e3SJoseph Koshy.Pp
144ebccf1e3SJoseph KoshyAllocated PMCs are started using the
145d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART
146ebccf1e3SJoseph Koshyoperation, and stopped using the
147d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTOP
148ebccf1e3SJoseph Koshyoperation.
149ebccf1e3SJoseph KoshyStopping and starting a PMC is permitted at any time the owner process
150ebccf1e3SJoseph Koshyhas a valid handle to the PMC.
151ebccf1e3SJoseph Koshy.Pp
152ebccf1e3SJoseph KoshyProcess-private PMCs need to be attached to a target process before
153ebccf1e3SJoseph Koshythey can be used.
154ebccf1e3SJoseph KoshyAttaching a process to a PMC is done using the
155d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
156ebccf1e3SJoseph Koshyoperation.
157ebccf1e3SJoseph KoshyAn already attached PMC may be detached from its target process
158ebccf1e3SJoseph Koshyusing the converse
159d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH
160ebccf1e3SJoseph Koshyoperation.
161d9a5f346SJoseph KoshyIssuing a
162d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART
163ebccf1e3SJoseph Koshyoperation on an as yet unattached PMC will cause it to be attached
164ebccf1e3SJoseph Koshyto its owner process.
165ebccf1e3SJoseph KoshyThe following rules determine whether a given process may attach
166ebccf1e3SJoseph Koshya PMC to another target process:
167ebccf1e3SJoseph Koshy.Bl -bullet -compact
168ebccf1e3SJoseph Koshy.It
169ebccf1e3SJoseph KoshyA non-jailed process with super-user privileges is allowed to attach
170ebccf1e3SJoseph Koshyto any other process in the system.
171ebccf1e3SJoseph Koshy.It
172ebccf1e3SJoseph KoshyOther processes are only allowed to attach to targets that they would
173ebccf1e3SJoseph Koshybe able to attach to for debugging (as determined by
174ebccf1e3SJoseph Koshy.Xr p_candebug 9 ) .
175ebccf1e3SJoseph Koshy.El
176ebccf1e3SJoseph Koshy.Pp
177ebccf1e3SJoseph KoshyPMCs are released using
178d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRELEASE .
179ebccf1e3SJoseph KoshyAfter a successful
180d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRELEASE
181ebccf1e3SJoseph Koshyoperation the handle to the PMC will become invalid.
182d9a5f346SJoseph Koshy.Ss Modifier Flags
183ebccf1e3SJoseph KoshyThe
184d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
185ebccf1e3SJoseph Koshyoperation supports the following flags that modify the behavior
186ebccf1e3SJoseph Koshyof an allocated PMC:
187d9a5f346SJoseph Koshy.Bl -tag -width indent
188ebccf1e3SJoseph Koshy.It Dv PMC_F_DESCENDANTS
189f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private
190ebccf1e3SJoseph Koshymode.
191ebccf1e3SJoseph KoshyIt signifies that the PMC will track hardware events for its
192ebccf1e3SJoseph Koshytarget process and the target's current and future descendants.
193f263522aSJoseph Koshy.It Dv PMC_F_KGMON
194f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in system-wide
195f263522aSJoseph Koshysampling mode.
196f263522aSJoseph KoshyIt signifies that the PMC's sampling interrupt is to be used to drive
197f263522aSJoseph Koshykernel profiling via
198f263522aSJoseph Koshy.Xr kgmon 8 .
199f263522aSJoseph Koshy.It Dv PMC_F_LOG_PROCCSW
200f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private
201f263522aSJoseph Koshymode.
2023bc6c674SJoseph KoshyWhen this modifier is present, at every context switch,
203f263522aSJoseph Koshy.Nm
2043bc6c674SJoseph Koshywill log a record containing the number of hardware events
2053bc6c674SJoseph Koshyseen by the target process when it was scheduled on the CPU.
206f263522aSJoseph Koshy.It Dv PMC_F_LOG_PROCEXIT
207f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private
208f263522aSJoseph Koshymode.
209f263522aSJoseph KoshyWith this modifier present,
210f263522aSJoseph Koshy.Nm
211f263522aSJoseph Koshywill maintain per-process counts for each target process attached to
212f263522aSJoseph Koshya PMC.
213d9a5f346SJoseph KoshyAt process exit time, a record containing the target process' PID and
214f263522aSJoseph Koshythe accumulated per-process count for that process will be written to the
215f263522aSJoseph Koshyconfigured log file.
216ebccf1e3SJoseph Koshy.El
217d9a5f346SJoseph Koshy.Pp
218f263522aSJoseph KoshyModifiers
219f263522aSJoseph Koshy.Dv PMC_F_LOG_PROCEXIT
220f263522aSJoseph Koshyand
221f263522aSJoseph Koshy.Dv PMC_F_LOG_PROCCSW
222f263522aSJoseph Koshymay be used in combination with modifier
223f263522aSJoseph Koshy.Dv PMC_F_DESCENDANTS
2244f00efe0SJoseph Koshyto track the behavior of complex pipelines of processes.
2253bc6c674SJoseph KoshyPMCs with modifiers
2263bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT
2273bc6c674SJoseph Koshyand
2283bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCCSW
2293bc6c674SJoseph Koshycannot be started until their owner process has configured a log file.
230d9a5f346SJoseph Koshy.Ss Signals
231ebccf1e3SJoseph KoshyThe
232ebccf1e3SJoseph Koshy.Nm
233ebccf1e3SJoseph Koshydriver may deliver signals to processes that have allocated PMCs:
234d9a5f346SJoseph Koshy.Bl -tag -width ".Dv SIGBUS"
235d9a5f346SJoseph Koshy.It Dv SIGIO
236ebccf1e3SJoseph KoshyA
237d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
238ebccf1e3SJoseph Koshyoperation was attempted on a process-private PMC that does not have
239ebccf1e3SJoseph Koshyattached target processes.
240d9a5f346SJoseph Koshy.It Dv SIGBUS
241ebccf1e3SJoseph KoshyThe
242ebccf1e3SJoseph Koshy.Nm
243ebccf1e3SJoseph Koshydriver is being unloaded from the kernel.
244ebccf1e3SJoseph Koshy.El
245ebccf1e3SJoseph Koshy.Sh PROGRAMMING API
246ebccf1e3SJoseph KoshyThe recommended way for application programs to use the facilities of
247ebccf1e3SJoseph Koshythe
248ebccf1e3SJoseph Koshy.Nm
249d9a5f346SJoseph Koshydriver is using the API provided by the
250d9a5f346SJoseph Koshy.Xr pmc 3
251d9a5f346SJoseph Koshylibrary.
252ebccf1e3SJoseph Koshy.Pp
253ebccf1e3SJoseph KoshyThe
254ebccf1e3SJoseph Koshy.Nm
255ebccf1e3SJoseph Koshydriver operates using a system call number that is dynamically
256ebccf1e3SJoseph Koshyallotted to it when it is loaded into the kernel.
257ebccf1e3SJoseph Koshy.Pp
258ebccf1e3SJoseph KoshyThe
259ebccf1e3SJoseph Koshy.Nm
260ebccf1e3SJoseph Koshydriver supports the following operations:
261ebccf1e3SJoseph Koshy.Bl -tag -width indent
262d9a5f346SJoseph Koshy.It Dv PMC_OP_CONFIGURELOG
263ebccf1e3SJoseph KoshyConfigure a log file for sampling mode PMCs.
264d9a5f346SJoseph Koshy.It Dv PMC_OP_FLUSHLOG
265f263522aSJoseph KoshyTransfer buffered log data inside
266f263522aSJoseph Koshy.Nm
267f263522aSJoseph Koshyto a configured output file.
268f263522aSJoseph KoshyThis operation returns to the caller after the write operation
269f263522aSJoseph Koshyhas returned.
270d9a5f346SJoseph Koshy.It Dv PMC_OP_GETCPUINFO
271ebccf1e3SJoseph KoshyRetrieve information about the number of CPUs on the system and
272ebccf1e3SJoseph Koshythe number of hardware performance monitoring counters available per-CPU.
273d9a5f346SJoseph Koshy.It Dv PMC_OP_GETDRIVERSTATS
274ebccf1e3SJoseph KoshyRetrieve module statistics (for analyzing the behavior of
275ebccf1e3SJoseph Koshy.Nm
276ebccf1e3SJoseph Koshyitself).
277d9a5f346SJoseph Koshy.It Dv PMC_OP_GETMODULEVERSION
278ebccf1e3SJoseph KoshyRetrieve the version number of API.
279d9a5f346SJoseph Koshy.It Dv PMC_OP_GETPMCINFO
280ebccf1e3SJoseph KoshyRetrieve information about the current state of the PMCs on a
281ebccf1e3SJoseph Koshygiven CPU.
282d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCADMIN
283ebccf1e3SJoseph KoshySet the administrative state (i.e., whether enabled or disabled) for
284ebccf1e3SJoseph Koshythe hardware PMCs managed by the
285ebccf1e3SJoseph Koshy.Nm
286ebccf1e3SJoseph Koshydriver.
287d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCALLOCATE
288ebccf1e3SJoseph KoshyAllocate and configure a PMC.
289ebccf1e3SJoseph KoshyOn successful allocation, a handle to the PMC (a small integer)
290ebccf1e3SJoseph Koshyis returned.
291d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCATTACH
292ebccf1e3SJoseph KoshyAttach a process mode PMC to a target process.
293ebccf1e3SJoseph KoshyThe PMC will be active whenever a thread in the target process is
294ebccf1e3SJoseph Koshyscheduled on a CPU.
295ebccf1e3SJoseph Koshy.Pp
296ebccf1e3SJoseph KoshyIf the
297ebccf1e3SJoseph Koshy.Dv PMC_F_DESCENDANTS
298ebccf1e3SJoseph Koshyflag had been specified at PMC allocation time, then the PMC is
299ebccf1e3SJoseph Koshyattached to all current and future descendants of the target process.
300d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCDETACH
301ebccf1e3SJoseph KoshyDetach a PMC from its target process.
302d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCRELEASE
303ebccf1e3SJoseph KoshyRelease a PMC.
304d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCRW
305ebccf1e3SJoseph KoshyRead and write a PMC.
306ebccf1e3SJoseph KoshyThis operation is valid only for PMCs configured in counting modes.
307d9a5f346SJoseph Koshy.It Dv PMC_OP_SETCOUNT
308ebccf1e3SJoseph KoshySet the initial count (for counting mode PMCs) or the desired sampling
309ebccf1e3SJoseph Koshyrate (for sampling mode PMCs).
310d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCSTART
311ebccf1e3SJoseph KoshyStart a PMC.
312d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCSTOP
313ebccf1e3SJoseph KoshyStop a PMC.
314d9a5f346SJoseph Koshy.It Dv PMC_OP_WRITELOG
315ebccf1e3SJoseph KoshyInsert a timestamped user record into the log file.
316ebccf1e3SJoseph Koshy.El
317d9a5f346SJoseph Koshy.Ss i386 Specific API
318ebccf1e3SJoseph KoshySome i386 family CPUs support the RDPMC instruction which allows a
319ebccf1e3SJoseph Koshyuser process to read a PMC value without needing to invoke a
320d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
321ebccf1e3SJoseph Koshyoperation.
322ebccf1e3SJoseph KoshyOn such CPUs, the machine address associated with an allocated PMC is
323ebccf1e3SJoseph Koshyretrievable using the
324d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR
325ebccf1e3SJoseph Koshysystem call.
326ebccf1e3SJoseph Koshy.Bl -tag -width indent
327d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCX86GETMSR
328ebccf1e3SJoseph KoshyRetrieve the MSR (machine specific register) number associated with
329ebccf1e3SJoseph Koshythe given PMC handle.
330ebccf1e3SJoseph Koshy.Pp
331c5153e19SJoseph KoshyThe PMC needs to be in process-private mode and allocated without the
332d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS
333c5153e19SJoseph Koshymodifier flag, and should be attached only to its owner process at the
334c5153e19SJoseph Koshytime of the call.
335ebccf1e3SJoseph Koshy.El
336d9a5f346SJoseph Koshy.Ss amd64 Specific API
337d9a5f346SJoseph KoshyAMD64 CPUs support the RDPMC instruction which allows a
338ebccf1e3SJoseph Koshyuser process to read a PMC value without needing to invoke a
339d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
340ebccf1e3SJoseph Koshyoperation.
341ebccf1e3SJoseph KoshyThe machine address associated with an allocated PMC is
342ebccf1e3SJoseph Koshyretrievable using the
343d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR
344ebccf1e3SJoseph Koshysystem call.
345ebccf1e3SJoseph Koshy.Bl -tag -width indent
346d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCX86GETMSR
347ebccf1e3SJoseph KoshyRetrieve the MSR (machine specific register) number associated with
348ebccf1e3SJoseph Koshythe given PMC handle.
349ebccf1e3SJoseph Koshy.Pp
350c5153e19SJoseph KoshyThe PMC needs to be in process-private mode and allocated without the
351d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS
352c5153e19SJoseph Koshymodifier flag, and should be attached only to its owner process at the
353c5153e19SJoseph Koshytime of the call.
354ebccf1e3SJoseph Koshy.El
35544cb3ab0SHiroki Sato.Sh SYSCTL VARIABLES AND LOADER TUNABLES
356ebccf1e3SJoseph KoshyThe behavior of
357ebccf1e3SJoseph Koshy.Nm
358ebccf1e3SJoseph Koshyis influenced by the following
359ebccf1e3SJoseph Koshy.Xr sysctl 8
360f263522aSJoseph Koshyand
361f263522aSJoseph Koshy.Xr loader 8
362ebccf1e3SJoseph Koshytunables:
363ebccf1e3SJoseph Koshy.Bl -tag -width indent
364f263522aSJoseph Koshy.It Va kern.hwpmc.debugflags Pq string, read-write
365ebccf1e3SJoseph Koshy(Only available if the
366ebccf1e3SJoseph Koshy.Nm
367ebccf1e3SJoseph Koshydriver was compiled with
368d9a5f346SJoseph Koshy.Fl DDEBUG . )
369ebccf1e3SJoseph KoshyControl the verbosity of debug messages from the
370ebccf1e3SJoseph Koshy.Nm
371ebccf1e3SJoseph Koshydriver.
372f263522aSJoseph Koshy.It Va kern.hwpmc.hashsize Pq integer, read-only
373d9a5f346SJoseph KoshyThe number of rows in the hash tables used to keep track of owner and
374ebccf1e3SJoseph Koshytarget processes.
375f263522aSJoseph KoshyThe default is 16.
376f263522aSJoseph Koshy.It Va kern.hwpmc.logbuffersize Pq integer, read-only
377f263522aSJoseph KoshyThe size in kilobytes of each log buffer used by
378d9a5f346SJoseph Koshy.Nm Ns 's
379f263522aSJoseph Koshylogging function.
38024bae989SJoseph KoshyThe default buffer size is 4KB.
381f263522aSJoseph Koshy.It Va kern.hwpmc.mtxpoolsize Pq integer, read-only
382ebccf1e3SJoseph KoshyThe size of the spin mutex pool used by the PMC driver.
383f263522aSJoseph KoshyThe default is 32.
384f263522aSJoseph Koshy.It Va kern.hwpmc.nbuffers Pq integer, read-only
385f263522aSJoseph KoshyThe number of log buffers used by
386f263522aSJoseph Koshy.Nm
387f263522aSJoseph Koshyfor logging.
388f263522aSJoseph KoshyThe default is 16.
389f263522aSJoseph Koshy.It Va kern.hwpmc.nsamples Pq integer, read-only
390d9a5f346SJoseph KoshyThe number of entries in the per-CPU ring buffer used during sampling.
391f263522aSJoseph KoshyThe default is 16.
392f263522aSJoseph Koshy.It Va security.bsd.unprivileged_syspmcs Pq boolean, read-write
393ebccf1e3SJoseph KoshyIf set to non-zero, allow unprivileged processes to allocate system-wide
394ebccf1e3SJoseph KoshyPMCs.
395ebccf1e3SJoseph KoshyThe default value is 0.
396f263522aSJoseph Koshy.It Va security.bsd.unprivileged_proc_debug Pq boolean, read-write
397ebccf1e3SJoseph KoshyIf set to 0, the
398ebccf1e3SJoseph Koshy.Nm
399f263522aSJoseph Koshydriver will only allow privileged processes to attach PMCs to other
400ebccf1e3SJoseph Koshyprocesses.
401ebccf1e3SJoseph Koshy.El
402ebccf1e3SJoseph Koshy.Pp
403ebccf1e3SJoseph KoshyThese variables may be set in the kernel environment using
404ebccf1e3SJoseph Koshy.Xr kenv 1
405ebccf1e3SJoseph Koshybefore
406ebccf1e3SJoseph Koshy.Nm
407ebccf1e3SJoseph Koshyis loaded.
408ebccf1e3SJoseph Koshy.Sh SECURITY CONSIDERATIONS
4094f00efe0SJoseph KoshyPMCs may be used to monitor the actual behavior of the system on hardware.
410ebccf1e3SJoseph KoshyIn situations where this constitutes an undesirable information leak,
411ebccf1e3SJoseph Koshythe following options are available:
412ebccf1e3SJoseph Koshy.Bl -enum
413ebccf1e3SJoseph Koshy.It
414ebccf1e3SJoseph KoshySet the
415ebccf1e3SJoseph Koshy.Xr sysctl 8
416ebccf1e3SJoseph Koshytunable
417d9a5f346SJoseph Koshy.Va security.bsd.unprivileged_syspmcs
418ebccf1e3SJoseph Koshyto 0.
419ebccf1e3SJoseph KoshyThis ensures that unprivileged processes cannot allocate system-wide
420ebccf1e3SJoseph KoshyPMCs and thus cannot observe the hardware behavior of the system
421ebccf1e3SJoseph Koshyas a whole.
422ebccf1e3SJoseph KoshyThis tunable may also be set at boot time using
423ebccf1e3SJoseph Koshy.Xr loader 8 ,
424ebccf1e3SJoseph Koshyor with
425ebccf1e3SJoseph Koshy.Xr kenv 1
426ebccf1e3SJoseph Koshyprior to loading the
427ebccf1e3SJoseph Koshy.Nm
428ebccf1e3SJoseph Koshydriver into the kernel.
429ebccf1e3SJoseph Koshy.It
430ebccf1e3SJoseph KoshySet the
431ebccf1e3SJoseph Koshy.Xr sysctl 8
432ebccf1e3SJoseph Koshytunable
433d9a5f346SJoseph Koshy.Va security.bsd.unprivileged_proc_debug
434ebccf1e3SJoseph Koshyto 0.
435ebccf1e3SJoseph KoshyThis will ensure that an unprivileged process cannot attach a PMC
436ebccf1e3SJoseph Koshyto any process other than itself and thus cannot observe the hardware
437ebccf1e3SJoseph Koshybehavior of other processes with the same credentials.
438ebccf1e3SJoseph Koshy.El
439ebccf1e3SJoseph Koshy.Pp
440ebccf1e3SJoseph KoshySystem administrators should note that on IA-32 platforms
441ebccf1e3SJoseph Koshy.Fx
442ebccf1e3SJoseph Koshymakes the content of the IA-32 TSC counter available to all processes
443ebccf1e3SJoseph Koshyvia the RDTSC instruction.
444ebccf1e3SJoseph Koshy.Sh IMPLEMENTATION NOTES
445f263522aSJoseph Koshy.Ss SMP Symmetry
446f263522aSJoseph KoshyThe kernel driver requires all physical CPUs in an SMP system to have
447f263522aSJoseph Koshyidentical performance monitoring counter hardware.
44879247772SJoseph Koshy.Ss x86 TSC Handling
449ebccf1e3SJoseph KoshyHistorically, on the x86 architecture,
450ebccf1e3SJoseph Koshy.Fx
451ebccf1e3SJoseph Koshyhas permitted user processes running at a processor CPL of 3 to
452ebccf1e3SJoseph Koshyread the TSC using the RDTSC instruction.
453ebccf1e3SJoseph KoshyThe
454ebccf1e3SJoseph Koshy.Nm
4554f00efe0SJoseph Koshydriver preserves this behavior.
456ebccf1e3SJoseph Koshy.Ss Intel P4/HTT Handling
457ebccf1e3SJoseph KoshyOn CPUs with HTT support, Intel P4 PMCs are capable of qualifying
458ebccf1e3SJoseph Koshyonly a subset of hardware events on a per-logical CPU basis.
459ebccf1e3SJoseph KoshyConsequently, if HTT is enabled on a system with Intel Pentium P4
460ebccf1e3SJoseph KoshyPMCs, then the
461ebccf1e3SJoseph Koshy.Nm
462ebccf1e3SJoseph Koshydriver will reject allocation requests for process-private PMCs that
463ebccf1e3SJoseph Koshyrequest counting of hardware events that cannot be counted separately
464ebccf1e3SJoseph Koshyfor each logical CPU.
465f263522aSJoseph Koshy.Ss Intel Pentium-Pro Handling
466d48fe4c5SJoseph KoshyWriting a value to the PMC MSRs found in Intel Pentium-Pro style PMCs
467f263522aSJoseph Koshy(found in
468f263522aSJoseph Koshy.Tn "Intel Pentium Pro" ,
469f263522aSJoseph Koshy.Tn "Pentium II" ,
470f263522aSJoseph Koshy.Tn "Pentium III" ,
471f263522aSJoseph Koshy.Tn "Pentium M"
472f263522aSJoseph Koshyand
473f263522aSJoseph Koshy.Tn "Celeron"
474f263522aSJoseph Koshyprocessors) will replicate bit 31 of the
475f263522aSJoseph Koshyvalue being written into the upper 8 bits of the MSR,
476f263522aSJoseph Koshybringing down the usable width of these PMCs to 31 bits.
477f263522aSJoseph KoshyFor process-virtual PMCs, the
478f263522aSJoseph Koshy.Nm
479f263522aSJoseph Koshydriver implements a workaround in software and makes the corrected 64
480f263522aSJoseph Koshybit count available via the
481d9a5f346SJoseph Koshy.Dv PMC_OP_RW
482f263522aSJoseph Koshyoperation.
483f263522aSJoseph KoshyProcesses that intend to use RDPMC instructions directly or
484f263522aSJoseph Koshythat intend to write values larger than 2^31 into these PMCs with
485d9a5f346SJoseph Koshy.Dv PMC_OP_RW
486f263522aSJoseph Koshyneed to be aware of this hardware limitation.
487f263522aSJoseph Koshy.Sh DIAGNOSTICS
488f263522aSJoseph Koshy.Bl -diag
489953adc17SJoseph Koshy.It "hwpmc: [class/npmc/capabilities]..."
490953adc17SJoseph KoshyAnnounce the presence of
491953adc17SJoseph Koshy.Va npmc
492953adc17SJoseph KoshyPMCs of class
493953adc17SJoseph Koshy.Va class ,
494953adc17SJoseph Koshywith capabilities described by bit string
495953adc17SJoseph Koshy.Va capabilities .
496953adc17SJoseph Koshy.It "hwpmc: kernel version (0x%x) does not match module version (0x%x)."
497953adc17SJoseph KoshyThe module loading process failed because a version mismatch was detected
498953adc17SJoseph Koshybetween the currently executing kernel and the module being loaded.
4993419317cSJoseph Koshy.It "hwpmc: this kernel has not been compiled with 'options HWPMC_HOOKS'."
5003419317cSJoseph KoshyThe module loading process failed because the currently executing kernel
5013419317cSJoseph Koshywas not configured with the required configuration option
50278ad5421SRuslan Ermilov.Dv HWPMC_HOOKS .
503d9a5f346SJoseph Koshy.It "hwpmc: tunable hashsize=%d must be greater than zero."
504f263522aSJoseph KoshyA negative value was supplied for tunable
505f263522aSJoseph Koshy.Va kern.hwpmc.hashsize .
506d9a5f346SJoseph Koshy.It "hwpmc: tunable logbuffersize=%d must be greater than zero."
507f263522aSJoseph KoshyA negative value was supplied for tunable
508f263522aSJoseph Koshy.Va kern.hwpmc.logbuffersize .
509d9a5f346SJoseph Koshy.It "hwpmc: tunable nlogbuffers=%d must be greater than zero."
510f263522aSJoseph KoshyA negative value was supplied for tunable
511f263522aSJoseph Koshy.Va kern.hwpmc.nlogbuffers .
512d9a5f346SJoseph Koshy.It "hwpmc: tunable nsamples=%d out of range."
513f263522aSJoseph KoshyThe value for tunable
514f263522aSJoseph Koshy.Va kern.hwpmc.nsamples
515f263522aSJoseph Koshywas negative or greater than 65535.
516f263522aSJoseph Koshy.El
5176d6a103aSJoseph Koshy.Sh COMPATIBILITY
5186d6a103aSJoseph KoshyThe
5196d6a103aSJoseph Koshy.Nm
5206d6a103aSJoseph Koshydriver is
5216d6a103aSJoseph Koshy.Ud
5226d6a103aSJoseph KoshyThe API and ABI documented in this manual page may change in
5236d6a103aSJoseph Koshythe future.
5246d6a103aSJoseph KoshyThe recommended method of accessing this driver is using the
5256d6a103aSJoseph Koshy.Xr pmc 3
5266d6a103aSJoseph KoshyAPI.
527ebccf1e3SJoseph Koshy.Sh ERRORS
528d9a5f346SJoseph KoshyA command issued to the
529ebccf1e3SJoseph Koshy.Nm
530ebccf1e3SJoseph Koshydriver may fail with the following errors:
531ebccf1e3SJoseph Koshy.Bl -tag -width Er
532ebccf1e3SJoseph Koshy.It Bq Er EBUSY
533d9a5f346SJoseph KoshyA
534d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG
535ebccf1e3SJoseph Koshyoperation was requested while an existing log was active.
536ebccf1e3SJoseph Koshy.It Bq Er EBUSY
537d9a5f346SJoseph KoshyA DISABLE operation was requested using the
538d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
539ebccf1e3SJoseph Koshyrequest for a set of hardware resources currently in use for
540ebccf1e3SJoseph Koshyprocess-private PMCs.
541ebccf1e3SJoseph Koshy.It Bq Er EBUSY
542ebccf1e3SJoseph KoshyA
543d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
544ebccf1e3SJoseph Koshyoperation was requested on an active system mode PMC.
545ebccf1e3SJoseph Koshy.It Bq Er EBUSY
546ebccf1e3SJoseph KoshyA
547d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
548ebccf1e3SJoseph Koshyoperation was requested for a target process that already had another
549ebccf1e3SJoseph KoshyPMC using the same hardware resources attached to it.
550ebccf1e3SJoseph Koshy.It Bq Er EBUSY
551d9a5f346SJoseph KoshyA
552d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
553ebccf1e3SJoseph Koshyrequest writing a new value was issued on a PMC that was active.
554953adc17SJoseph Koshy.It Bq Er EBUSY
555953adc17SJoseph KoshyA
556953adc17SJoseph Koshy.Dv PMC_OP_PMCSETCOUNT
557953adc17SJoseph Koshyrequest was issued on a PMC that was active.
5583bc6c674SJoseph Koshy.It Bq Er EDOOFUS
5593bc6c674SJoseph KoshyA
560d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART
5613bc6c674SJoseph Koshyoperation was requested without a log file being configured for a
5623bc6c674SJoseph KoshyPMC allocated with
5633bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCCSW
5643bc6c674SJoseph Koshyand
5653bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT
5663bc6c674SJoseph Koshymodifiers.
567ebccf1e3SJoseph Koshy.It Bq Er EEXIST
568ebccf1e3SJoseph KoshyA
569d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
570ebccf1e3SJoseph Koshyrequest was reissued for a target process that already is the target
571ebccf1e3SJoseph Koshyof this PMC.
572ebccf1e3SJoseph Koshy.It Bq Er EFAULT
573ebccf1e3SJoseph KoshyA bad address was passed in to the driver.
574ebccf1e3SJoseph Koshy.It Bq Er EINVAL
575ebccf1e3SJoseph KoshyA process specified an invalid PMC handle.
576ebccf1e3SJoseph Koshy.It Bq Er EINVAL
577d9a5f346SJoseph KoshyAn invalid CPU number was passed in for a
578d9a5f346SJoseph Koshy.Dv PMC_OP_GETPMCINFO
579ebccf1e3SJoseph Koshyoperation.
580ebccf1e3SJoseph Koshy.It Bq Er EINVAL
581d9a5f346SJoseph KoshyAn invalid CPU number was passed in for a
582d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
583ebccf1e3SJoseph Koshyoperation.
584ebccf1e3SJoseph Koshy.It Bq Er EINVAL
585d9a5f346SJoseph KoshyAn invalid operation request was passed in for a
586d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
587ebccf1e3SJoseph Koshyoperation.
588ebccf1e3SJoseph Koshy.It Bq Er EINVAL
589d9a5f346SJoseph KoshyAn invalid PMC ID was passed in for a
590d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
591ebccf1e3SJoseph Koshyoperation.
592ebccf1e3SJoseph Koshy.It Bq Er EINVAL
593ebccf1e3SJoseph KoshyA suitable PMC matching the parameters passed in to a
594d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
595ebccf1e3SJoseph Koshyrequest could not be allocated.
596ebccf1e3SJoseph Koshy.It Bq Er EINVAL
597ebccf1e3SJoseph KoshyAn invalid PMC mode was requested during a
598d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
599ebccf1e3SJoseph Koshyrequest.
600ebccf1e3SJoseph Koshy.It Bq Er EINVAL
601ebccf1e3SJoseph KoshyAn invalid CPU number was specified during a
602d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
603ebccf1e3SJoseph Koshyrequest.
604ebccf1e3SJoseph Koshy.It Bq Er EINVAL
605d9a5f346SJoseph KoshyA CPU other than
606d9a5f346SJoseph Koshy.Dv PMC_CPU_ANY
607ebccf1e3SJoseph Koshywas specified in a
608d9a5f346SJoseph Koshy.Dv PMC_OP_ALLOCATE
609ebccf1e3SJoseph Koshyrequest for a process-private PMC.
610ebccf1e3SJoseph Koshy.It Bq Er EINVAL
611d9a5f346SJoseph KoshyA CPU number of
612d9a5f346SJoseph Koshy.Dv PMC_CPU_ANY
613ebccf1e3SJoseph Koshywas specified in a
614d9a5f346SJoseph Koshy.Dv PMC_OP_ALLOCATE
615ebccf1e3SJoseph Koshyrequest for a system-wide PMC.
616ebccf1e3SJoseph Koshy.It Bq Er EINVAL
617ebccf1e3SJoseph KoshyThe
618ebccf1e3SJoseph Koshy.Ar pm_flags
619ebccf1e3SJoseph Koshyargument to an
620d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
621ebccf1e3SJoseph Koshyrequest contained unknown flags.
622ebccf1e3SJoseph Koshy.It Bq Er EINVAL
623ebccf1e3SJoseph KoshyA PMC allocated for system-wide operation was specified with a
624d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
625ebccf1e3SJoseph Koshyrequest.
626ebccf1e3SJoseph Koshy.It Bq Er EINVAL
627ebccf1e3SJoseph KoshyThe
628ebccf1e3SJoseph Koshy.Ar pm_pid
629ebccf1e3SJoseph Koshyargument to a
630d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
631d9a5f346SJoseph Koshyrequest specified an illegal process ID.
632ebccf1e3SJoseph Koshy.It Bq Er EINVAL
633ebccf1e3SJoseph KoshyA
634d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH
635ebccf1e3SJoseph Koshyrequest was issued for a PMC not attached to the target process.
636ebccf1e3SJoseph Koshy.It Bq Er EINVAL
637ebccf1e3SJoseph KoshyArgument
638ebccf1e3SJoseph Koshy.Ar pm_flags
639ebccf1e3SJoseph Koshyto a
640d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW
641ebccf1e3SJoseph Koshyrequest contained illegal flags.
642ebccf1e3SJoseph Koshy.It Bq Er EINVAL
643ebccf1e3SJoseph KoshyA
644d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR
645c5153e19SJoseph Koshyoperation was requested for a PMC not in process-virtual mode, or
646c5153e19SJoseph Koshyfor a PMC that is not solely attached to its owner process, or for
647c5153e19SJoseph Koshya PMC that was allocated with flag
648d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS .
649ebccf1e3SJoseph Koshy.It Bq Er EINVAL
650d9a5f346SJoseph Koshy(On Intel Pentium 4 CPUs with HTT support)
651d9a5f346SJoseph KoshyAn allocation request for
652ebccf1e3SJoseph Koshya process-private PMC was issued for an event that does not support
653ebccf1e3SJoseph Koshycounting on a per-logical CPU basis.
654ebccf1e3SJoseph Koshy.It Bq Er ENOMEM
655ebccf1e3SJoseph KoshyThe system was not able to allocate kernel memory.
656ebccf1e3SJoseph Koshy.It Bq Er ENOSYS
657d9a5f346SJoseph Koshy(i386 architectures)
658d9a5f346SJoseph KoshyA
659d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR
660ebccf1e3SJoseph Koshyoperation was requested for hardware that does not support reading
661ebccf1e3SJoseph KoshyPMCs directly with the RDPMC instruction.
662ebccf1e3SJoseph Koshy.It Bq Er ENXIO
663d9a5f346SJoseph KoshyA
664d9a5f346SJoseph Koshy.Dv PMC_OP_GETPMCINFO
665ebccf1e3SJoseph Koshyoperation was requested for a disabled CPU.
666ebccf1e3SJoseph Koshy.It Bq Er ENXIO
667ebccf1e3SJoseph KoshyA system-wide PMC on a disabled CPU was requested to be allocated with
668d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE .
669ebccf1e3SJoseph Koshy.It Bq Er ENXIO
670ebccf1e3SJoseph KoshyA
671d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART
672ebccf1e3SJoseph Koshyor
673d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTOP
674ebccf1e3SJoseph Koshyrequest was issued for a system-wide PMC that was allocated on a
675ebccf1e3SJoseph Koshycurrently disabled CPU.
676953adc17SJoseph Koshy.It Bq Er EOPNOTSUPP
677953adc17SJoseph KoshyA
678953adc17SJoseph Koshy.Dv PMC_OP_PMCALLOCATE
679953adc17SJoseph Koshyrequest was issued for PMC capabilities not supported
680953adc17SJoseph Koshyby the specified PMC class.
681fe5ca00aSJoseph Koshy.It Bq Er EOPNOTSUPP
682fe5ca00aSJoseph Koshy(i386 architectures)
683fe5ca00aSJoseph KoshyA sampling mode PMC was requested on a CPU lacking an APIC.
684ebccf1e3SJoseph Koshy.It Bq Er EPERM
685d9a5f346SJoseph KoshyA
686d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN
687ebccf1e3SJoseph Koshyrequest was issued by a process without super-user
688ebccf1e3SJoseph Koshyprivilege or by a jailed super-user process.
689ebccf1e3SJoseph Koshy.It Bq Er EPERM
690d9a5f346SJoseph KoshyA
691d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
692ebccf1e3SJoseph Koshyoperation was issued for a target process that the current process
693ebccf1e3SJoseph Koshydoes not have permission to attach to.
694c5153e19SJoseph Koshy.It Bq Er EPERM
695d9a5f346SJoseph Koshy(i386 and amd64 architectures)
696d9a5f346SJoseph KoshyA
697d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
698c5153e19SJoseph Koshyoperation was issued on a PMC whose MSR has been retrieved using
699d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR .
700ebccf1e3SJoseph Koshy.It Bq Er ESRCH
701f263522aSJoseph KoshyA process issued a PMC operation request without having allocated any
702f263522aSJoseph KoshyPMCs.
703f263522aSJoseph Koshy.It Bq Er ESRCH
704f263522aSJoseph KoshyA process issued a PMC operation request after the PMC was detached
705f263522aSJoseph Koshyfrom all of its target processes.
706ebccf1e3SJoseph Koshy.It Bq Er ESRCH
707ebccf1e3SJoseph KoshyA
708d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH
709d9a5f346SJoseph Koshyrequest specified a non-existent process ID.
710ebccf1e3SJoseph Koshy.It Bq Er ESRCH
711ebccf1e3SJoseph KoshyThe target process for a
712d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH
713ebccf1e3SJoseph Koshyoperation is not being monitored by the
714ebccf1e3SJoseph Koshy.Nm
715ebccf1e3SJoseph Koshydriver.
716ebccf1e3SJoseph Koshy.El
717ebccf1e3SJoseph Koshy.Sh SEE ALSO
718ebccf1e3SJoseph Koshy.Xr kenv 1 ,
719ebccf1e3SJoseph Koshy.Xr pmc 3 ,
7206d6a103aSJoseph Koshy.Xr pmclog 3 ,
721f263522aSJoseph Koshy.Xr kgmon 8 ,
722ebccf1e3SJoseph Koshy.Xr kldload 8 ,
723ebccf1e3SJoseph Koshy.Xr pmccontrol 8 ,
724ebccf1e3SJoseph Koshy.Xr pmcstat 8 ,
725ebccf1e3SJoseph Koshy.Xr sysctl 8 ,
726ebccf1e3SJoseph Koshy.Xr p_candebug 9
7276d6a103aSJoseph Koshy.Sh HISTORY
7286d6a103aSJoseph KoshyThe
7296d6a103aSJoseph Koshy.Nm
7306d6a103aSJoseph Koshydriver first appeared in
7316d6a103aSJoseph Koshy.Fx 6.0 .
732d9a5f346SJoseph Koshy.Sh BUGS
733d9a5f346SJoseph KoshyThe driver samples the state of the kernel's logical processor support
734d9a5f346SJoseph Koshyat the time of initialization (i.e., at module load time).
735d9a5f346SJoseph KoshyOn CPUs supporting logical processors, the driver could misbehave if
736d9a5f346SJoseph Koshylogical processors are subsequently enabled or disabled while the
737d9a5f346SJoseph Koshydriver is active.
738953adc17SJoseph Koshy.Pp
73979247772SJoseph KoshyOn the i386 architecture, the driver requires that the local APIC on the
740953adc17SJoseph KoshyCPU be enabled for sampling mode to be supported.
741953adc17SJoseph KoshyMany single-processor motherboards keep the APIC disabled in BIOS; on
742953adc17SJoseph Koshysuch systems
743953adc17SJoseph Koshy.Nm
744953adc17SJoseph Koshywill not support sampling PMCs.
745