2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH CPC_SET_CREATE 3CPC "Aug 20, 2007"
8 cpc_set_create, cpc_set_destroy, cpc_set_add_request, cpc_walk_requests \-
9 manage sets of counter requests
13 cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lcpc\fR [ \fIlibrary\fR\&.\|.\|. ]
16 \fBcpc_set_t *\fR\fBcpc_set_create\fR(\fBcpc_t *\fR\fIcpc\fR);
21 \fBint\fR \fBcpc_set_destroy\fR(\fBcpc_t *\fR\fIcpc\fR, \fBcpc_set_t *\fR\fIset\fR);
26 \fBint\fR \fBcpc_set_add_request\fR(\fBcpc_t *\fR\fIcpc\fR, \fBcpc_set_t *\fR\fIset\fR,
27 \fBconst char *\fR\fIevent\fR, \fBuint64_t\fR \fIpreset\fR, \fBuint_t\fR \fIflags\fR,
28 \fBuint_t\fR \fInattrs\fR, \fBconst cpc_attr_t *\fR\fIattrs\fR);
33 \fBvoid\fR \fBcpc_walk_requests\fR(\fBcpc_t *\fR\fIcpc\fR, \fBcpc_set_t *\fR\fIset\fR, \fBvoid *\fR\fIarg\fR,
34 \fBvoid (*\fR\fIaction\fR)(void *\fIarg\fR, int \fIindex\fR, const char *\fIevent\fR,
35 uint64_t \fIpreset\fR, uint_t \fIflags\fR, int \fInattrs\fR,
36 const cpc_attr_t *\fIattrs\fR));
42 The \fBcpc_set_create()\fR function returns an initialized and empty CPC set. A
43 CPC set contains some number of requests, where a request represents a specific
44 configuration of a hardware performance instrumentation counter present on the
45 processor. The \fBcpc_set_t\fR data structure is opaque and must not be
46 accessed directly by the application.
49 Applications wanting to program one or more performance counters must create an
50 empty set with \fBcpc_set_create()\fR and add requests to the set with
51 \fBcpc_set_add_request()\fR. Once all requests have been added to a set, the
52 set must be bound to the hardware performance counters (see
53 \fBcpc_bind_curlwp()\fR, \fBcpc_bind_pctx()\fR, and \fBcpc_bind_cpu()\fR, all
54 described on \fBcpc_bind_curlwp\fR(3CPC)) before counting events. At bind time,
55 the system attempts to match each request with an available physical counter
56 capable of counting the event specified in the request. If the bind is
57 successful, a 64-bit virtualized counter is created to store the counts
58 accumulated by the hardware counter. These counts are stored and managed in CPC
59 buffers separate from the CPC set whose requests are being counted. See
60 \fBcpc_buf_create\fR(3CPC) and \fBcpc_set_sample\fR(3CPC).
63 The \fBcpc_set_add_request()\fR function specifies a configuration of a
64 hardware counter. The arguments to \fBcpc_set_add_request()\fR are:
71 A string containing the name of an event supported by the system's processor.
72 The \fBcpc_walk_events_all()\fR and \fBcpc_walk_events_pic()\fR functions (both
73 described on \fBcpc_npic\fR(3CPC)) can be used to query the processor for the
74 names of available events. Certain processors allow the use of raw event codes,
75 in which case a string representation of an event code in a form acceptable to
76 \fBstrtol\fR(3C) can be used as the \fIevent\fR argument.
85 The value with which the system initializes the counter.
94 Three flags are defined that modify the behavior of the counter acting on
95 behalf of this request:
99 \fB\fBCPC_COUNT_USER\fR\fR
103 The counter should count events that occur while the processor is in user mode.
109 \fB\fBCPC_COUNT_SYSTEM\fR\fR
113 The counter should count events that occur while the processor is in privileged
120 \fB\fBCPC_OVF_NOTIFY_EMT\fR\fR
124 Request a signal to be sent to the application when the physical counter
125 overflows. A \fBSIGEMT\fR signal is delivered if the processor is capable of
126 delivering an interrupt when the counter counts past its maximum value. All
127 requests in the set containing the counter that overflowed are stopped until
131 At least one of \fBCPC_COUNT_USER\fR or \fBCPC_COUNT_SYSTEM\fR must be
132 specified to program the hardware for counting.
138 \fB\fInattrs\fR, \fIattrs\fR\fR
141 The \fInattrs\fR argument specifies the number of attributes pointed to by the
142 \fIattrs\fR argument, which is an array of \fBcpc_attr_t\fR structures
143 containing processor-specific attributes that modify the request's
144 configuration. The \fBcpc_walk_attrs()\fR function (see \fBcpc_npic\fR(3CPC))
145 can be used to query the processor for the list of attributes it accepts. The
146 library makes a private copy of the \fIattrs\fR array, allowing the application
147 to dispose of it immediately after calling \fBcpc_set_add_request()\fR.
152 The \fBcpc_walk_requests()\fR function calls the action function on each
153 request that has been added to the set. The \fIarg\fR argument is passed
154 unmodified to the \fIaction\fR function with each call.
158 Upon successful completion, \fBcpc_set_create()\fR returns a handle to the
159 opaque \fBcpc_set_t\fR data structure. Otherwise, NULL is returned and
160 \fBerrno\fR is set to indicate the error.
163 Upon successful completion, \fBCpc_set_destroy()\fR returns 0. Otherwise, -1 is
164 returned and \fBerrno\fR is set to indicate the error.
167 Upon successful completion, \fBcpc_set_add_request()\fR returns an integer
168 index used to refer to the data generated by that request during data
169 retrieval. Otherwise, -1 is returned and \fBerrno\fR is set to indicate the
174 These functions will fail if:
181 An event, attribute, or flag passed to \fBcpc_set_add_request()\fR was invalid.
183 For \fBcpc_set_destroy()\fR and \fBcpc_set_add_request()\fR, the set parameter
184 was not created with the given cpc_t.
193 There was not enough memory available to the process to create the library's
200 See \fBattributes\fR(5) for descriptions of the following attributes:
208 ATTRIBUTE TYPE ATTRIBUTE VALUE
210 Interface Stability Committed
218 \fBcpc_bind_curlwp\fR(3CPC), \fBcpc_buf_create\fR(3CPC), \fBcpc_npic\fR(3CPC),
219 \fBcpc_seterrhndlr\fR(3CPC), \fBlibcpc\fR(3LIB), \fBstrtol\fR(3C),
224 The system automatically determines which particular physical counter to use to
225 count the events specified by each request. Applications can force the system
226 to use a particular counter by specifying the counter number in an attribute
227 named \fIpicnum\fR that is passed to \fBcpc_set_add_request()\fR. Counters are
228 numbered from 0 to \fIn\fR - 1, where n is the number of counters in the
229 processor as returned by \fBcpc_npic\fR(3CPC).
232 Some processors, such as UltraSPARC, do not allow the hardware counters to be
233 programmed differently. In this case, all requests in the set must have the
234 same configuration, or an attempt to bind the set will return \fBEINVAL\fR. If
235 a \fBcpc_errhndlr_t\fR has been registered with \fBcpc_seterrhndlr\fR(3CPC),
236 the error handler is called with subcode \fBCPC_CONFLICTING_REQS\fR. For
237 example, on UltraSPARC \fBpic0\fR and \fBpic1\fR must both program events in
238 the same processor mode (user mode, kernel mode, or both). For example,
239 \fBpic0\fR cannot be programmed with \fBCPC_COUNT_USER\fR while \fBpic1\fR is
240 programmed with \fBCPC_COUNT_SYSTEM\fR. Refer to the hardware documentation
241 referenced by \fBcpc_cpuref\fR(3CPC) for details about a particular processor's
242 performance instrumentation hardware.