xref: /illumos-gate/usr/src/man/man3cpc/cpc.3cpc (revision 7e3dbbac)
1c10c16deSRichard Lowe.\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
2c10c16deSRichard Lowe.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
3c10c16deSRichard Lowe.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
4c10c16deSRichard Lowe.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
5*7e3dbbacSRobert Mustacchi.\" Copyright (c) 2018, Joyent, Inc.
6*7e3dbbacSRobert Mustacchi.Dd June 28, 2018
7*7e3dbbacSRobert Mustacchi.Dt CPC 3CPC
8*7e3dbbacSRobert Mustacchi.Os
9*7e3dbbacSRobert Mustacchi.Sh NAME
10*7e3dbbacSRobert Mustacchi.Nm cpc
11*7e3dbbacSRobert Mustacchi.Nd hardware performance counters
12*7e3dbbacSRobert Mustacchi.Sh DESCRIPTION
13*7e3dbbacSRobert MustacchiModern microprocessors contain
14*7e3dbbacSRobert Mustacchi.Em hardware performance counters
15*7e3dbbacSRobert Mustacchithat allow
16c10c16deSRichard Lowethe measurement of many different hardware events related to CPU behavior,
17c10c16deSRichard Loweincluding instruction and data cache misses as well as various internal states
18*7e3dbbacSRobert Mustacchiof the processor.
19*7e3dbbacSRobert MustacchiThe counters can be configured to count user events, system
20*7e3dbbacSRobert Mustacchievents, or both.
21*7e3dbbacSRobert MustacchiData from the performance counters can be used to analyze and
22c10c16deSRichard Lowetune the behavior of software on a particular type of processor.
23*7e3dbbacSRobert Mustacchi.Pp
24c10c16deSRichard LoweMost processors are able to generate an interrupt on counter overflow, allowing
25c10c16deSRichard Lowethe counters to be used for various forms of profiling.
26*7e3dbbacSRobert Mustacchi.Pp
27*7e3dbbacSRobert MustacchiThis manual page describes a set of APIs that allow illumos applications to use
28*7e3dbbacSRobert Mustacchithese counters.
29*7e3dbbacSRobert MustacchiApplications can measure their own behavior, the behavior of
30c10c16deSRichard Loweother applications, or the behavior of the whole system.
31*7e3dbbacSRobert Mustacchi.Ss Shared Counters or Private Counters
32*7e3dbbacSRobert MustacchiThere are two principal models for using these performance counters.
33*7e3dbbacSRobert MustacchiSome users of these statistics want to observe system-wide behavior.
34*7e3dbbacSRobert MustacchiOther users want to view the performance counters as part of the register set
35*7e3dbbacSRobert Mustacchiexported by each
36*7e3dbbacSRobert Mustacchi.Sy LWP .
37*7e3dbbacSRobert MustacchiOn a machine performing more than one activity, these two models are
38c10c16deSRichard Lowein conflict because the counters represent a critical hardware resource that
39c10c16deSRichard Lowecannot simultaneously be both shared and private.
40*7e3dbbacSRobert Mustacchi.Ss Configuration Interfaces
41c10c16deSRichard LoweThe following configuration interfaces are provided:
42*7e3dbbacSRobert Mustacchi.Bl -tag -width Xr
43*7e3dbbacSRobert Mustacchi.It Xr cpc_open 3CPC
44c10c16deSRichard LoweCheck the version the application was compiled with against the version of the
45*7e3dbbacSRobert Mustacchi.It Xr cpc_cciname 3CPC
46c10c16deSRichard LoweReturn a printable string to describe the performance counters of the
47c10c16deSRichard Loweprocessor.
48*7e3dbbacSRobert Mustacchi.It Xr cpc_npic 3CPC
49c10c16deSRichard LoweReturn the number of performance counters on the processor.
50*7e3dbbacSRobert Mustacchi.It cpc_cpuref 3CPC
51c10c16deSRichard LoweReturn a reference to documentation that should be consulted to understand how
52c10c16deSRichard Loweto use and interpret data from the performance counters.
53*7e3dbbacSRobert Mustacchi.El
54*7e3dbbacSRobert Mustacchi.Ss Performance Counter Access
55c10c16deSRichard LowePerformance counters can be present in hardware but not acccessible because
56c10c16deSRichard Loweeither some of the necessary system software components are not available or
57*7e3dbbacSRobert Mustacchinot installed, or the counters might be in use by other processes.
58*7e3dbbacSRobert MustacchiThe
59*7e3dbbacSRobert Mustacchi.Xr cpc_open 3CPC
60*7e3dbbacSRobert Mustacchifunction determines the accessibility of the counters and
61c10c16deSRichard Lowemust be invoked before any attempt to program the counters.
62*7e3dbbacSRobert Mustacchi.Ss "Finding Events"
63c10c16deSRichard LoweEach different type of processor has its own set of events available for
64*7e3dbbacSRobert Mustacchimeasurement.
65*7e3dbbacSRobert MustacchiThe
66*7e3dbbacSRobert Mustacchi.Xr cpc_walk_events_all 3CPC
67*7e3dbbacSRobert Mustacchiand
68*7e3dbbacSRobert Mustacchi.Xr cpc_walk_events_pic 3CPC
69*7e3dbbacSRobert Mustacchifunctions allow an application to determine the
70*7e3dbbacSRobert Mustacchinames of events supported by the underlying processor.
71*7e3dbbacSRobert MustacchiA collection of generic, platform independent event names are defined by
72*7e3dbbacSRobert Mustacchi.Xr generic_events 3CPC .
73c10c16deSRichard LoweEach generic event maps to an underlying hardware event specific to the
74*7e3dbbacSRobert Mustacchiunderlying processor and any optional attributes.
75*7e3dbbacSRobert MustacchiThe
76*7e3dbbacSRobert Mustacchi.Xr cpc_walk_generic_events_all 3CPC
77*7e3dbbacSRobert Mustacchiand
78*7e3dbbacSRobert Mustacchi.Xr cpc_walk_generic_events_pic 3CPC
79*7e3dbbacSRobert Mustacchifunctions allow an application to determine the generic events supported
80*7e3dbbacSRobert Mustacchion the underlying platform.
81*7e3dbbacSRobert Mustacchi.Ss Processor Specific Events
82*7e3dbbacSRobert MustacchiManual pages specific to events for recent Intel processors are
83*7e3dbbacSRobert Mustacchiavailable.
84*7e3dbbacSRobert MustacchiThe following manual pages cover the following Intel processor models
85*7e3dbbacSRobert Mustacchiwhich are listed in hexadecimal:
86*7e3dbbacSRobert Mustacchi.Bl -tag -width Xr
87*7e3dbbacSRobert Mustacchi.It Xr bdw_de_events 3CPC
88*7e3dbbacSRobert MustacchiIntel Broadwell-DE events; covers model 56h.
89*7e3dbbacSRobert Mustacchi.It Xr bdw_events 3CPC
90*7e3dbbacSRobert MustacchiIntel Broadwell client events; covers models 3dh and 47h.
91*7e3dbbacSRobert Mustacchi.It Xr bdx_events 3CPC
92*7e3dbbacSRobert MustacchiIntel Broadwell server events; covers model 4fh.
93*7e3dbbacSRobert Mustacchi.It Xr bnl_events 3CPC
94*7e3dbbacSRobert MustacchiIntel Atom Bonnell events; covers models 35h, 36h, 27h, 26h, and 1ch.
95*7e3dbbacSRobert Mustacchi.It Xr glm_events 3CPC
96*7e3dbbacSRobert MustacchiIntel Goldmont SoC events; covers models 5fh and 5ch.
97*7e3dbbacSRobert Mustacchi.It Xr glp_events 3CPC
98*7e3dbbacSRobert MustacchiIntel Goldmont Plus SoC events; covers model 7ah.
99*7e3dbbacSRobert Mustacchi.It Xr hsw_events 3CPC
100*7e3dbbacSRobert MustacchiIntel Haswell client events; covers models 46h, 45h, and 3ch.
101*7e3dbbacSRobert Mustacchi.It Xr hsx_events 3CPC
102*7e3dbbacSRobert MustacchiIntel Haswell server events; covers model 3fh.
103*7e3dbbacSRobert Mustacchi.It Xr ivb_events 3CPC
104*7e3dbbacSRobert MustacchiIntel Ivy Bridge client events; covers model 3ah.
105*7e3dbbacSRobert Mustacchi.It Xr ivt_events 3CPC
106*7e3dbbacSRobert MustacchiIntel Ivy Bridge server events; covers model 3eh.
107*7e3dbbacSRobert Mustacchi.It Xr jkt_events 3CPC
108*7e3dbbacSRobert MustacchiIntel Sandy Bridge server events; covers model 2dh.
109*7e3dbbacSRobert Mustacchi.It Xr nhm_ep_events 3CPC
110*7e3dbbacSRobert MustacchiIntel Nehalem-EP events; covers models, 1ah, 1fh, and 1eh.
111*7e3dbbacSRobert Mustacchi.It Xr nhm_ex_events 3CPC
112*7e3dbbacSRobert MustacchiIntel Sandy Bridge server events; covers model 23h.
113*7e3dbbacSRobert Mustacchi.It Xr skl_events 3CPC
114*7e3dbbacSRobert MustacchiIntel Skylake client events; covers model 9eh, 8eh, 5e, and 4eh.
115*7e3dbbacSRobert Mustacchi.It Xr skx_events 3CPC
116*7e3dbbacSRobert MustacchiIntel Skylake server events; covers model 55h.
117*7e3dbbacSRobert Mustacchi.It Xr slm_events 3CPC
118*7e3dbbacSRobert MustacchiIntel Atom Silvermont events; covers models 4ch, 4dh, and 37h.
119*7e3dbbacSRobert Mustacchi.It Xr snb_events 3CPC
120*7e3dbbacSRobert MustacchiIntel Sandy Bridge Client events; covers model 2ah.
121*7e3dbbacSRobert Mustacchi.It Xr wsm_ep_dp_events 3CPC
122*7e3dbbacSRobert MustacchiIntel Westmere-EP-DP events; covers model 2ch.
123*7e3dbbacSRobert Mustacchi.It Xr wsm_ep_sp_events 3CPC
124*7e3dbbacSRobert MustacchiIntel Westmere-EP-SP events; covers model 25h.
125*7e3dbbacSRobert Mustacchi.It Xr wsm_ex_events 3CPC
126*7e3dbbacSRobert MustacchiIntel Westmere-EX events; covers model 2fh.
127*7e3dbbacSRobert Mustacchi.El
128*7e3dbbacSRobert Mustacchi.Ss Using Attributes
129c10c16deSRichard LoweSome processors have advanced performance counter capabilities that are
130*7e3dbbacSRobert Mustacchiconfigured with attributes.
131*7e3dbbacSRobert MustacchiThe
132*7e3dbbacSRobert Mustacchi.Xr cpc_walk_attrs 3CPC
133*7e3dbbacSRobert Mustacchifunction can be used to determine the names of attributes supported by
134*7e3dbbacSRobert Mustacchithe underlying processor.
135*7e3dbbacSRobert MustacchiThe documentation referenced by
136*7e3dbbacSRobert Mustacchi.Xr cpc_cpuref 3CPC
137*7e3dbbacSRobert Mustacchishould be consulted to understand the meaning of a processor's performance
138*7e3dbbacSRobert Mustacchicounter attributes.
139*7e3dbbacSRobert Mustacchi.Ss Performance Counter Context
140c10c16deSRichard LoweEach processor on the system possesses its own set of performance counter
141*7e3dbbacSRobert Mustacchiregisters.
142*7e3dbbacSRobert MustacchiFor a single process, it is often desirable to maintain the illusion
143c10c16deSRichard Lowethat the counters are an intrinsic part of that process (whichever processors
144c10c16deSRichard Loweit runs on), since this allows the events to be directly attributed to the
145c10c16deSRichard Loweprocess without having to make passive all other activity on the system.
146*7e3dbbacSRobert Mustacchi.Pp
147*7e3dbbacSRobert MustacchiTo achieve this behavior, the library associates
148*7e3dbbacSRobert Mustacchi.Em performance counter context
149*7e3dbbacSRobert Mustacchiwith each
150*7e3dbbacSRobert Mustacchi.Sy LWP
151*7e3dbbacSRobert Mustacchiin the process.
152*7e3dbbacSRobert MustacchiThe context consists of a small amount of kernel memory to hold the counter
153*7e3dbbacSRobert Mustacchivalues when the
154*7e3dbbacSRobert Mustacchi.Sy BLWP
155*7e3dbbacSRobert Mustacchiis not running, and some simple kernel functions to save and restore those counter
156*7e3dbbacSRobert Mustacchivalues from and to the hardware registers when the
157*7e3dbbacSRobert Mustacchi.Sy LWP
158*7e3dbbacSRobert Mustacchiperforms a normal context switch.
159*7e3dbbacSRobert MustacchiA process can only observe and manipulate its own copy of the
160c10c16deSRichard Loweperformance counter control and data registers.
161*7e3dbbacSRobert Mustacchi.Ss Performance Counters \&In Other Processes
162c10c16deSRichard LoweThough applications can be modified to instrument themselves as demonstrated
163c10c16deSRichard Loweabove, it is frequently useful to be able to examine the behavior of an
164*7e3dbbacSRobert Mustacchiexisting application without changing the source code.
165*7e3dbbacSRobert MustacchiA separate library,
166*7e3dbbacSRobert Mustacchi.Sy libpctx ,
167*7e3dbbacSRobert Mustacchiprovides a simple set of interfaces that use the facilities of
168*7e3dbbacSRobert Mustacchi.Xr proc 4
169*7e3dbbacSRobert Mustacchito control a target process, and together with functions in
170*7e3dbbacSRobert Mustacchi.Sy libcpc ,
171*7e3dbbacSRobert Mustacchiallow
172*7e3dbbacSRobert Mustacchi.Sy truss No -like
173*7e3dbbacSRobert Mustacchitools to be constructed to measure the performance counters in other
174*7e3dbbacSRobert Mustacchiapplications.
175*7e3dbbacSRobert MustacchiAn example of one such application is
176*7e3dbbacSRobert Mustacchi.Xr cputrack 1 .
177*7e3dbbacSRobert Mustacchi.Pp
178*7e3dbbacSRobert MustacchiThe functions in
179*7e3dbbacSRobert Mustacchi.Sy libpctx
180*7e3dbbacSRobert Mustacchiare independent of those in
181*7e3dbbacSRobert Mustacchi.Sy libcpc .
182*7e3dbbacSRobert MustacchiThese functions manage a process using an event-loop paradigm \(em that is, the
183c10c16deSRichard Loweexecution of certain system calls by the controlled process cause the library
184c10c16deSRichard Loweto stop the controlled process and execute callback functions in the context of
185*7e3dbbacSRobert Mustacchithe controlling process.
186*7e3dbbacSRobert MustacchiThese handlers can perform various operations on the target process using APIs
187*7e3dbbacSRobert Mustacchiin
188*7e3dbbacSRobert Mustacchi.Sy libpctx
189*7e3dbbacSRobert Mustacchiand
190*7e3dbbacSRobert Mustacchi.Sy libcpc
191*7e3dbbacSRobert Mustacchithat consume
192*7e3dbbacSRobert Mustacchi.Vt pctx_t
193*7e3dbbacSRobert Mustacchihandles.
194*7e3dbbacSRobert Mustacchi.Sh SEE ALSO
195*7e3dbbacSRobert Mustacchi.Xr cputrack 1 ,
196*7e3dbbacSRobert Mustacchi.Xr cpustat 1M ,
197*7e3dbbacSRobert Mustacchi.Xr cpc_bind_curlwp 3CPC ,
198*7e3dbbacSRobert Mustacchi.Xr cpc_buf_create 3CPC ,
199*7e3dbbacSRobert Mustacchi.Xr cpc_enable 3CPC ,
200*7e3dbbacSRobert Mustacchi.Xr cpc_npic 3CPC ,
201*7e3dbbacSRobert Mustacchi.Xr cpc_open 3CPC ,
202*7e3dbbacSRobert Mustacchi.Xr cpc_set_create 3CPC ,
203*7e3dbbacSRobert Mustacchi.Xr cpc_seterrhndlr 3CPC ,
204*7e3dbbacSRobert Mustacchi.Xr generic_events 3CPC ,
205*7e3dbbacSRobert Mustacchi.Xr pctx_capture 3CPC ,
206*7e3dbbacSRobert Mustacchi.Xr pctx_set_events 3CPC ,
207*7e3dbbacSRobert Mustacchi.Xr libcpc 3LIB ,
208*7e3dbbacSRobert Mustacchi.Xr proc 4
209