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