xref: /titanic_44/usr/src/man/man3cpc/cpc.3cpc (revision d573a5661b3f90d56bd90e44b1d931805839ec80)
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]
5fea24e13SRobert Mustacchi.\" Copyright (c) 2019, Joyent, Inc.
6*d573a566SRobert Mustacchi.Dd March 25, 2019
712ae924aSRobert Mustacchi.Dt CPC 3CPC
812ae924aSRobert Mustacchi.Os
912ae924aSRobert Mustacchi.Sh NAME
1012ae924aSRobert Mustacchi.Nm cpc
1112ae924aSRobert Mustacchi.Nd hardware performance counters
1212ae924aSRobert Mustacchi.Sh DESCRIPTION
1312ae924aSRobert MustacchiModern microprocessors contain
1412ae924aSRobert Mustacchi.Em hardware performance counters
1512ae924aSRobert 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
1812ae924aSRobert Mustacchiof the processor.
1912ae924aSRobert MustacchiThe counters can be configured to count user events, system
2012ae924aSRobert Mustacchievents, or both.
2112ae924aSRobert MustacchiData from the performance counters can be used to analyze and
22c10c16deSRichard Lowetune the behavior of software on a particular type of processor.
2312ae924aSRobert 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.
2612ae924aSRobert Mustacchi.Pp
2712ae924aSRobert MustacchiThis manual page describes a set of APIs that allow illumos applications to use
2812ae924aSRobert Mustacchithese counters.
2912ae924aSRobert MustacchiApplications can measure their own behavior, the behavior of
30c10c16deSRichard Loweother applications, or the behavior of the whole system.
3112ae924aSRobert Mustacchi.Ss Shared Counters or Private Counters
3212ae924aSRobert MustacchiThere are two principal models for using these performance counters.
3312ae924aSRobert MustacchiSome users of these statistics want to observe system-wide behavior.
3412ae924aSRobert MustacchiOther users want to view the performance counters as part of the register set
3512ae924aSRobert Mustacchiexported by each
3612ae924aSRobert Mustacchi.Sy LWP .
3712ae924aSRobert 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.
4012ae924aSRobert Mustacchi.Ss Configuration Interfaces
41c10c16deSRichard LoweThe following configuration interfaces are provided:
4212ae924aSRobert Mustacchi.Bl -tag -width Xr
4312ae924aSRobert Mustacchi.It Xr cpc_open 3CPC
44c10c16deSRichard LoweCheck the version the application was compiled with against the version of the
4512ae924aSRobert Mustacchi.It Xr cpc_cciname 3CPC
46c10c16deSRichard LoweReturn a printable string to describe the performance counters of the
47c10c16deSRichard Loweprocessor.
4812ae924aSRobert Mustacchi.It Xr cpc_npic 3CPC
49c10c16deSRichard LoweReturn the number of performance counters on the processor.
5012ae924aSRobert 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.
5312ae924aSRobert Mustacchi.El
5412ae924aSRobert 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
5712ae924aSRobert Mustacchinot installed, or the counters might be in use by other processes.
5812ae924aSRobert MustacchiThe
5912ae924aSRobert Mustacchi.Xr cpc_open 3CPC
6012ae924aSRobert Mustacchifunction determines the accessibility of the counters and
61c10c16deSRichard Lowemust be invoked before any attempt to program the counters.
6212ae924aSRobert Mustacchi.Ss "Finding Events"
63c10c16deSRichard LoweEach different type of processor has its own set of events available for
6412ae924aSRobert Mustacchimeasurement.
6512ae924aSRobert MustacchiThe
6612ae924aSRobert Mustacchi.Xr cpc_walk_events_all 3CPC
6712ae924aSRobert Mustacchiand
6812ae924aSRobert Mustacchi.Xr cpc_walk_events_pic 3CPC
6912ae924aSRobert Mustacchifunctions allow an application to determine the
7012ae924aSRobert Mustacchinames of events supported by the underlying processor.
7112ae924aSRobert MustacchiA collection of generic, platform independent event names are defined by
7212ae924aSRobert Mustacchi.Xr generic_events 3CPC .
73c10c16deSRichard LoweEach generic event maps to an underlying hardware event specific to the
7412ae924aSRobert Mustacchiunderlying processor and any optional attributes.
7512ae924aSRobert MustacchiThe
7612ae924aSRobert Mustacchi.Xr cpc_walk_generic_events_all 3CPC
7712ae924aSRobert Mustacchiand
7812ae924aSRobert Mustacchi.Xr cpc_walk_generic_events_pic 3CPC
7912ae924aSRobert Mustacchifunctions allow an application to determine the generic events supported
8012ae924aSRobert Mustacchion the underlying platform.
81*d573a566SRobert Mustacchi.Ss Intel Processor Specific Events
82*d573a566SRobert MustacchiThe following manual pages provide more detailed information on the
83*d573a566SRobert Mustacchievents available for the specific Intel processor models.
84*d573a566SRobert MustacchiThe covered processor models are listed in hexadecimal.
8512ae924aSRobert Mustacchi.Bl -tag -width Xr
8612ae924aSRobert Mustacchi.It Xr bdw_de_events 3CPC
8712ae924aSRobert MustacchiIntel Broadwell-DE events; covers model 56h.
8812ae924aSRobert Mustacchi.It Xr bdw_events 3CPC
8912ae924aSRobert MustacchiIntel Broadwell client events; covers models 3dh and 47h.
9012ae924aSRobert Mustacchi.It Xr bdx_events 3CPC
9112ae924aSRobert MustacchiIntel Broadwell server events; covers model 4fh.
9212ae924aSRobert Mustacchi.It Xr bnl_events 3CPC
9312ae924aSRobert MustacchiIntel Atom Bonnell events; covers models 35h, 36h, 27h, 26h, and 1ch.
94fea24e13SRobert Mustacchi.It Xr clx_events 3CPC
95fea24e13SRobert MustacchiIntel Cascade Lake server events; covers model 55h, steppings 5-fh.
9612ae924aSRobert Mustacchi.It Xr glm_events 3CPC
9712ae924aSRobert MustacchiIntel Goldmont SoC events; covers models 5fh and 5ch.
9812ae924aSRobert Mustacchi.It Xr glp_events 3CPC
9912ae924aSRobert MustacchiIntel Goldmont Plus SoC events; covers model 7ah.
10012ae924aSRobert Mustacchi.It Xr hsw_events 3CPC
10112ae924aSRobert MustacchiIntel Haswell client events; covers models 46h, 45h, and 3ch.
10212ae924aSRobert Mustacchi.It Xr hsx_events 3CPC
10312ae924aSRobert MustacchiIntel Haswell server events; covers model 3fh.
10412ae924aSRobert Mustacchi.It Xr ivb_events 3CPC
10512ae924aSRobert MustacchiIntel Ivy Bridge client events; covers model 3ah.
10612ae924aSRobert Mustacchi.It Xr ivt_events 3CPC
10712ae924aSRobert MustacchiIntel Ivy Bridge server events; covers model 3eh.
10812ae924aSRobert Mustacchi.It Xr jkt_events 3CPC
10912ae924aSRobert MustacchiIntel Sandy Bridge server events; covers model 2dh.
11012ae924aSRobert Mustacchi.It Xr nhm_ep_events 3CPC
11112ae924aSRobert MustacchiIntel Nehalem-EP events; covers models, 1ah, 1fh, and 1eh.
11212ae924aSRobert Mustacchi.It Xr nhm_ex_events 3CPC
11312ae924aSRobert MustacchiIntel Sandy Bridge server events; covers model 23h.
11412ae924aSRobert Mustacchi.It Xr skl_events 3CPC
11512ae924aSRobert MustacchiIntel Skylake client events; covers model 9eh, 8eh, 5e, and 4eh.
11612ae924aSRobert Mustacchi.It Xr skx_events 3CPC
117fea24e13SRobert MustacchiIntel Skylake server events; covers model 55h, steppings 0-4h.
11812ae924aSRobert Mustacchi.It Xr slm_events 3CPC
11912ae924aSRobert MustacchiIntel Atom Silvermont events; covers models 4ch, 4dh, and 37h.
12012ae924aSRobert Mustacchi.It Xr snb_events 3CPC
12112ae924aSRobert MustacchiIntel Sandy Bridge Client events; covers model 2ah.
12212ae924aSRobert Mustacchi.It Xr wsm_ep_dp_events 3CPC
12312ae924aSRobert MustacchiIntel Westmere-EP-DP events; covers model 2ch.
12412ae924aSRobert Mustacchi.It Xr wsm_ep_sp_events 3CPC
12512ae924aSRobert MustacchiIntel Westmere-EP-SP events; covers model 25h.
12612ae924aSRobert Mustacchi.It Xr wsm_ex_events 3CPC
12712ae924aSRobert MustacchiIntel Westmere-EX events; covers model 2fh.
12812ae924aSRobert Mustacchi.El
129*d573a566SRobert Mustacchi.Ss AMD Processor Specific Events
130*d573a566SRobert MustacchiThe following manual pages provide more detailed information on the
131*d573a566SRobert Mustacchievents available for the specific AMD processor models.
132*d573a566SRobert MustacchiThe covered processor families are listed in hexadecimal.
133*d573a566SRobert Mustacchi.Bl -tag -width Xr
134*d573a566SRobert Mustacchi.It Xr amd_f17h_events 3CPC
135*d573a566SRobert MustacchiAMD Family 17h processors, including models 00-2fh.
136*d573a566SRobert MustacchiInclude Ryzen, ThreadRipper, and EPYC branded processors.
137*d573a566SRobert Mustacchi.El
13812ae924aSRobert Mustacchi.Ss Using Attributes
139c10c16deSRichard LoweSome processors have advanced performance counter capabilities that are
14012ae924aSRobert Mustacchiconfigured with attributes.
14112ae924aSRobert MustacchiThe
14212ae924aSRobert Mustacchi.Xr cpc_walk_attrs 3CPC
14312ae924aSRobert Mustacchifunction can be used to determine the names of attributes supported by
14412ae924aSRobert Mustacchithe underlying processor.
14512ae924aSRobert MustacchiThe documentation referenced by
14612ae924aSRobert Mustacchi.Xr cpc_cpuref 3CPC
14712ae924aSRobert Mustacchishould be consulted to understand the meaning of a processor's performance
14812ae924aSRobert Mustacchicounter attributes.
14912ae924aSRobert Mustacchi.Ss Performance Counter Context
150c10c16deSRichard LoweEach processor on the system possesses its own set of performance counter
15112ae924aSRobert Mustacchiregisters.
15212ae924aSRobert 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.
15612ae924aSRobert Mustacchi.Pp
15712ae924aSRobert MustacchiTo achieve this behavior, the library associates
15812ae924aSRobert Mustacchi.Em performance counter context
15912ae924aSRobert Mustacchiwith each
16012ae924aSRobert Mustacchi.Sy LWP
16112ae924aSRobert Mustacchiin the process.
16212ae924aSRobert MustacchiThe context consists of a small amount of kernel memory to hold the counter
16312ae924aSRobert Mustacchivalues when the
16412ae924aSRobert Mustacchi.Sy BLWP
16512ae924aSRobert Mustacchiis not running, and some simple kernel functions to save and restore those counter
16612ae924aSRobert Mustacchivalues from and to the hardware registers when the
16712ae924aSRobert Mustacchi.Sy LWP
16812ae924aSRobert Mustacchiperforms a normal context switch.
16912ae924aSRobert MustacchiA process can only observe and manipulate its own copy of the
170c10c16deSRichard Loweperformance counter control and data registers.
17112ae924aSRobert 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
17412ae924aSRobert Mustacchiexisting application without changing the source code.
17512ae924aSRobert MustacchiA separate library,
17612ae924aSRobert Mustacchi.Sy libpctx ,
17712ae924aSRobert Mustacchiprovides a simple set of interfaces that use the facilities of
17812ae924aSRobert Mustacchi.Xr proc 4
17912ae924aSRobert Mustacchito control a target process, and together with functions in
18012ae924aSRobert Mustacchi.Sy libcpc ,
18112ae924aSRobert Mustacchiallow
18212ae924aSRobert Mustacchi.Sy truss No -like
18312ae924aSRobert Mustacchitools to be constructed to measure the performance counters in other
18412ae924aSRobert Mustacchiapplications.
18512ae924aSRobert MustacchiAn example of one such application is
18612ae924aSRobert Mustacchi.Xr cputrack 1 .
18712ae924aSRobert Mustacchi.Pp
18812ae924aSRobert MustacchiThe functions in
18912ae924aSRobert Mustacchi.Sy libpctx
19012ae924aSRobert Mustacchiare independent of those in
19112ae924aSRobert Mustacchi.Sy libcpc .
19212ae924aSRobert 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
19512ae924aSRobert Mustacchithe controlling process.
19612ae924aSRobert MustacchiThese handlers can perform various operations on the target process using APIs
19712ae924aSRobert Mustacchiin
19812ae924aSRobert Mustacchi.Sy libpctx
19912ae924aSRobert Mustacchiand
20012ae924aSRobert Mustacchi.Sy libcpc
20112ae924aSRobert Mustacchithat consume
20212ae924aSRobert Mustacchi.Vt pctx_t
20312ae924aSRobert Mustacchihandles.
20412ae924aSRobert Mustacchi.Sh SEE ALSO
20512ae924aSRobert Mustacchi.Xr cputrack 1 ,
20612ae924aSRobert Mustacchi.Xr cpustat 1M ,
20712ae924aSRobert Mustacchi.Xr cpc_bind_curlwp 3CPC ,
20812ae924aSRobert Mustacchi.Xr cpc_buf_create 3CPC ,
20912ae924aSRobert Mustacchi.Xr cpc_enable 3CPC ,
21012ae924aSRobert Mustacchi.Xr cpc_npic 3CPC ,
21112ae924aSRobert Mustacchi.Xr cpc_open 3CPC ,
21212ae924aSRobert Mustacchi.Xr cpc_set_create 3CPC ,
21312ae924aSRobert Mustacchi.Xr cpc_seterrhndlr 3CPC ,
21412ae924aSRobert Mustacchi.Xr generic_events 3CPC ,
21512ae924aSRobert Mustacchi.Xr pctx_capture 3CPC ,
21612ae924aSRobert Mustacchi.Xr pctx_set_events 3CPC ,
21712ae924aSRobert Mustacchi.Xr libcpc 3LIB ,
21812ae924aSRobert Mustacchi.Xr proc 4
219