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