xref: /dragonfly/sys/sys/kinfo.h (revision 2b3f93ea)
1 /*
2  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Joerg Sonnenberger <joerg@bec.de>.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #ifndef _SYS_KINFO_H_
36 #define _SYS_KINFO_H_
37 
38 #ifndef _SYS_TYPES_H_
39 #include <sys/types.h>
40 #endif
41 #ifndef _SYS_PARAM_H_
42 #include <sys/param.h>
43 #endif
44 #ifndef _SYS_CAPS_H_
45 #include <sys/caps.h>
46 #endif
47 #include <sys/resource.h>
48 #include <sys/rtprio.h>
49 #include <sys/proc_common.h>
50 #ifdef _KERNEL
51 #include <sys/proc.h>
52 #endif
53 
54 /*
55  * NOTE: correct way to use this header from non kernel code is to include
56  * the <sys/user.h> first!
57  */
58 
59 struct kinfo_file {
60 	size_t	 f_size;	/* size of struct kinfo_file */
61 	pid_t	 f_pid;		/* owning process */
62 	uid_t	 f_uid;		/* effective uid of owning process */
63 	int	 f_fd;		/* descriptor number */
64 	void	*f_file;	/* address of struct file */
65 	short	 f_type;	/* descriptor type */
66 	int	 f_count;	/* reference count */
67 	int	 f_msgcount;	/* references from message queue */
68 	off_t	 f_offset;	/* file offset */
69 	void	*f_data;	/* file descriptor specific data */
70 	u_int	 f_flag;	/* flags (see fcntl.h) */
71 };
72 
73 /*
74  * CPU time statistics
75  */
76 struct kinfo_cputime {
77 	uint64_t	cp_user;
78 	uint64_t	cp_nice;
79 	uint64_t	cp_sys;
80 	uint64_t	cp_intr;
81 	uint64_t	cp_idle;
82 	uint64_t	cp_unused01;
83 	uint64_t	cp_unused02;
84 	uint64_t	cp_sample_pc;
85 	uint64_t	cp_sample_sp;
86 	char		cp_msg[32];	/* code stall token or mplock */
87 };
88 
89 /*
90  * CPU system/interrupt program counter sampler
91  */
92 #define PCTRACK_ARYSIZE	32	/* must be a power of 2 */
93 #define PCTRACK_ARYMASK	(PCTRACK_ARYSIZE - 1)
94 
95 struct kinfo_pcheader {
96 	int		pc_ntrack;	/* number of tracks per cpu (2) */
97 	int		pc_arysize;	/* size of storage array (32) */
98 };
99 
100 struct kinfo_pctrack {
101 	int		pc_index;
102 	void		*pc_array[PCTRACK_ARYSIZE];
103 };
104 
105 #define PCTRACK_SYS	0
106 #define PCTRACK_INT	1
107 #define PCTRACK_SIZE	2
108 
109 struct kinfo_clockinfo {
110 	int	ci_hz;		/* clock frequency */
111 	int	ci_tick;	/* micro-seconds per hz tick */
112 	int	ci_tickadj;	/* clock skew rate for adjtime() */
113 	int	ci_stathz;	/* statistics clock frequency */
114 	int	ci_profhz;	/* profiling clock frequency */
115 };
116 
117 /*
118  * Structure definition for the lwp-specific data in struct kinfo_proc.
119  */
120 struct kinfo_lwp {
121 	pid_t		kl_pid;		/* PID of our associated proc */
122 	lwpid_t		kl_tid;		/* thread id */
123 
124 	int		kl_flags;	/* LWP_ flags */
125 	enum lwpstat	kl_stat;	/* LS* lwp status */
126 	int		kl_lock;	/* lwp lock (prevent destruct) count */
127 	int		kl_tdflags;	/* thread flags */
128 	int		kl_mpcount;	/* MP lock held count */
129 	int		kl_prio;	/* scheduling priority */
130 	int		kl_tdprio;	/* lwkt sched priority */
131 	struct rtprio	kl_rtprio;	/* real-time scheduling prio */
132 
133 	/* accounting */
134 	uint64_t	kl_uticks;	/* time accounting */
135 	uint64_t	kl_sticks;
136 	uint64_t	kl_iticks;
137 	uint64_t	kl_cpticks;	/* sched quantums used */
138 	u_int		kl_pctcpu;	/* percentage cputime */
139 	u_int		kl_slptime;	/* time since last blocked */
140 	int		kl_origcpu;	/* originally scheduled on cpu */
141 	int		kl_estcpu;
142 	int		kl_cpuid;	/* CPU this lwp was last scheduled on */
143 
144 	struct rusage	kl_ru;		/* resource usage stats */
145 
146 	sigset_t	kl_siglist;	/* pending signals */
147 	sigset_t	kl_sigmask;	/* masked signals */
148 #define WMESGLEN 8
149 	uintptr_t	kl_wchan;	/* waiting channel */
150 	char		kl_wmesg[WMESGLEN+1];	/* waiting message */
151 
152 	char		kl_comm[MAXCOMLEN+1];	/* lwp name */
153 };
154 
155 /*
156  * KERN_PROC subtype ops return arrays of normalized proc structures:
157  *
158  * NOTE: Access to capability bits beyond __KP_NSYSCAPS not available
159  *	 via this structure.
160  */
161 #define __KP_NSYSCAPS 	(sizeof(__syscapelm_t) * 8)	/* in structure */
162 
163 #define __KP_SYSCAP_AVAIL(cap)				\
164 		((cap) < __KP_NSYSCAPS)
165 
166 #define __KP_SYSCAP_GET(base, cap)			\
167 		(((base)[__SYSCAP_INDEX(cap)] >>	\
168 		  __SYSCAP_SHIFT(cap)) & __SYSCAP_BITS_MASK)
169 
170 #define __KP_SYSCAP_GET_SELF(base, cap)			\
171 		(__KP_SYSCAP_GET(base, cap) & __SYSCAP_SELF)
172 
173 struct kinfo_proc {
174 	uintptr_t	kp_paddr;	/* address of this proc */
175 
176 	/* proc information */
177 	int		kp_flags;
178 	enum procstat	kp_stat;
179 	int		kp_lock;
180 	int		kp_acflag;	/* accounting flags */
181 	int		kp_traceflag;
182 
183 	uintptr_t	kp_fd;		/* address of the proc's files */
184 
185 	sigset_t	kp_siglist;
186 	sigset_t	kp_sigignore;
187 	sigset_t	kp_sigcatch;
188 	int		kp_sigflag;	/* from ps_flag */
189 	struct timeval	kp_start;
190 
191 	char		kp_comm[MAXCOMLEN+1];
192 
193 	/* cred information */
194 	uid_t		kp_uid;
195 	short		kp_ngroups;
196 	gid_t		kp_groups[NGROUPS];
197 	uid_t		kp_ruid;
198 	uid_t		kp_svuid;
199 	gid_t		kp_rgid;
200 	gid_t		kp_svgid;
201 
202 	pid_t		kp_pid;		/* process id */
203 	pid_t		kp_ppid;	/* parent process id */
204 	pid_t		kp_pgid;	/* process group id */
205 	int		kp_jobc;	/* job control counter */
206 	pid_t		kp_sid;		/* session id */
207 	char		kp_login[roundup(MAXLOGNAME, sizeof(long))];
208 					/* setlogin() name */
209 	dev_t		kp_tdev;	/* controlling tty dev */
210 	pid_t		kp_tpgid;	/* tty process group id */
211 	pid_t		kp_tsid;	/* tty session id */
212 
213 	u_short		kp_exitstat;	/* exit status information */
214 	int		kp_nthreads;
215 	int		kp_nice;
216 	unsigned int	kp_swtime;
217 
218 	size_t		kp_vm_map_size;		/* vmmap virtual size in bytes */
219 	segsz_t		kp_vm_rssize;		/* resident set size in pages */
220 	segsz_t		kp_vm_swrss;		/* rss before last swap in pages */
221 	segsz_t		kp_vm_tsize;		/* text size in pages */
222 	segsz_t		kp_vm_dsize;		/* data size in pages */
223 	segsz_t		kp_vm_ssize;		/* stack size in pages */
224 	u_int		kp_vm_prssize;		/* proportional rss in pages */
225 
226 	int		kp_jailid;
227 
228 	struct rusage	kp_ru;
229 	struct rusage	kp_cru;
230 
231 	int		kp_auxflags;	/* generated flags */
232 #define KI_CTTY	1
233 #define KI_SLEADER	2
234 
235 	struct kinfo_lwp kp_lwp;
236 
237 	uintptr_t	kp_ktaddr;	/* address of this kernel thread */
238 	__syscapelm_t	kp_syscaps[__KP_NSYSCAPS / sizeof(__syscapelm_t)];
239 };
240 
241 /*
242  * KERN_SIGTRAMP, public, KERN_PROC_SIGTRAMP used in external codes
243  */
244 struct kinfo_sigtramp {
245 	void		*ksigtramp_start;
246 	void		*ksigtramp_end;
247 	void		*ksigtramp_spare[4];
248 };
249 
250 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
251 struct proc;
252 struct lwp;
253 struct thread;
254 
255 __BEGIN_DECLS
256 void fill_kinfo_proc(struct proc *, struct kinfo_proc *);
257 void fill_kinfo_lwp(struct lwp *, struct kinfo_lwp *);
258 void fill_kinfo_proc_kthread(struct thread *, struct kinfo_proc *);
259 __END_DECLS
260 #endif	/* defined(_KERNEL) || defined(_KERNEL_STRUCTURES) */
261 
262 #ifdef _KERNEL
263 #define cpu_time	cputime_percpu[mycpuid]
264 extern struct kinfo_cputime cputime_percpu[MAXCPU];
265 #endif	/* _KERNEL */
266 
267 #endif	/* !_SYS_KINFO_H_ */
268