xref: /freebsd/share/man/man4/hwpmc.4 (revision 35a04710d7286aa9538917fd7f8e417dbee95b82)
1.\" Copyright (c) 2003-2007 Joseph Koshy
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd November 24, 2007
28.Dt HWPMC 4
29.Os
30.Sh NAME
31.Nm hwpmc
32.Nd "Hardware Performance Monitoring Counter support"
33.Sh SYNOPSIS
34.Cd "options HWPMC_HOOKS"
35.Cd "device hwpmc"
36.Pp
37Additionally, for i386 systems:
38.Cd "device apic"
39.Sh DESCRIPTION
40The
41.Nm
42driver virtualizes the hardware performance monitoring facilities in
43modern CPUs and provides support for using these facilities from
44user level processes.
45.Pp
46The driver supports multi-processor systems.
47.Pp
48PMCs are allocated using the
49.Dv PMC_OP_PMCALLOCATE
50request.
51A successful
52.Dv PMC_OP_PMCALLOCATE
53request will return a handle to the requesting process.
54Subsequent operations on the allocated PMC use this handle to denote
55the specific PMC.
56A process that has successfully allocated a PMC is termed an
57.Dq "owner process" .
58.Pp
59PMCs may be allocated with process or system scope.
60.Bl -tag -width ".Em Process-scope"
61.It Em "Process-scope"
62The PMC is active only when a thread belonging
63to a process it is attached to is scheduled on a CPU.
64.It Em "System-scope"
65The PMC operates independently of processes and
66measures hardware events for the system as a whole.
67.El
68.Pp
69PMCs may be allocated for counting or for sampling:
70.Bl -tag -width ".Em Counting"
71.It Em Counting
72In counting modes, the PMCs count hardware events.
73These counts are retrievable using the
74.Dv PMC_OP_PMCREAD
75system call on all architectures.
76Some architectures offer faster methods of reading these counts.
77.It Em Sampling
78In sampling modes, the PMCs are configured to sample the CPU
79instruction pointer after a configurable number of hardware events
80have been observed.
81These instruction pointer samples are usually directed to a log file
82for subsequent analysis.
83.El
84.Pp
85Scope and operational mode are orthogonal; a PMC may thus be
86configured to operate in one of the following four modes:
87.Bl -tag -width indent
88.It Process-scope, counting
89These PMCs count hardware events whenever a thread in their attached process is
90scheduled on a CPU.
91These PMCs normally count from zero, but the initial count may be
92set using the
93.Dv PMC_OP_SETCOUNT
94operation.
95Applications can read the value of the PMC anytime using the
96.Dv PMC_OP_PMCRW
97operation.
98.It Process-scope, sampling
99These PMCs sample the target processes instruction pointer after they
100have seen the configured number of hardware events.
101The PMCs only count events when a thread belonging to their attached
102process is active.
103The desired frequency of sampling is set using the
104.Dv PMC_OP_SETCOUNT
105operation prior to starting the PMC.
106Log files are configured using the
107.Dv PMC_OP_CONFIGURELOG
108operation.
109.It System-scope, counting
110These PMCs count hardware events seen by them independent of the
111processes that are executing.
112The current count on these PMCs can be read using the
113.Dv PMC_OP_PMCRW
114request.
115These PMCs normally count from zero, but the initial count may be
116set using the
117.Dv PMC_OP_SETCOUNT
118operation.
119.It System-scope, sampling
120These PMCs will periodically sample the instruction pointer of the CPU
121they are allocated on, and will write the sample to a log for further
122processing.
123The desired frequency of sampling is set using the
124.Dv PMC_OP_SETCOUNT
125operation prior to starting the PMC.
126Log files are configured using the
127.Dv PMC_OP_CONFIGURELOG
128operation.
129.Pp
130System-wide statistical sampling can only be enabled by a process with
131super-user privileges.
132.El
133.Pp
134Processes are allowed to allocate as many PMCs as the hardware and
135current operating conditions permit.
136Processes may mix allocations of system-wide and process-private
137PMCs.
138Multiple processes may be using PMCs simultaneously.
139.Pp
140Allocated PMCs are started using the
141.Dv PMC_OP_PMCSTART
142operation, and stopped using the
143.Dv PMC_OP_PMCSTOP
144operation.
145Stopping and starting a PMC is permitted at any time the owner process
146has a valid handle to the PMC.
147.Pp
148Process-private PMCs need to be attached to a target process before
149they can be used.
150Attaching a process to a PMC is done using the
151.Dv PMC_OP_PMCATTACH
152operation.
153An already attached PMC may be detached from its target process
154using the converse
155.Dv PMC_OP_PMCDETACH
156operation.
157Issuing a
158.Dv PMC_OP_PMCSTART
159operation on an as yet unattached PMC will cause it to be attached
160to its owner process.
161The following rules determine whether a given process may attach
162a PMC to another target process:
163.Bl -bullet -compact
164.It
165A non-jailed process with super-user privileges is allowed to attach
166to any other process in the system.
167.It
168Other processes are only allowed to attach to targets that they would
169be able to attach to for debugging (as determined by
170.Xr p_candebug 9 ) .
171.El
172.Pp
173PMCs are released using
174.Dv PMC_OP_PMCRELEASE .
175After a successful
176.Dv PMC_OP_PMCRELEASE
177operation the handle to the PMC will become invalid.
178.Ss Modifier Flags
179The
180.Dv PMC_OP_PMCALLOCATE
181operation supports the following flags that modify the behavior
182of an allocated PMC:
183.Bl -tag -width indent
184.It Dv PMC_F_DESCENDANTS
185This modifier is valid only for a PMC being allocated in process-private
186mode.
187It signifies that the PMC will track hardware events for its
188target process and the target's current and future descendants.
189.It Dv PMC_F_KGMON
190This modifier is valid only for a PMC being allocated in system-wide
191sampling mode.
192It signifies that the PMC's sampling interrupt is to be used to drive
193kernel profiling via
194.Xr kgmon 8 .
195This functionality is currently unimplemented.
196.It Dv PMC_F_LOG_PROCCSW
197This modifier is valid only for a PMC being allocated in process-private
198mode.
199When this modifier is present, at every context switch,
200.Nm
201will log a record containing the number of hardware events
202seen by the target process when it was scheduled on the CPU.
203.It Dv PMC_F_LOG_PROCEXIT
204This modifier is valid only for a PMC being allocated in process-private
205mode.
206With this modifier present,
207.Nm
208will maintain per-process counts for each target process attached to
209a PMC.
210At process exit time, a record containing the target process' PID and
211the accumulated per-process count for that process will be written to the
212configured log file.
213.El
214.Pp
215Modifiers
216.Dv PMC_F_LOG_PROCEXIT
217and
218.Dv PMC_F_LOG_PROCCSW
219may be used in combination with modifier
220.Dv PMC_F_DESCENDANTS
221to track the behavior of complex pipelines of processes.
222PMCs with modifiers
223.Dv PMC_F_LOG_PROCEXIT
224and
225.Dv PMC_F_LOG_PROCCSW
226cannot be started until their owner process has configured a log file.
227.Ss Signals
228The
229.Nm
230driver may deliver signals to processes that have allocated PMCs:
231.Bl -tag -width ".Dv SIGBUS"
232.It Dv SIGIO
233A
234.Dv PMC_OP_PMCRW
235operation was attempted on a process-private PMC that does not have
236attached target processes.
237.It Dv SIGBUS
238The
239.Nm
240driver is being unloaded from the kernel.
241.El
242.Ss PMC ROW DISPOSITIONS
243A PMC row is defined as the set of PMC resources at the same hardware
244address in the CPUs in a system.
245Since process scope PMCs need to move between CPUs following their
246target threads, allocation of a process scope PMC reserves all PMCs in
247a PMC row for use only with process scope PMCs.
248Accordingly a PMC row will be in one of the following dispositions:
249.Bl -tag -width ".Dv PMC_DISP_STANDALONE" -compact
250.It Dv PMC_DISP_FREE
251Hardware counters in this row are free and may be use to satisfy
252either of system scope or process scope allocation requests.
253.It Dv PMC_DISP_THREAD
254Hardware counters in this row are in use by process scope PMCs
255and are only available for process scope allocation requests.
256.It Dv PMC_DISP_STANDALONE
257Some hardware counters in this row have been administratively
258disabled or are in use by system scope PMCs.
259Non-disabled hardware counters in such a row may be used
260for satisfying system scope allocation requests.
261No process scope PMCs will use hardware counters in this row.
262.El
263.Sh PROGRAMMING API
264The recommended way for application programs to use the facilities of
265the
266.Nm
267driver is using the API provided by the
268.Xr pmc 3
269library.
270.Pp
271The
272.Nm
273driver operates using a system call number that is dynamically
274allotted to it when it is loaded into the kernel.
275.Pp
276The
277.Nm
278driver supports the following operations:
279.Bl -tag -width indent
280.It Dv PMC_OP_CONFIGURELOG
281Configure a log file for PMCs that require a log file.
282The
283.Nm
284driver will write log data to this file asynchronously.
285If it encounters an error, logging will be stopped and the error code
286encountered will be saved for subsequent retrieval by a
287.Dv PMC_OP_FLUSHLOG
288request.
289.It Dv PMC_OP_FLUSHLOG
290Transfer buffered log data inside
291.Nm
292to a configured output file.
293This operation returns to the caller after the write operation
294has returned.
295The returned error code reflects any pending error state inside
296.Nm .
297.It Dv PMC_OP_GETCPUINFO
298Retrieve information about the number of CPUs on the system and
299the number of hardware performance monitoring counters available per-CPU.
300.It Dv PMC_OP_GETDRIVERSTATS
301Retrieve module statistics (for analyzing the behavior of
302.Nm
303itself).
304.It Dv PMC_OP_GETMODULEVERSION
305Retrieve the version number of API.
306.It Dv PMC_OP_GETPMCINFO
307Retrieve information about the current state of the PMCs on a
308given CPU.
309.It Dv PMC_OP_PMCADMIN
310Set the administrative state (i.e., whether enabled or disabled) for
311the hardware PMCs managed by the
312.Nm
313driver.
314The invoking process needs to possess the
315.Dv PRIV_PMC_MANAGE
316privilege.
317.It Dv PMC_OP_PMCALLOCATE
318Allocate and configure a PMC.
319On successful allocation, a handle to the PMC (a 32 bit value)
320is returned.
321.It Dv PMC_OP_PMCATTACH
322Attach a process mode PMC to a target process.
323The PMC will be active whenever a thread in the target process is
324scheduled on a CPU.
325.Pp
326If the
327.Dv PMC_F_DESCENDANTS
328flag had been specified at PMC allocation time, then the PMC is
329attached to all current and future descendants of the target process.
330.It Dv PMC_OP_PMCDETACH
331Detach a PMC from its target process.
332.It Dv PMC_OP_PMCRELEASE
333Release a PMC.
334.It Dv PMC_OP_PMCRW
335Read and write a PMC.
336This operation is valid only for PMCs configured in counting modes.
337.It Dv PMC_OP_SETCOUNT
338Set the initial count (for counting mode PMCs) or the desired sampling
339rate (for sampling mode PMCs).
340.It Dv PMC_OP_PMCSTART
341Start a PMC.
342.It Dv PMC_OP_PMCSTOP
343Stop a PMC.
344.It Dv PMC_OP_WRITELOG
345Insert a timestamped user record into the log file.
346.El
347.Ss i386 Specific API
348Some i386 family CPUs support the RDPMC instruction which allows a
349user process to read a PMC value without needing to invoke a
350.Dv PMC_OP_PMCRW
351operation.
352On such CPUs, the machine address associated with an allocated PMC is
353retrievable using the
354.Dv PMC_OP_PMCX86GETMSR
355system call.
356.Bl -tag -width indent
357.It Dv PMC_OP_PMCX86GETMSR
358Retrieve the MSR (machine specific register) number associated with
359the given PMC handle.
360.Pp
361The PMC needs to be in process-private mode and allocated without the
362.Dv PMC_F_DESCENDANTS
363modifier flag, and should be attached only to its owner process at the
364time of the call.
365.El
366.Ss amd64 Specific API
367AMD64 CPUs support the RDPMC instruction which allows a
368user process to read a PMC value without needing to invoke a
369.Dv PMC_OP_PMCRW
370operation.
371The machine address associated with an allocated PMC is
372retrievable using the
373.Dv PMC_OP_PMCX86GETMSR
374system call.
375.Bl -tag -width indent
376.It Dv PMC_OP_PMCX86GETMSR
377Retrieve the MSR (machine specific register) number associated with
378the given PMC handle.
379.Pp
380The PMC needs to be in process-private mode and allocated without the
381.Dv PMC_F_DESCENDANTS
382modifier flag, and should be attached only to its owner process at the
383time of the call.
384.El
385.Sh SYSCTL VARIABLES AND LOADER TUNABLES
386The behavior of
387.Nm
388is influenced by the following
389.Xr sysctl 8
390and
391.Xr loader 8
392tunables:
393.Bl -tag -width indent
394.It Va kern.hwpmc.debugflags Pq string, read-write
395(Only available if the
396.Nm
397driver was compiled with
398.Fl DDEBUG . )
399Control the verbosity of debug messages from the
400.Nm
401driver.
402.It Va kern.hwpmc.hashsize Pq integer, read-only
403The number of rows in the hash tables used to keep track of owner and
404target processes.
405The default is 16.
406.It Va kern.hwpmc.logbuffersize Pq integer, read-only
407The size in kilobytes of each log buffer used by
408.Nm Ns 's
409logging function.
410The default buffer size is 4KB.
411.It Va kern.hwpmc.mtxpoolsize Pq integer, read-only
412The size of the spin mutex pool used by the PMC driver.
413The default is 32.
414.It Va kern.hwpmc.nbuffers Pq integer, read-only
415The number of log buffers used by
416.Nm
417for logging.
418The default is 16.
419.It Va kern.hwpmc.nsamples Pq integer, read-only
420The number of entries in the per-CPU ring buffer used during sampling.
421The default is 16.
422.It Va security.bsd.unprivileged_syspmcs Pq boolean, read-write
423If set to non-zero, allow unprivileged processes to allocate system-wide
424PMCs.
425The default value is 0.
426.It Va security.bsd.unprivileged_proc_debug Pq boolean, read-write
427If set to 0, the
428.Nm
429driver will only allow privileged processes to attach PMCs to other
430processes.
431.El
432.Pp
433These variables may be set in the kernel environment using
434.Xr kenv 1
435before
436.Nm
437is loaded.
438.Sh SECURITY CONSIDERATIONS
439PMCs may be used to monitor the actual behavior of the system on hardware.
440In situations where this constitutes an undesirable information leak,
441the following options are available:
442.Bl -enum
443.It
444Set the
445.Xr sysctl 8
446tunable
447.Va security.bsd.unprivileged_syspmcs
448to 0.
449This ensures that unprivileged processes cannot allocate system-wide
450PMCs and thus cannot observe the hardware behavior of the system
451as a whole.
452This tunable may also be set at boot time using
453.Xr loader 8 ,
454or with
455.Xr kenv 1
456prior to loading the
457.Nm
458driver into the kernel.
459.It
460Set the
461.Xr sysctl 8
462tunable
463.Va security.bsd.unprivileged_proc_debug
464to 0.
465This will ensure that an unprivileged process cannot attach a PMC
466to any process other than itself and thus cannot observe the hardware
467behavior of other processes with the same credentials.
468.El
469.Pp
470System administrators should note that on IA-32 platforms
471.Fx
472makes the content of the IA-32 TSC counter available to all processes
473via the RDTSC instruction.
474.Sh IMPLEMENTATION NOTES
475.Ss SMP Symmetry
476The kernel driver requires all physical CPUs in an SMP system to have
477identical performance monitoring counter hardware.
478.Ss x86 TSC Handling
479Historically, on the x86 architecture,
480.Fx
481has permitted user processes running at a processor CPL of 3 to
482read the TSC using the RDTSC instruction.
483The
484.Nm
485driver preserves this behavior.
486.Ss Intel P4/HTT Handling
487On CPUs with HTT support, Intel P4 PMCs are capable of qualifying
488only a subset of hardware events on a per-logical CPU basis.
489Consequently, if HTT is enabled on a system with Intel Pentium P4
490PMCs, then the
491.Nm
492driver will reject allocation requests for process-private PMCs that
493request counting of hardware events that cannot be counted separately
494for each logical CPU.
495.Ss Intel Pentium-Pro Handling
496Writing a value to the PMC MSRs found in Intel Pentium-Pro style PMCs
497(found in
498.Tn "Intel Pentium Pro" ,
499.Tn "Pentium II" ,
500.Tn "Pentium III" ,
501.Tn "Pentium M"
502and
503.Tn "Celeron"
504processors) will replicate bit 31 of the
505value being written into the upper 8 bits of the MSR,
506bringing down the usable width of these PMCs to 31 bits.
507For process-virtual PMCs, the
508.Nm
509driver implements a workaround in software and makes the corrected 64
510bit count available via the
511.Dv PMC_OP_RW
512operation.
513Processes that intend to use RDPMC instructions directly or
514that intend to write values larger than 2^31 into these PMCs with
515.Dv PMC_OP_RW
516need to be aware of this hardware limitation.
517.Sh DIAGNOSTICS
518.Bl -diag
519.It "hwpmc: [class/npmc/capabilities]..."
520Announce the presence of
521.Va npmc
522PMCs of class
523.Va class ,
524with capabilities described by bit string
525.Va capabilities .
526.It "hwpmc: kernel version (0x%x) does not match module version (0x%x)."
527The module loading process failed because a version mismatch was detected
528between the currently executing kernel and the module being loaded.
529.It "hwpmc: this kernel has not been compiled with 'options HWPMC_HOOKS'."
530The module loading process failed because the currently executing kernel
531was not configured with the required configuration option
532.Dv HWPMC_HOOKS .
533.It "hwpmc: tunable hashsize=%d must be greater than zero."
534A negative value was supplied for tunable
535.Va kern.hwpmc.hashsize .
536.It "hwpmc: tunable logbuffersize=%d must be greater than zero."
537A negative value was supplied for tunable
538.Va kern.hwpmc.logbuffersize .
539.It "hwpmc: tunable nlogbuffers=%d must be greater than zero."
540A negative value was supplied for tunable
541.Va kern.hwpmc.nlogbuffers .
542.It "hwpmc: tunable nsamples=%d out of range."
543The value for tunable
544.Va kern.hwpmc.nsamples
545was negative or greater than 65535.
546.El
547.Sh COMPATIBILITY
548The
549.Nm
550driver is
551.Ud
552The API and ABI documented in this manual page may change in
553the future.
554The recommended method of accessing this driver is using the
555.Xr pmc 3
556API.
557.Sh ERRORS
558A command issued to the
559.Nm
560driver may fail with the following errors:
561.Bl -tag -width Er
562.It Bq Er EAGAIN
563Helper process creation failed for a
564.Dv PMC_OP_CONFIGURELOG
565request due to a temporary resource shortage in the kernel.
566.It Bq Er EBUSY
567A
568.Dv PMC_OP_CONFIGURELOG
569operation was requested while an existing log was active.
570.It Bq Er EBUSY
571A DISABLE operation was requested using the
572.Dv PMC_OP_PMCADMIN
573request for a set of hardware resources currently in use for
574process-private PMCs.
575.It Bq Er EBUSY
576A
577.Dv PMC_OP_PMCADMIN
578operation was requested on an active system mode PMC.
579.It Bq Er EBUSY
580A
581.Dv PMC_OP_PMCATTACH
582operation was requested for a target process that already had another
583PMC using the same hardware resources attached to it.
584.It Bq Er EBUSY
585A
586.Dv PMC_OP_PMCRW
587request writing a new value was issued on a PMC that was active.
588.It Bq Er EBUSY
589A
590.Dv PMC_OP_PMCSETCOUNT
591request was issued on a PMC that was active.
592.It Bq Er EDOOFUS
593A
594.Dv PMC_OP_PMCSTART
595operation was requested without a log file being configured for a
596PMC allocated with
597.Dv PMC_F_LOG_PROCCSW
598and
599.Dv PMC_F_LOG_PROCEXIT
600modifiers.
601.It Bq Er EDOOFUS
602A
603.Dv PMC_OP_PMCSTART
604operation was requested on a system-wide sampling PMC without a log
605file being configured.
606.It Bq Er EEXIST
607A
608.Dv PMC_OP_PMCATTACH
609request was reissued for a target process that already is the target
610of this PMC.
611.It Bq Er EFAULT
612A bad address was passed in to the driver.
613.It Bq Er EINVAL
614An invalid PMC handle was specified.
615.It Bq Er EINVAL
616An invalid CPU number was passed in for a
617.Dv PMC_OP_GETPMCINFO
618operation.
619.It Bq Er EINVAL
620A
621.Dv PMC_OP_CONFIGURELOG
622request to de-configure a log file was issued without a log file
623being configured.
624.It Bq Er EINVAL
625A
626.Dv PMC_OP_FLUSHLOG
627request was issued without a log file being configured.
628.It Bq Er EINVAL
629An invalid CPU number was passed in for a
630.Dv PMC_OP_PMCADMIN
631operation.
632.It Bq Er EINVAL
633An invalid operation request was passed in for a
634.Dv PMC_OP_PMCADMIN
635operation.
636.It Bq Er EINVAL
637An invalid PMC ID was passed in for a
638.Dv PMC_OP_PMCADMIN
639operation.
640.It Bq Er EINVAL
641A suitable PMC matching the parameters passed in to a
642.Dv PMC_OP_PMCALLOCATE
643request could not be allocated.
644.It Bq Er EINVAL
645An invalid PMC mode was requested during a
646.Dv PMC_OP_PMCALLOCATE
647request.
648.It Bq Er EINVAL
649An invalid CPU number was specified during a
650.Dv PMC_OP_PMCALLOCATE
651request.
652.It Bq Er EINVAL
653A CPU other than
654.Dv PMC_CPU_ANY
655was specified in a
656.Dv PMC_OP_PMCALLOCATE
657request for a process-private PMC.
658.It Bq Er EINVAL
659A CPU number of
660.Dv PMC_CPU_ANY
661was specified in a
662.Dv PMC_OP_PMCALLOCATE
663request for a system-wide PMC.
664.It Bq Er EINVAL
665The
666.Ar pm_flags
667argument to an
668.Dv PMC_OP_PMCALLOCATE
669request contained unknown flags.
670.It Bq Er EINVAL
671(On Intel Pentium 4 CPUs with HTT support)
672A
673.Dv PMC_OP_PMCALLOCATE
674request for a process-private PMC was issued for an event that does
675not support counting on a per-logical CPU basis.
676.It Bq Er EINVAL
677A PMC allocated for system-wide operation was specified with a
678.Dv PMC_OP_PMCATTACH
679or
680.Dv PMC_OP_PMCDETACH
681request.
682.It Bq Er EINVAL
683The
684.Ar pm_pid
685argument to a
686.Dv PMC_OP_PMCATTACH
687or
688.Dv PMC_OP_PMCDETACH
689request specified an illegal process ID.
690.It Bq Er EINVAL
691A
692.Dv PMC_OP_PMCDETACH
693request was issued for a PMC not attached to the target process.
694.It Bq Er EINVAL
695Argument
696.Ar pm_flags
697to a
698.Dv PMC_OP_PMCRW
699request contained illegal flags.
700.It Bq Er EINVAL
701A
702.Dv PMC_OP_PMCX86GETMSR
703operation was requested for a PMC not in process-virtual mode, or
704for a PMC that is not solely attached to its owner process, or for
705a PMC that was allocated with flag
706.Dv PMC_F_DESCENDANTS .
707.It Bq Er EINVAL
708A
709.Dv PMC_OP_WRITELOG
710request was issued for an owner process without a log file
711configured.
712.It Bq Er ENOMEM
713The system was not able to allocate kernel memory.
714.It Bq Er ENOSYS
715(On i386 and amd64 architectures)
716A
717.Dv PMC_OP_PMCX86GETMSR
718operation was requested for hardware that does not support reading
719PMCs directly with the RDPMC instruction.
720.It Bq Er ENXIO
721A
722.Dv PMC_OP_GETPMCINFO
723operation was requested for a disabled CPU.
724.It Bq Er ENXIO
725A system-wide PMC on a disabled CPU was requested to be allocated with
726.Dv PMC_OP_PMCALLOCATE .
727.It Bq Er ENXIO
728A
729.Dv PMC_OP_PMCSTART
730or
731.Dv PMC_OP_PMCSTOP
732request was issued for a system-wide PMC that was allocated on a
733currently disabled CPU.
734.It Bq Er EOPNOTSUPP
735A
736.Dv PMC_OP_PMCALLOCATE
737request was issued for PMC capabilities not supported
738by the specified PMC class.
739.It Bq Er EOPNOTSUPP
740(i386 architectures)
741A sampling mode PMC was requested on a CPU lacking an APIC.
742.It Bq Er EPERM
743A
744.Dv PMC_OP_PMCADMIN
745request was issued by a process without super-user
746privilege or by a jailed super-user process.
747.It Bq Er EPERM
748A
749.Dv PMC_OP_PMCATTACH
750operation was issued for a target process that the current process
751does not have permission to attach to.
752.It Bq Er EPERM
753(i386 and amd64 architectures)
754A
755.Dv PMC_OP_PMCATTACH
756operation was issued on a PMC whose MSR has been retrieved using
757.Dv PMC_OP_PMCX86GETMSR .
758.It Bq Er ESRCH
759A process issued a PMC operation request without having allocated any
760PMCs.
761.It Bq Er ESRCH
762A process issued a PMC operation request after the PMC was detached
763from all of its target processes.
764.It Bq Er ESRCH
765A
766.Dv PMC_OP_PMCATTACH
767or
768.Dv PMC_OP_PMCDETACH
769request specified a non-existent process ID.
770.It Bq Er ESRCH
771The target process for a
772.Dv PMC_OP_PMCDETACH
773operation is not being monitored by
774.Nm .
775.El
776.Sh SEE ALSO
777.Xr kenv 1 ,
778.Xr pmc 3 ,
779.Xr pmclog 3 ,
780.Xr kgmon 8 ,
781.Xr kldload 8 ,
782.Xr pmccontrol 8 ,
783.Xr pmcstat 8 ,
784.Xr sysctl 8 ,
785.Xr kproc_create 9 ,
786.Xr p_candebug 9
787.Sh HISTORY
788The
789.Nm
790driver first appeared in
791.Fx 6.0 .
792.Sh AUTHORS
793The
794.Nm
795driver was written by
796.An "Joseph Koshy"
797.Aq jkoshy@FreeBSD.org .
798.Sh BUGS
799The driver samples the state of the kernel's logical processor support
800at the time of initialization (i.e., at module load time).
801On CPUs supporting logical processors, the driver could misbehave if
802logical processors are subsequently enabled or disabled while the
803driver is active.
804.Pp
805On the i386 architecture, the driver requires that the local APIC on the
806CPU be enabled for sampling mode to be supported.
807Many single-processor motherboards keep the APIC disabled in BIOS; on
808such systems
809.Nm
810will not support sampling PMCs.
811