xref: /illumos-gate/usr/src/uts/common/sys/sysinfo.h (revision 30165b7f6753bc3d48c52319bed7ec7b3ea36b3c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22 /*	  All Rights Reserved	*/
23 
24 
25 /*
26  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #ifndef _SYS_SYSINFO_H
31 #define	_SYS_SYSINFO_H
32 
33 #include <sys/types.h>
34 #include <sys/t_lock.h>
35 #include <sys/kstat.h>
36 #include <sys/machlock.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  *	System Information.
44  */
45 #define	CPU_IDLE	0
46 #define	CPU_USER	1
47 #define	CPU_KERNEL	2
48 #define	CPU_WAIT	3
49 #define	CPU_STATES	4
50 
51 #define	W_IO		0
52 #define	W_SWAP		1
53 #define	W_PIO		2
54 #define	W_STATES	3
55 
56 typedef struct cpu_sysinfo {
57 	uint_t	cpu[CPU_STATES]; /* CPU utilization			*/
58 	uint_t	wait[W_STATES];	/* CPU wait time breakdown		*/
59 	/*
60 	 * The two stats lwrite and bwrite are used by sar(1) to
61 	 * generate the write cache hit percentage (%wcache value).
62 	 *
63 	 * The value is calculated as follows (unless lwrite < 0.5 and
64 	 * then %wcache is coded to 100%):
65 	 *
66 	 *	(lwrite - bwrite)/lwrite * 100.0
67 	 *
68 	 * This calculation assumes that when a physical write occurs
69 	 * (bwrite incremented), that a logical write (lwrite
70 	 * incremented) has also occured. Note that a logical write
71 	 * (lwrite incremented) my occur on its own.
72 	 *
73 	 * Similar for lread/bread and %rcache.
74 	 */
75 	uint_t	bread;		/* physical block reads			*/
76 	uint_t	bwrite;		/* physical block writes (sync+async)	*/
77 	uint_t	lread;		/* logical block reads			*/
78 	uint_t	lwrite;		/* logical block writes			*/
79 	uint_t	phread;		/* raw I/O reads			*/
80 	uint_t	phwrite;	/* raw I/O writes			*/
81 	uint_t	pswitch;	/* context switches			*/
82 	uint_t	trap;		/* traps				*/
83 	uint_t	intr;		/* device interrupts			*/
84 	uint_t	syscall;	/* system calls				*/
85 	uint_t	sysread;	/* read() + readv() system calls	*/
86 	uint_t	syswrite;	/* write() + writev() system calls	*/
87 	uint_t	sysfork;	/* forks				*/
88 	uint_t	sysvfork;	/* vforks				*/
89 	uint_t	sysexec;	/* execs				*/
90 	uint_t	readch;		/* bytes read by rdwr()			*/
91 	uint_t	writech;	/* bytes written by rdwr()		*/
92 	uint_t	rcvint;		/* XXX: UNUSED				*/
93 	uint_t	xmtint;		/* XXX: UNUSED				*/
94 	uint_t	mdmint;		/* XXX: UNUSED				*/
95 	uint_t	rawch;		/* terminal input characters		*/
96 	uint_t	canch;		/* chars handled in canonical mode	*/
97 	uint_t	outch;		/* terminal output characters		*/
98 	uint_t	msg;		/* msg count (msgrcv()+msgsnd() calls)	*/
99 	uint_t	sema;		/* semaphore ops count (semop() calls)	*/
100 	uint_t	namei;		/* pathname lookups			*/
101 	uint_t	ufsiget;	/* ufs_iget() calls			*/
102 	uint_t	ufsdirblk;	/* directory blocks read		*/
103 	uint_t	ufsipage;	/* inodes taken with attached pages	*/
104 	uint_t	ufsinopage;	/* inodes taked with no attached pages	*/
105 	uint_t	inodeovf;	/* inode table overflows		*/
106 	uint_t	fileovf;	/* file table overflows			*/
107 	uint_t	procovf;	/* proc table overflows			*/
108 	uint_t	intrthread;	/* interrupts as threads (below clock)	*/
109 	uint_t	intrblk;	/* intrs blkd/prempted/released (swtch)	*/
110 	uint_t	idlethread;	/* times idle thread scheduled		*/
111 	uint_t	inv_swtch;	/* involuntary context switches		*/
112 	uint_t	nthreads;	/* thread_create()s			*/
113 	uint_t	cpumigrate;	/* cpu migrations by threads 		*/
114 	uint_t	xcalls;		/* xcalls to other cpus 		*/
115 	uint_t	mutex_adenters;	/* failed mutex enters (adaptive)	*/
116 	uint_t	rw_rdfails;	/* rw reader failures			*/
117 	uint_t	rw_wrfails;	/* rw writer failures			*/
118 	uint_t	modload;	/* times loadable module loaded		*/
119 	uint_t	modunload;	/* times loadable module unloaded 	*/
120 	uint_t	bawrite;	/* physical block writes (async)	*/
121 /* Following are gathered only under #ifdef STATISTICS in source 	*/
122 	uint_t	rw_enters;	/* tries to acquire rw lock		*/
123 	uint_t	win_uo_cnt;	/* reg window user overflows		*/
124 	uint_t	win_uu_cnt;	/* reg window user underflows		*/
125 	uint_t	win_so_cnt;	/* reg window system overflows		*/
126 	uint_t	win_su_cnt;	/* reg window system underflows		*/
127 	uint_t	win_suo_cnt;	/* reg window system user overflows	*/
128 } cpu_sysinfo_t;
129 
130 typedef struct sysinfo {	/* (update freq) update action		*/
131 	uint_t	updates;	/* (1 sec) ++				*/
132 	uint_t	runque;		/* (1 sec) += num runnable procs	*/
133 	uint_t	runocc;		/* (1 sec) ++ if num runnable procs > 0	*/
134 	uint_t	swpque;		/* (1 sec) += num swapped procs		*/
135 	uint_t	swpocc;		/* (1 sec) ++ if num swapped procs > 0	*/
136 	uint_t	waiting;	/* (1 sec) += jobs waiting for I/O	*/
137 } sysinfo_t;
138 
139 typedef struct cpu_syswait {
140 	int	iowait;		/* procs waiting for block I/O		*/
141 	int	swap;		/* XXX: UNUSED				*/
142 	int	physio;		/* XXX: UNUSED 				*/
143 } cpu_syswait_t;
144 
145 typedef struct cpu_vminfo {
146 	uint_t	pgrec;		/* page reclaims (includes pageout)	*/
147 	uint_t	pgfrec;		/* page reclaims from free list		*/
148 	uint_t	pgin;		/* pageins				*/
149 	uint_t	pgpgin;		/* pages paged in			*/
150 	uint_t	pgout;		/* pageouts				*/
151 	uint_t	pgpgout;	/* pages paged out			*/
152 	uint_t	swapin;		/* swapins				*/
153 	uint_t	pgswapin;	/* pages swapped in			*/
154 	uint_t	swapout;	/* swapouts				*/
155 	uint_t	pgswapout;	/* pages swapped out			*/
156 	uint_t	zfod;		/* pages zero filled on demand		*/
157 	uint_t	dfree;		/* pages freed by daemon or auto	*/
158 	uint_t	scan;		/* pages examined by pageout daemon	*/
159 	uint_t	rev;		/* revolutions of the page daemon hand	*/
160 	uint_t	hat_fault;	/* minor page faults via hat_fault()	*/
161 	uint_t	as_fault;	/* minor page faults via as_fault()	*/
162 	uint_t	maj_fault;	/* major page faults			*/
163 	uint_t	cow_fault;	/* copy-on-write faults			*/
164 	uint_t	prot_fault;	/* protection faults			*/
165 	uint_t	softlock;	/* faults due to software locking req	*/
166 	uint_t	kernel_asflt;	/* as_fault()s in kernel addr space	*/
167 	uint_t	pgrrun;		/* times pager scheduled		*/
168 	uint_t  execpgin;	/* executable pages paged in		*/
169 	uint_t  execpgout;	/* executable pages paged out		*/
170 	uint_t  execfree;	/* executable pages freed		*/
171 	uint_t  anonpgin;	/* anon pages paged in			*/
172 	uint_t  anonpgout;	/* anon pages paged out			*/
173 	uint_t  anonfree;	/* anon pages freed			*/
174 	uint_t  fspgin;		/* fs pages paged in			*/
175 	uint_t  fspgout;	/* fs pages paged out			*/
176 	uint_t  fsfree;		/* fs pages free			*/
177 } cpu_vminfo_t;
178 
179 typedef struct vminfo {		/* (update freq) update action		*/
180 	uint64_t freemem; 	/* (1 sec) += freemem in pages		*/
181 	uint64_t swap_resv;	/* (1 sec) += reserved swap in pages	*/
182 	uint64_t swap_alloc;	/* (1 sec) += allocated swap in pages	*/
183 	uint64_t swap_avail;	/* (1 sec) += unreserved swap in pages	*/
184 	uint64_t swap_free;	/* (1 sec) += unallocated swap in pages	*/
185 	uint64_t updates;	/* (1 sec) ++				*/
186 } vminfo_t;
187 
188 typedef struct cpu_stat {
189 	uint_t		__cpu_stat_lock[2];	/* 32-bit kstat compat. */
190 	cpu_sysinfo_t	cpu_sysinfo;
191 	cpu_syswait_t	cpu_syswait;
192 	cpu_vminfo_t	cpu_vminfo;
193 } cpu_stat_t;
194 
195 typedef struct cpu_sys_stats {
196 	uint64_t cpu_ticks_idle; 	/* CPU utilization */
197 	uint64_t cpu_ticks_user;
198 	uint64_t cpu_ticks_kernel;
199 	uint64_t cpu_ticks_wait;
200 	uint64_t wait_ticks_io;		/* CPU wait time breakdown */
201 	uint64_t bread;			/* physical block reads */
202 	uint64_t bwrite;		/* physical block writes (sync+async) */
203 	uint64_t lread;			/* logical block reads */
204 	uint64_t lwrite;		/* logical block writes */
205 	uint64_t phread;		/* raw I/O Reads */
206 	uint64_t phwrite;		/* raw I/O writes */
207 	uint64_t pswitch;		/* context switches */
208 	uint64_t trap;			/* traps */
209 	uint64_t intr[PIL_MAX];		/* device interrupts per PIL */
210 	uint64_t syscall;		/* system calls */
211 	uint64_t sysread;		/* read() + readv() system calls */
212 	uint64_t syswrite;		/* write() + writev() system calls */
213 	uint64_t sysfork;		/* forks */
214 	uint64_t sysvfork;		/* vforks */
215 	uint64_t sysexec;		/* execs */
216 	uint64_t readch;		/* bytes read by rdwr() */
217 	uint64_t writech;		/* bytes written by rdwr() */
218 	uint64_t rcvint;		/* XXX: unused (mostly) */
219 	uint64_t xmtint;		/* XXX: unused */
220 	uint64_t mdmint;		/* XXX: unused */
221 	uint64_t rawch;			/* terminal input characters */
222 	uint64_t canch;			/* chars handled in canonical mode */
223 	uint64_t outch;			/* terminal output characters */
224 	uint64_t msg;			/* msg count (msgrcv() + msgsnd()) */
225 	uint64_t sema;			/* semaphore ops count (semop()) */
226 	uint64_t namei;			/* pathname lookups */
227 	uint64_t ufsiget;		/* ufs_iget() calls */
228 	uint64_t ufsdirblk;		/* directory blocks read */
229 	uint64_t ufsipage;		/* inodes taken with attached pages */
230 	uint64_t ufsinopage;		/* inodes taken with no attached pgs */
231 	uint64_t procovf;		/* failed forks */
232 	uint64_t intrblk;		/* ints blkd/prempted/rel'd (swtch) */
233 	uint64_t intrunpin;		/* intr thread unpins pinned thread */
234 	uint64_t idlethread;		/* times idle thread scheduled */
235 	uint64_t inv_swtch;		/* involuntary context switches */
236 	uint64_t nthreads;		/* thread_create()s */
237 	uint64_t cpumigrate;		/* cpu migrations by threads */
238 	uint64_t xcalls;		/* xcalls to other cpus */
239 	uint64_t mutex_adenters;	/* failed mutex enters (adaptive) */
240 	uint64_t rw_rdfails;		/* rw reader failures */
241 	uint64_t rw_wrfails;		/* rw writer failures */
242 	uint64_t modload;		/* times loadable module loaded */
243 	uint64_t modunload; 		/* times loadable module unloaded */
244 	uint64_t bawrite;		/* physical block writes (async) */
245 	uint64_t iowait; 		/* count of waiters for block I/O */
246 } cpu_sys_stats_t;
247 
248 typedef struct cpu_vm_stats {
249 	uint64_t pgrec;			/* page reclaims (includes pageout) */
250 	uint64_t pgfrec;		/* page reclaims from free list */
251 	uint64_t pgin;			/* pageins */
252 	uint64_t pgpgin;		/* pages paged in */
253 	uint64_t pgout;			/* pageouts */
254 	uint64_t pgpgout;		/* pages paged out */
255 	uint64_t swapin;		/* swapins */
256 	uint64_t pgswapin;		/* pages swapped in */
257 	uint64_t swapout;		/* swapouts */
258 	uint64_t pgswapout;		/* pages swapped out */
259 	uint64_t zfod;			/* pages zero filled on demand */
260 	uint64_t dfree;			/* pages freed by daemon or auto */
261 	uint64_t scan;			/* pages examined by pageout daemon */
262 	uint64_t rev;			/* revolutions of page daemon hand */
263 	uint64_t hat_fault;		/* minor page faults via hat_fault() */
264 	uint64_t as_fault;		/* minor page faults via as_fault() */
265 	uint64_t maj_fault;		/* major page faults */
266 	uint64_t cow_fault;		/* copy-on-write faults */
267 	uint64_t prot_fault;		/* protection faults */
268 	uint64_t softlock;		/* faults due to software locking req */
269 	uint64_t kernel_asflt;		/* as_fault()s in kernel addr space */
270 	uint64_t pgrrun;		/* times pager scheduled */
271 	uint64_t execpgin;		/* executable pages paged in */
272 	uint64_t execpgout;		/* executable pages paged out */
273 	uint64_t execfree;		/* executable pages freed */
274 	uint64_t anonpgin;		/* anon pages paged in */
275 	uint64_t anonpgout;		/* anon pages paged out */
276 	uint64_t anonfree;		/* anon pages freed */
277 	uint64_t fspgin;		/* fs pages paged in */
278 	uint64_t fspgout;		/* fs pages paged out */
279 	uint64_t fsfree;		/* fs pages free */
280 } cpu_vm_stats_t;
281 
282 typedef struct cpu_stats {
283 	cpu_sys_stats_t	sys;
284 	cpu_vm_stats_t	vm;
285 } cpu_stats_t;
286 
287 #ifdef	__cplusplus
288 }
289 #endif
290 
291 #endif	/* _SYS_SYSINFO_H */
292