kern_turnstile.c revision 1.1.2.5 1 1.1.2.5 thorpej /* $NetBSD: kern_turnstile.c,v 1.1.2.5 2002/03/11 00:44:31 thorpej Exp $ */
2 1.1.2.1 thorpej
3 1.1.2.1 thorpej /*-
4 1.1.2.1 thorpej * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1.2.1 thorpej * All rights reserved.
6 1.1.2.1 thorpej *
7 1.1.2.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.1 thorpej * by Jason R. Thorpe.
9 1.1.2.1 thorpej *
10 1.1.2.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1.2.1 thorpej * modification, are permitted provided that the following conditions
12 1.1.2.1 thorpej * are met:
13 1.1.2.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1.2.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1.2.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1.2.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1.2.1 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1.2.1 thorpej * must display the following acknowledgement:
20 1.1.2.1 thorpej * This product includes software developed by the NetBSD
21 1.1.2.1 thorpej * Foundation, Inc. and its contributors.
22 1.1.2.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.1 thorpej * contributors may be used to endorse or promote products derived
24 1.1.2.1 thorpej * from this software without specific prior written permission.
25 1.1.2.1 thorpej *
26 1.1.2.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.1 thorpej */
38 1.1.2.1 thorpej
39 1.1.2.1 thorpej /*
40 1.1.2.1 thorpej * Turnsiles are specialized sleep queues for use by locks. Turnstiles
41 1.1.2.1 thorpej * are described in detail in:
42 1.1.2.1 thorpej *
43 1.1.2.1 thorpej * Solaris Internals: Core Kernel Architecture, Jim Mauro and
44 1.1.2.1 thorpej * Richard McDougall.
45 1.1.2.1 thorpej *
46 1.1.2.3 thorpej * Turnstiles are kept in a hash table. There are likely to be many more
47 1.1.2.3 thorpej * lock objects than there are threads. Since a thread can block on only
48 1.1.2.3 thorpej * one lock at a time, we only need one turnstile per thread, and so they
49 1.1.2.3 thorpej * are allocated at thread creation time.
50 1.1.2.1 thorpej *
51 1.1.2.1 thorpej * When a thread decides it needs to block on a lock, it looks up the
52 1.1.2.1 thorpej * active turnstile for that lock. If no active turnstile exists, then
53 1.1.2.1 thorpej * the process lends its turnstile to the lock. If there is already
54 1.1.2.1 thorpej * an active turnstile for the lock, the thread places its turnstile on
55 1.1.2.1 thorpej * a list of free turnstiles, and references the active one instead.
56 1.1.2.1 thorpej *
57 1.1.2.1 thorpej * The act of looking up the turnstile acquires an interlock on the sleep
58 1.1.2.1 thorpej * queue. If a thread decides it doesn't need to block after all, then
59 1.1.2.1 thorpej * this interlock must be released by explicitly aborting the turnstile
60 1.1.2.1 thorpej * operation.
61 1.1.2.1 thorpej *
62 1.1.2.1 thorpej * When a thread is awakened, it needs to get its turnstile back. If
63 1.1.2.1 thorpej * there are still other threads waiting in the active turnstile, the
64 1.1.2.1 thorpej * the thread grabs a free turnstile off the free list. Otherwise, it
65 1.1.2.1 thorpej * can take back the active turnstile from the lock (thus deactivating
66 1.1.2.1 thorpej * the turnstile).
67 1.1.2.1 thorpej *
68 1.1.2.1 thorpej * Turnstiles are the place to do priority inheritence. However, we do
69 1.1.2.1 thorpej * not currently implement that.
70 1.1.2.1 thorpej *
71 1.1.2.1 thorpej * We also do not differentiate between the reader and writer queues,
72 1.1.2.1 thorpej * although we currently provide for it in the API so that we can add
73 1.1.2.1 thorpej * support for it later.
74 1.1.2.1 thorpej *
75 1.1.2.1 thorpej * XXX We currently have to interlock with the sched_lock. The locking
76 1.1.2.1 thorpej * order is:
77 1.1.2.1 thorpej *
78 1.1.2.1 thorpej * turnstile chain -> sched_lock
79 1.1.2.1 thorpej */
80 1.1.2.1 thorpej
81 1.1.2.1 thorpej #include <sys/cdefs.h>
82 1.1.2.5 thorpej __KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.1.2.5 2002/03/11 00:44:31 thorpej Exp $");
83 1.1.2.1 thorpej
84 1.1.2.1 thorpej #include <sys/param.h>
85 1.1.2.5 thorpej #include <sys/simplelock.h>
86 1.1.2.1 thorpej #include <sys/pool.h>
87 1.1.2.1 thorpej #include <sys/proc.h>
88 1.1.2.1 thorpej #include <sys/resourcevar.h>
89 1.1.2.1 thorpej #include <sys/sched.h>
90 1.1.2.1 thorpej #include <sys/systm.h>
91 1.1.2.1 thorpej
92 1.1.2.1 thorpej /*
93 1.1.2.1 thorpej * Turnstile hash -- shift the lock object to eliminate the zero bits
94 1.1.2.1 thorpej * of the address, and mask it off with the turnstile table's size.
95 1.1.2.1 thorpej */
96 1.1.2.1 thorpej #if LONG_BIT == 64
97 1.1.2.1 thorpej #define TURNSTILE_HASH_SHIFT 3
98 1.1.2.1 thorpej #elif LONG_BIT == 32
99 1.1.2.1 thorpej #define TURNSTILE_HASH_SHIFT 2
100 1.1.2.1 thorpej #else
101 1.1.2.1 thorpej #error "Don't know how big your pointers are."
102 1.1.2.1 thorpej #endif
103 1.1.2.1 thorpej
104 1.1.2.1 thorpej #define TURNSTILE_HASH_SIZE 64 /* XXXJRT tune */
105 1.1.2.1 thorpej #define TURNSTILE_HASH_MASK (TURNSTILE_HASH_SIZE - 1)
106 1.1.2.1 thorpej
107 1.1.2.1 thorpej #define TURNSTILE_HASH(obj) \
108 1.1.2.1 thorpej ((((u_long)(obj)) >> TURNSTILE_HASH_SHIFT) & TURNSTILE_HASH_MASK)
109 1.1.2.1 thorpej
110 1.1.2.1 thorpej struct turnstile_chain {
111 1.1.2.1 thorpej __cpu_simple_lock_t tc_lock; /* lock on hash chain */
112 1.1.2.3 thorpej int tc_oldspl; /* saved spl of lock holder
113 1.1.2.3 thorpej (only valid while tc_lock held) */
114 1.1.2.1 thorpej LIST_HEAD(, turnstile) tc_chain;/* turnstile chain */
115 1.1.2.1 thorpej } turnstile_table[TURNSTILE_HASH_SIZE];
116 1.1.2.1 thorpej
117 1.1.2.1 thorpej #define TURNSTILE_CHAIN(obj) \
118 1.1.2.1 thorpej &turnstile_table[TURNSTILE_HASH(obj)]
119 1.1.2.1 thorpej
120 1.1.2.1 thorpej #define TURNSTILE_CHAIN_LOCK(tc) \
121 1.1.2.1 thorpej do { \
122 1.1.2.1 thorpej int _s_ = splsched(); \
123 1.1.2.1 thorpej __cpu_simple_lock(&(tc)->tc_lock); \
124 1.1.2.1 thorpej (tc)->tc_oldspl = _s_; \
125 1.1.2.1 thorpej } while (/*CONSTCOND*/0)
126 1.1.2.1 thorpej
127 1.1.2.1 thorpej #define TURNSTILE_CHAIN_UNLOCK(tc) \
128 1.1.2.1 thorpej do { \
129 1.1.2.2 thorpej int _s_ = (tc)->tc_oldspl; \
130 1.1.2.1 thorpej __cpu_simple_unlock(&(tc)->tc_lock); \
131 1.1.2.2 thorpej splx(_s_); \
132 1.1.2.1 thorpej } while (/*CONSTCOND*/0)
133 1.1.2.1 thorpej
134 1.1.2.1 thorpej static const char turnstile_wmesg[] = "tstile";
135 1.1.2.1 thorpej
136 1.1.2.1 thorpej struct pool turnstile_pool;
137 1.1.2.3 thorpej struct pool_cache turnstile_cache;
138 1.1.2.3 thorpej
139 1.1.2.3 thorpej int turnstile_ctor(void *, void *, int);
140 1.1.2.1 thorpej
141 1.1.2.1 thorpej /*
142 1.1.2.1 thorpej * turnstile_init:
143 1.1.2.1 thorpej *
144 1.1.2.1 thorpej * Initialize the turnstile mechanism.
145 1.1.2.1 thorpej */
146 1.1.2.1 thorpej void
147 1.1.2.1 thorpej turnstile_init(void)
148 1.1.2.1 thorpej {
149 1.1.2.1 thorpej struct turnstile_chain *tc;
150 1.1.2.1 thorpej int i;
151 1.1.2.1 thorpej
152 1.1.2.1 thorpej for (i = 0; i < TURNSTILE_HASH_SIZE; i++) {
153 1.1.2.1 thorpej tc = &turnstile_table[i];
154 1.1.2.1 thorpej __cpu_simple_lock_init(&tc->tc_lock);
155 1.1.2.1 thorpej LIST_INIT(&tc->tc_chain);
156 1.1.2.1 thorpej }
157 1.1.2.1 thorpej
158 1.1.2.1 thorpej pool_init(&turnstile_pool, sizeof(struct turnstile), 0, 0, 0,
159 1.1.2.1 thorpej "tspool", &pool_allocator_nointr);
160 1.1.2.3 thorpej pool_cache_init(&turnstile_cache, &turnstile_pool,
161 1.1.2.3 thorpej turnstile_ctor, NULL, NULL);
162 1.1.2.3 thorpej }
163 1.1.2.3 thorpej
164 1.1.2.3 thorpej /*
165 1.1.2.3 thorpej * turnstile_ctor:
166 1.1.2.3 thorpej *
167 1.1.2.3 thorpej * Constructor for turnstiles.
168 1.1.2.3 thorpej */
169 1.1.2.3 thorpej int
170 1.1.2.3 thorpej turnstile_ctor(void *arg, void *obj, int flags)
171 1.1.2.3 thorpej {
172 1.1.2.3 thorpej struct turnstile *ts = obj;
173 1.1.2.3 thorpej
174 1.1.2.3 thorpej memset(ts, 0, sizeof(*ts));
175 1.1.2.3 thorpej return (0);
176 1.1.2.1 thorpej }
177 1.1.2.1 thorpej
178 1.1.2.1 thorpej static void
179 1.1.2.1 thorpej turnstile_remque(struct turnstile *ts, struct proc *p, struct slpque *qp)
180 1.1.2.1 thorpej {
181 1.1.2.1 thorpej struct proc **q = &qp->sq_head;
182 1.1.2.1 thorpej struct turnstile *nts;
183 1.1.2.1 thorpej
184 1.1.2.1 thorpej KASSERT(p->p_ts == ts);
185 1.1.2.1 thorpej
186 1.1.2.1 thorpej /*
187 1.1.2.1 thorpej * This process is no longer using the active turnstile.
188 1.1.2.1 thorpej * Find an inactive one on the free list to give to it.
189 1.1.2.1 thorpej */
190 1.1.2.3 thorpej if ((nts = ts->ts_free) != NULL) {
191 1.1.2.1 thorpej KASSERT(ts->ts_waiters > 1);
192 1.1.2.1 thorpej p->p_ts = nts;
193 1.1.2.1 thorpej ts->ts_free = nts->ts_free;
194 1.1.2.1 thorpej nts->ts_free = NULL;
195 1.1.2.1 thorpej } else {
196 1.1.2.1 thorpej /*
197 1.1.2.1 thorpej * If the free list is empty, this is the last
198 1.1.2.1 thorpej * waiter.
199 1.1.2.1 thorpej */
200 1.1.2.1 thorpej KASSERT(ts->ts_waiters == 1);
201 1.1.2.1 thorpej LIST_REMOVE(ts, ts_chain);
202 1.1.2.1 thorpej }
203 1.1.2.1 thorpej
204 1.1.2.1 thorpej ts->ts_waiters--;
205 1.1.2.1 thorpej
206 1.1.2.1 thorpej *q = p->p_forw;
207 1.1.2.1 thorpej if (qp->sq_tailp == &p->p_forw)
208 1.1.2.1 thorpej qp->sq_tailp = q;
209 1.1.2.3 thorpej
210 1.1.2.3 thorpej KASSERT(ts->ts_waiters != 0 || ts->ts_sleepq.sq_head == NULL);
211 1.1.2.3 thorpej KASSERT(ts->ts_waiters == 0 || ts->ts_sleepq.sq_head != NULL);
212 1.1.2.1 thorpej }
213 1.1.2.1 thorpej
214 1.1.2.1 thorpej /*
215 1.1.2.1 thorpej * turnstile_lookup:
216 1.1.2.1 thorpej *
217 1.1.2.1 thorpej * Look up the turnstile for the specified lock object. This
218 1.1.2.1 thorpej * acquires and holds the turnstile chain lock (sleep queue
219 1.1.2.1 thorpej * interlock).
220 1.1.2.1 thorpej */
221 1.1.2.1 thorpej struct turnstile *
222 1.1.2.1 thorpej turnstile_lookup(void *lp)
223 1.1.2.1 thorpej {
224 1.1.2.1 thorpej struct turnstile_chain *tc = TURNSTILE_CHAIN(lp);
225 1.1.2.1 thorpej struct turnstile *ts;
226 1.1.2.1 thorpej
227 1.1.2.1 thorpej TURNSTILE_CHAIN_LOCK(tc);
228 1.1.2.1 thorpej
229 1.1.2.1 thorpej LIST_FOREACH(ts, &tc->tc_chain, ts_chain)
230 1.1.2.1 thorpej if (ts->ts_obj == lp)
231 1.1.2.1 thorpej return (ts);
232 1.1.2.1 thorpej
233 1.1.2.1 thorpej /*
234 1.1.2.1 thorpej * No turnstile yet for this lock. No problem, turnstile_block()
235 1.1.2.1 thorpej * handle this by fetching the turnstile from the blocking thread.
236 1.1.2.1 thorpej */
237 1.1.2.1 thorpej return (NULL);
238 1.1.2.1 thorpej }
239 1.1.2.1 thorpej
240 1.1.2.1 thorpej /*
241 1.1.2.1 thorpej * turnstile_exit:
242 1.1.2.1 thorpej *
243 1.1.2.1 thorpej * Abort a turnstile operation.
244 1.1.2.1 thorpej */
245 1.1.2.1 thorpej void
246 1.1.2.1 thorpej turnstile_exit(void *lp)
247 1.1.2.1 thorpej {
248 1.1.2.1 thorpej struct turnstile_chain *tc = TURNSTILE_CHAIN(lp);
249 1.1.2.1 thorpej
250 1.1.2.1 thorpej TURNSTILE_CHAIN_UNLOCK(tc);
251 1.1.2.1 thorpej }
252 1.1.2.1 thorpej
253 1.1.2.1 thorpej /*
254 1.1.2.1 thorpej * turnstile_block:
255 1.1.2.1 thorpej *
256 1.1.2.1 thorpej * Block a thread on a lock object.
257 1.1.2.1 thorpej */
258 1.1.2.1 thorpej int
259 1.1.2.4 thorpej turnstile_block(struct turnstile *ts, int rw, int pri, void *lp)
260 1.1.2.1 thorpej {
261 1.1.2.1 thorpej struct turnstile_chain *tc = TURNSTILE_CHAIN(lp);
262 1.1.2.1 thorpej struct proc *p = curproc;
263 1.1.2.1 thorpej struct turnstile *ots;
264 1.1.2.1 thorpej struct slpque *qp;
265 1.1.2.1 thorpej int s;
266 1.1.2.1 thorpej
267 1.1.2.1 thorpej KASSERT(p->p_ts != NULL);
268 1.1.2.1 thorpej
269 1.1.2.1 thorpej if (ts == NULL) {
270 1.1.2.1 thorpej /*
271 1.1.2.1 thorpej * We are the first thread to wait for this lock;
272 1.1.2.1 thorpej * lend our turnstile to it.
273 1.1.2.1 thorpej */
274 1.1.2.1 thorpej ts = p->p_ts;
275 1.1.2.1 thorpej KASSERT(ts->ts_waiters == 0);
276 1.1.2.1 thorpej KASSERT(ts->ts_sleepq.sq_head == NULL);
277 1.1.2.1 thorpej ts->ts_obj = lp;
278 1.1.2.1 thorpej LIST_INSERT_HEAD(&tc->tc_chain, ts, ts_chain);
279 1.1.2.1 thorpej } else {
280 1.1.2.1 thorpej /*
281 1.1.2.1 thorpej * Lock already has a turnstile. Put our turnstile
282 1.1.2.1 thorpej * onto the free list, and reference the existing
283 1.1.2.1 thorpej * turnstile instead.
284 1.1.2.1 thorpej */
285 1.1.2.1 thorpej ots = p->p_ts;
286 1.1.2.1 thorpej ots->ts_free = ts->ts_free;
287 1.1.2.1 thorpej ts->ts_free = ots;
288 1.1.2.1 thorpej p->p_ts = ts;
289 1.1.2.1 thorpej }
290 1.1.2.1 thorpej
291 1.1.2.1 thorpej #ifdef DIAGNOSTIC
292 1.1.2.1 thorpej if (p->p_stat != SONPROC)
293 1.1.2.1 thorpej panic("turnstile_block: p_stat %d != SONPROC", p->p_stat);
294 1.1.2.1 thorpej if (p->p_back != NULL)
295 1.1.2.1 thorpej panic("turnstile_block: p_back != NULL");
296 1.1.2.1 thorpej #endif
297 1.1.2.1 thorpej
298 1.1.2.1 thorpej #ifdef KTRACE
299 1.1.2.1 thorpej if (KTRPOINT(p, KTR_CSW))
300 1.1.2.1 thorpej ktrcsw(p, 1, 0);
301 1.1.2.1 thorpej #endif
302 1.1.2.1 thorpej
303 1.1.2.1 thorpej /* XXXJRT PCATCH? */
304 1.1.2.1 thorpej
305 1.1.2.1 thorpej p->p_wchan = lp;
306 1.1.2.1 thorpej p->p_wmesg = turnstile_wmesg;
307 1.1.2.1 thorpej p->p_slptime = 0;
308 1.1.2.4 thorpej p->p_priority = pri & PRIMASK;
309 1.1.2.1 thorpej
310 1.1.2.1 thorpej ts->ts_waiters++;
311 1.1.2.1 thorpej
312 1.1.2.1 thorpej qp = &ts->ts_sleepq;
313 1.1.2.1 thorpej if (qp->sq_head == NULL)
314 1.1.2.1 thorpej qp->sq_head = p;
315 1.1.2.1 thorpej else
316 1.1.2.1 thorpej *qp->sq_tailp = p;
317 1.1.2.1 thorpej *(qp->sq_tailp = &p->p_forw) = NULL;
318 1.1.2.1 thorpej
319 1.1.2.1 thorpej p->p_stat = SSLEEP;
320 1.1.2.1 thorpej p->p_stats->p_ru.ru_nvcsw++;
321 1.1.2.1 thorpej
322 1.1.2.1 thorpej /*
323 1.1.2.1 thorpej * XXX We currently need to interlock with sched_lock.
324 1.1.2.1 thorpej * Note we're already at splsched().
325 1.1.2.1 thorpej */
326 1.1.2.1 thorpej _SCHED_LOCK;
327 1.1.2.1 thorpej
328 1.1.2.1 thorpej /*
329 1.1.2.1 thorpej * We can now release the turnstile chain interlock; the
330 1.1.2.1 thorpej * scheduler lock is held, so a thread can't get in to
331 1.1.2.1 thorpej * do a turnstile_wakeup() before we do the switch.
332 1.1.2.1 thorpej *
333 1.1.2.1 thorpej * Note: we need to remember our old spl which is currently
334 1.1.2.1 thorpej * stored in the turnstile chain, because we have to stay
335 1.1.2.1 thorpej * st splsched while the sched_lock is held.
336 1.1.2.1 thorpej */
337 1.1.2.1 thorpej s = tc->tc_oldspl;
338 1.1.2.1 thorpej __cpu_simple_unlock(&tc->tc_lock);
339 1.1.2.1 thorpej
340 1.1.2.1 thorpej mi_switch(p);
341 1.1.2.1 thorpej
342 1.1.2.1 thorpej SCHED_ASSERT_UNLOCKED();
343 1.1.2.1 thorpej splx(s);
344 1.1.2.1 thorpej
345 1.1.2.1 thorpej /*
346 1.1.2.1 thorpej * We are now back to the base spl level we were at when the
347 1.1.2.1 thorpej * caller called turnstile_lookup().
348 1.1.2.1 thorpej */
349 1.1.2.1 thorpej
350 1.1.2.1 thorpej KDASSERT(p->p_cpu != NULL);
351 1.1.2.1 thorpej KDASSERT(p->p_cpu == curcpu());
352 1.1.2.1 thorpej p->p_cpu->ci_schedstate.spc_curpriority = p->p_usrpri;
353 1.1.2.1 thorpej
354 1.1.2.1 thorpej KDASSERT((p->p_flag & (P_SINTR|P_TIMEOUT)) == 0);
355 1.1.2.1 thorpej
356 1.1.2.1 thorpej #ifdef KTRACE
357 1.1.2.1 thorpej if (KTRPOINT(p, KTR_CSW))
358 1.1.2.1 thorpej ktrcsw(p, 0, 0);
359 1.1.2.1 thorpej #endif
360 1.1.2.1 thorpej
361 1.1.2.1 thorpej return (0);
362 1.1.2.1 thorpej }
363 1.1.2.1 thorpej
364 1.1.2.1 thorpej /*
365 1.1.2.1 thorpej * turnstile_wakeup:
366 1.1.2.1 thorpej *
367 1.1.2.1 thorpej * Wake up the specified number of threads that are blocked
368 1.1.2.1 thorpej * in a turnstile.
369 1.1.2.1 thorpej */
370 1.1.2.1 thorpej void
371 1.1.2.1 thorpej turnstile_wakeup(struct turnstile *ts, int rw, int count)
372 1.1.2.1 thorpej {
373 1.1.2.1 thorpej struct turnstile_chain *tc = TURNSTILE_CHAIN(ts->ts_obj);
374 1.1.2.1 thorpej struct slpque *qp = &ts->ts_sleepq;
375 1.1.2.1 thorpej struct proc *p;
376 1.1.2.1 thorpej
377 1.1.2.1 thorpej /* XXX We currently interlock with sched_lock. */
378 1.1.2.1 thorpej _SCHED_LOCK;
379 1.1.2.1 thorpej
380 1.1.2.1 thorpej while (count-- > 0) {
381 1.1.2.1 thorpej p = qp->sq_head;
382 1.1.2.1 thorpej
383 1.1.2.1 thorpej KASSERT(p != NULL);
384 1.1.2.1 thorpej
385 1.1.2.1 thorpej turnstile_remque(ts, p, qp);
386 1.1.2.1 thorpej
387 1.1.2.1 thorpej p->p_wchan = NULL;
388 1.1.2.1 thorpej
389 1.1.2.1 thorpej if (p->p_stat == SSLEEP)
390 1.1.2.1 thorpej awaken(p);
391 1.1.2.1 thorpej }
392 1.1.2.1 thorpej
393 1.1.2.1 thorpej _SCHED_UNLOCK;
394 1.1.2.1 thorpej
395 1.1.2.1 thorpej TURNSTILE_CHAIN_UNLOCK(tc);
396 1.1.2.1 thorpej }
397