e7123fe910a56d6a57bafbd1109a297654448fba
[dragonfly.git] / sys / sys / kinfo.h
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  * $DragonFly: src/sys/sys/kinfo.h,v 1.13 2007/02/18 16:17:09 corecode Exp $
35  */
36
37 #ifndef _SYS_KINFO_H_
38 #define _SYS_KINFO_H_
39
40 #ifndef _KERNEL_STRUCTURES
41 #define _KERNEL_STRUCTURES
42 #endif
43
44 #ifndef _SYS_TYPES_H_
45 #include <sys/types.h>
46 #endif
47 #ifndef _SYS_PARAM_H_
48 #include <sys/param.h>
49 #endif
50 #include <sys/resource.h>
51 #include <sys/rtprio.h>
52 #include <sys/proc.h>
53
54 struct kinfo_file {
55         size_t   f_size;        /* size of struct kinfo_file */
56         pid_t    f_pid;         /* owning process */
57         uid_t    f_uid;         /* effective uid of owning process */
58         int      f_fd;          /* descriptor number */
59         void    *f_file;        /* address of struct file */
60         short    f_type;        /* descriptor type */
61         int      f_count;       /* reference count */
62         int      f_msgcount;    /* references from message queue */
63         off_t    f_offset;      /* file offset */
64         void    *f_data;        /* file descriptor specific data */
65         u_int    f_flag;        /* flags (see fcntl.h) */
66 };
67
68 /*
69  * CPU time statistics
70  */
71 struct kinfo_cputime {
72         uint64_t        cp_user;
73         uint64_t        cp_nice;
74         uint64_t        cp_sys;
75         uint64_t        cp_intr;
76         uint64_t        cp_idle;
77 };
78
79 /*
80  * CPU system/interrupt program counter sampler
81  */
82 #define PCTRACK_ARYSIZE 32      /* must be a power of 2 */
83 #define PCTRACK_ARYMASK (PCTRACK_ARYSIZE - 1)
84
85 struct kinfo_pcheader {
86         int             pc_ntrack;      /* number of tracks per cpu (2) */
87         int             pc_arysize;     /* size of storage array (32) */
88 };
89
90 struct kinfo_pctrack {
91         int             pc_index;
92         void            *pc_array[PCTRACK_ARYSIZE];
93 };
94
95 #define PCTRACK_SYS     0
96 #define PCTRACK_INT     1
97 #define PCTRACK_SIZE    2
98
99 struct kinfo_clockinfo {
100         int     ci_hz;          /* clock frequency */
101         int     ci_tick;        /* micro-seconds per hz tick */
102         int     ci_tickadj;     /* clock skew rate for adjtime() */
103         int     ci_stathz;      /* statistics clock frequency */
104         int     ci_profhz;      /* profiling clock frequency */
105 };
106
107 /*
108  * Structure definition for the lwp-specific data in struct kinfo_proc.
109  */
110 struct kinfo_lwp {
111         pid_t           kl_pid;         /* PID of our associated proc */
112         lwpid_t         kl_tid;         /* thread id */
113
114         int             kl_flags;       /* LWP_ flags */
115         enum lwpstat    kl_stat;        /* LS* lwp status */
116         int             kl_lock;        /* lwp lock (prevent destruct) count */
117         int             kl_tdflags;     /* thread flags */
118         int             kl_mpcount;     /* MP lock held count */
119         int             kl_prio;        /* scheduling priority */
120         int             kl_tdprio;      /* lwkt sched priority */
121         struct rtprio   kl_rtprio;      /* real-time scheduling prio */
122
123         /* accounting */
124         uint64_t        kl_uticks;      /* time accounting */
125         uint64_t        kl_sticks;
126         uint64_t        kl_iticks;
127         uint64_t        kl_cpticks;     /* sched quantums used */
128         u_int           kl_pctcpu;      /* percentage cputime */
129         u_int           kl_slptime;     /* time since last blocked */
130         int             kl_origcpu;     /* originally scheduled on cpu */
131         int             kl_estcpu;
132         int             kl_cpuid;       /* CPU this lwp was last scheduled on */
133
134         struct rusage   kl_ru;          /* resource usage stats */
135
136         sigset_t        kl_siglist;     /* pending signals */
137         sigset_t        kl_sigmask;     /* masked signals */
138 #define WMESGLEN 7
139         uintptr_t       kl_wchan;       /* waiting channel */
140         char            kl_wmesg[WMESGLEN+1];   /* waiting message */
141 };
142
143 /*
144  * KERN_PROC subtype ops return arrays of normalized proc structures:
145  */
146 struct kinfo_proc {
147         uintptr_t       kp_paddr;       /* address of this proc */
148
149         /* proc information */
150         int             kp_flags;
151         enum procstat   kp_stat;
152         int             kp_lock;
153         int             kp_acflag;      /* accounting flags */
154         int             kp_traceflag;
155
156         uintptr_t       kp_fd;          /* address of the proc's files */
157
158         sigset_t        kp_siglist;
159         sigset_t        kp_sigignore;
160         sigset_t        kp_sigcatch;
161         int             kp_sigflag;     /* from ps_flag */
162         struct timeval  kp_start;
163
164         char            kp_comm[MAXCOMLEN+1];
165
166         /* cred information */
167         uid_t           kp_uid;
168         short           kp_ngroups;
169         gid_t           kp_groups[NGROUPS];
170         uid_t           kp_ruid;
171         uid_t           kp_svuid;
172         gid_t           kp_rgid;
173         gid_t           kp_svgid;
174
175         pid_t           kp_pid; /* process id */
176         pid_t           kp_ppid;        /* parent process id */
177         pid_t           kp_pgid;        /* process group id */
178         int             kp_jobc;        /* job control counter */
179         pid_t           kp_sid; /* session id */
180         char            kp_login[roundup(MAXLOGNAME, sizeof(long))];    /* setlogin() name */
181         dev_t           kp_tdev;        /* controlling tty dev */
182         pid_t           kp_tpgid;       /* tty process group id */
183         pid_t           kp_tsid;        /* tty session id */
184
185         u_short         kp_exitstat;    /* exit status information */
186         int             kp_nthreads;
187         int             kp_nice;
188         unsigned int    kp_swtime;
189
190         vm_size_t       kp_vm_map_size; /* vmmap virtual size */
191         segsz_t         kp_vm_rssize;           /* resident set size */
192         segsz_t         kp_vm_swrss;            /* rss before last swap */
193         segsz_t         kp_vm_tsize;            /* text size */
194         segsz_t         kp_vm_dsize;            /* data size */
195         segsz_t         kp_vm_ssize;            /* stack size */
196
197         int             kp_jailid;
198
199         struct rusage   kp_ru;
200         struct rusage   kp_cru;
201
202         int             kp_auxflags;    /* generated flags */
203 #define KI_CTTY 1
204 #define KI_SLEADER      2
205
206         struct kinfo_lwp kp_lwp;
207
208         int             kp_spare[4];
209 };
210
211 struct proc;
212 struct lwp;
213 struct thread;
214
215 void fill_kinfo_proc(struct proc *, struct kinfo_proc *);
216 void fill_kinfo_lwp(struct lwp *, struct kinfo_lwp *);
217 void fill_kinfo_proc_kthread(struct thread *, struct kinfo_proc *);
218
219 #define KINFO_NEXT(kp)  ((union kinfo *)((uintptr_t)kp + kp->gen.len))
220 #define KINFO_END(kp)   (kp->gen.type == KINFO_TYPE_END)
221
222 #if defined(_KERNEL)
223 #ifdef SMP
224 #define cpu_time        cputime_percpu[mycpuid]
225 #else
226 #define cpu_time        cputime_percpu[0]
227 #endif
228 #endif
229
230 #if defined(_KERNEL)
231 extern struct kinfo_cputime cputime_percpu[MAXCPU];
232 #endif
233
234 #endif /* !_SYS_KINFO_H_ */