Print this page
NEX-3729 KRRP changes mess up iostat(1M)
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/stat/common/statcommon.h
+++ new/usr/src/cmd/stat/common/statcommon.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * Common routines for acquiring snapshots of kstats for
28 28 * iostat, mpstat, and vmstat.
29 29 */
30 30
31 31 #ifndef _STATCOMMON_H
32 32 #define _STATCOMMON_H
33 33
34 34 #ifdef __cplusplus
35 35 extern "C" {
36 36 #endif
37 37
38 38 #include <stdio.h>
39 39 #include <kstat.h>
40 40 #include <sys/time.h>
41 41 #include <sys/types.h>
42 42 #include <sys/buf.h>
43 43 #include <sys/dnlc.h>
44 44 #include <sys/sysinfo.h>
45 45 #include <sys/processor.h>
46 46 #include <sys/pset.h>
47 47 #include <sys/avl.h>
48 48
49 49 /* No CPU present at this CPU position */
50 50 #define ID_NO_CPU -1
51 51 /* CPU belongs to no pset (we number this as "pset 0") */
52 52 #define ID_NO_PSET 0
53 53 /* CPU is usable */
54 54 #define CPU_ONLINE(s) ((s) == P_ONLINE || (s) == P_NOINTR)
55 55 /* will the CPU have kstats */
56 56 #define CPU_ACTIVE(c) (CPU_ONLINE((c)->cs_state) && (c)->cs_id != ID_NO_CPU)
57 57 /* IO device has no identified ID */
58 58 #define IODEV_NO_ID -1
59 59 /* no limit to iodevs to collect */
60 60 #define UNLIMITED_IODEVS ((size_t)-1)
61 61
62 62 #define NODATE 0 /* Default: No time stamp */
63 63 #define DDATE 1 /* Standard date format */
64 64 #define UDATE 2 /* Internal representation of Unix time */
65 65
66 66
67 67 enum snapshot_types {
68 68 /* All CPUs separately */
69 69 SNAP_CPUS = 1 << 0,
70 70 /* Aggregated processor sets */
71 71 SNAP_PSETS = 1 << 1,
72 72 /* sys-wide stats including aggregated CPU stats */
73 73 SNAP_SYSTEM = 1 << 2,
74 74 /* interrupt sources and counts */
75 75 SNAP_INTERRUPTS = 1 << 3,
76 76 /* disk etc. stats */
77 77 SNAP_IODEVS = 1 << 4,
78 78 /* disk controller aggregates */
79 79 SNAP_CONTROLLERS = 1 << 5,
80 80 /* mpxio L I (multipath) paths: -X: Lun,LunInitiator */
81 81 SNAP_IOPATHS_LI = 1 << 6,
82 82 /* mpxio LTI (multipath) paths: -Y: Lun,LunTarget,LunTargetInitiator */
83 83 SNAP_IOPATHS_LTI = 1 << 7,
84 84 /* disk error stats */
85 85 SNAP_IODEV_ERRORS = 1 << 8,
86 86 /* pretty names for iodevs */
87 87 SNAP_IODEV_PRETTY = 1 << 9,
88 88 /* devid for iodevs */
89 89 SNAP_IODEV_DEVID = 1 << 10
90 90 };
91 91
92 92 struct cpu_snapshot {
93 93 /* may be ID_NO_CPU if no CPU present */
94 94 processorid_t cs_id;
95 95 /* may be ID_NO_PSET if no pset */
96 96 psetid_t cs_pset_id;
97 97 /* as in p_online(2) */
98 98 int cs_state;
99 99 /* stats for this CPU */
100 100 kstat_t cs_vm;
101 101 kstat_t cs_sys;
102 102 };
103 103
104 104 struct pset_snapshot {
105 105 /* ID may be zero to indicate the "none set" */
106 106 psetid_t ps_id;
107 107 /* number of CPUs in set */
108 108 size_t ps_nr_cpus;
109 109 /* the CPUs in this set */
110 110 struct cpu_snapshot **ps_cpus;
111 111 };
112 112
113 113 struct intr_snapshot {
114 114 /* name of interrupt source */
115 115 char is_name[KSTAT_STRLEN];
116 116 /* total number of interrupts from this source */
117 117 ulong_t is_total;
118 118 };
119 119
120 120 struct sys_snapshot {
121 121 sysinfo_t ss_sysinfo;
122 122 vminfo_t ss_vminfo;
123 123 struct nc_stats ss_nc;
124 124 /* vm/sys stats aggregated across all CPUs */
125 125 kstat_t ss_agg_vm;
126 126 kstat_t ss_agg_sys;
127 127 /* ticks since boot */
128 128 ulong_t ss_ticks;
129 129 long ss_deficit;
130 130 };
131 131
|
↓ open down ↓ |
131 lines elided |
↑ open up ↑ |
132 132 /* order is significant (see sort_before()) */
133 133 enum iodev_type {
134 134 IODEV_CONTROLLER = 1 << 0,
135 135 IODEV_DISK = 1 << 1,
136 136 IODEV_PARTITION = 1 << 2,
137 137 IODEV_TAPE = 1 << 3,
138 138 IODEV_NFS = 1 << 4,
139 139 IODEV_IOPATH_LT = 1 << 5, /* synthetic LunTarget */
140 140 IODEV_IOPATH_LI = 1 << 6, /* synthetic LunInitiator */
141 141 IODEV_IOPATH_LTI = 1 << 7, /* LunTgtInitiator (pathinfo) */
142 - IODEV_UNKNOWN = 1 << 8
142 + IODEV_ZFS = 1 << 8,
143 + IODEV_UNKNOWN = 1 << 9
143 144 };
144 145
145 146 /* identify a disk, partition, etc. */
146 147 struct iodev_id {
147 148 int id;
148 149 /* target id (for disks) */
149 150 char tid[KSTAT_STRLEN];
150 151 };
151 152
152 153 /*
153 154 * Used for disks, partitions, tapes, nfs, controllers, iopaths
154 155 * Each entry can be a branch of a tree; for example, the disks
155 156 * of a controller constitute the children of the controller
156 157 * iodev_snapshot. This relationship is not strictly maintained
157 158 * if is_pretty can't be found.
158 159 */
159 160 struct iodev_snapshot {
160 161 /* original kstat name */
161 162 char is_name[KSTAT_STRLEN];
162 163 /* type of kstat */
163 164 enum iodev_type is_type;
164 165 /* ID if meaningful */
165 166 struct iodev_id is_id;
166 167 /* parent ID if meaningful */
167 168 struct iodev_id is_parent_id;
168 169 /* user-friendly name if found */
169 170 char *is_pretty;
170 171 /* device ID if applicable */
171 172 char *is_devid;
172 173 /* mount-point if applicable */
173 174 char *is_dname;
174 175 /* number of direct children */
175 176 int is_nr_children;
176 177 /* children of this I/O device */
177 178 struct iodev_snapshot *is_children;
178 179 /* standard I/O stats */
179 180 kstat_io_t is_stats;
180 181 /* iodev error stats */
181 182 kstat_t is_errors;
182 183 /* creation time of the stats */
183 184 hrtime_t is_crtime;
184 185 /* time at which iodev snapshot was taken */
185 186 hrtime_t is_snaptime;
186 187 /* kstat module */
187 188 char is_module[KSTAT_STRLEN];
188 189 /* kstat instance */
189 190 int is_instance;
190 191 /* kstat (only used temporarily) */
191 192 kstat_t *is_ksp;
192 193 struct iodev_snapshot *is_prev;
193 194 struct iodev_snapshot *is_next;
194 195 /* AVL structures to speedup insertion */
195 196 avl_tree_t *avl_list; /* list this element belongs to */
196 197 avl_node_t avl_link;
197 198 };
198 199
199 200 /* which iodevs to show. */
200 201 struct iodev_filter {
201 202 /* nr. of iodevs to choose */
202 203 size_t if_max_iodevs;
203 204 /* bit mask of enum io_types to allow */
204 205 int if_allowed_types;
205 206 /* should we show floppy ? if_names can override this */
206 207 int if_skip_floppy;
207 208 /* nr. of named iodevs */
208 209 size_t if_nr_names;
209 210 char **if_names;
210 211 };
211 212
212 213 /* The primary structure of a system snapshot. */
213 214 struct snapshot {
214 215 /* what types were *requested* */
215 216 enum snapshot_types s_types;
216 217 size_t s_nr_cpus;
217 218 struct cpu_snapshot *s_cpus;
218 219 size_t s_nr_psets;
219 220 struct pset_snapshot *s_psets;
220 221 size_t s_nr_intrs;
221 222 struct intr_snapshot *s_intrs;
222 223 size_t s_nr_iodevs;
223 224 struct iodev_snapshot *s_iodevs;
224 225 size_t s_iodevs_is_name_maxlen;
225 226 struct sys_snapshot s_sys;
226 227 struct biostats s_biostats;
227 228 size_t s_nr_active_cpus;
228 229 };
229 230
230 231 /* print a message and exit with failure */
231 232 void fail(int do_perror, char *message, ...);
232 233
233 234 /* strdup str, or exit with failure */
234 235 char *safe_strdup(char *str);
235 236
236 237 /* malloc successfully, or exit with failure */
237 238 void *safe_alloc(size_t size);
238 239
239 240 /*
240 241 * Copy a kstat from src to dst. If the source kstat contains no data,
241 242 * then set the destination kstat data to NULL and size to zero.
242 243 * Returns 0 on success.
243 244 */
244 245 int kstat_copy(const kstat_t *src, kstat_t *dst);
245 246
246 247 /*
247 248 * Look up the named kstat, and give the ui64 difference i.e.
248 249 * new - old, or if old is NULL, return new.
249 250 */
250 251 uint64_t kstat_delta(kstat_t *old, kstat_t *new, char *name);
251 252
252 253 /* Return the number of ticks delta between two hrtime_t values. */
253 254 uint64_t hrtime_delta(hrtime_t old, hrtime_t new);
254 255
255 256 /*
256 257 * Add the integer-valued stats from "src" to the
257 258 * existing ones in "dst". If "dst" does not contain
258 259 * stats, then a kstat_copy() is performed.
259 260 */
260 261 int kstat_add(const kstat_t *src, kstat_t *dst);
261 262
262 263 /* return the number of CPUs with kstats (i.e. present and online) */
263 264 int nr_active_cpus(struct snapshot *ss);
264 265
265 266 /*
266 267 * Return the difference in CPU ticks between the two sys
267 268 * kstats.
268 269 */
269 270 uint64_t cpu_ticks_delta(kstat_t *old, kstat_t *new);
270 271
271 272 /*
272 273 * Open the kstat chain. Cannot fail.
273 274 */
274 275 kstat_ctl_t *open_kstat(void);
275 276
276 277 /*
277 278 * Return a struct snapshot based on the snapshot_types parameter
278 279 * passed in. iodev_filter may be NULL in which case all iodevs
279 280 * are selected if SNAP_IODEVS is passed.
280 281 */
281 282 struct snapshot *acquire_snapshot(kstat_ctl_t *, int, struct iodev_filter *);
282 283
283 284 /* free a snapshot */
284 285 void free_snapshot(struct snapshot *ss);
285 286
286 287 typedef void (*snapshot_cb)(void *old, void *new, void *data);
287 288
288 289 /*
289 290 * Call the call back for each pair of data items of the given type,
290 291 * passing the data pointer passed in as well. If an item has been
291 292 * added, the first pointer will be NULL; if removed, the second pointer
292 293 * will be NULL.
293 294 *
294 295 * A non-zero return value indicates configuration has changed.
295 296 */
296 297 int snapshot_walk(enum snapshot_types type, struct snapshot *old,
297 298 struct snapshot *new, snapshot_cb cb, void *data);
298 299
299 300 /*
300 301 * Output a line detailing any configuration changes such as a CPU
301 302 * brought online, etc, bracketed by << >>.
302 303 */
303 304 void snapshot_report_changes(struct snapshot *old, struct snapshot *new);
304 305
305 306 /* Return non-zero if configuration has changed. */
306 307 int snapshot_has_changed(struct snapshot *old, struct snapshot *new);
307 308
308 309 /* free the given iodev */
309 310 void free_iodev(struct iodev_snapshot *iodev);
310 311
311 312 /* acquire the I/O devices */
312 313 int acquire_iodevs(struct snapshot *ss, kstat_ctl_t *kc,
313 314 struct iodev_filter *df);
314 315
315 316 /* strcmp-style I/O device comparator */
316 317 int iodev_cmp(struct iodev_snapshot *io1, struct iodev_snapshot *io2);
317 318
318 319 /* sleep until *wakeup + interval, keeping cadence where desired */
319 320 void sleep_until(hrtime_t *wakeup, hrtime_t interval, int forever,
320 321 int *caught_cont);
321 322
322 323 /* signal handler - so we can be aware of SIGCONT */
323 324 void cont_handler(int sig_number);
324 325
325 326 /* Print a timestamp in either Unix or standard format. */
326 327 void print_timestamp(uint_t);
327 328
328 329 #ifdef __cplusplus
329 330 }
330 331 #endif
331 332
332 333 #endif /* _STATCOMMON_H */
|
↓ open down ↓ |
180 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX