xref: /freebsd/lib/libpmc/pmc_capabilities.3 (revision 026dbd291e755e792b8427a9f84ad107e2d1470c)
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.\" $FreeBSD$
25.\"
26.Dd September 22, 2008
27.Dt PMC_CAPABILITIES 3
28.Os
29.Sh NAME
30.Nm pmc_capabilities ,
31.Nm pmc_cpuinfo ,
32.Nm pmc_ncpu ,
33.Nm pmc_npmc ,
34.Nm pmc_pmcinfo ,
35.Nm pmc_width
36.Nd retrieve information about performance monitoring counters
37.Sh LIBRARY
38.Lb libpmc
39.Sh SYNOPSIS
40.In pmc.h
41.Ft int
42.Fn pmc_capabilities "pmc_id_t pmc" "uint32_t *caps"
43.Ft int
44.Fn pmc_cpuinfo "const struct pmc_cpuinfo **cpu_info"
45.Ft int
46.Fn pmc_ncpu void
47.Ft int
48.Fn pmc_npmc "int cpu"
49.Ft int
50.Fn pmc_pmcinfo "int cpu" "struct pmc_pmcinfo **pmc_info"
51.Ft int
52.Fn pmc_width "pmc_id_t pmc" "uint32_t *width"
53.Sh DESCRIPTION
54These functions retrieve information about performance monitoring
55hardware.
56.Pp
57Function
58.Fn pmc_capabilities
59retrieves the hardware capabilities of a PMC.
60Argument
61.Fa pmc
62is a PMC handle obtained by a prior call to
63.Fn pmc_allocate .
64The function sets argument
65.Fa caps
66to a bit mask of capabilities supported by the PMC denoted by
67argument
68.Fa pmc .
69PMC capabilities are described in
70.Xr pmc 3 .
71.Pp
72Function
73.Fn pmc_cpuinfo
74retrieves information about the CPUs in the system.
75Argument
76.Fa cpu_info
77will be set to point to an internal structure with information about
78the system's CPUs.
79The caller should not free this pointer value.
80This structure has the following fields:
81.Bl -tag -width "pm_classes" -offset indent -compact
82.It pm_cputype
83Specifies the CPU type.
84.It pm_ncpu
85Specifies the number of CPUs in the system.
86.It pm_npmc
87Specifies the number of PMC rows per CPU.
88.It pm_nclass
89Specifies the number of distinct classes of PMCs in the system.
90.It pm_classes
91Contains an array of
92.Vt "struct pmc_classinfo"
93descriptors describing the properties of each class of PMCs
94in the system.
95.El
96.Pp
97Function
98.Fn pmc_ncpu
99is a convenience function that returns the maximum CPU number in
100the system.
101On systems that support sparsely numbered CPUs, not all CPUs may
102be physically present.
103Applications need to be prepared to deal with nonexistent CPUs.
104.Pp
105Function
106.Fn pmc_npmc
107is a convenience function that returns the number of PMCs available
108in the CPU specified by argument
109.Fa cpu .
110.Pp
111Function
112.Fn pmc_pmcinfo
113returns information about the current state of the PMC hardware
114in the CPU specified by argument
115.Fa cpu .
116The location specified by argument
117.Fa pmc_info
118is set to point an array of
119.Vt "struct pmc_info"
120structures each describing the state of one PMC in the CPU.
121These structure contain the following fields:
122.Bl -tag -width pm_ownerpid -offset indent -compact
123.It pm_name
124A human readable name for the PMC.
125.It pm_class
126The PMC class for the PMC.
127.It pm_enabled
128Non-zero if the PMC is enabled.
129.It pm_rowdisp
130The disposition of the PMC row for this PMC.
131Row dispositions are documented in
132.Xr hwpmc 4 .
133.It pm_ownerpid
134If the hardware is in use, the process id of the owner of the PMC.
135.It pm_mode
136The PMC mode as described in
137.Xr pmc 3 .
138.It pm_event
139If the hardware is in use, the PMC event being measured.
140.It pm_flags
141If the hardware is in use, the flags associated with the PMC.
142.It pm_reloadcount
143For sampling PMCs, the reload count associated with the PMC.
144.El
145.Pp
146Function
147.Fn pmc_width
148is used to retrieve the width in bits of the hardware counters
149associated with a PMC.
150Argument
151.Fa pmc
152is a PMC handle obtained by a prior call to
153.Fn pmc_allocate .
154The function sets the location pointed to by argument
155.Fa width
156to the width of the physical counters associated with PMC
157.Fa pmc .
158.Sh RETURN VALUES
159Functions
160.Fn pmc_ncpu
161and
162.Fn pmc_npmc
163returns a positive integer if successful; otherwise the value -1 is
164returned and the global variable
165.Va errno
166is set to indicate the error.
167.Pp
168Functions
169.Fn pmc_capabilities ,
170.Fn pmc_cpuinfo ,
171.Fn pmc_pmcinfo
172and
173.Fn pmc_width
174return 0 if successful; otherwise the value -1 is returned and the
175global variable
176.Va errno
177is set to indicate the error.
178.Sh ERRORS
179A call to function
180.Fn pmc_capabilities
181may fail with the following errors:
182.Bl -tag -width Er
183.It Bq Er EINVAL
184The argument to the function was invalid.
185.El
186.Pp
187Calls to functions
188.Fn pmc_cpuinfo ,
189.Fn pmc_ncpu
190and
191.Fn pmc_npmc
192may fail with the following errors:
193.Bl -tag -width Er
194.It Bq Er ENXIO
195A prior call to
196.Fn pmc_init
197to initialize the PMC library had failed.
198.El
199.Pp
200A call to function
201.Fn pmc_pmcinfo
202may fail with the following errors:
203.Bl -tag -width Er
204.It Bq Er EINVAL
205The argument
206.Fa cpu
207was invalid.
208.It Bq Er ENXIO
209The argument
210.Fa cpu
211specified a disabled or absent CPU.
212.El
213.Pp
214A call to function
215.Fn pmc_width
216may fail with the following errors:
217.Bl -tag -width Er
218.It Bq Er EINVAL
219The argument to the function was invalid.
220.El
221.Sh SEE ALSO
222.Xr pmc 3 ,
223.Xr pmc_allocate 3 ,
224.Xr pmc_get_driver_stats 3 ,
225.Xr pmc_name_of_capability 3 ,
226.Xr pmc_name_of_cputype 3 ,
227.Xr pmc_name_of_class 3 ,
228.Xr pmc_name_of_event 3 ,
229.Xr pmc_name_of_mode 3 ,
230.Xr hwpmc 4
231