FreeBSD/Linux Kernel Cross Reference
sys/sys/lwp.h
1 /* $NetBSD: lwp.h,v 1.21.2.1 2005/03/20 11:58:55 tron Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _SYS_LWP_H
40 #define _SYS_LWP_H
41
42
43 #if defined(_KERNEL)
44 #include <machine/cpu.h> /* curcpu() and cpu_info */
45 #endif
46 #include <machine/proc.h> /* Machine-dependent proc substruct. */
47 #include <sys/queue.h>
48 #include <sys/callout.h>
49 #include <sys/ucontext.h>
50
51 struct lwp {
52 struct lwp *l_forw; /* Doubly-linked run/sleep queue. */
53 struct lwp *l_back;
54 LIST_ENTRY(lwp) l_list; /* Entry on list of all LWPs. */
55
56 struct proc *l_proc; /* Process with which we are associated. */
57
58 LIST_ENTRY(lwp) l_sibling; /* Entry on process's list of LWPs. */
59
60 struct cpu_info * __volatile l_cpu; /* CPU we're running on if
61 SONPROC */
62 int l_flag;
63 int l_stat;
64 lwpid_t l_lid; /* LWP identifier; local to process. */
65
66 #define l_startzero l_swtime
67 u_int l_swtime; /* Time swapped in or out. */
68 u_int l_slptime; /* Time since last blocked. */
69
70 const void *l_wchan; /* Sleep address. */
71 struct callout l_tsleep_ch; /* callout for tsleep */
72 const char *l_wmesg; /* Reason for sleep. */
73 int l_holdcnt; /* If non-zero, don't swap. */
74 void *l_ctxlink; /* uc_link {get,set}context */
75 int l_dupfd; /* Sideways return value from cloning devices XXX */
76 struct sadata_vp *l_savp; /* SA "virtual processor" */
77
78 #define l_endzero l_priority
79
80 #define l_startcopy l_priority
81
82 u_char l_priority; /* Process priority. */
83 u_char l_usrpri; /* User-priority based on p_cpu and p_nice. */
84
85 #define l_endcopy l_private
86
87 void *l_private; /* svr4-style lwp-private data */
88 void *l_emuldata; /* kernel lwp-private data */
89
90 int l_locks; /* DEBUG: lockmgr count of held locks */
91
92 struct user *l_addr; /* Kernel virtual addr of u-area (PROC ONLY). */
93 struct mdlwp l_md; /* Any machine-dependent fields. */
94
95 };
96
97 LIST_HEAD(lwplist, lwp); /* a list of LWPs */
98
99 extern struct lwplist alllwp; /* List of all LWPs. */
100
101 extern struct pool lwp_pool; /* memory pool for LWPs */
102 extern struct pool lwp_uc_pool; /* memory pool for LWP startup args */
103
104 extern struct lwp lwp0; /* LWP for proc0 */
105
106 /* These flags are kept in l_flag. */
107 #define L_INMEM 0x00004 /* Loaded into memory. */
108 #define L_SELECT 0x00040 /* Selecting; wakeup/waiting danger. */
109 #define L_SINTR 0x00080 /* Sleep is interruptible. */
110 #define L_TIMEOUT 0x00400 /* Timing out during sleep. */
111 #define L_PROCEXIT 0x00800 /* In process exit, l_proc no longer valid */
112 #define L_BIGLOCK 0x80000 /* LWP needs kernel "big lock" to run */
113 #define L_SA 0x100000 /* Scheduler activations LWP */
114 #define L_SA_UPCALL 0x200000 /* SA upcall is pending */
115 #define L_SA_BLOCKING 0x400000 /* Blocking in tsleep() */
116 #define L_DETACHED 0x800000 /* Won't be waited for. */
117 #define L_CANCELLED 0x2000000 /* tsleep should not sleep */
118 #define L_SA_PAGEFAULT 0x4000000 /* SA LWP in pagefault handler */
119 #define L_SA_YIELD 0x10000000 /* LWP on VP is yielding */
120 #define L_SA_IDLE 0x20000000 /* VP is idle */
121 #define L_SA_SWITCHING 0x80000000 /* SA LWP in context switch */
122
123 /*
124 * Status values.
125 *
126 * A note about SRUN and SONPROC: SRUN indicates that a process is
127 * runnable but *not* yet running, i.e. is on a run queue. SONPROC
128 * indicates that the process is actually executing on a CPU, i.e.
129 * it is no longer on a run queue.
130 */
131 #define LSIDL 1 /* Process being created by fork. */
132 #define LSRUN 2 /* Currently runnable. */
133 #define LSSLEEP 3 /* Sleeping on an address. */
134 #define LSSTOP 4 /* Process debugging or suspension. */
135 #define LSZOMB 5 /* Awaiting collection by parent. */
136 #define LSDEAD 6 /* Process is almost a zombie. */
137 #define LSONPROC 7 /* Process is currently on a CPU. */
138 #define LSSUSPENDED 8 /* Not running, not signalable. */
139
140 #ifdef _KERNEL
141 #define PHOLD(l) \
142 do { \
143 if ((l)->l_holdcnt++ == 0 && ((l)->l_flag & L_INMEM) == 0) \
144 uvm_swapin(l); \
145 } while (/* CONSTCOND */ 0)
146 #define PRELE(l) (--(l)->l_holdcnt)
147
148
149 void preempt (int);
150 int mi_switch (struct lwp *, struct lwp *);
151 #ifndef remrunqueue
152 void remrunqueue (struct lwp *);
153 #endif
154 void resetpriority (struct lwp *);
155 void setrunnable (struct lwp *);
156 #ifndef setrunqueue
157 void setrunqueue (struct lwp *);
158 #endif
159 #ifndef nextrunqueue
160 struct lwp *nextrunqueue(void);
161 #endif
162 void unsleep (struct lwp *);
163 #ifndef cpu_switch
164 int cpu_switch (struct lwp *, struct lwp *);
165 #endif
166 #ifndef cpu_switchto
167 void cpu_switchto (struct lwp *, struct lwp *);
168 #endif
169
170 int newlwp(struct lwp *, struct proc *, vaddr_t, int /* XXX boolean_t */, int,
171 void *, size_t, void (*)(void *), void *, struct lwp **);
172
173 /* Flags for _lwp_wait1 */
174 #define LWPWAIT_EXITCONTROL 0x00000001
175 int lwp_wait1(struct lwp *, lwpid_t, lwpid_t *, int);
176 void lwp_continue(struct lwp *);
177 void cpu_setfunc(struct lwp *, void (*)(void *), void *);
178 void startlwp(void *);
179 void upcallret(struct lwp *);
180 void lwp_exit (struct lwp *);
181 void lwp_exit2 (struct lwp *);
182 struct lwp *proc_representative_lwp(struct proc *);
183 inline int lwp_suspend(struct lwp *, struct lwp *);
184 #endif /* _KERNEL */
185
186 /* Flags for _lwp_create(), as per Solaris. */
187
188 #define LWP_DETACHED 0x00000040
189 #define LWP_SUSPENDED 0x00000080
190 #define __LWP_ASLWP 0x00000100 /* XXX more icky signal semantics */
191
192 #endif /* !_SYS_LWP_H_ */
193
Cache object: 342a245d1d38081318a347c2ce563ada
|