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 53ebccf1e3SJoseph Koshyrequest will return an integer handle (typically a small integer) to 54ebccf1e3SJoseph Koshythe requesting process. 55ebccf1e3SJoseph KoshySubsequent operations on the allocated PMC use this handle to denote 56ebccf1e3SJoseph Koshythe specific PMC. 57ebccf1e3SJoseph KoshyA process that has successfully allocated a PMC is termed an 58ebccf1e3SJoseph Koshy.Dq "owner process" . 59ebccf1e3SJoseph Koshy.Pp 60ebccf1e3SJoseph KoshyPMCs may be allocated to operate in process-private or in system-wide 61ebccf1e3SJoseph Koshymodes. 62d9a5f346SJoseph Koshy.Bl -tag -width ".Em Process-private" 63ebccf1e3SJoseph Koshy.It Em Process-private 64ebccf1e3SJoseph KoshyIn process-private mode, a PMC is active only when a thread belonging 65ebccf1e3SJoseph Koshyto a process it is attached to is scheduled on a CPU. 66ebccf1e3SJoseph Koshy.It Em System-wide 67d9a5f346SJoseph KoshyIn system-wide mode, a PMC operates independently of processes and 68ebccf1e3SJoseph Koshymeasures hardware events for the system as a whole. 69ebccf1e3SJoseph Koshy.El 70ebccf1e3SJoseph Koshy.Pp 71ebccf1e3SJoseph KoshyThe 72ebccf1e3SJoseph Koshy.Nm 73ebccf1e3SJoseph Koshydriver supports the use of hardware PMCs for counting or for 74ebccf1e3SJoseph Koshysampling: 75d9a5f346SJoseph Koshy.Bl -tag -width ".Em Counting" 766d6a103aSJoseph Koshy.It Em Counting 77ebccf1e3SJoseph KoshyIn counting modes, the PMCs count hardware events. 78ebccf1e3SJoseph KoshyThese counts are retrievable using the 79d9a5f346SJoseph Koshy.Dv PMC_OP_PMCREAD 80ebccf1e3SJoseph Koshysystem call on all architectures, though some architectures like the 8179247772SJoseph Koshyi386 and amd64 offer faster methods of reading these counts. 82ebccf1e3SJoseph Koshy.It Em Sampling 83ebccf1e3SJoseph KoshyIn sampling modes, where PMCs are configured to sample the CPU 84ebccf1e3SJoseph Koshyinstruction pointer after a configurable number of hardware events 85ebccf1e3SJoseph Koshyhave been observed. 86ebccf1e3SJoseph KoshyThese instruction pointer samples are directed to a log file for 87ebccf1e3SJoseph Koshysubsequent analysis. 88ebccf1e3SJoseph Koshy.El 89ebccf1e3SJoseph Koshy.Pp 90ebccf1e3SJoseph KoshyThese modes of operation are orthogonal; a PMC may be configured to 91ebccf1e3SJoseph Koshyoperate in one of four modes: 92ebccf1e3SJoseph Koshy.Bl -tag -width indent 93ebccf1e3SJoseph Koshy.It Process-private, counting 94ebccf1e3SJoseph KoshyThese PMCs count hardware events whenever a thread in their attached process is 95ebccf1e3SJoseph Koshyscheduled on a CPU. 96ebccf1e3SJoseph KoshyThese PMCs normally count from zero, but the initial count may be 97ebccf1e3SJoseph Koshyset using the 98d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT 99ebccf1e3SJoseph Koshyoperation. 100ebccf1e3SJoseph KoshyApplications can read the value of the PMC anytime using the 101d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW 102ebccf1e3SJoseph Koshyoperation. 103ebccf1e3SJoseph Koshy.It Process-private, sampling 104ebccf1e3SJoseph KoshyThese PMCs sample the target processes instruction pointer after they 105ebccf1e3SJoseph Koshyhave seen the configured number of hardware events. 106ebccf1e3SJoseph KoshyThe PMCs only count events when a thread belonging to their attached 107ebccf1e3SJoseph Koshyprocess is active. 108ebccf1e3SJoseph KoshyThe desired frequency of sampling is set using the 109d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT 110ebccf1e3SJoseph Koshyoperation prior to starting the PMC. 111ebccf1e3SJoseph KoshyLog files are configured using the 112d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG 113ebccf1e3SJoseph Koshyoperation. 114ebccf1e3SJoseph Koshy.It System-wide, counting 115ebccf1e3SJoseph KoshyThese PMCs count hardware events seen by them independent of the 116ebccf1e3SJoseph Koshyprocesses that are executing. 117ebccf1e3SJoseph KoshyThe current count on these PMCs can be read using the 118d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW 119ebccf1e3SJoseph Koshyrequest. 120ebccf1e3SJoseph KoshyThese PMCs normally count from zero, but the initial count may be 121ebccf1e3SJoseph Koshyset using the 122d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT 123ebccf1e3SJoseph Koshyoperation. 124ebccf1e3SJoseph Koshy.It System-wide, sampling 125ebccf1e3SJoseph KoshyThese PMCs will periodically sample the instruction pointer of the CPU 126ebccf1e3SJoseph Koshythey are allocated on, and will write the sample to a log for further 127ebccf1e3SJoseph Koshyprocessing. 128ebccf1e3SJoseph KoshyThe desired frequency of sampling is set using the 129d9a5f346SJoseph Koshy.Dv PMC_OP_SETCOUNT 130ebccf1e3SJoseph Koshyoperation prior to starting the PMC. 131ebccf1e3SJoseph KoshyLog files are configured using the 132d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG 133ebccf1e3SJoseph Koshyoperation. 134ebccf1e3SJoseph Koshy.Pp 135ebccf1e3SJoseph KoshySystem-wide statistical sampling can only be enabled by a process with 136ebccf1e3SJoseph Koshysuper-user privileges. 137ebccf1e3SJoseph Koshy.El 138ebccf1e3SJoseph Koshy.Pp 139ebccf1e3SJoseph KoshyProcesses are allowed to allocate as many PMCs are the hardware and 140ebccf1e3SJoseph Koshycurrent operating conditions permit. 141ebccf1e3SJoseph KoshyProcesses may mix allocations of system-wide and process-private 142ebccf1e3SJoseph KoshyPMCs. 143ebccf1e3SJoseph KoshyMultiple processes are allowed to be concurrently using the facilities 144ebccf1e3SJoseph Koshyof the 145ebccf1e3SJoseph Koshy.Nm 146ebccf1e3SJoseph Koshydriver. 147ebccf1e3SJoseph Koshy.Pp 148ebccf1e3SJoseph KoshyAllocated PMCs are started using the 149d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART 150ebccf1e3SJoseph Koshyoperation, and stopped using the 151d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTOP 152ebccf1e3SJoseph Koshyoperation. 153ebccf1e3SJoseph KoshyStopping and starting a PMC is permitted at any time the owner process 154ebccf1e3SJoseph Koshyhas a valid handle to the PMC. 155ebccf1e3SJoseph Koshy.Pp 156ebccf1e3SJoseph KoshyProcess-private PMCs need to be attached to a target process before 157ebccf1e3SJoseph Koshythey can be used. 158ebccf1e3SJoseph KoshyAttaching a process to a PMC is done using the 159d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH 160ebccf1e3SJoseph Koshyoperation. 161ebccf1e3SJoseph KoshyAn already attached PMC may be detached from its target process 162ebccf1e3SJoseph Koshyusing the converse 163d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH 164ebccf1e3SJoseph Koshyoperation. 165d9a5f346SJoseph KoshyIssuing a 166d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART 167ebccf1e3SJoseph Koshyoperation on an as yet unattached PMC will cause it to be attached 168ebccf1e3SJoseph Koshyto its owner process. 169ebccf1e3SJoseph KoshyThe following rules determine whether a given process may attach 170ebccf1e3SJoseph Koshya PMC to another target process: 171ebccf1e3SJoseph Koshy.Bl -bullet -compact 172ebccf1e3SJoseph Koshy.It 173ebccf1e3SJoseph KoshyA non-jailed process with super-user privileges is allowed to attach 174ebccf1e3SJoseph Koshyto any other process in the system. 175ebccf1e3SJoseph Koshy.It 176ebccf1e3SJoseph KoshyOther processes are only allowed to attach to targets that they would 177ebccf1e3SJoseph Koshybe able to attach to for debugging (as determined by 178ebccf1e3SJoseph Koshy.Xr p_candebug 9 ) . 179ebccf1e3SJoseph Koshy.El 180ebccf1e3SJoseph Koshy.Pp 181ebccf1e3SJoseph KoshyPMCs are released using 182d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRELEASE . 183ebccf1e3SJoseph KoshyAfter a successful 184d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRELEASE 185ebccf1e3SJoseph Koshyoperation the handle to the PMC will become invalid. 186d9a5f346SJoseph Koshy.Ss Modifier Flags 187ebccf1e3SJoseph KoshyThe 188d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE 189ebccf1e3SJoseph Koshyoperation supports the following flags that modify the behavior 190ebccf1e3SJoseph Koshyof an allocated PMC: 191d9a5f346SJoseph Koshy.Bl -tag -width indent 192ebccf1e3SJoseph Koshy.It Dv PMC_F_DESCENDANTS 193f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private 194ebccf1e3SJoseph Koshymode. 195ebccf1e3SJoseph KoshyIt signifies that the PMC will track hardware events for its 196ebccf1e3SJoseph Koshytarget process and the target's current and future descendants. 197f263522aSJoseph Koshy.It Dv PMC_F_KGMON 198f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in system-wide 199f263522aSJoseph Koshysampling mode. 200f263522aSJoseph KoshyIt signifies that the PMC's sampling interrupt is to be used to drive 201f263522aSJoseph Koshykernel profiling via 202f263522aSJoseph Koshy.Xr kgmon 8 . 203f263522aSJoseph Koshy.It Dv PMC_F_LOG_PROCCSW 204f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private 205f263522aSJoseph Koshymode. 2063bc6c674SJoseph KoshyWhen this modifier is present, at every context switch, 207f263522aSJoseph Koshy.Nm 2083bc6c674SJoseph Koshywill log a record containing the number of hardware events 2093bc6c674SJoseph Koshyseen by the target process when it was scheduled on the CPU. 210f263522aSJoseph Koshy.It Dv PMC_F_LOG_PROCEXIT 211f263522aSJoseph KoshyThis modifier is valid only for a PMC being allocated in process-private 212f263522aSJoseph Koshymode. 213f263522aSJoseph KoshyWith this modifier present, 214f263522aSJoseph Koshy.Nm 215f263522aSJoseph Koshywill maintain per-process counts for each target process attached to 216f263522aSJoseph Koshya PMC. 217d9a5f346SJoseph KoshyAt process exit time, a record containing the target process' PID and 218f263522aSJoseph Koshythe accumulated per-process count for that process will be written to the 219f263522aSJoseph Koshyconfigured log file. 220ebccf1e3SJoseph Koshy.El 221d9a5f346SJoseph Koshy.Pp 222f263522aSJoseph KoshyModifiers 223f263522aSJoseph Koshy.Dv PMC_F_LOG_PROCEXIT 224f263522aSJoseph Koshyand 225f263522aSJoseph Koshy.Dv PMC_F_LOG_PROCCSW 226f263522aSJoseph Koshymay be used in combination with modifier 227f263522aSJoseph Koshy.Dv PMC_F_DESCENDANTS 228f263522aSJoseph Koshyto track the behaviour of complex pipelines of processes. 2293bc6c674SJoseph KoshyPMCs with modifiers 2303bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT 2313bc6c674SJoseph Koshyand 2323bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCCSW 2333bc6c674SJoseph Koshycannot be started until their owner process has configured a log file. 234d9a5f346SJoseph Koshy.Ss Signals 235ebccf1e3SJoseph KoshyThe 236ebccf1e3SJoseph Koshy.Nm 237ebccf1e3SJoseph Koshydriver may deliver signals to processes that have allocated PMCs: 238d9a5f346SJoseph Koshy.Bl -tag -width ".Dv SIGBUS" 239d9a5f346SJoseph Koshy.It Dv SIGIO 240ebccf1e3SJoseph KoshyA 241d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW 242ebccf1e3SJoseph Koshyoperation was attempted on a process-private PMC that does not have 243ebccf1e3SJoseph Koshyattached target processes. 244d9a5f346SJoseph Koshy.It Dv SIGBUS 245ebccf1e3SJoseph KoshyThe 246ebccf1e3SJoseph Koshy.Nm 247ebccf1e3SJoseph Koshydriver is being unloaded from the kernel. 248ebccf1e3SJoseph Koshy.El 249ebccf1e3SJoseph Koshy.Sh PROGRAMMING API 250ebccf1e3SJoseph KoshyThe recommended way for application programs to use the facilities of 251ebccf1e3SJoseph Koshythe 252ebccf1e3SJoseph Koshy.Nm 253d9a5f346SJoseph Koshydriver is using the API provided by the 254d9a5f346SJoseph Koshy.Xr pmc 3 255d9a5f346SJoseph Koshylibrary. 256ebccf1e3SJoseph Koshy.Pp 257ebccf1e3SJoseph KoshyThe 258ebccf1e3SJoseph Koshy.Nm 259ebccf1e3SJoseph Koshydriver operates using a system call number that is dynamically 260ebccf1e3SJoseph Koshyallotted to it when it is loaded into the kernel. 261ebccf1e3SJoseph Koshy.Pp 262ebccf1e3SJoseph KoshyThe 263ebccf1e3SJoseph Koshy.Nm 264ebccf1e3SJoseph Koshydriver supports the following operations: 265ebccf1e3SJoseph Koshy.Bl -tag -width indent 266d9a5f346SJoseph Koshy.It Dv PMC_OP_CONFIGURELOG 267ebccf1e3SJoseph KoshyConfigure a log file for sampling mode PMCs. 268d9a5f346SJoseph Koshy.It Dv PMC_OP_FLUSHLOG 269f263522aSJoseph KoshyTransfer buffered log data inside 270f263522aSJoseph Koshy.Nm 271f263522aSJoseph Koshyto a configured output file. 272f263522aSJoseph KoshyThis operation returns to the caller after the write operation 273f263522aSJoseph Koshyhas returned. 274d9a5f346SJoseph Koshy.It Dv PMC_OP_GETCPUINFO 275ebccf1e3SJoseph KoshyRetrieve information about the number of CPUs on the system and 276ebccf1e3SJoseph Koshythe number of hardware performance monitoring counters available per-CPU. 277d9a5f346SJoseph Koshy.It Dv PMC_OP_GETDRIVERSTATS 278ebccf1e3SJoseph KoshyRetrieve module statistics (for analyzing the behavior of 279ebccf1e3SJoseph Koshy.Nm 280ebccf1e3SJoseph Koshyitself). 281d9a5f346SJoseph Koshy.It Dv PMC_OP_GETMODULEVERSION 282ebccf1e3SJoseph KoshyRetrieve the version number of API. 283d9a5f346SJoseph Koshy.It Dv PMC_OP_GETPMCINFO 284ebccf1e3SJoseph KoshyRetrieve information about the current state of the PMCs on a 285ebccf1e3SJoseph Koshygiven CPU. 286d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCADMIN 287ebccf1e3SJoseph KoshySet the administrative state (i.e., whether enabled or disabled) for 288ebccf1e3SJoseph Koshythe hardware PMCs managed by the 289ebccf1e3SJoseph Koshy.Nm 290ebccf1e3SJoseph Koshydriver. 291d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCALLOCATE 292ebccf1e3SJoseph KoshyAllocate and configure a PMC. 293ebccf1e3SJoseph KoshyOn successful allocation, a handle to the PMC (a small integer) 294ebccf1e3SJoseph Koshyis returned. 295d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCATTACH 296ebccf1e3SJoseph KoshyAttach a process mode PMC to a target process. 297ebccf1e3SJoseph KoshyThe PMC will be active whenever a thread in the target process is 298ebccf1e3SJoseph Koshyscheduled on a CPU. 299ebccf1e3SJoseph Koshy.Pp 300ebccf1e3SJoseph KoshyIf the 301ebccf1e3SJoseph Koshy.Dv PMC_F_DESCENDANTS 302ebccf1e3SJoseph Koshyflag had been specified at PMC allocation time, then the PMC is 303ebccf1e3SJoseph Koshyattached to all current and future descendants of the target process. 304d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCDETACH 305ebccf1e3SJoseph KoshyDetach a PMC from its target process. 306d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCRELEASE 307ebccf1e3SJoseph KoshyRelease a PMC. 308d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCRW 309ebccf1e3SJoseph KoshyRead and write a PMC. 310ebccf1e3SJoseph KoshyThis operation is valid only for PMCs configured in counting modes. 311d9a5f346SJoseph Koshy.It Dv PMC_OP_SETCOUNT 312ebccf1e3SJoseph KoshySet the initial count (for counting mode PMCs) or the desired sampling 313ebccf1e3SJoseph Koshyrate (for sampling mode PMCs). 314d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCSTART 315ebccf1e3SJoseph KoshyStart a PMC. 316d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCSTOP 317ebccf1e3SJoseph KoshyStop a PMC. 318d9a5f346SJoseph Koshy.It Dv PMC_OP_WRITELOG 319ebccf1e3SJoseph KoshyInsert a timestamped user record into the log file. 320ebccf1e3SJoseph Koshy.El 321d9a5f346SJoseph Koshy.Ss i386 Specific API 322ebccf1e3SJoseph KoshySome i386 family CPUs support the RDPMC instruction which allows a 323ebccf1e3SJoseph Koshyuser process to read a PMC value without needing to invoke a 324d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW 325ebccf1e3SJoseph Koshyoperation. 326ebccf1e3SJoseph KoshyOn such CPUs, the machine address associated with an allocated PMC is 327ebccf1e3SJoseph Koshyretrievable using the 328d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR 329ebccf1e3SJoseph Koshysystem call. 330ebccf1e3SJoseph Koshy.Bl -tag -width indent 331d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCX86GETMSR 332ebccf1e3SJoseph KoshyRetrieve the MSR (machine specific register) number associated with 333ebccf1e3SJoseph Koshythe given PMC handle. 334ebccf1e3SJoseph Koshy.Pp 335c5153e19SJoseph KoshyThe PMC needs to be in process-private mode and allocated without the 336d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS 337c5153e19SJoseph Koshymodifier flag, and should be attached only to its owner process at the 338c5153e19SJoseph Koshytime of the call. 339ebccf1e3SJoseph Koshy.El 340d9a5f346SJoseph Koshy.Ss amd64 Specific API 341d9a5f346SJoseph KoshyAMD64 CPUs support the RDPMC instruction which allows a 342ebccf1e3SJoseph Koshyuser process to read a PMC value without needing to invoke a 343d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW 344ebccf1e3SJoseph Koshyoperation. 345ebccf1e3SJoseph KoshyThe machine address associated with an allocated PMC is 346ebccf1e3SJoseph Koshyretrievable using the 347d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR 348ebccf1e3SJoseph Koshysystem call. 349ebccf1e3SJoseph Koshy.Bl -tag -width indent 350d9a5f346SJoseph Koshy.It Dv PMC_OP_PMCX86GETMSR 351ebccf1e3SJoseph KoshyRetrieve the MSR (machine specific register) number associated with 352ebccf1e3SJoseph Koshythe given PMC handle. 353ebccf1e3SJoseph Koshy.Pp 354c5153e19SJoseph KoshyThe PMC needs to be in process-private mode and allocated without the 355d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS 356c5153e19SJoseph Koshymodifier flag, and should be attached only to its owner process at the 357c5153e19SJoseph Koshytime of the call. 358ebccf1e3SJoseph Koshy.El 35944cb3ab0SHiroki Sato.Sh SYSCTL VARIABLES AND LOADER TUNABLES 360ebccf1e3SJoseph KoshyThe behavior of 361ebccf1e3SJoseph Koshy.Nm 362ebccf1e3SJoseph Koshyis influenced by the following 363ebccf1e3SJoseph Koshy.Xr sysctl 8 364f263522aSJoseph Koshyand 365f263522aSJoseph Koshy.Xr loader 8 366ebccf1e3SJoseph Koshytunables: 367ebccf1e3SJoseph Koshy.Bl -tag -width indent 368f263522aSJoseph Koshy.It Va kern.hwpmc.debugflags Pq string, read-write 369ebccf1e3SJoseph Koshy(Only available if the 370ebccf1e3SJoseph Koshy.Nm 371ebccf1e3SJoseph Koshydriver was compiled with 372d9a5f346SJoseph Koshy.Fl DDEBUG . ) 373ebccf1e3SJoseph KoshyControl the verbosity of debug messages from the 374ebccf1e3SJoseph Koshy.Nm 375ebccf1e3SJoseph Koshydriver. 376f263522aSJoseph Koshy.It Va kern.hwpmc.hashsize Pq integer, read-only 377d9a5f346SJoseph KoshyThe number of rows in the hash tables used to keep track of owner and 378ebccf1e3SJoseph Koshytarget processes. 379f263522aSJoseph KoshyThe default is 16. 380f263522aSJoseph Koshy.It Va kern.hwpmc.logbuffersize Pq integer, read-only 381f263522aSJoseph KoshyThe size in kilobytes of each log buffer used by 382d9a5f346SJoseph Koshy.Nm Ns 's 383f263522aSJoseph Koshylogging function. 38424bae989SJoseph KoshyThe default buffer size is 4KB. 385f263522aSJoseph Koshy.It Va kern.hwpmc.mtxpoolsize Pq integer, read-only 386ebccf1e3SJoseph KoshyThe size of the spin mutex pool used by the PMC driver. 387f263522aSJoseph KoshyThe default is 32. 388f263522aSJoseph Koshy.It Va kern.hwpmc.nbuffers Pq integer, read-only 389f263522aSJoseph KoshyThe number of log buffers used by 390f263522aSJoseph Koshy.Nm 391f263522aSJoseph Koshyfor logging. 392f263522aSJoseph KoshyThe default is 16. 393f263522aSJoseph Koshy.It Va kern.hwpmc.nsamples Pq integer, read-only 394d9a5f346SJoseph KoshyThe number of entries in the per-CPU ring buffer used during sampling. 395f263522aSJoseph KoshyThe default is 16. 396f263522aSJoseph Koshy.It Va security.bsd.unprivileged_syspmcs Pq boolean, read-write 397ebccf1e3SJoseph KoshyIf set to non-zero, allow unprivileged processes to allocate system-wide 398ebccf1e3SJoseph KoshyPMCs. 399ebccf1e3SJoseph KoshyThe default value is 0. 400f263522aSJoseph Koshy.It Va security.bsd.unprivileged_proc_debug Pq boolean, read-write 401ebccf1e3SJoseph KoshyIf set to 0, the 402ebccf1e3SJoseph Koshy.Nm 403f263522aSJoseph Koshydriver will only allow privileged processes to attach PMCs to other 404ebccf1e3SJoseph Koshyprocesses. 405ebccf1e3SJoseph Koshy.El 406ebccf1e3SJoseph Koshy.Pp 407ebccf1e3SJoseph KoshyThese variables may be set in the kernel environment using 408ebccf1e3SJoseph Koshy.Xr kenv 1 409ebccf1e3SJoseph Koshybefore 410ebccf1e3SJoseph Koshy.Nm 411ebccf1e3SJoseph Koshyis loaded. 412ebccf1e3SJoseph Koshy.Sh SECURITY CONSIDERATIONS 413ebccf1e3SJoseph KoshyPMCs may be used to monitor the actual behaviour of the system on hardware. 414ebccf1e3SJoseph KoshyIn situations where this constitutes an undesirable information leak, 415ebccf1e3SJoseph Koshythe following options are available: 416ebccf1e3SJoseph Koshy.Bl -enum 417ebccf1e3SJoseph Koshy.It 418ebccf1e3SJoseph KoshySet the 419ebccf1e3SJoseph Koshy.Xr sysctl 8 420ebccf1e3SJoseph Koshytunable 421d9a5f346SJoseph Koshy.Va security.bsd.unprivileged_syspmcs 422ebccf1e3SJoseph Koshyto 0. 423ebccf1e3SJoseph KoshyThis ensures that unprivileged processes cannot allocate system-wide 424ebccf1e3SJoseph KoshyPMCs and thus cannot observe the hardware behavior of the system 425ebccf1e3SJoseph Koshyas a whole. 426ebccf1e3SJoseph KoshyThis tunable may also be set at boot time using 427ebccf1e3SJoseph Koshy.Xr loader 8 , 428ebccf1e3SJoseph Koshyor with 429ebccf1e3SJoseph Koshy.Xr kenv 1 430ebccf1e3SJoseph Koshyprior to loading the 431ebccf1e3SJoseph Koshy.Nm 432ebccf1e3SJoseph Koshydriver into the kernel. 433ebccf1e3SJoseph Koshy.It 434ebccf1e3SJoseph KoshySet the 435ebccf1e3SJoseph Koshy.Xr sysctl 8 436ebccf1e3SJoseph Koshytunable 437d9a5f346SJoseph Koshy.Va security.bsd.unprivileged_proc_debug 438ebccf1e3SJoseph Koshyto 0. 439ebccf1e3SJoseph KoshyThis will ensure that an unprivileged process cannot attach a PMC 440ebccf1e3SJoseph Koshyto any process other than itself and thus cannot observe the hardware 441ebccf1e3SJoseph Koshybehavior of other processes with the same credentials. 442ebccf1e3SJoseph Koshy.El 443ebccf1e3SJoseph Koshy.Pp 444ebccf1e3SJoseph KoshySystem administrators should note that on IA-32 platforms 445ebccf1e3SJoseph Koshy.Fx 446ebccf1e3SJoseph Koshymakes the content of the IA-32 TSC counter available to all processes 447ebccf1e3SJoseph Koshyvia the RDTSC instruction. 448ebccf1e3SJoseph Koshy.Sh IMPLEMENTATION NOTES 449f263522aSJoseph Koshy.Ss SMP Symmetry 450f263522aSJoseph KoshyThe kernel driver requires all physical CPUs in an SMP system to have 451f263522aSJoseph Koshyidentical performance monitoring counter hardware. 45279247772SJoseph Koshy.Ss x86 TSC Handling 453ebccf1e3SJoseph KoshyHistorically, on the x86 architecture, 454ebccf1e3SJoseph Koshy.Fx 455ebccf1e3SJoseph Koshyhas permitted user processes running at a processor CPL of 3 to 456ebccf1e3SJoseph Koshyread the TSC using the RDTSC instruction. 457ebccf1e3SJoseph KoshyThe 458ebccf1e3SJoseph Koshy.Nm 459d9a5f346SJoseph Koshydriver preserves this semantics. 460ebccf1e3SJoseph Koshy.Ss Intel P4/HTT Handling 461ebccf1e3SJoseph KoshyOn CPUs with HTT support, Intel P4 PMCs are capable of qualifying 462ebccf1e3SJoseph Koshyonly a subset of hardware events on a per-logical CPU basis. 463ebccf1e3SJoseph KoshyConsequently, if HTT is enabled on a system with Intel Pentium P4 464ebccf1e3SJoseph KoshyPMCs, then the 465ebccf1e3SJoseph Koshy.Nm 466ebccf1e3SJoseph Koshydriver will reject allocation requests for process-private PMCs that 467ebccf1e3SJoseph Koshyrequest counting of hardware events that cannot be counted separately 468ebccf1e3SJoseph Koshyfor each logical CPU. 469f263522aSJoseph Koshy.Ss Intel Pentium-Pro Handling 470f263522aSJoseph KoshyWriting a value to the PMC MSRs found ing Intel Pentium-Pro style PMCs 471f263522aSJoseph Koshy(found in 472f263522aSJoseph Koshy.Tn "Intel Pentium Pro" , 473f263522aSJoseph Koshy.Tn "Pentium II" , 474f263522aSJoseph Koshy.Tn "Pentium III" , 475f263522aSJoseph Koshy.Tn "Pentium M" 476f263522aSJoseph Koshyand 477f263522aSJoseph Koshy.Tn "Celeron" 478f263522aSJoseph Koshyprocessors) will replicate bit 31 of the 479f263522aSJoseph Koshyvalue being written into the upper 8 bits of the MSR, 480f263522aSJoseph Koshybringing down the usable width of these PMCs to 31 bits. 481f263522aSJoseph KoshyFor process-virtual PMCs, the 482f263522aSJoseph Koshy.Nm 483f263522aSJoseph Koshydriver implements a workaround in software and makes the corrected 64 484f263522aSJoseph Koshybit count available via the 485d9a5f346SJoseph Koshy.Dv PMC_OP_RW 486f263522aSJoseph Koshyoperation. 487f263522aSJoseph KoshyProcesses that intend to use RDPMC instructions directly or 488f263522aSJoseph Koshythat intend to write values larger than 2^31 into these PMCs with 489d9a5f346SJoseph Koshy.Dv PMC_OP_RW 490f263522aSJoseph Koshyneed to be aware of this hardware limitation. 491f263522aSJoseph Koshy.Sh DIAGNOSTICS 492f263522aSJoseph Koshy.Bl -diag 493953adc17SJoseph Koshy.It "hwpmc: [class/npmc/capabilities]..." 494953adc17SJoseph KoshyAnnounce the presence of 495953adc17SJoseph Koshy.Va npmc 496953adc17SJoseph KoshyPMCs of class 497953adc17SJoseph Koshy.Va class , 498953adc17SJoseph Koshywith capabilities described by bit string 499953adc17SJoseph Koshy.Va capabilities . 500953adc17SJoseph Koshy.It "hwpmc: kernel version (0x%x) does not match module version (0x%x)." 501953adc17SJoseph KoshyThe module loading process failed because a version mismatch was detected 502953adc17SJoseph Koshybetween the currently executing kernel and the module being loaded. 5033419317cSJoseph Koshy.It "hwpmc: this kernel has not been compiled with 'options HWPMC_HOOKS'." 5043419317cSJoseph KoshyThe module loading process failed because the currently executing kernel 5053419317cSJoseph Koshywas not configured with the required configuration option 50678ad5421SRuslan Ermilov.Dv HWPMC_HOOKS . 507d9a5f346SJoseph Koshy.It "hwpmc: tunable hashsize=%d must be greater than zero." 508f263522aSJoseph KoshyA negative value was supplied for tunable 509f263522aSJoseph Koshy.Va kern.hwpmc.hashsize . 510d9a5f346SJoseph Koshy.It "hwpmc: tunable logbuffersize=%d must be greater than zero." 511f263522aSJoseph KoshyA negative value was supplied for tunable 512f263522aSJoseph Koshy.Va kern.hwpmc.logbuffersize . 513d9a5f346SJoseph Koshy.It "hwpmc: tunable nlogbuffers=%d must be greater than zero." 514f263522aSJoseph KoshyA negative value was supplied for tunable 515f263522aSJoseph Koshy.Va kern.hwpmc.nlogbuffers . 516d9a5f346SJoseph Koshy.It "hwpmc: tunable nsamples=%d out of range." 517f263522aSJoseph KoshyThe value for tunable 518f263522aSJoseph Koshy.Va kern.hwpmc.nsamples 519f263522aSJoseph Koshywas negative or greater than 65535. 520f263522aSJoseph Koshy.El 5216d6a103aSJoseph Koshy.Sh COMPATIBILITY 5226d6a103aSJoseph KoshyThe 5236d6a103aSJoseph Koshy.Nm 5246d6a103aSJoseph Koshydriver is 5256d6a103aSJoseph Koshy.Ud 5266d6a103aSJoseph KoshyThe API and ABI documented in this manual page may change in 5276d6a103aSJoseph Koshythe future. 5286d6a103aSJoseph KoshyThe recommended method of accessing this driver is using the 5296d6a103aSJoseph Koshy.Xr pmc 3 5306d6a103aSJoseph KoshyAPI. 531ebccf1e3SJoseph Koshy.Sh ERRORS 532d9a5f346SJoseph KoshyA command issued to the 533ebccf1e3SJoseph Koshy.Nm 534ebccf1e3SJoseph Koshydriver may fail with the following errors: 535ebccf1e3SJoseph Koshy.Bl -tag -width Er 536ebccf1e3SJoseph Koshy.It Bq Er EBUSY 537d9a5f346SJoseph KoshyA 538d9a5f346SJoseph Koshy.Dv PMC_OP_CONFIGURELOG 539ebccf1e3SJoseph Koshyoperation was requested while an existing log was active. 540ebccf1e3SJoseph Koshy.It Bq Er EBUSY 541d9a5f346SJoseph KoshyA DISABLE operation was requested using the 542d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN 543ebccf1e3SJoseph Koshyrequest for a set of hardware resources currently in use for 544ebccf1e3SJoseph Koshyprocess-private PMCs. 545ebccf1e3SJoseph Koshy.It Bq Er EBUSY 546ebccf1e3SJoseph KoshyA 547d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN 548ebccf1e3SJoseph Koshyoperation was requested on an active system mode PMC. 549ebccf1e3SJoseph Koshy.It Bq Er EBUSY 550ebccf1e3SJoseph KoshyA 551d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH 552ebccf1e3SJoseph Koshyoperation was requested for a target process that already had another 553ebccf1e3SJoseph KoshyPMC using the same hardware resources attached to it. 554ebccf1e3SJoseph Koshy.It Bq Er EBUSY 555d9a5f346SJoseph KoshyA 556d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW 557ebccf1e3SJoseph Koshyrequest writing a new value was issued on a PMC that was active. 558953adc17SJoseph Koshy.It Bq Er EBUSY 559953adc17SJoseph KoshyA 560953adc17SJoseph Koshy.Dv PMC_OP_PMCSETCOUNT 561953adc17SJoseph Koshyrequest was issued on a PMC that was active. 5623bc6c674SJoseph Koshy.It Bq Er EDOOFUS 5633bc6c674SJoseph KoshyA 564d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART 5653bc6c674SJoseph Koshyoperation was requested without a log file being configured for a 5663bc6c674SJoseph KoshyPMC allocated with 5673bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCCSW 5683bc6c674SJoseph Koshyand 5693bc6c674SJoseph Koshy.Dv PMC_F_LOG_PROCEXIT 5703bc6c674SJoseph Koshymodifiers. 571ebccf1e3SJoseph Koshy.It Bq Er EEXIST 572ebccf1e3SJoseph KoshyA 573d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH 574ebccf1e3SJoseph Koshyrequest was reissued for a target process that already is the target 575ebccf1e3SJoseph Koshyof this PMC. 576ebccf1e3SJoseph Koshy.It Bq Er EFAULT 577ebccf1e3SJoseph KoshyA bad address was passed in to the driver. 578ebccf1e3SJoseph Koshy.It Bq Er EINVAL 579ebccf1e3SJoseph KoshyA process specified an invalid PMC handle. 580ebccf1e3SJoseph Koshy.It Bq Er EINVAL 581d9a5f346SJoseph KoshyAn invalid CPU number was passed in for a 582d9a5f346SJoseph Koshy.Dv PMC_OP_GETPMCINFO 583ebccf1e3SJoseph Koshyoperation. 584ebccf1e3SJoseph Koshy.It Bq Er EINVAL 585d9a5f346SJoseph KoshyAn invalid CPU number was passed in for a 586d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN 587ebccf1e3SJoseph Koshyoperation. 588ebccf1e3SJoseph Koshy.It Bq Er EINVAL 589d9a5f346SJoseph KoshyAn invalid operation request was passed in for a 590d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN 591ebccf1e3SJoseph Koshyoperation. 592ebccf1e3SJoseph Koshy.It Bq Er EINVAL 593d9a5f346SJoseph KoshyAn invalid PMC ID was passed in for a 594d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN 595ebccf1e3SJoseph Koshyoperation. 596ebccf1e3SJoseph Koshy.It Bq Er EINVAL 597ebccf1e3SJoseph KoshyA suitable PMC matching the parameters passed in to a 598d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE 599ebccf1e3SJoseph Koshyrequest could not be allocated. 600ebccf1e3SJoseph Koshy.It Bq Er EINVAL 601ebccf1e3SJoseph KoshyAn invalid PMC mode was requested during a 602d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE 603ebccf1e3SJoseph Koshyrequest. 604ebccf1e3SJoseph Koshy.It Bq Er EINVAL 605ebccf1e3SJoseph KoshyAn invalid CPU number was specified during a 606d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE 607ebccf1e3SJoseph Koshyrequest. 608ebccf1e3SJoseph Koshy.It Bq Er EINVAL 609d9a5f346SJoseph KoshyA CPU other than 610d9a5f346SJoseph Koshy.Dv PMC_CPU_ANY 611ebccf1e3SJoseph Koshywas specified in a 612d9a5f346SJoseph Koshy.Dv PMC_OP_ALLOCATE 613ebccf1e3SJoseph Koshyrequest for a process-private PMC. 614ebccf1e3SJoseph Koshy.It Bq Er EINVAL 615d9a5f346SJoseph KoshyA CPU number of 616d9a5f346SJoseph Koshy.Dv PMC_CPU_ANY 617ebccf1e3SJoseph Koshywas specified in a 618d9a5f346SJoseph Koshy.Dv PMC_OP_ALLOCATE 619ebccf1e3SJoseph Koshyrequest for a system-wide PMC. 620ebccf1e3SJoseph Koshy.It Bq Er EINVAL 621ebccf1e3SJoseph KoshyThe 622ebccf1e3SJoseph Koshy.Ar pm_flags 623ebccf1e3SJoseph Koshyargument to an 624d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE 625ebccf1e3SJoseph Koshyrequest contained unknown flags. 626ebccf1e3SJoseph Koshy.It Bq Er EINVAL 627ebccf1e3SJoseph KoshyA PMC allocated for system-wide operation was specified with a 628d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH 629ebccf1e3SJoseph Koshyrequest. 630ebccf1e3SJoseph Koshy.It Bq Er EINVAL 631ebccf1e3SJoseph KoshyThe 632ebccf1e3SJoseph Koshy.Ar pm_pid 633ebccf1e3SJoseph Koshyargument to a 634d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH 635d9a5f346SJoseph Koshyrequest specified an illegal process ID. 636ebccf1e3SJoseph Koshy.It Bq Er EINVAL 637ebccf1e3SJoseph KoshyA 638d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH 639ebccf1e3SJoseph Koshyrequest was issued for a PMC not attached to the target process. 640ebccf1e3SJoseph Koshy.It Bq Er EINVAL 641ebccf1e3SJoseph KoshyArgument 642ebccf1e3SJoseph Koshy.Ar pm_flags 643ebccf1e3SJoseph Koshyto a 644d9a5f346SJoseph Koshy.Dv PMC_OP_PMCRW 645ebccf1e3SJoseph Koshyrequest contained illegal flags. 646ebccf1e3SJoseph Koshy.It Bq Er EINVAL 647ebccf1e3SJoseph KoshyA 648d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR 649c5153e19SJoseph Koshyoperation was requested for a PMC not in process-virtual mode, or 650c5153e19SJoseph Koshyfor a PMC that is not solely attached to its owner process, or for 651c5153e19SJoseph Koshya PMC that was allocated with flag 652d9a5f346SJoseph Koshy.Dv PMC_F_DESCENDANTS . 653ebccf1e3SJoseph Koshy.It Bq Er EINVAL 654d9a5f346SJoseph Koshy(On Intel Pentium 4 CPUs with HTT support) 655d9a5f346SJoseph KoshyAn allocation request for 656ebccf1e3SJoseph Koshya process-private PMC was issued for an event that does not support 657ebccf1e3SJoseph Koshycounting on a per-logical CPU basis. 658ebccf1e3SJoseph Koshy.It Bq Er ENOMEM 659ebccf1e3SJoseph KoshyThe system was not able to allocate kernel memory. 660ebccf1e3SJoseph Koshy.It Bq Er ENOSYS 661d9a5f346SJoseph Koshy(i386 architectures) 662d9a5f346SJoseph KoshyA 663d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR 664ebccf1e3SJoseph Koshyoperation was requested for hardware that does not support reading 665ebccf1e3SJoseph KoshyPMCs directly with the RDPMC instruction. 666ebccf1e3SJoseph Koshy.It Bq Er ENXIO 667d9a5f346SJoseph KoshyA 668d9a5f346SJoseph Koshy.Dv PMC_OP_GETPMCINFO 669ebccf1e3SJoseph Koshyoperation was requested for a disabled CPU. 670ebccf1e3SJoseph Koshy.It Bq Er ENXIO 671ebccf1e3SJoseph KoshyA system-wide PMC on a disabled CPU was requested to be allocated with 672d9a5f346SJoseph Koshy.Dv PMC_OP_PMCALLOCATE . 673ebccf1e3SJoseph Koshy.It Bq Er ENXIO 674ebccf1e3SJoseph KoshyA 675d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTART 676ebccf1e3SJoseph Koshyor 677d9a5f346SJoseph Koshy.Dv PMC_OP_PMCSTOP 678ebccf1e3SJoseph Koshyrequest was issued for a system-wide PMC that was allocated on a 679ebccf1e3SJoseph Koshycurrently disabled CPU. 680953adc17SJoseph Koshy.It Bq Er EOPNOTSUPP 681953adc17SJoseph KoshyA 682953adc17SJoseph Koshy.Dv PMC_OP_PMCALLOCATE 683953adc17SJoseph Koshyrequest was issued for PMC capabilities not supported 684953adc17SJoseph Koshyby the specified PMC class. 685ebccf1e3SJoseph Koshy.It Bq Er EPERM 686d9a5f346SJoseph KoshyA 687d9a5f346SJoseph Koshy.Dv PMC_OP_PMCADMIN 688ebccf1e3SJoseph Koshyrequest was issued by a process without super-user 689ebccf1e3SJoseph Koshyprivilege or by a jailed super-user process. 690ebccf1e3SJoseph Koshy.It Bq Er EPERM 691d9a5f346SJoseph KoshyA 692d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH 693ebccf1e3SJoseph Koshyoperation was issued for a target process that the current process 694ebccf1e3SJoseph Koshydoes not have permission to attach to. 695c5153e19SJoseph Koshy.It Bq Er EPERM 696d9a5f346SJoseph Koshy(i386 and amd64 architectures) 697d9a5f346SJoseph KoshyA 698d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH 699c5153e19SJoseph Koshyoperation was issued on a PMC whose MSR has been retrieved using 700d9a5f346SJoseph Koshy.Dv PMC_OP_PMCX86GETMSR . 701ebccf1e3SJoseph Koshy.It Bq Er ESRCH 702f263522aSJoseph KoshyA process issued a PMC operation request without having allocated any 703f263522aSJoseph KoshyPMCs. 704f263522aSJoseph Koshy.It Bq Er ESRCH 705f263522aSJoseph KoshyA process issued a PMC operation request after the PMC was detached 706f263522aSJoseph Koshyfrom all of its target processes. 707ebccf1e3SJoseph Koshy.It Bq Er ESRCH 708ebccf1e3SJoseph KoshyA 709d9a5f346SJoseph Koshy.Dv PMC_OP_PMCATTACH 710d9a5f346SJoseph Koshyrequest specified a non-existent process ID. 711ebccf1e3SJoseph Koshy.It Bq Er ESRCH 712ebccf1e3SJoseph KoshyThe target process for a 713d9a5f346SJoseph Koshy.Dv PMC_OP_PMCDETACH 714ebccf1e3SJoseph Koshyoperation is not being monitored by the 715ebccf1e3SJoseph Koshy.Nm 716ebccf1e3SJoseph Koshydriver. 717ebccf1e3SJoseph Koshy.El 718ebccf1e3SJoseph Koshy.Sh SEE ALSO 719ebccf1e3SJoseph Koshy.Xr kenv 1 , 720ebccf1e3SJoseph Koshy.Xr pmc 3 , 7216d6a103aSJoseph Koshy.Xr pmclog 3 , 722f263522aSJoseph Koshy.Xr kgmon 8 , 723ebccf1e3SJoseph Koshy.Xr kldload 8 , 724ebccf1e3SJoseph Koshy.Xr pmccontrol 8 , 725ebccf1e3SJoseph Koshy.Xr pmcstat 8 , 726ebccf1e3SJoseph Koshy.Xr sysctl 8 , 727ebccf1e3SJoseph Koshy.Xr p_candebug 9 7286d6a103aSJoseph Koshy.Sh HISTORY 7296d6a103aSJoseph KoshyThe 7306d6a103aSJoseph Koshy.Nm 7316d6a103aSJoseph Koshydriver first appeared in 7326d6a103aSJoseph Koshy.Fx 6.0 . 733d9a5f346SJoseph Koshy.Sh BUGS 734d9a5f346SJoseph KoshyThe driver samples the state of the kernel's logical processor support 735d9a5f346SJoseph Koshyat the time of initialization (i.e., at module load time). 736d9a5f346SJoseph KoshyOn CPUs supporting logical processors, the driver could misbehave if 737d9a5f346SJoseph Koshylogical processors are subsequently enabled or disabled while the 738d9a5f346SJoseph Koshydriver is active. 739953adc17SJoseph Koshy.Pp 74079247772SJoseph KoshyOn the i386 architecture, the driver requires that the local APIC on the 741953adc17SJoseph KoshyCPU be enabled for sampling mode to be supported. 742953adc17SJoseph KoshyMany single-processor motherboards keep the APIC disabled in BIOS; on 743953adc17SJoseph Koshysuch systems 744953adc17SJoseph Koshy.Nm 745953adc17SJoseph Koshywill not support sampling PMCs. 746