xref: /titanic_51/usr/src/man/man3cpc/cpc.3cpc (revision 3db3a4ac8d5c81055f03a962e4d709dc5e13e2df)
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]
55fc40de0SRobert Mustacchi.\" Copyright (c) 2019, Joyent, Inc.
6*3db3a4acSRobert Mustacchi.Dd March 25, 2019
753548f91SRobert Mustacchi.Dt CPC 3CPC
853548f91SRobert Mustacchi.Os
953548f91SRobert Mustacchi.Sh NAME
1053548f91SRobert Mustacchi.Nm cpc
1153548f91SRobert Mustacchi.Nd hardware performance counters
1253548f91SRobert Mustacchi.Sh DESCRIPTION
1353548f91SRobert MustacchiModern microprocessors contain
1453548f91SRobert Mustacchi.Em hardware performance counters
1553548f91SRobert 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
1853548f91SRobert Mustacchiof the processor.
1953548f91SRobert MustacchiThe counters can be configured to count user events, system
2053548f91SRobert Mustacchievents, or both.
2153548f91SRobert MustacchiData from the performance counters can be used to analyze and
22c10c16deSRichard Lowetune the behavior of software on a particular type of processor.
2353548f91SRobert 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.
2653548f91SRobert Mustacchi.Pp
2753548f91SRobert MustacchiThis manual page describes a set of APIs that allow illumos applications to use
2853548f91SRobert Mustacchithese counters.
2953548f91SRobert MustacchiApplications can measure their own behavior, the behavior of
30c10c16deSRichard Loweother applications, or the behavior of the whole system.
3153548f91SRobert Mustacchi.Ss Shared Counters or Private Counters
3253548f91SRobert MustacchiThere are two principal models for using these performance counters.
3353548f91SRobert MustacchiSome users of these statistics want to observe system-wide behavior.
3453548f91SRobert MustacchiOther users want to view the performance counters as part of the register set
3553548f91SRobert Mustacchiexported by each
3653548f91SRobert Mustacchi.Sy LWP .
3753548f91SRobert 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.
4053548f91SRobert Mustacchi.Ss Configuration Interfaces
41c10c16deSRichard LoweThe following configuration interfaces are provided:
4253548f91SRobert Mustacchi.Bl -tag -width Xr
4353548f91SRobert Mustacchi.It Xr cpc_open 3CPC
44c10c16deSRichard LoweCheck the version the application was compiled with against the version of the
4553548f91SRobert Mustacchi.It Xr cpc_cciname 3CPC
46c10c16deSRichard LoweReturn a printable string to describe the performance counters of the
47c10c16deSRichard Loweprocessor.
4853548f91SRobert Mustacchi.It Xr cpc_npic 3CPC
49c10c16deSRichard LoweReturn the number of performance counters on the processor.
5053548f91SRobert 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.
5353548f91SRobert Mustacchi.El
5453548f91SRobert 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
5753548f91SRobert Mustacchinot installed, or the counters might be in use by other processes.
5853548f91SRobert MustacchiThe
5953548f91SRobert Mustacchi.Xr cpc_open 3CPC
6053548f91SRobert Mustacchifunction determines the accessibility of the counters and
61c10c16deSRichard Lowemust be invoked before any attempt to program the counters.
6253548f91SRobert Mustacchi.Ss "Finding Events"
63c10c16deSRichard LoweEach different type of processor has its own set of events available for
6453548f91SRobert Mustacchimeasurement.
6553548f91SRobert MustacchiThe
6653548f91SRobert Mustacchi.Xr cpc_walk_events_all 3CPC
6753548f91SRobert Mustacchiand
6853548f91SRobert Mustacchi.Xr cpc_walk_events_pic 3CPC
6953548f91SRobert Mustacchifunctions allow an application to determine the
7053548f91SRobert Mustacchinames of events supported by the underlying processor.
7153548f91SRobert MustacchiA collection of generic, platform independent event names are defined by
7253548f91SRobert Mustacchi.Xr generic_events 3CPC .
73c10c16deSRichard LoweEach generic event maps to an underlying hardware event specific to the
7453548f91SRobert Mustacchiunderlying processor and any optional attributes.
7553548f91SRobert MustacchiThe
7653548f91SRobert Mustacchi.Xr cpc_walk_generic_events_all 3CPC
7753548f91SRobert Mustacchiand
7853548f91SRobert Mustacchi.Xr cpc_walk_generic_events_pic 3CPC
7953548f91SRobert Mustacchifunctions allow an application to determine the generic events supported
8053548f91SRobert Mustacchion the underlying platform.
81*3db3a4acSRobert Mustacchi.Ss Intel Processor Specific Events
82*3db3a4acSRobert MustacchiThe following manual pages provide more detailed information on the
83*3db3a4acSRobert Mustacchievents available for the specific Intel processor models.
84*3db3a4acSRobert MustacchiThe covered processor models are listed in hexadecimal.
8553548f91SRobert Mustacchi.Bl -tag -width Xr
8653548f91SRobert Mustacchi.It Xr bdw_de_events 3CPC
8753548f91SRobert MustacchiIntel Broadwell-DE events; covers model 56h.
8853548f91SRobert Mustacchi.It Xr bdw_events 3CPC
8953548f91SRobert MustacchiIntel Broadwell client events; covers models 3dh and 47h.
9053548f91SRobert Mustacchi.It Xr bdx_events 3CPC
9153548f91SRobert MustacchiIntel Broadwell server events; covers model 4fh.
9253548f91SRobert Mustacchi.It Xr bnl_events 3CPC
9353548f91SRobert MustacchiIntel Atom Bonnell events; covers models 35h, 36h, 27h, 26h, and 1ch.
945fc40de0SRobert Mustacchi.It Xr clx_events 3CPC
955fc40de0SRobert MustacchiIntel Cascade Lake server events; covers model 55h, steppings 5-fh.
9653548f91SRobert Mustacchi.It Xr glm_events 3CPC
9753548f91SRobert MustacchiIntel Goldmont SoC events; covers models 5fh and 5ch.
9853548f91SRobert Mustacchi.It Xr glp_events 3CPC
9953548f91SRobert MustacchiIntel Goldmont Plus SoC events; covers model 7ah.
10053548f91SRobert Mustacchi.It Xr hsw_events 3CPC
10153548f91SRobert MustacchiIntel Haswell client events; covers models 46h, 45h, and 3ch.
10253548f91SRobert Mustacchi.It Xr hsx_events 3CPC
10353548f91SRobert MustacchiIntel Haswell server events; covers model 3fh.
10453548f91SRobert Mustacchi.It Xr ivb_events 3CPC
10553548f91SRobert MustacchiIntel Ivy Bridge client events; covers model 3ah.
10653548f91SRobert Mustacchi.It Xr ivt_events 3CPC
10753548f91SRobert MustacchiIntel Ivy Bridge server events; covers model 3eh.
10853548f91SRobert Mustacchi.It Xr jkt_events 3CPC
10953548f91SRobert MustacchiIntel Sandy Bridge server events; covers model 2dh.
11053548f91SRobert Mustacchi.It Xr nhm_ep_events 3CPC
11153548f91SRobert MustacchiIntel Nehalem-EP events; covers models, 1ah, 1fh, and 1eh.
11253548f91SRobert Mustacchi.It Xr nhm_ex_events 3CPC
11353548f91SRobert MustacchiIntel Sandy Bridge server events; covers model 23h.
11453548f91SRobert Mustacchi.It Xr skl_events 3CPC
11553548f91SRobert MustacchiIntel Skylake client events; covers model 9eh, 8eh, 5e, and 4eh.
11653548f91SRobert Mustacchi.It Xr skx_events 3CPC
1175fc40de0SRobert MustacchiIntel Skylake server events; covers model 55h, steppings 0-4h.
11853548f91SRobert Mustacchi.It Xr slm_events 3CPC
11953548f91SRobert MustacchiIntel Atom Silvermont events; covers models 4ch, 4dh, and 37h.
12053548f91SRobert Mustacchi.It Xr snb_events 3CPC
12153548f91SRobert MustacchiIntel Sandy Bridge Client events; covers model 2ah.
12253548f91SRobert Mustacchi.It Xr wsm_ep_dp_events 3CPC
12353548f91SRobert MustacchiIntel Westmere-EP-DP events; covers model 2ch.
12453548f91SRobert Mustacchi.It Xr wsm_ep_sp_events 3CPC
12553548f91SRobert MustacchiIntel Westmere-EP-SP events; covers model 25h.
12653548f91SRobert Mustacchi.It Xr wsm_ex_events 3CPC
12753548f91SRobert MustacchiIntel Westmere-EX events; covers model 2fh.
12853548f91SRobert Mustacchi.El
129*3db3a4acSRobert Mustacchi.Ss AMD Processor Specific Events
130*3db3a4acSRobert MustacchiThe following manual pages provide more detailed information on the
131*3db3a4acSRobert Mustacchievents available for the specific AMD processor models.
132*3db3a4acSRobert MustacchiThe covered processor families are listed in hexadecimal.
133*3db3a4acSRobert Mustacchi.Bl -tag -width Xr
134*3db3a4acSRobert Mustacchi.It Xr amd_f17h_events 3CPC
135*3db3a4acSRobert MustacchiAMD Family 17h processors, including models 00-2fh.
136*3db3a4acSRobert MustacchiInclude Ryzen, ThreadRipper, and EPYC branded processors.
137*3db3a4acSRobert Mustacchi.El
13853548f91SRobert Mustacchi.Ss Using Attributes
139c10c16deSRichard LoweSome processors have advanced performance counter capabilities that are
14053548f91SRobert Mustacchiconfigured with attributes.
14153548f91SRobert MustacchiThe
14253548f91SRobert Mustacchi.Xr cpc_walk_attrs 3CPC
14353548f91SRobert Mustacchifunction can be used to determine the names of attributes supported by
14453548f91SRobert Mustacchithe underlying processor.
14553548f91SRobert MustacchiThe documentation referenced by
14653548f91SRobert Mustacchi.Xr cpc_cpuref 3CPC
14753548f91SRobert Mustacchishould be consulted to understand the meaning of a processor's performance
14853548f91SRobert Mustacchicounter attributes.
14953548f91SRobert Mustacchi.Ss Performance Counter Context
150c10c16deSRichard LoweEach processor on the system possesses its own set of performance counter
15153548f91SRobert Mustacchiregisters.
15253548f91SRobert MustacchiFor a single process, it is often desirable to maintain the illusion
153c10c16deSRichard Lowethat the counters are an intrinsic part of that process (whichever processors
154c10c16deSRichard Loweit runs on), since this allows the events to be directly attributed to the
155c10c16deSRichard Loweprocess without having to make passive all other activity on the system.
15653548f91SRobert Mustacchi.Pp
15753548f91SRobert MustacchiTo achieve this behavior, the library associates
15853548f91SRobert Mustacchi.Em performance counter context
15953548f91SRobert Mustacchiwith each
16053548f91SRobert Mustacchi.Sy LWP
16153548f91SRobert Mustacchiin the process.
16253548f91SRobert MustacchiThe context consists of a small amount of kernel memory to hold the counter
16353548f91SRobert Mustacchivalues when the
16453548f91SRobert Mustacchi.Sy BLWP
16553548f91SRobert Mustacchiis not running, and some simple kernel functions to save and restore those counter
16653548f91SRobert Mustacchivalues from and to the hardware registers when the
16753548f91SRobert Mustacchi.Sy LWP
16853548f91SRobert Mustacchiperforms a normal context switch.
16953548f91SRobert MustacchiA process can only observe and manipulate its own copy of the
170c10c16deSRichard Loweperformance counter control and data registers.
17153548f91SRobert Mustacchi.Ss Performance Counters \&In Other Processes
172c10c16deSRichard LoweThough applications can be modified to instrument themselves as demonstrated
173c10c16deSRichard Loweabove, it is frequently useful to be able to examine the behavior of an
17453548f91SRobert Mustacchiexisting application without changing the source code.
17553548f91SRobert MustacchiA separate library,
17653548f91SRobert Mustacchi.Sy libpctx ,
17753548f91SRobert Mustacchiprovides a simple set of interfaces that use the facilities of
17853548f91SRobert Mustacchi.Xr proc 4
17953548f91SRobert Mustacchito control a target process, and together with functions in
18053548f91SRobert Mustacchi.Sy libcpc ,
18153548f91SRobert Mustacchiallow
18253548f91SRobert Mustacchi.Sy truss No -like
18353548f91SRobert Mustacchitools to be constructed to measure the performance counters in other
18453548f91SRobert Mustacchiapplications.
18553548f91SRobert MustacchiAn example of one such application is
18653548f91SRobert Mustacchi.Xr cputrack 1 .
18753548f91SRobert Mustacchi.Pp
18853548f91SRobert MustacchiThe functions in
18953548f91SRobert Mustacchi.Sy libpctx
19053548f91SRobert Mustacchiare independent of those in
19153548f91SRobert Mustacchi.Sy libcpc .
19253548f91SRobert MustacchiThese functions manage a process using an event-loop paradigm \(em that is, the
193c10c16deSRichard Loweexecution of certain system calls by the controlled process cause the library
194c10c16deSRichard Loweto stop the controlled process and execute callback functions in the context of
19553548f91SRobert Mustacchithe controlling process.
19653548f91SRobert MustacchiThese handlers can perform various operations on the target process using APIs
19753548f91SRobert Mustacchiin
19853548f91SRobert Mustacchi.Sy libpctx
19953548f91SRobert Mustacchiand
20053548f91SRobert Mustacchi.Sy libcpc
20153548f91SRobert Mustacchithat consume
20253548f91SRobert Mustacchi.Vt pctx_t
20353548f91SRobert Mustacchihandles.
20453548f91SRobert Mustacchi.Sh SEE ALSO
20553548f91SRobert Mustacchi.Xr cputrack 1 ,
20653548f91SRobert Mustacchi.Xr cpustat 1M ,
20753548f91SRobert Mustacchi.Xr cpc_bind_curlwp 3CPC ,
20853548f91SRobert Mustacchi.Xr cpc_buf_create 3CPC ,
20953548f91SRobert Mustacchi.Xr cpc_enable 3CPC ,
21053548f91SRobert Mustacchi.Xr cpc_npic 3CPC ,
21153548f91SRobert Mustacchi.Xr cpc_open 3CPC ,
21253548f91SRobert Mustacchi.Xr cpc_set_create 3CPC ,
21353548f91SRobert Mustacchi.Xr cpc_seterrhndlr 3CPC ,
21453548f91SRobert Mustacchi.Xr generic_events 3CPC ,
21553548f91SRobert Mustacchi.Xr pctx_capture 3CPC ,
21653548f91SRobert Mustacchi.Xr pctx_set_events 3CPC ,
21753548f91SRobert Mustacchi.Xr libcpc 3LIB ,
21853548f91SRobert Mustacchi.Xr proc 4
219