1*2fe8fb19SBen Gras.\" $NetBSD: pmc_control.2,v 1.7 2005/10/31 11:34:16 wiz Exp $ 2*2fe8fb19SBen Gras.\" 3*2fe8fb19SBen Gras.\" Copyright (c) 2002 Wasabi Systems, Inc. 4*2fe8fb19SBen Gras.\" All rights reserved. 5*2fe8fb19SBen Gras.\" 6*2fe8fb19SBen Gras.\" Written by Allen Briggs for Wasabi Systems, Inc. 7*2fe8fb19SBen Gras.\" 8*2fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 9*2fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 10*2fe8fb19SBen Gras.\" are met: 11*2fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 12*2fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 13*2fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 14*2fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 15*2fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 16*2fe8fb19SBen Gras.\" 3. All advertising materials mentioning features or use of this software 17*2fe8fb19SBen Gras.\" must display the following acknowledgement: 18*2fe8fb19SBen Gras.\" This product includes software developed for the NetBSD Project by 19*2fe8fb19SBen Gras.\" Wasabi Systems, Inc. 20*2fe8fb19SBen Gras.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse 21*2fe8fb19SBen Gras.\" or promote products derived from this software without specific prior 22*2fe8fb19SBen Gras.\" written permission. 23*2fe8fb19SBen Gras.\" 24*2fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 25*2fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26*2fe8fb19SBen Gras.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27*2fe8fb19SBen Gras.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28*2fe8fb19SBen Gras.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29*2fe8fb19SBen Gras.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30*2fe8fb19SBen Gras.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31*2fe8fb19SBen Gras.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32*2fe8fb19SBen Gras.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33*2fe8fb19SBen Gras.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34*2fe8fb19SBen Gras.\" POSSIBILITY OF SUCH DAMAGE. 35*2fe8fb19SBen Gras.\" 36*2fe8fb19SBen Gras.Dd October 27, 2005 37*2fe8fb19SBen Gras.Dt PMC_CONTROL 2 38*2fe8fb19SBen Gras.Os 39*2fe8fb19SBen Gras.Sh NAME 40*2fe8fb19SBen Gras.Nm pmc_control , 41*2fe8fb19SBen Gras.Nm pmc_get_info 42*2fe8fb19SBen Gras.Nd Hardware Performance Monitoring Interface 43*2fe8fb19SBen Gras.Sh LIBRARY 44*2fe8fb19SBen Gras.Lb libc 45*2fe8fb19SBen Gras.Sh SYNOPSIS 46*2fe8fb19SBen Gras.In sys/pmc.h 47*2fe8fb19SBen Gras.Ft int 48*2fe8fb19SBen Gras.Fn pmc_control "int ctr" "int op" "void *argp" 49*2fe8fb19SBen Gras.Ft int 50*2fe8fb19SBen Gras.Fn pmc_get_info "int ctr" "int op" "void *argp" 51*2fe8fb19SBen Gras.Sh DESCRIPTION 52*2fe8fb19SBen Gras.Fn pmc_get_info 53*2fe8fb19SBen Grasreturns the number of counters in the system or information on a specified 54*2fe8fb19SBen Grascounter 55*2fe8fb19SBen Gras.Fa ctr . 56*2fe8fb19SBen GrasThe possible values for 57*2fe8fb19SBen Gras.Fa op 58*2fe8fb19SBen Grasare: 59*2fe8fb19SBen Gras.Bl -tag -width width 60*2fe8fb19SBen Gras.It Dv PMC_INFO_NCOUNTERS 61*2fe8fb19SBen GrasWhen querying the number of counters in the system, 62*2fe8fb19SBen Gras.Fa ctr 63*2fe8fb19SBen Grasis ignored and 64*2fe8fb19SBen Gras.Fa argp 65*2fe8fb19SBen Grasis of type 66*2fe8fb19SBen Gras.Ft int * . 67*2fe8fb19SBen GrasUpon return, the integer pointed to by 68*2fe8fb19SBen Gras.Fa argp 69*2fe8fb19SBen Graswill contain the number of counters that are available in the system. 70*2fe8fb19SBen Gras.It Dv PMC_INFO_CPUCTR_TYPE 71*2fe8fb19SBen GrasWhen querying the type of a counter in the system, 72*2fe8fb19SBen Gras.Fa ctr 73*2fe8fb19SBen Grasrefers to the counter being queried, and 74*2fe8fb19SBen Gras.Fa argp 75*2fe8fb19SBen Grasis of type 76*2fe8fb19SBen Gras.Ft int * . 77*2fe8fb19SBen GrasUpon return, the integer pointed to by 78*2fe8fb19SBen Gras.Fa argp 79*2fe8fb19SBen Graswill contain the implementation-dependent type of the specified counter. 80*2fe8fb19SBen Gras.Pp 81*2fe8fb19SBen GrasIf 82*2fe8fb19SBen Gras.Fa ctr 83*2fe8fb19SBen Grasis \-1, the integer pointed to by 84*2fe8fb19SBen Gras.Fa argp 85*2fe8fb19SBen Graswill contain the machine-dependent type 86*2fe8fb19SBen Grasdescribing the CPU or counter configuration. 87*2fe8fb19SBen Gras.It Dv PMC_INFO_COUNTER_VALUE 88*2fe8fb19SBen GrasWhen querying the value of a counter in the system, 89*2fe8fb19SBen Gras.Fa ctr 90*2fe8fb19SBen Grasrefers to the counter being queried, and 91*2fe8fb19SBen Gras.Fa argp 92*2fe8fb19SBen Grasis of type 93*2fe8fb19SBen Gras.Ft uint64_t * . 94*2fe8fb19SBen GrasUpon return, the 64-bit integer pointed to by 95*2fe8fb19SBen Gras.Fa argp 96*2fe8fb19SBen Graswill contain the value of the specified counter. 97*2fe8fb19SBen Gras.It Dv PMC_INFO_ACCUMULATED_COUNTER_VALUE 98*2fe8fb19SBen GrasWhen querying the value of a counter in the system, 99*2fe8fb19SBen Gras.Fa ctr 100*2fe8fb19SBen Grasrefers to the counter being queried, and 101*2fe8fb19SBen Gras.Fa argp 102*2fe8fb19SBen Grasis of type 103*2fe8fb19SBen Gras.Ft uint64_t * . 104*2fe8fb19SBen GrasUpon return, the 64-bit integer pointed to by 105*2fe8fb19SBen Gras.Fa argp 106*2fe8fb19SBen Graswill contain the sum of the accumulated values of specified counter in 107*2fe8fb19SBen Grasall exited subprocesses of the current process. 108*2fe8fb19SBen Gras.El 109*2fe8fb19SBen Gras.Pp 110*2fe8fb19SBen Gras.Fn pmc_control 111*2fe8fb19SBen Grasmanipulates the specified counter 112*2fe8fb19SBen Gras.Fa ctr 113*2fe8fb19SBen Grasin one of several fashions. 114*2fe8fb19SBen GrasThe 115*2fe8fb19SBen Gras.Fa op 116*2fe8fb19SBen Grasparameter determines the action taken by the kernel and also the interpretation of the 117*2fe8fb19SBen Gras.Fa argp 118*2fe8fb19SBen Grasparameter. 119*2fe8fb19SBen GrasThe possible values for 120*2fe8fb19SBen Gras.Fa op 121*2fe8fb19SBen Grasare: 122*2fe8fb19SBen Gras.Bl -tag -width width 123*2fe8fb19SBen Gras.It Dv PMC_OP_START 124*2fe8fb19SBen GrasStarts the specified 125*2fe8fb19SBen Gras.Fa ctr 126*2fe8fb19SBen Grasrunning. 127*2fe8fb19SBen GrasIt must be preceded by a call with 128*2fe8fb19SBen Gras.Dv PMC_OP_CONFIGURE . 129*2fe8fb19SBen Gras.Fa argp 130*2fe8fb19SBen Grasis ignored in this case and may be 131*2fe8fb19SBen Gras.Dv NULL . 132*2fe8fb19SBen Gras.It Dv PMC_OP_STOP 133*2fe8fb19SBen GrasStops the specified 134*2fe8fb19SBen Gras.Fa ctr 135*2fe8fb19SBen Grasfrom running. 136*2fe8fb19SBen Gras.Fa argp 137*2fe8fb19SBen Grasis ignored in this case and may be 138*2fe8fb19SBen Gras.Dv NULL . 139*2fe8fb19SBen Gras.It Dv PMC_OP_CONFIGURE 140*2fe8fb19SBen GrasConfigures the specified 141*2fe8fb19SBen Gras.Fa ctr 142*2fe8fb19SBen Grasprior to running. 143*2fe8fb19SBen Gras.Fa argp 144*2fe8fb19SBen Grasis a pointer to a 145*2fe8fb19SBen Gras.Ft struct pmc_counter_cfg . 146*2fe8fb19SBen Gras.Bd -literal 147*2fe8fb19SBen Gras struct pmc_counter_cfg { 148*2fe8fb19SBen Gras pmc_evid_t event_id; 149*2fe8fb19SBen Gras pmc_ctr_t reset_value; 150*2fe8fb19SBen Gras uint32_t flags; 151*2fe8fb19SBen Gras }; 152*2fe8fb19SBen Gras.Ed 153*2fe8fb19SBen Gras.Bl -tag -width width 154*2fe8fb19SBen Gras.It Dv event_id 155*2fe8fb19SBen Grasis the event ID to be counted. 156*2fe8fb19SBen Gras.It Dv reset_value 157*2fe8fb19SBen Grasis a value to which the counter should be reset on overflow (if supported 158*2fe8fb19SBen Grasby the implementation). 159*2fe8fb19SBen GrasThis is most useful when profiling (see 160*2fe8fb19SBen Gras.Dv PMC_OP_PROFSTART , 161*2fe8fb19SBen Grasbelow). 162*2fe8fb19SBen GrasThis value is defined to be the number of counter ticks before 163*2fe8fb19SBen Grasthe next overflow. 164*2fe8fb19SBen GrasSo, to get a profiling tick on every hundredth data cache miss, set the 165*2fe8fb19SBen Gras.Dv event_id 166*2fe8fb19SBen Grasto the proper value for 167*2fe8fb19SBen Gras.Dq dcache-miss 168*2fe8fb19SBen Grasand set 169*2fe8fb19SBen Gras.Dv reset_value 170*2fe8fb19SBen Grasto 100. 171*2fe8fb19SBen Gras.It Dv flags 172*2fe8fb19SBen GrasCurrently unused. 173*2fe8fb19SBen Gras.El 174*2fe8fb19SBen Gras.It Dv PMC_OP_PROFSTART 175*2fe8fb19SBen GrasConfigures the specified 176*2fe8fb19SBen Gras.Fa ctr 177*2fe8fb19SBen Grasfor use in profiling. 178*2fe8fb19SBen Gras.Fa argp 179*2fe8fb19SBen Grasis a pointer to a 180*2fe8fb19SBen Gras.Ft struct pmc_counter_cfg 181*2fe8fb19SBen Grasas in 182*2fe8fb19SBen Gras.Dv PMC_OP_CONFIGURE , 183*2fe8fb19SBen Grasabove. 184*2fe8fb19SBen GrasThis request allocates a kernel counter, which will fail if any 185*2fe8fb19SBen Grasprocess is using the requested counter. 186*2fe8fb19SBen GrasNot all implementations or counters may support this option. 187*2fe8fb19SBen Gras.It Dv PMC_OP_PROFSTOP 188*2fe8fb19SBen GrasStops the specified 189*2fe8fb19SBen Gras.Fa ctr 190*2fe8fb19SBen Grasfrom being used for profiling. 191*2fe8fb19SBen Gras.Fa argp 192*2fe8fb19SBen Grasis ignored in this case and may be 193*2fe8fb19SBen Gras.Dv NULL . 194*2fe8fb19SBen Gras.El 195*2fe8fb19SBen Gras.Sh RETURN VALUES 196*2fe8fb19SBen GrasA return value of 0 indicates that the call succeeded. 197*2fe8fb19SBen GrasOtherwise, \-1 is returned and the global variable 198*2fe8fb19SBen Gras.Va errno 199*2fe8fb19SBen Grasis set to indicate the error. 200*2fe8fb19SBen Gras.Sh ERRORS 201*2fe8fb19SBen GrasAmong the possible error codes from 202*2fe8fb19SBen Gras.Fn pmc_control 203*2fe8fb19SBen Grasand 204*2fe8fb19SBen Gras.Fn pmc_get_info 205*2fe8fb19SBen Grasare 206*2fe8fb19SBen Gras.Bl -tag -width Er 207*2fe8fb19SBen Gras.It Bq Er EFAULT 208*2fe8fb19SBen GrasThe address specified for the 209*2fe8fb19SBen Gras.Fa argp 210*2fe8fb19SBen Grasis invalid. 211*2fe8fb19SBen Gras.It Bq Er ENXIO 212*2fe8fb19SBen GrasSpecified counter is not yet configured. 213*2fe8fb19SBen Gras.It Bq Er EINPROGRESS 214*2fe8fb19SBen Gras.Dv PMC_OP_START 215*2fe8fb19SBen Graswas passed for a counter that is already running. 216*2fe8fb19SBen Gras.It Bq Er EINVAL 217*2fe8fb19SBen GrasSpecified counter was invalid. 218*2fe8fb19SBen Gras.It Bq Er EBUSY 219*2fe8fb19SBen GrasIf the requested counter is already in use--either by the current process 220*2fe8fb19SBen Grasor by the kernel. 221*2fe8fb19SBen Gras.It Bq Er ENODEV 222*2fe8fb19SBen GrasIf and only if the specified counter event is not valid for the specified 223*2fe8fb19SBen Grascounter when configuring a counter or starting profiling. 224*2fe8fb19SBen Gras.It Bq Er ENOMEM 225*2fe8fb19SBen GrasIf the kernel is unable to allocate memory. 226*2fe8fb19SBen Gras.El 227*2fe8fb19SBen Gras.Sh SEE ALSO 228*2fe8fb19SBen Gras.Xr pmc 1 , 229*2fe8fb19SBen Gras.Xr pmc 9 230*2fe8fb19SBen Gras.Sh HISTORY 231*2fe8fb19SBen GrasThe 232*2fe8fb19SBen Gras.Fn pmc_control 233*2fe8fb19SBen Grasand 234*2fe8fb19SBen Gras.Fn pmc_get_info 235*2fe8fb19SBen Grassystem calls appeared in 236*2fe8fb19SBen Gras.Nx 2.0 . 237