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