1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <string.h>
32*0Sstevel@tonic-gate #include <strings.h>
33*0Sstevel@tonic-gate #include <libintl.h>
34*0Sstevel@tonic-gate #include <sys/types.h>
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate #include <libcpc.h>
38*0Sstevel@tonic-gate #include "cpucmds.h"
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate #define CHARS_PER_REQ 11 /* space required for printing column headers */
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate * These routines are solely used to manage a list of request sets.
44*0Sstevel@tonic-gate */
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate struct __cpc_setgrp {
47*0Sstevel@tonic-gate struct setgrp_elem {
48*0Sstevel@tonic-gate cpc_set_t *set;
49*0Sstevel@tonic-gate uint8_t sysonly; /* All reqs sys-mode only ? */
50*0Sstevel@tonic-gate int nreqs;
51*0Sstevel@tonic-gate int *picnums; /* picnum used per req */
52*0Sstevel@tonic-gate cpc_buf_t *data1;
53*0Sstevel@tonic-gate cpc_buf_t *data2;
54*0Sstevel@tonic-gate cpc_buf_t *scratch;
55*0Sstevel@tonic-gate char *name;
56*0Sstevel@tonic-gate char *hdr;
57*0Sstevel@tonic-gate } *sets; /* array of events and names */
58*0Sstevel@tonic-gate int nelem; /* size of array */
59*0Sstevel@tonic-gate int current; /* currently bound event in eventset */
60*0Sstevel@tonic-gate int smt; /* Measures physical events on SMT CPU */
61*0Sstevel@tonic-gate int has_sysonly_set; /* Does this group have a system-only set? */
62*0Sstevel@tonic-gate cpc_t *cpc; /* library handle */
63*0Sstevel@tonic-gate };
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate static void *emalloc(size_t n);
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate cpc_setgrp_t *
cpc_setgrp_new(cpc_t * cpc,int smt)68*0Sstevel@tonic-gate cpc_setgrp_new(cpc_t *cpc, int smt)
69*0Sstevel@tonic-gate {
70*0Sstevel@tonic-gate cpc_setgrp_t *sgrp;
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate sgrp = emalloc(sizeof (*sgrp));
73*0Sstevel@tonic-gate sgrp->current = -1;
74*0Sstevel@tonic-gate sgrp->cpc = cpc;
75*0Sstevel@tonic-gate sgrp->smt = smt;
76*0Sstevel@tonic-gate sgrp->has_sysonly_set = 0;
77*0Sstevel@tonic-gate return (sgrp);
78*0Sstevel@tonic-gate }
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate /*
81*0Sstevel@tonic-gate * Walker to count the number of requests in a set, and check if any requests
82*0Sstevel@tonic-gate * count user-mode events.
83*0Sstevel@tonic-gate */
84*0Sstevel@tonic-gate /*ARGSUSED*/
85*0Sstevel@tonic-gate static void
cpc_setgrp_walker(void * arg,int index,const char * event,uint64_t preset,uint_t flags,int nattrs,const cpc_attr_t * attrs)86*0Sstevel@tonic-gate cpc_setgrp_walker(void *arg, int index, const char *event, uint64_t preset,
87*0Sstevel@tonic-gate uint_t flags, int nattrs, const cpc_attr_t *attrs)
88*0Sstevel@tonic-gate {
89*0Sstevel@tonic-gate struct setgrp_elem *se = arg;
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate se->nreqs++;
92*0Sstevel@tonic-gate if (flags & CPC_COUNT_USER)
93*0Sstevel@tonic-gate se->sysonly = 0;
94*0Sstevel@tonic-gate }
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate /*
97*0Sstevel@tonic-gate * Walker to discover the picnums used by the requests in a set.
98*0Sstevel@tonic-gate */
99*0Sstevel@tonic-gate /*ARGSUSED*/
100*0Sstevel@tonic-gate static void
cpc_setgrp_picwalker(void * arg,int index,const char * event,uint64_t preset,uint_t flags,int nattrs,const cpc_attr_t * attrs)101*0Sstevel@tonic-gate cpc_setgrp_picwalker(void *arg, int index, const char *event, uint64_t preset,
102*0Sstevel@tonic-gate uint_t flags, int nattrs, const cpc_attr_t *attrs)
103*0Sstevel@tonic-gate {
104*0Sstevel@tonic-gate int *picnums = arg;
105*0Sstevel@tonic-gate int i;
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate for (i = 0; i < nattrs; i++) {
108*0Sstevel@tonic-gate if (strncmp(attrs[i].ca_name, "picnum", 7) == 0)
109*0Sstevel@tonic-gate break;
110*0Sstevel@tonic-gate }
111*0Sstevel@tonic-gate if (i == nattrs)
112*0Sstevel@tonic-gate picnums[index] = -1;
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate picnums[index] = (int)attrs[i].ca_val;
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate cpc_setgrp_t *
cpc_setgrp_newset(cpc_setgrp_t * sgrp,const char * spec,int * errcnt)118*0Sstevel@tonic-gate cpc_setgrp_newset(cpc_setgrp_t *sgrp, const char *spec, int *errcnt)
119*0Sstevel@tonic-gate {
120*0Sstevel@tonic-gate cpc_set_t *set;
121*0Sstevel@tonic-gate struct setgrp_elem *new;
122*0Sstevel@tonic-gate char hdr[CHARS_PER_REQ+1];
123*0Sstevel@tonic-gate int i;
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate if ((set = cpc_strtoset(sgrp->cpc, spec, sgrp->smt)) == NULL) {
126*0Sstevel@tonic-gate *errcnt += 1;
127*0Sstevel@tonic-gate return (NULL);
128*0Sstevel@tonic-gate }
129*0Sstevel@tonic-gate
130*0Sstevel@tonic-gate if ((new = realloc(sgrp->sets, (1 + sgrp->nelem) * sizeof (*new)))
131*0Sstevel@tonic-gate == NULL) {
132*0Sstevel@tonic-gate (void) fprintf(stderr,
133*0Sstevel@tonic-gate gettext("cpc_setgrp: no re memory available\n"));
134*0Sstevel@tonic-gate exit(0);
135*0Sstevel@tonic-gate }
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate sgrp->sets = new;
138*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].set = set;
139*0Sstevel@tonic-gate /*
140*0Sstevel@tonic-gate * Count the number of requests in the set we just made. If any requests
141*0Sstevel@tonic-gate * in the set have CPC_COUNT_USER in the flags, the sysonly flag will
142*0Sstevel@tonic-gate * be cleared.
143*0Sstevel@tonic-gate */
144*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].nreqs = 0;
145*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].sysonly = 1;
146*0Sstevel@tonic-gate cpc_walk_requests(sgrp->cpc, set, &(sgrp->sets[sgrp->nelem]),
147*0Sstevel@tonic-gate cpc_setgrp_walker);
148*0Sstevel@tonic-gate
149*0Sstevel@tonic-gate if (sgrp->sets[sgrp->nelem].sysonly == 1)
150*0Sstevel@tonic-gate sgrp->has_sysonly_set = 1;
151*0Sstevel@tonic-gate
152*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].picnums = emalloc(sgrp->sets[sgrp->nelem].nreqs
153*0Sstevel@tonic-gate * sizeof (int));
154*0Sstevel@tonic-gate
155*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].hdr = emalloc((sgrp->sets[sgrp->nelem].nreqs *
156*0Sstevel@tonic-gate CHARS_PER_REQ) + 1);
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gate /*
159*0Sstevel@tonic-gate * Find out which picnums the requests are using.
160*0Sstevel@tonic-gate */
161*0Sstevel@tonic-gate cpc_walk_requests(sgrp->cpc, set, sgrp->sets[sgrp->nelem].picnums,
162*0Sstevel@tonic-gate cpc_setgrp_picwalker);
163*0Sstevel@tonic-gate /*
164*0Sstevel@tonic-gate * Use the picnums we discovered to build a printable header for this
165*0Sstevel@tonic-gate * set.
166*0Sstevel@tonic-gate */
167*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].hdr[0] = '\0';
168*0Sstevel@tonic-gate for (i = 0; i < sgrp->sets[sgrp->nelem].nreqs; i++) {
169*0Sstevel@tonic-gate (void) snprintf(hdr, CHARS_PER_REQ, "%8s%-2d ", "pic",
170*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].picnums[i]);
171*0Sstevel@tonic-gate (void) strncat(sgrp->sets[sgrp->nelem].hdr, hdr,
172*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].nreqs * CHARS_PER_REQ);
173*0Sstevel@tonic-gate }
174*0Sstevel@tonic-gate sgrp->sets[sgrp->nelem].hdr[strlen(sgrp->sets[sgrp->nelem].hdr)] = '\0';
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate if ((sgrp->sets[sgrp->nelem].name = strdup(spec)) == NULL) {
177*0Sstevel@tonic-gate (void) fprintf(stderr,
178*0Sstevel@tonic-gate gettext("cpc_setgrp: no memory available\n"));
179*0Sstevel@tonic-gate exit(0);
180*0Sstevel@tonic-gate }
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate if ((sgrp->sets[sgrp->nelem].data1 = cpc_buf_create(sgrp->cpc, set))
183*0Sstevel@tonic-gate == NULL ||
184*0Sstevel@tonic-gate (sgrp->sets[sgrp->nelem].data2 = cpc_buf_create(sgrp->cpc, set))
185*0Sstevel@tonic-gate == NULL ||
186*0Sstevel@tonic-gate (sgrp->sets[sgrp->nelem].scratch = cpc_buf_create(sgrp->cpc, set))
187*0Sstevel@tonic-gate == NULL) {
188*0Sstevel@tonic-gate (void) fprintf(stderr,
189*0Sstevel@tonic-gate gettext("cpc_setgrp: no memory available\n"));
190*0Sstevel@tonic-gate exit(0);
191*0Sstevel@tonic-gate }
192*0Sstevel@tonic-gate
193*0Sstevel@tonic-gate if (sgrp->current < 0)
194*0Sstevel@tonic-gate sgrp->current = 0;
195*0Sstevel@tonic-gate sgrp->nelem++;
196*0Sstevel@tonic-gate return (sgrp);
197*0Sstevel@tonic-gate }
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate int
cpc_setgrp_getbufs(cpc_setgrp_t * sgrp,cpc_buf_t *** data1,cpc_buf_t *** data2,cpc_buf_t *** scratch)200*0Sstevel@tonic-gate cpc_setgrp_getbufs(cpc_setgrp_t *sgrp, cpc_buf_t ***data1, cpc_buf_t ***data2,
201*0Sstevel@tonic-gate cpc_buf_t ***scratch)
202*0Sstevel@tonic-gate {
203*0Sstevel@tonic-gate if ((uint_t)sgrp->current >= sgrp->nelem)
204*0Sstevel@tonic-gate return (-1);
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate *data1 = &(sgrp->sets[sgrp->current].data1);
207*0Sstevel@tonic-gate *data2 = &(sgrp->sets[sgrp->current].data2);
208*0Sstevel@tonic-gate *scratch = &(sgrp->sets[sgrp->current].scratch);
209*0Sstevel@tonic-gate
210*0Sstevel@tonic-gate return (sgrp->sets[sgrp->current].nreqs);
211*0Sstevel@tonic-gate }
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gate cpc_setgrp_t *
cpc_setgrp_clone(cpc_setgrp_t * old)214*0Sstevel@tonic-gate cpc_setgrp_clone(cpc_setgrp_t *old)
215*0Sstevel@tonic-gate {
216*0Sstevel@tonic-gate int i;
217*0Sstevel@tonic-gate cpc_setgrp_t *new;
218*0Sstevel@tonic-gate struct setgrp_elem *newa;
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate new = emalloc(sizeof (*new));
221*0Sstevel@tonic-gate newa = emalloc(old->nelem * sizeof (*newa));
222*0Sstevel@tonic-gate
223*0Sstevel@tonic-gate new->nelem = old->nelem;
224*0Sstevel@tonic-gate new->current = old->current;
225*0Sstevel@tonic-gate new->cpc = old->cpc;
226*0Sstevel@tonic-gate new->sets = newa;
227*0Sstevel@tonic-gate new->smt = old->smt;
228*0Sstevel@tonic-gate new->has_sysonly_set = old->has_sysonly_set;
229*0Sstevel@tonic-gate for (i = 0; i < old->nelem; i++) {
230*0Sstevel@tonic-gate if ((newa[i].set = cpc_strtoset(old->cpc, old->sets[i].name,
231*0Sstevel@tonic-gate old->smt)) == NULL) {
232*0Sstevel@tonic-gate (void) fprintf(stderr,
233*0Sstevel@tonic-gate gettext("cpc_setgrp: cpc_strtoset() failed\n"));
234*0Sstevel@tonic-gate exit(0);
235*0Sstevel@tonic-gate }
236*0Sstevel@tonic-gate if ((newa[i].name = strdup(old->sets[i].name)) == NULL) {
237*0Sstevel@tonic-gate (void) fprintf(stderr,
238*0Sstevel@tonic-gate gettext("cpc_setgrp: no memory available\n"));
239*0Sstevel@tonic-gate exit(0);
240*0Sstevel@tonic-gate }
241*0Sstevel@tonic-gate newa[i].sysonly = old->sets[i].sysonly;
242*0Sstevel@tonic-gate newa[i].nreqs = old->sets[i].nreqs;
243*0Sstevel@tonic-gate newa[i].data1 = cpc_buf_create(old->cpc, newa[i].set);
244*0Sstevel@tonic-gate newa[i].data2 = cpc_buf_create(old->cpc, newa[i].set);
245*0Sstevel@tonic-gate newa[i].scratch = cpc_buf_create(old->cpc, newa[i].set);
246*0Sstevel@tonic-gate if (newa[i].data1 == NULL || newa[i].data2 == NULL ||
247*0Sstevel@tonic-gate newa[i].scratch == NULL) {
248*0Sstevel@tonic-gate (void) fprintf(stderr,
249*0Sstevel@tonic-gate gettext("cpc_setgrp: no memory available\n"));
250*0Sstevel@tonic-gate exit(0);
251*0Sstevel@tonic-gate }
252*0Sstevel@tonic-gate cpc_buf_copy(old->cpc, newa[i].data1, old->sets[i].data1);
253*0Sstevel@tonic-gate cpc_buf_copy(old->cpc, newa[i].data2, old->sets[i].data2);
254*0Sstevel@tonic-gate cpc_buf_copy(old->cpc, newa[i].scratch, old->sets[i].scratch);
255*0Sstevel@tonic-gate }
256*0Sstevel@tonic-gate return (new);
257*0Sstevel@tonic-gate }
258*0Sstevel@tonic-gate
259*0Sstevel@tonic-gate static void
cpc_setgrp_delset(cpc_setgrp_t * sgrp)260*0Sstevel@tonic-gate cpc_setgrp_delset(cpc_setgrp_t *sgrp)
261*0Sstevel@tonic-gate {
262*0Sstevel@tonic-gate int l;
263*0Sstevel@tonic-gate
264*0Sstevel@tonic-gate if ((uint_t)sgrp->current >= sgrp->nelem)
265*0Sstevel@tonic-gate sgrp->current = sgrp->nelem - 1;
266*0Sstevel@tonic-gate if (sgrp->current < 0)
267*0Sstevel@tonic-gate return;
268*0Sstevel@tonic-gate free(sgrp->sets[sgrp->current].name);
269*0Sstevel@tonic-gate free(sgrp->sets[sgrp->current].hdr);
270*0Sstevel@tonic-gate free(sgrp->sets[sgrp->current].picnums);
271*0Sstevel@tonic-gate (void) cpc_buf_destroy(sgrp->cpc, sgrp->sets[sgrp->current].data1);
272*0Sstevel@tonic-gate (void) cpc_buf_destroy(sgrp->cpc, sgrp->sets[sgrp->current].data2);
273*0Sstevel@tonic-gate (void) cpc_buf_destroy(sgrp->cpc, sgrp->sets[sgrp->current].scratch);
274*0Sstevel@tonic-gate for (l = sgrp->current; l < sgrp->nelem - 1; l++)
275*0Sstevel@tonic-gate sgrp->sets[l] = sgrp->sets[l + 1];
276*0Sstevel@tonic-gate sgrp->nelem--;
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate
279*0Sstevel@tonic-gate void
cpc_setgrp_free(cpc_setgrp_t * sgrp)280*0Sstevel@tonic-gate cpc_setgrp_free(cpc_setgrp_t *sgrp)
281*0Sstevel@tonic-gate {
282*0Sstevel@tonic-gate if (sgrp->sets) {
283*0Sstevel@tonic-gate while (sgrp->nelem)
284*0Sstevel@tonic-gate cpc_setgrp_delset(sgrp);
285*0Sstevel@tonic-gate free(sgrp->sets);
286*0Sstevel@tonic-gate }
287*0Sstevel@tonic-gate free(sgrp);
288*0Sstevel@tonic-gate }
289*0Sstevel@tonic-gate
290*0Sstevel@tonic-gate cpc_set_t *
cpc_setgrp_getset(cpc_setgrp_t * sgrp)291*0Sstevel@tonic-gate cpc_setgrp_getset(cpc_setgrp_t *sgrp)
292*0Sstevel@tonic-gate {
293*0Sstevel@tonic-gate if ((uint_t)sgrp->current >= sgrp->nelem)
294*0Sstevel@tonic-gate return (NULL);
295*0Sstevel@tonic-gate return (sgrp->sets[sgrp->current].set);
296*0Sstevel@tonic-gate }
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate const char *
cpc_setgrp_getname(cpc_setgrp_t * sgrp)299*0Sstevel@tonic-gate cpc_setgrp_getname(cpc_setgrp_t *sgrp)
300*0Sstevel@tonic-gate {
301*0Sstevel@tonic-gate if ((uint_t)sgrp->current >= sgrp->nelem)
302*0Sstevel@tonic-gate return (NULL);
303*0Sstevel@tonic-gate return (sgrp->sets[sgrp->current].name);
304*0Sstevel@tonic-gate }
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gate const char *
cpc_setgrp_gethdr(cpc_setgrp_t * sgrp)307*0Sstevel@tonic-gate cpc_setgrp_gethdr(cpc_setgrp_t *sgrp)
308*0Sstevel@tonic-gate {
309*0Sstevel@tonic-gate if ((uint_t)sgrp->current >= sgrp->nelem)
310*0Sstevel@tonic-gate return (NULL);
311*0Sstevel@tonic-gate return (sgrp->sets[sgrp->current].hdr);
312*0Sstevel@tonic-gate }
313*0Sstevel@tonic-gate
314*0Sstevel@tonic-gate int
cpc_setgrp_numsets(cpc_setgrp_t * sgrp)315*0Sstevel@tonic-gate cpc_setgrp_numsets(cpc_setgrp_t *sgrp)
316*0Sstevel@tonic-gate {
317*0Sstevel@tonic-gate return (sgrp->nelem);
318*0Sstevel@tonic-gate }
319*0Sstevel@tonic-gate
320*0Sstevel@tonic-gate cpc_set_t *
cpc_setgrp_nextset(cpc_setgrp_t * sgrp)321*0Sstevel@tonic-gate cpc_setgrp_nextset(cpc_setgrp_t *sgrp)
322*0Sstevel@tonic-gate {
323*0Sstevel@tonic-gate if (sgrp->current < 0)
324*0Sstevel@tonic-gate return (NULL);
325*0Sstevel@tonic-gate
326*0Sstevel@tonic-gate if (++sgrp->current >= sgrp->nelem)
327*0Sstevel@tonic-gate sgrp->current = 0;
328*0Sstevel@tonic-gate
329*0Sstevel@tonic-gate return (cpc_setgrp_getset(sgrp));
330*0Sstevel@tonic-gate }
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate /*
333*0Sstevel@tonic-gate * Put the setgrp pointer back to the beginning of the set
334*0Sstevel@tonic-gate */
335*0Sstevel@tonic-gate void
cpc_setgrp_reset(cpc_setgrp_t * sgrp)336*0Sstevel@tonic-gate cpc_setgrp_reset(cpc_setgrp_t *sgrp)
337*0Sstevel@tonic-gate {
338*0Sstevel@tonic-gate if (sgrp->current > 0)
339*0Sstevel@tonic-gate sgrp->current = 0;
340*0Sstevel@tonic-gate }
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate /*
343*0Sstevel@tonic-gate * Adds the data from the 'data1' buf into the accum setgrp.
344*0Sstevel@tonic-gate */
345*0Sstevel@tonic-gate void
cpc_setgrp_accum(cpc_setgrp_t * accum,cpc_setgrp_t * sgrp)346*0Sstevel@tonic-gate cpc_setgrp_accum(cpc_setgrp_t *accum, cpc_setgrp_t *sgrp)
347*0Sstevel@tonic-gate {
348*0Sstevel@tonic-gate int i;
349*0Sstevel@tonic-gate
350*0Sstevel@tonic-gate cpc_setgrp_reset(accum);
351*0Sstevel@tonic-gate cpc_setgrp_reset(sgrp);
352*0Sstevel@tonic-gate if (accum->nelem != sgrp->nelem)
353*0Sstevel@tonic-gate return;
354*0Sstevel@tonic-gate
355*0Sstevel@tonic-gate for (i = 0; i < sgrp->nelem; i++) {
356*0Sstevel@tonic-gate if (accum->sets[i].nreqs != sgrp->sets[i].nreqs)
357*0Sstevel@tonic-gate return;
358*0Sstevel@tonic-gate cpc_buf_add(sgrp->cpc, accum->sets[i].data1,
359*0Sstevel@tonic-gate accum->sets[i].data1, sgrp->sets[i].data1);
360*0Sstevel@tonic-gate }
361*0Sstevel@tonic-gate }
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gate /*
364*0Sstevel@tonic-gate * Returns 1 if all requests in the current set count only system-mode events.
365*0Sstevel@tonic-gate */
366*0Sstevel@tonic-gate int
cpc_setgrp_sysonly(cpc_setgrp_t * sgrp)367*0Sstevel@tonic-gate cpc_setgrp_sysonly(cpc_setgrp_t *sgrp)
368*0Sstevel@tonic-gate {
369*0Sstevel@tonic-gate return ((int)sgrp->sets[sgrp->current].sysonly);
370*0Sstevel@tonic-gate }
371*0Sstevel@tonic-gate
372*0Sstevel@tonic-gate /*
373*0Sstevel@tonic-gate * Returns 1 if any set in the group is a system-mode-only set.
374*0Sstevel@tonic-gate */
375*0Sstevel@tonic-gate int
cpc_setgrp_has_sysonly(cpc_setgrp_t * sgrp)376*0Sstevel@tonic-gate cpc_setgrp_has_sysonly(cpc_setgrp_t *sgrp)
377*0Sstevel@tonic-gate {
378*0Sstevel@tonic-gate return (sgrp->has_sysonly_set);
379*0Sstevel@tonic-gate }
380*0Sstevel@tonic-gate
381*0Sstevel@tonic-gate /*
382*0Sstevel@tonic-gate * If we ever fail to get memory, we print an error message and exit.
383*0Sstevel@tonic-gate */
384*0Sstevel@tonic-gate static void *
emalloc(size_t n)385*0Sstevel@tonic-gate emalloc(size_t n)
386*0Sstevel@tonic-gate {
387*0Sstevel@tonic-gate /*
388*0Sstevel@tonic-gate * Several callers of this routine need zero-filled buffers.
389*0Sstevel@tonic-gate */
390*0Sstevel@tonic-gate void *p = calloc(1, n);
391*0Sstevel@tonic-gate
392*0Sstevel@tonic-gate if (p == NULL) {
393*0Sstevel@tonic-gate (void) fprintf(stderr,
394*0Sstevel@tonic-gate gettext("cpc_setgrp: no memory available\n"));
395*0Sstevel@tonic-gate exit(0);
396*0Sstevel@tonic-gate }
397*0Sstevel@tonic-gate
398*0Sstevel@tonic-gate return (p);
399*0Sstevel@tonic-gate }
400