2 .\" Copyright (c) 2004, Sun Microsystems, Inc.
3 .\" All Rights Reserved.
4 .\" 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.
5 .\" 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.
6 .\" 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]
7 .TH CPC_SHARED_OPEN 3CPC "Mar 28, 2005"
9 cpc_shared_open, cpc_shared_bind_event, cpc_shared_take_sample,
10 cpc_shared_rele, cpc_shared_close \- use CPU performance counters on processors
14 cc [ \fIflag\fR... ] \fIfile\fR... \(milcpc [ \fIlibrary\fR... ]
17 \fBint\fR \fBcpc_shared_open\fR(\fBvoid\fR);
22 \fBint\fR \fBcpc_shared_bind_event\fR(\fBint\fR \fIfd\fR, \fBcpc_event_t *\fR\fIevent\fR, \fBint\fR \fIflags\fR);
27 \fBint\fR \fBcpc_shared_take_sample\fR(\fBint\fR \fIfd\fR, \fBcpc_event_t *\fR\fIevent\fR);
32 \fBint\fR \fBcpc_shared_rele\fR(\fBint\fR \fIfd\fR);
37 \fBvoid\fR \fBcpc_shared_close\fR(\fBint\fR \fIfd\fR);
43 The \fBcpc_shared_open()\fR function allows the caller to access the hardware
44 counters in such a way that the performance of the currently bound CPU can be
45 measured. The function returns a file descriptor if successful. Only one such
46 open can be active at a time on any CPU.
49 The \fBcpc_shared_bind_event()\fR, \fBcpc_shared_take_sample()\fR, and
50 \fBcpc_shared_rele()\fR functions are directly analogous to the corresponding
51 \fBcpc_bind_event()\fR, \fBcpc_take_sample()\fR, and \fBcpc_rele()\fR functions
52 described on the \fBcpc_bind_event\fR(3CPC)manual page, except that they
53 operate on the counters of a particular processor.
57 If a thread wishes to access the counters using this interface, it \fBmust\fR
58 do so using a thread bound to an lwp, (see the \fBTHR_BOUND\fR flag to
59 \fBthr_create\fR(3C)), that has in turn bound itself to a processor using
60 \fBprocessor_bind\fR(2).
63 Unlike the \fBcpc_bind_event\fR(3CPC) family of functions, no counter context
64 is attached to those lwps, so the performance counter samples from the
65 processors reflects the system-wide usage, instead of per-lwp usage.
68 The first successful invocation of \fBcpc_shared_open()\fR will immediately
69 \fBinvalidate\fR \fIall\fR existing performance counter context on the system,
70 and \fBprevent\fR \fIall\fR subsequent attempts to bind counter context to lwps
71 from succeeding anywhere on the system until the last caller invokes
72 \fBcpc_shared_close()\fR.
75 This is because it is impossible to simultaneously use the counters to
76 accurately measure per-lwp and system-wide events, so there is an exclusive
77 interlock between these uses.
80 Access to the shared counters is mediated by file permissions on a \fBcpc\fR
81 pseudo device. Only a user with the {\fBPRIV_SYS_CONFIG\fR} privilege is
82 allowed to access the shared device. This control prevents use of the counters
83 on a per-lwp basis to other users.
86 The \fBCPC_BIND_LWP_INHERIT\fR and \fBCPC_BIND_EMT_OVF\fR flags are invalid for
91 On success, the functions (except for \fBcpc_shared_close()\fR) return 0. On
92 failure, the functions return -1 and set \fBerrno\fR to indicate the reason.
100 The caller does not have appropriate privilege to access the CPU performance
101 counters system-wide.
110 For cpc_shared_open(\|), this value implies that the counters on the bound cpu
111 are busy because they are already being used to measure system-wide events by
121 Otherwise, this return value implies that the counters are not available
122 because the thread has been unbound from the processor it was bound to at open
123 time. Robust programs should be coded to expect this behavior, and should
124 invoke \fBcpc_shared_close\fR(\|), before retrying the operation.
133 The counters cannot be accessed on the current CPU because the calling thread
134 is not bound to that CPU using \fBprocessor_bind\fR(2).
143 The caller has attempted an operation that is illegal or not supported on the
153 The current machine either has no performance counters, or has been configured
154 to disallow access to them system-wide.
160 See \fBattributes\fR(5) for descriptions of the following attributes:
168 ATTRIBUTE TYPE ATTRIBUTE VALUE
172 Interface Stability Obsolete
178 \fBprocessor_bind\fR(2), \fBcpc\fR(3CPC), \fBcpc_bind_cpu\fR(3CPC),
179 \fBcpc_bind_event\fR(3CPC), \fBcpc_set_sample\fR(3CPC), \fBcpc_unbind\fR(3CPC),
180 \fBlibcpc\fR(3LIB), \fBthr_create\fR(3C), \fBattributes\fR(5)
184 The \fBcpc_shared_open()\fR, \fBcpc_shared_bind_event()\fR,
185 \fBcpc_shared_take_sample()\fR, \fBcpc_shared_rele()\fR, and
186 \fBcpc_shared_close()\fR functions exist for binary compatibility only. Source
187 containing these functions will not compile. These functions are obsolete and
188 might be removed in a future release. Applications should use
189 \fBcpc_bind_cpu\fR(3CPC), \fBcpc_set_sample\fR(3CPC), and
190 \fBcpc_unbind\fR(3CPC) instead.