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 /*
28*7c478bd9Sstevel@tonic-gate * sa_kstat - kstat statistic adapter, collects statistic data provided
29*7c478bd9Sstevel@tonic-gate * by kstat.
30*7c478bd9Sstevel@tonic-gate */
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include <locale.h>
33*7c478bd9Sstevel@tonic-gate #include <string.h>
34*7c478bd9Sstevel@tonic-gate #include <assert.h>
35*7c478bd9Sstevel@tonic-gate #include <kstat.h>
36*7c478bd9Sstevel@tonic-gate #include <pool.h>
37*7c478bd9Sstevel@tonic-gate #include "utils.h"
38*7c478bd9Sstevel@tonic-gate #include <sys/pset.h>
39*7c478bd9Sstevel@tonic-gate #include "poolstat.h"
40*7c478bd9Sstevel@tonic-gate #include "poolstat_utils.h"
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate /* marks 'sdata_t' element as updated */
43*7c478bd9Sstevel@tonic-gate #define SD_UPDATED 1
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate /* Specified value for an invalid set. */
46*7c478bd9Sstevel@tonic-gate #define INVALID_SET -2
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate /* statistic data */
49*7c478bd9Sstevel@tonic-gate typedef struct sdata {
50*7c478bd9Sstevel@tonic-gate kstat_t sd_oks; /* old kstat */
51*7c478bd9Sstevel@tonic-gate kstat_t sd_nks; /* new kstat */
52*7c478bd9Sstevel@tonic-gate void *sd_udata; /* user data */
53*7c478bd9Sstevel@tonic-gate uint_t sd_state; /* state of this data (UPDATED) */
54*7c478bd9Sstevel@tonic-gate struct sdata *sd_next;
55*7c478bd9Sstevel@tonic-gate } sdata_t;
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate /* pset user data */
58*7c478bd9Sstevel@tonic-gate typedef struct {
59*7c478bd9Sstevel@tonic-gate psetid_t opset; /* old pset sysid */
60*7c478bd9Sstevel@tonic-gate psetid_t npset; /* new pset sysid */
61*7c478bd9Sstevel@tonic-gate } pset_ud_t;
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gate /* shortcuts to access set's id in 'pset_ud_t' */
64*7c478bd9Sstevel@tonic-gate #define SD_OPSET(p) (((pset_ud_t *)(p)->sd_udata)->opset)
65*7c478bd9Sstevel@tonic-gate #define SD_NPSET(p) (((pset_ud_t *)(p)->sd_udata)->npset)
66*7c478bd9Sstevel@tonic-gate
67*7c478bd9Sstevel@tonic-gate static kstat_ctl_t *ks_ctl; /* libkstat handle */
68*7c478bd9Sstevel@tonic-gate static sdata_t *cpu_list; /* list with cpu statistics */
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate static sdata_t *update_sdata_list(sdata_t *, kstat_ctl_t *, char *, int,
71*7c478bd9Sstevel@tonic-gate char *, int *);
72*7c478bd9Sstevel@tonic-gate static void update_cpu_list(sdata_t *list);
73*7c478bd9Sstevel@tonic-gate static void update_pset_stats(statistic_bag_t *, sdata_t *);
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
76*7c478bd9Sstevel@tonic-gate void
sa_kstat_init(void * unused)77*7c478bd9Sstevel@tonic-gate sa_kstat_init(void *unused)
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate if ((ks_ctl = kstat_open()) == NULL)
80*7c478bd9Sstevel@tonic-gate die(gettext(ERR_KSTAT_OPEN), get_errstr());
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate void
sa_kstat_update(statistic_bag_t * sbag,int flags)84*7c478bd9Sstevel@tonic-gate sa_kstat_update(statistic_bag_t *sbag, int flags)
85*7c478bd9Sstevel@tonic-gate {
86*7c478bd9Sstevel@tonic-gate /* The SA_REFRESH flag forces the update of local data structures. */
87*7c478bd9Sstevel@tonic-gate if (flags & SA_REFRESH) {
88*7c478bd9Sstevel@tonic-gate int ks_error = 0;
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate if (kstat_chain_update(ks_ctl) == -1)
91*7c478bd9Sstevel@tonic-gate die(gettext(ERR_KSTAT_DATA), get_errstr());
92*7c478bd9Sstevel@tonic-gate cpu_list = update_sdata_list(cpu_list, ks_ctl, "cpu",
93*7c478bd9Sstevel@tonic-gate -1, "sys", &ks_error);
94*7c478bd9Sstevel@tonic-gate if (ks_error)
95*7c478bd9Sstevel@tonic-gate die(gettext(ERR_KSTAT_DATA), get_errstr());
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate /* update info about cpu binding to processor sets */
98*7c478bd9Sstevel@tonic-gate update_cpu_list(cpu_list);
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate if (strcmp(sbag->sb_type, PSET_TYPE_NAME) == 0) {
102*7c478bd9Sstevel@tonic-gate update_pset_stats(sbag, cpu_list);
103*7c478bd9Sstevel@tonic-gate } else if (strcmp(sbag->sb_type, POOL_TYPE_NAME) == 0) {
104*7c478bd9Sstevel@tonic-gate return;
105*7c478bd9Sstevel@tonic-gate } else {
106*7c478bd9Sstevel@tonic-gate die(gettext(ERR_UNSUPP_STYPE), sbag->sb_type);
107*7c478bd9Sstevel@tonic-gate }
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate static void *
safe_kstat_data_lookup(kstat_t * ksp,char * name)112*7c478bd9Sstevel@tonic-gate safe_kstat_data_lookup(kstat_t *ksp, char *name)
113*7c478bd9Sstevel@tonic-gate {
114*7c478bd9Sstevel@tonic-gate void *dp;
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate if ((dp = kstat_data_lookup(ksp, name)) == NULL)
117*7c478bd9Sstevel@tonic-gate die(gettext(ERR_KSTAT_DLOOKUP),
118*7c478bd9Sstevel@tonic-gate ksp->ks_name, name, get_errstr());
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate return (dp);
121*7c478bd9Sstevel@tonic-gate }
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate /*
124*7c478bd9Sstevel@tonic-gate * Find the delta over the interval between new_ksp and old_ksp.
125*7c478bd9Sstevel@tonic-gate * If old_ksp->ks_data is NULL and 'oz' is set then pretend
126*7c478bd9Sstevel@tonic-gate * that old_ksp is zero otherwise return 0.
127*7c478bd9Sstevel@tonic-gate */
128*7c478bd9Sstevel@tonic-gate static uint64_t
delta(kstat_t * new_ksp,kstat_t * old_ksp,char * name,int oz)129*7c478bd9Sstevel@tonic-gate delta(kstat_t *new_ksp, kstat_t *old_ksp, char *name, int oz)
130*7c478bd9Sstevel@tonic-gate {
131*7c478bd9Sstevel@tonic-gate kstat_named_t *new_ksn;
132*7c478bd9Sstevel@tonic-gate kstat_named_t *old_ksn;
133*7c478bd9Sstevel@tonic-gate
134*7c478bd9Sstevel@tonic-gate new_ksn = (kstat_named_t *)safe_kstat_data_lookup(new_ksp, name);
135*7c478bd9Sstevel@tonic-gate if (old_ksp == NULL || old_ksp->ks_data == NULL)
136*7c478bd9Sstevel@tonic-gate return ((oz == 1) ? new_ksn->value.ui64 : 0);
137*7c478bd9Sstevel@tonic-gate old_ksn = (kstat_named_t *)safe_kstat_data_lookup(old_ksp, name);
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate return (new_ksn->value.ui64 - old_ksn->value.ui64);
140*7c478bd9Sstevel@tonic-gate }
141*7c478bd9Sstevel@tonic-gate
142*7c478bd9Sstevel@tonic-gate /*
143*7c478bd9Sstevel@tonic-gate * Create a clone of the passed kstat_t structure 'kstat_t'. If
144*7c478bd9Sstevel@tonic-gate * 'fr' flag is set free the old ks_data structure in 'dst'.
145*7c478bd9Sstevel@tonic-gate */
146*7c478bd9Sstevel@tonic-gate static void
kstat_clone(kstat_t * src,kstat_t * dst,int fr)147*7c478bd9Sstevel@tonic-gate kstat_clone(kstat_t *src, kstat_t *dst, int fr)
148*7c478bd9Sstevel@tonic-gate {
149*7c478bd9Sstevel@tonic-gate if (fr)
150*7c478bd9Sstevel@tonic-gate FREE(dst->ks_data);
151*7c478bd9Sstevel@tonic-gate *dst = *src;
152*7c478bd9Sstevel@tonic-gate if (src->ks_data != NULL) {
153*7c478bd9Sstevel@tonic-gate dst->ks_data = ZALLOC(src->ks_data_size);
154*7c478bd9Sstevel@tonic-gate (void) memcpy(dst->ks_data, src->ks_data, src->ks_data_size);
155*7c478bd9Sstevel@tonic-gate } else {
156*7c478bd9Sstevel@tonic-gate dst->ks_data = NULL;
157*7c478bd9Sstevel@tonic-gate dst->ks_data_size = 0;
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate /*
162*7c478bd9Sstevel@tonic-gate * Erase the data from 'src'.
163*7c478bd9Sstevel@tonic-gate */
164*7c478bd9Sstevel@tonic-gate static void
kstat_erase(kstat_t * src)165*7c478bd9Sstevel@tonic-gate kstat_erase(kstat_t *src)
166*7c478bd9Sstevel@tonic-gate {
167*7c478bd9Sstevel@tonic-gate FREE(src->ks_data);
168*7c478bd9Sstevel@tonic-gate (void) memset(src, 0, sizeof (*src));
169*7c478bd9Sstevel@tonic-gate }
170*7c478bd9Sstevel@tonic-gate
171*7c478bd9Sstevel@tonic-gate /*
172*7c478bd9Sstevel@tonic-gate * Create a new statistic data object with its own copy of the passed
173*7c478bd9Sstevel@tonic-gate * kstat.
174*7c478bd9Sstevel@tonic-gate */
175*7c478bd9Sstevel@tonic-gate static sdata_t *
sdata_new(kstat_t * ksp)176*7c478bd9Sstevel@tonic-gate sdata_new(kstat_t *ksp)
177*7c478bd9Sstevel@tonic-gate {
178*7c478bd9Sstevel@tonic-gate sdata_t *sdp;
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate NEW0(sdp);
181*7c478bd9Sstevel@tonic-gate kstat_clone(ksp, &sdp->sd_nks, 0);
182*7c478bd9Sstevel@tonic-gate
183*7c478bd9Sstevel@tonic-gate return (sdp);
184*7c478bd9Sstevel@tonic-gate }
185*7c478bd9Sstevel@tonic-gate
186*7c478bd9Sstevel@tonic-gate static void
sdata_free(sdata_t * sdp)187*7c478bd9Sstevel@tonic-gate sdata_free(sdata_t *sdp)
188*7c478bd9Sstevel@tonic-gate {
189*7c478bd9Sstevel@tonic-gate FREE(sdp->sd_oks.ks_data);
190*7c478bd9Sstevel@tonic-gate FREE(sdp->sd_nks.ks_data);
191*7c478bd9Sstevel@tonic-gate FREE(sdp->sd_udata);
192*7c478bd9Sstevel@tonic-gate FREE(sdp);
193*7c478bd9Sstevel@tonic-gate }
194*7c478bd9Sstevel@tonic-gate
195*7c478bd9Sstevel@tonic-gate /*
196*7c478bd9Sstevel@tonic-gate * Create new or update an existing list of cpu statistics. For each
197*7c478bd9Sstevel@tonic-gate * cpu two kstats are kept. One old kstat which contains the data from
198*7c478bd9Sstevel@tonic-gate * the previous scan, and new with the current data. The old and the new
199*7c478bd9Sstevel@tonic-gate * kstats *must* be for the same instance and have the same kid.
200*7c478bd9Sstevel@tonic-gate * If 'instance' argument is set to -1 don't use it as a filter.
201*7c478bd9Sstevel@tonic-gate */
202*7c478bd9Sstevel@tonic-gate static sdata_t *
update_sdata_list(sdata_t * list,kstat_ctl_t * kc,char * module,int instance,char * name,int * errp)203*7c478bd9Sstevel@tonic-gate update_sdata_list(sdata_t *list, kstat_ctl_t *kc, char *module,
204*7c478bd9Sstevel@tonic-gate int instance, char *name, int *errp)
205*7c478bd9Sstevel@tonic-gate {
206*7c478bd9Sstevel@tonic-gate kstat_t *ksp;
207*7c478bd9Sstevel@tonic-gate sdata_t *sdp, *sdpp; /* kstat instance pointer/previous-pointer */
208*7c478bd9Sstevel@tonic-gate
209*7c478bd9Sstevel@tonic-gate for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
210*7c478bd9Sstevel@tonic-gate if (strcmp(ksp->ks_module, module) == 0 &&
211*7c478bd9Sstevel@tonic-gate (name == NULL || strcmp(ksp->ks_name, name) == 0) &&
212*7c478bd9Sstevel@tonic-gate (instance == -1 || ksp->ks_instance == instance)) {
213*7c478bd9Sstevel@tonic-gate if (kstat_read(kc, ksp, NULL) == -1) {
214*7c478bd9Sstevel@tonic-gate *errp = -1;
215*7c478bd9Sstevel@tonic-gate return (list);
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate /*
218*7c478bd9Sstevel@tonic-gate * Find the kstat in the existing list:
219*7c478bd9Sstevel@tonic-gate * If we find one for the same instance and with the
220*7c478bd9Sstevel@tonic-gate * same ks_kid we'll save it as old_kstat.
221*7c478bd9Sstevel@tonic-gate * If we find one for the same instance but with a
222*7c478bd9Sstevel@tonic-gate * different ks_kid we'll removed it.
223*7c478bd9Sstevel@tonic-gate */
224*7c478bd9Sstevel@tonic-gate for (sdpp = sdp = list; sdp; sdp = sdp->sd_next) {
225*7c478bd9Sstevel@tonic-gate if (ksp->ks_instance ==
226*7c478bd9Sstevel@tonic-gate sdp->sd_nks.ks_instance) {
227*7c478bd9Sstevel@tonic-gate if (ksp->ks_kid == sdp->sd_nks.ks_kid) {
228*7c478bd9Sstevel@tonic-gate kstat_clone(&sdp->sd_nks,
229*7c478bd9Sstevel@tonic-gate &sdp->sd_oks, 1);
230*7c478bd9Sstevel@tonic-gate } else {
231*7c478bd9Sstevel@tonic-gate kstat_erase(&sdp->sd_oks);
232*7c478bd9Sstevel@tonic-gate }
233*7c478bd9Sstevel@tonic-gate kstat_clone(ksp, &sdp->sd_nks, 1);
234*7c478bd9Sstevel@tonic-gate sdp->sd_state |= SD_UPDATED;
235*7c478bd9Sstevel@tonic-gate break;
236*7c478bd9Sstevel@tonic-gate }
237*7c478bd9Sstevel@tonic-gate sdpp = sdp;
238*7c478bd9Sstevel@tonic-gate }
239*7c478bd9Sstevel@tonic-gate /* add a new kstat instance */
240*7c478bd9Sstevel@tonic-gate if (!sdp) {
241*7c478bd9Sstevel@tonic-gate /* first instance */
242*7c478bd9Sstevel@tonic-gate if (!list) {
243*7c478bd9Sstevel@tonic-gate list = sdata_new(ksp);
244*7c478bd9Sstevel@tonic-gate list->sd_state |= SD_UPDATED;
245*7c478bd9Sstevel@tonic-gate } else {
246*7c478bd9Sstevel@tonic-gate sdpp->sd_next = sdata_new(ksp);
247*7c478bd9Sstevel@tonic-gate sdpp->sd_next->sd_state |= SD_UPDATED;
248*7c478bd9Sstevel@tonic-gate }
249*7c478bd9Sstevel@tonic-gate }
250*7c478bd9Sstevel@tonic-gate }
251*7c478bd9Sstevel@tonic-gate }
252*7c478bd9Sstevel@tonic-gate
253*7c478bd9Sstevel@tonic-gate /* remove untouched statistics */
254*7c478bd9Sstevel@tonic-gate sdp = list;
255*7c478bd9Sstevel@tonic-gate sdpp = NULL;
256*7c478bd9Sstevel@tonic-gate while (sdp != NULL) {
257*7c478bd9Sstevel@tonic-gate
258*7c478bd9Sstevel@tonic-gate if (sdp->sd_state & SD_UPDATED) {
259*7c478bd9Sstevel@tonic-gate sdp->sd_state &= ~SD_UPDATED;
260*7c478bd9Sstevel@tonic-gate sdpp = sdp;
261*7c478bd9Sstevel@tonic-gate sdp = sdp->sd_next;
262*7c478bd9Sstevel@tonic-gate } else {
263*7c478bd9Sstevel@tonic-gate sdata_t *tmp;
264*7c478bd9Sstevel@tonic-gate
265*7c478bd9Sstevel@tonic-gate if (sdpp == NULL)
266*7c478bd9Sstevel@tonic-gate list = sdp->sd_next;
267*7c478bd9Sstevel@tonic-gate else
268*7c478bd9Sstevel@tonic-gate sdpp->sd_next = sdp->sd_next;
269*7c478bd9Sstevel@tonic-gate tmp = sdp->sd_next;
270*7c478bd9Sstevel@tonic-gate sdata_free(sdp);
271*7c478bd9Sstevel@tonic-gate sdp = tmp;
272*7c478bd9Sstevel@tonic-gate }
273*7c478bd9Sstevel@tonic-gate }
274*7c478bd9Sstevel@tonic-gate
275*7c478bd9Sstevel@tonic-gate *errp = 0;
276*7c478bd9Sstevel@tonic-gate return (list);
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate
279*7c478bd9Sstevel@tonic-gate /*
280*7c478bd9Sstevel@tonic-gate * Update the pset assignment information for each cpu in the statistic
281*7c478bd9Sstevel@tonic-gate * data list.
282*7c478bd9Sstevel@tonic-gate */
283*7c478bd9Sstevel@tonic-gate static void
update_cpu_list(sdata_t * list)284*7c478bd9Sstevel@tonic-gate update_cpu_list(sdata_t *list)
285*7c478bd9Sstevel@tonic-gate {
286*7c478bd9Sstevel@tonic-gate sdata_t *sdp;
287*7c478bd9Sstevel@tonic-gate
288*7c478bd9Sstevel@tonic-gate for (sdp = list; sdp; sdp = sdp->sd_next) {
289*7c478bd9Sstevel@tonic-gate /* for new CPU create a new user data object */
290*7c478bd9Sstevel@tonic-gate if (sdp->sd_udata == NULL) {
291*7c478bd9Sstevel@tonic-gate sdp->sd_udata = ZALLOC(sizeof (pset_ud_t));
292*7c478bd9Sstevel@tonic-gate /*
293*7c478bd9Sstevel@tonic-gate * set its pset to invalid, so it will not be
294*7c478bd9Sstevel@tonic-gate * used in statistics calculation.
295*7c478bd9Sstevel@tonic-gate */
296*7c478bd9Sstevel@tonic-gate SD_NPSET(sdp) = INVALID_SET;
297*7c478bd9Sstevel@tonic-gate }
298*7c478bd9Sstevel@tonic-gate /* copy the pset assignment information to the previous stat */
299*7c478bd9Sstevel@tonic-gate SD_OPSET(sdp) = SD_NPSET(sdp);
300*7c478bd9Sstevel@tonic-gate /* set the current assignment */
301*7c478bd9Sstevel@tonic-gate if (pset_assign(PS_QUERY, sdp->sd_nks.ks_instance,
302*7c478bd9Sstevel@tonic-gate &(SD_NPSET(sdp))) == -1)
303*7c478bd9Sstevel@tonic-gate SD_NPSET(sdp) = INVALID_SET;
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate }
306*7c478bd9Sstevel@tonic-gate
307*7c478bd9Sstevel@tonic-gate /*
308*7c478bd9Sstevel@tonic-gate * Update statistic data for pset. Calculate the CPU usage in a pset.
309*7c478bd9Sstevel@tonic-gate */
310*7c478bd9Sstevel@tonic-gate static void
update_pset_stats(statistic_bag_t * sbag,sdata_t * list)311*7c478bd9Sstevel@tonic-gate update_pset_stats(statistic_bag_t *sbag, sdata_t *list)
312*7c478bd9Sstevel@tonic-gate {
313*7c478bd9Sstevel@tonic-gate sdata_t *sdp;
314*7c478bd9Sstevel@tonic-gate pset_statistic_bag_t *bag = (pset_statistic_bag_t *)sbag->bag;
315*7c478bd9Sstevel@tonic-gate uint64_t allticks, ust, kst, ist, wst;
316*7c478bd9Sstevel@tonic-gate
317*7c478bd9Sstevel@tonic-gate ust = kst = ist = wst = 0;
318*7c478bd9Sstevel@tonic-gate for (sdp = list; sdp; sdp = sdp->sd_next) {
319*7c478bd9Sstevel@tonic-gate /*
320*7c478bd9Sstevel@tonic-gate * only calculate for the asked pset id and if the cpu belongs
321*7c478bd9Sstevel@tonic-gate * to the same set in the previous and in the current snapshot.
322*7c478bd9Sstevel@tonic-gate * It means that the usage for CPUs that were rebound during
323*7c478bd9Sstevel@tonic-gate * the sampling interval are not charged to any set.
324*7c478bd9Sstevel@tonic-gate */
325*7c478bd9Sstevel@tonic-gate if ((SD_OPSET(sdp) == SD_NPSET(sdp)) &&
326*7c478bd9Sstevel@tonic-gate (SD_NPSET(sdp) == bag->pset_sb_sysid)) {
327*7c478bd9Sstevel@tonic-gate ust += delta(&sdp->sd_nks, &sdp->sd_oks,
328*7c478bd9Sstevel@tonic-gate "cpu_ticks_user", 0);
329*7c478bd9Sstevel@tonic-gate kst += delta(&sdp->sd_nks, &sdp->sd_oks,
330*7c478bd9Sstevel@tonic-gate "cpu_ticks_kernel", 0);
331*7c478bd9Sstevel@tonic-gate ist += delta(&sdp->sd_nks, &sdp->sd_oks,
332*7c478bd9Sstevel@tonic-gate "cpu_ticks_idle", 0);
333*7c478bd9Sstevel@tonic-gate wst += delta(&sdp->sd_nks, &sdp->sd_oks,
334*7c478bd9Sstevel@tonic-gate "cpu_ticks_wait", 0);
335*7c478bd9Sstevel@tonic-gate }
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate
338*7c478bd9Sstevel@tonic-gate if ((allticks = ust + kst + wst + ist) != 0) {
339*7c478bd9Sstevel@tonic-gate bag->pset_sb_used =
340*7c478bd9Sstevel@tonic-gate (double)(ust + kst) / allticks * bag->pset_sb_size;
341*7c478bd9Sstevel@tonic-gate } else {
342*7c478bd9Sstevel@tonic-gate bag->pset_sb_used = 0.0;
343*7c478bd9Sstevel@tonic-gate }
344*7c478bd9Sstevel@tonic-gate }
345