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