1 '\" te
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_BIND_EVENT 3CPC "Mar 02, 2007"
7 .SH NAME
8 cpc_bind_event, cpc_take_sample, cpc_rele \- use CPU performance counters on
9 lwps
10 .SH SYNOPSIS
11 .LP
12 .nf
13 cc [ \fIflag\fR... ] \fIfile\fR... \(milcpc [ \fIlibrary\fR... ]
14 #include <libcpc.h>
15
16 \fBint\fR \fBcpc_bind_event\fR(\fBcpc_event_t *\fR\fIevent\fR, \fBint\fR \fIflags\fR);
17 .fi
18
19 .LP
20 .nf
21 \fBint\fR \fBcpc_take_sample\fR(\fBcpc_event_t *\fR\fIevent\fR);
22 .fi
23
24 .LP
25 .nf
26 \fBint\fR \fBcpc_rele\fR(\fBvoid\fR);
167 if (cpc_strtoevent(cpuver, setting, &event) != 0)
168 error("can't measure '%s' on this processor", setting);
169 setting = cpc_eventtostr(&event);
170
171 if (cpc_access() == -1)
172 error("can't access perf counters: %s", strerror(errno));
173
174 if (cpc_bind_event(&event, 0) == -1)
175 error("can't bind lwp%d: %s", _lwp_self(), strerror(errno));
176
177 for (iter = 1; iter <= 20; iter++) {
178 cpc_event_t before, after;
179
180 if (cpc_take_sample(&before) == -1)
181 break;
182
183 /* ==> Computation to be measured goes here <== */
184
185 if (cpc_take_sample(&after) == -1)
186 break;
187 (void) printf("%3d: %" PRId64 " %" PRId64 "\n", iter,
188 after.ce_pic[0] - before.ce_pic[0],
189 after.ce_pic[1] - before.ce_pic[1]);
190 }
191
192 if (iter != 20)
193 error("can't sample '%s': %s", setting, strerror(errno));
194
195 free(setting);
196 return (0);
197 }\fR
198 .fi
199 .in -2
200
201 .LP
202 \fBExample 2 \fRWrite a signal handler to catch overflow signals.
203 .sp
204 .LP
205 This example builds on Example 1, but demonstrates how to write the signal
206 handler to catch overflow signals. The counters are preset so that counter zero
207 is 1000 counts short of overflowing, while counter one is set to zero. After
212 First the signal handler:
213
214 .sp
215 .in +2
216 .nf
217 #define PRESET0 (UINT64_MAX - UINT64_C(999))
218 #define PRESET1 0
219
220 void
221 emt_handler(int sig, siginfo_t *sip, void *arg)
222 {
223 ucontext_t *uap = arg;
224 cpc_event_t sample;
225
226 if (sig != SIGEMT || sip->si_code != EMT_CPCOVF) {
227 psignal(sig, "example");
228 psiginfo(sip, "example");
229 return;
230 }
231
232 (void) printf("lwp%d - si_addr %p ucontext: %%pc %p %%sp %p\n",
233 _lwp_self(), (void *)sip->si_addr,
234 (void *)uap->uc_mcontext.gregs[PC],
235 (void *)uap->uc_mcontext.gregs[USP]);
236
237 if (cpc_take_sample(&sample) == -1)
238 error("can't sample: %s", strerror(errno));
239
240 (void) printf("0x%" PRIx64 " 0x%" PRIx64 "\n",
241 sample.ce_pic[0], sample.ce_pic[1]);
242 (void) fflush(stdout);
243
244 sample.ce_pic[0] = PRESET0;
245 sample.ce_pic[1] = PRESET1;
246 if (cpc_bind_event(&sample, CPC_BIND_EMT_OVF) == -1)
247 error("cannot bind lwp%d: %s", _lwp_self(), strerror(errno));
248 }
249 .fi
250 .in -2
251
252 .sp
253 .LP
254 and second the setup code (this can be placed after the code that selects the
255 event to be measured):
256
257 .sp
258 .in +2
259 .nf
260 \fBstruct sigaction act;
|
1 '\" te
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_BIND_EVENT 3CPC "Sep 10, 2013"
7 .SH NAME
8 cpc_bind_event, cpc_take_sample, cpc_rele \- use CPU performance counters on
9 lwps
10 .SH SYNOPSIS
11 .LP
12 .nf
13 cc [ \fIflag\fR... ] \fIfile\fR... \(milcpc [ \fIlibrary\fR... ]
14 #include <libcpc.h>
15
16 \fBint\fR \fBcpc_bind_event\fR(\fBcpc_event_t *\fR\fIevent\fR, \fBint\fR \fIflags\fR);
17 .fi
18
19 .LP
20 .nf
21 \fBint\fR \fBcpc_take_sample\fR(\fBcpc_event_t *\fR\fIevent\fR);
22 .fi
23
24 .LP
25 .nf
26 \fBint\fR \fBcpc_rele\fR(\fBvoid\fR);
167 if (cpc_strtoevent(cpuver, setting, &event) != 0)
168 error("can't measure '%s' on this processor", setting);
169 setting = cpc_eventtostr(&event);
170
171 if (cpc_access() == -1)
172 error("can't access perf counters: %s", strerror(errno));
173
174 if (cpc_bind_event(&event, 0) == -1)
175 error("can't bind lwp%d: %s", _lwp_self(), strerror(errno));
176
177 for (iter = 1; iter <= 20; iter++) {
178 cpc_event_t before, after;
179
180 if (cpc_take_sample(&before) == -1)
181 break;
182
183 /* ==> Computation to be measured goes here <== */
184
185 if (cpc_take_sample(&after) == -1)
186 break;
187 (void) printf("%3d: %" PRId64 " %" PRId64 "\en", iter,
188 after.ce_pic[0] - before.ce_pic[0],
189 after.ce_pic[1] - before.ce_pic[1]);
190 }
191
192 if (iter != 20)
193 error("can't sample '%s': %s", setting, strerror(errno));
194
195 free(setting);
196 return (0);
197 }\fR
198 .fi
199 .in -2
200
201 .LP
202 \fBExample 2 \fRWrite a signal handler to catch overflow signals.
203 .sp
204 .LP
205 This example builds on Example 1, but demonstrates how to write the signal
206 handler to catch overflow signals. The counters are preset so that counter zero
207 is 1000 counts short of overflowing, while counter one is set to zero. After
212 First the signal handler:
213
214 .sp
215 .in +2
216 .nf
217 #define PRESET0 (UINT64_MAX - UINT64_C(999))
218 #define PRESET1 0
219
220 void
221 emt_handler(int sig, siginfo_t *sip, void *arg)
222 {
223 ucontext_t *uap = arg;
224 cpc_event_t sample;
225
226 if (sig != SIGEMT || sip->si_code != EMT_CPCOVF) {
227 psignal(sig, "example");
228 psiginfo(sip, "example");
229 return;
230 }
231
232 (void) printf("lwp%d - si_addr %p ucontext: %%pc %p %%sp %p\en",
233 _lwp_self(), (void *)sip->si_addr,
234 (void *)uap->uc_mcontext.gregs[PC],
235 (void *)uap->uc_mcontext.gregs[USP]);
236
237 if (cpc_take_sample(&sample) == -1)
238 error("can't sample: %s", strerror(errno));
239
240 (void) printf("0x%" PRIx64 " 0x%" PRIx64 "\en",
241 sample.ce_pic[0], sample.ce_pic[1]);
242 (void) fflush(stdout);
243
244 sample.ce_pic[0] = PRESET0;
245 sample.ce_pic[1] = PRESET1;
246 if (cpc_bind_event(&sample, CPC_BIND_EMT_OVF) == -1)
247 error("cannot bind lwp%d: %s", _lwp_self(), strerror(errno));
248 }
249 .fi
250 .in -2
251
252 .sp
253 .LP
254 and second the setup code (this can be placed after the code that selects the
255 event to be measured):
256
257 .sp
258 .in +2
259 .nf
260 \fBstruct sigaction act;
|