1.\" Copyright (c) 2007-2008 Joseph Koshy. All rights reserved. 2.\" 3.\" Redistribution and use in source and binary forms, with or without 4.\" modification, are permitted provided that the following conditions 5.\" are met: 6.\" 1. Redistributions of source code must retain the above copyright 7.\" notice, this list of conditions and the following disclaimer. 8.\" 2. Redistributions in binary form must reproduce the above copyright 9.\" notice, this list of conditions and the following disclaimer in the 10.\" documentation and/or other materials provided with the distribution. 11.\" 12.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22.\" SUCH DAMAGE. 23.\" 24.Dd September 22, 2008 25.Dt PMC_CAPABILITIES 3 26.Os 27.Sh NAME 28.Nm pmc_capabilities , 29.Nm pmc_cpuinfo , 30.Nm pmc_ncpu , 31.Nm pmc_npmc , 32.Nm pmc_pmcinfo , 33.Nm pmc_width 34.Nd retrieve information about performance monitoring counters 35.Sh LIBRARY 36.Lb libpmc 37.Sh SYNOPSIS 38.In pmc.h 39.Ft int 40.Fn pmc_capabilities "pmc_id_t pmc" "uint32_t *caps" 41.Ft int 42.Fn pmc_cpuinfo "const struct pmc_cpuinfo **cpu_info" 43.Ft int 44.Fn pmc_ncpu void 45.Ft int 46.Fn pmc_npmc "int cpu" 47.Ft int 48.Fn pmc_pmcinfo "int cpu" "struct pmc_pmcinfo **pmc_info" 49.Ft int 50.Fn pmc_width "pmc_id_t pmc" "uint32_t *width" 51.Sh DESCRIPTION 52These functions retrieve information about performance monitoring 53hardware. 54.Pp 55Function 56.Fn pmc_capabilities 57retrieves the hardware capabilities of a PMC. 58Argument 59.Fa pmc 60is a PMC handle obtained by a prior call to 61.Fn pmc_allocate . 62The function sets argument 63.Fa caps 64to a bit mask of capabilities supported by the PMC denoted by 65argument 66.Fa pmc . 67PMC capabilities are described in 68.Xr pmc 3 . 69.Pp 70Function 71.Fn pmc_cpuinfo 72retrieves information about the CPUs in the system. 73Argument 74.Fa cpu_info 75will be set to point to an internal structure with information about 76the system's CPUs. 77The caller should not free this pointer value. 78This structure has the following fields: 79.Bl -tag -width "pm_classes" -offset indent -compact 80.It pm_cputype 81Specifies the CPU type. 82.It pm_ncpu 83Specifies the number of CPUs in the system. 84.It pm_npmc 85Specifies the number of PMC rows per CPU. 86.It pm_nclass 87Specifies the number of distinct classes of PMCs in the system. 88.It pm_classes 89Contains an array of 90.Vt "struct pmc_classinfo" 91descriptors describing the properties of each class of PMCs 92in the system. 93.El 94.Pp 95Function 96.Fn pmc_ncpu 97is a convenience function that returns the maximum CPU number in 98the system. 99On systems that support sparsely numbered CPUs, not all CPUs may 100be physically present. 101Applications need to be prepared to deal with nonexistent CPUs. 102.Pp 103Function 104.Fn pmc_npmc 105is a convenience function that returns the number of PMCs available 106in the CPU specified by argument 107.Fa cpu . 108.Pp 109Function 110.Fn pmc_pmcinfo 111returns information about the current state of the PMC hardware 112in the CPU specified by argument 113.Fa cpu . 114The location specified by argument 115.Fa pmc_info 116is set to point an array of 117.Vt "struct pmc_info" 118structures each describing the state of one PMC in the CPU. 119These structure contain the following fields: 120.Bl -tag -width pm_ownerpid -offset indent -compact 121.It pm_name 122A human readable name for the PMC. 123.It pm_class 124The PMC class for the PMC. 125.It pm_enabled 126Non-zero if the PMC is enabled. 127.It pm_rowdisp 128The disposition of the PMC row for this PMC. 129Row dispositions are documented in 130.Xr hwpmc 4 . 131.It pm_ownerpid 132If the hardware is in use, the process id of the owner of the PMC. 133.It pm_mode 134The PMC mode as described in 135.Xr pmc 3 . 136.It pm_event 137If the hardware is in use, the PMC event being measured. 138.It pm_flags 139If the hardware is in use, the flags associated with the PMC. 140.It pm_reloadcount 141For sampling PMCs, the reload count associated with the PMC. 142.El 143.Pp 144Function 145.Fn pmc_width 146is used to retrieve the width in bits of the hardware counters 147associated with a PMC. 148Argument 149.Fa pmc 150is a PMC handle obtained by a prior call to 151.Fn pmc_allocate . 152The function sets the location pointed to by argument 153.Fa width 154to the width of the physical counters associated with PMC 155.Fa pmc . 156.Sh RETURN VALUES 157Functions 158.Fn pmc_ncpu 159and 160.Fn pmc_npmc 161returns a positive integer if successful; otherwise the value -1 is 162returned and the global variable 163.Va errno 164is set to indicate the error. 165.Pp 166Functions 167.Fn pmc_capabilities , 168.Fn pmc_cpuinfo , 169.Fn pmc_pmcinfo 170and 171.Fn pmc_width 172return 0 if successful; otherwise the value -1 is returned and the 173global variable 174.Va errno 175is set to indicate the error. 176.Sh ERRORS 177A call to function 178.Fn pmc_capabilities 179may fail with the following errors: 180.Bl -tag -width Er 181.It Bq Er EINVAL 182The argument to the function was invalid. 183.El 184.Pp 185Calls to functions 186.Fn pmc_cpuinfo , 187.Fn pmc_ncpu 188and 189.Fn pmc_npmc 190may fail with the following errors: 191.Bl -tag -width Er 192.It Bq Er ENXIO 193A prior call to 194.Fn pmc_init 195to initialize the PMC library had failed. 196.El 197.Pp 198A call to function 199.Fn pmc_pmcinfo 200may fail with the following errors: 201.Bl -tag -width Er 202.It Bq Er EINVAL 203The argument 204.Fa cpu 205was invalid. 206.It Bq Er ENXIO 207The argument 208.Fa cpu 209specified a disabled or absent CPU. 210.El 211.Pp 212A call to function 213.Fn pmc_width 214may fail with the following errors: 215.Bl -tag -width Er 216.It Bq Er EINVAL 217The argument to the function was invalid. 218.El 219.Sh SEE ALSO 220.Xr pmc 3 , 221.Xr pmc_allocate 3 , 222.Xr pmc_get_driver_stats 3 , 223.Xr pmc_name_of_capability 3 , 224.Xr pmc_name_of_class 3 , 225.Xr pmc_name_of_cputype 3 , 226.Xr pmc_name_of_event 3 , 227.Xr pmc_name_of_mode 3 , 228.Xr hwpmc 4 229