Home | History | Annotate | Line # | Download | only in kern
kern_turnstile.c revision 1.10.12.1
      1  1.10.12.1  bouyer /*	$NetBSD: kern_turnstile.c,v 1.10.12.1 2007/11/13 16:02:14 bouyer Exp $	*/
      2        1.2      ad 
      3        1.2      ad /*-
      4        1.2      ad  * Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc.
      5        1.2      ad  * All rights reserved.
      6        1.2      ad  *
      7        1.2      ad  * This code is derived from software contributed to The NetBSD Foundation
      8        1.2      ad  * by Jason R. Thorpe and Andrew Doran.
      9        1.2      ad  *
     10        1.2      ad  * Redistribution and use in source and binary forms, with or without
     11        1.2      ad  * modification, are permitted provided that the following conditions
     12        1.2      ad  * are met:
     13        1.2      ad  * 1. Redistributions of source code must retain the above copyright
     14        1.2      ad  *    notice, this list of conditions and the following disclaimer.
     15        1.2      ad  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.2      ad  *    notice, this list of conditions and the following disclaimer in the
     17        1.2      ad  *    documentation and/or other materials provided with the distribution.
     18        1.2      ad  * 3. All advertising materials mentioning features or use of this software
     19        1.2      ad  *    must display the following acknowledgement:
     20        1.2      ad  *	This product includes software developed by the NetBSD
     21        1.2      ad  *	Foundation, Inc. and its contributors.
     22        1.2      ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23        1.2      ad  *    contributors may be used to endorse or promote products derived
     24        1.2      ad  *    from this software without specific prior written permission.
     25        1.2      ad  *
     26        1.2      ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27        1.2      ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28        1.2      ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29        1.2      ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30        1.2      ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31        1.2      ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32        1.2      ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33        1.2      ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34        1.2      ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35        1.2      ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36        1.2      ad  * POSSIBILITY OF SUCH DAMAGE.
     37        1.2      ad  */
     38        1.2      ad 
     39        1.2      ad /*
     40        1.2      ad  * Turnstiles are described in detail in:
     41        1.2      ad  *
     42        1.2      ad  *	Solaris Internals: Core Kernel Architecture, Jim Mauro and
     43        1.2      ad  *	    Richard McDougall.
     44        1.2      ad  *
     45        1.2      ad  * Turnstiles are kept in a hash table.  There are likely to be many more
     46        1.2      ad  * synchronisation objects than there are threads.  Since a thread can block
     47        1.2      ad  * on only one lock at a time, we only need one turnstile per thread, and
     48        1.2      ad  * so they are allocated at thread creation time.
     49        1.2      ad  *
     50        1.2      ad  * When a thread decides it needs to block on a lock, it looks up the
     51        1.2      ad  * active turnstile for that lock.  If no active turnstile exists, then
     52        1.2      ad  * the process lends its turnstile to the lock.  If there is already an
     53        1.2      ad  * active turnstile for the lock, the thread places its turnstile on a
     54        1.2      ad  * list of free turnstiles, and references the active one instead.
     55        1.2      ad  *
     56        1.2      ad  * The act of looking up the turnstile acquires an interlock on the sleep
     57        1.2      ad  * queue.  If a thread decides it doesn't need to block after all, then this
     58        1.2      ad  * interlock must be released by explicitly aborting the turnstile
     59        1.2      ad  * operation.
     60        1.2      ad  *
     61        1.2      ad  * When a thread is awakened, it needs to get its turnstile back.  If there
     62        1.2      ad  * are still other threads waiting in the active turnstile, the the thread
     63        1.2      ad  * grabs a free turnstile off the free list.  Otherwise, it can take back
     64        1.2      ad  * the active turnstile from the lock (thus deactivating the turnstile).
     65        1.2      ad  *
     66        1.4    yamt  * Turnstiles are the place to do priority inheritence.
     67        1.2      ad  */
     68        1.2      ad 
     69        1.2      ad #include <sys/cdefs.h>
     70  1.10.12.1  bouyer __KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.10.12.1 2007/11/13 16:02:14 bouyer Exp $");
     71        1.2      ad 
     72        1.2      ad #include <sys/param.h>
     73        1.2      ad #include <sys/lock.h>
     74        1.4    yamt #include <sys/lockdebug.h>
     75        1.2      ad #include <sys/pool.h>
     76        1.2      ad #include <sys/proc.h>
     77        1.2      ad #include <sys/sleepq.h>
     78        1.2      ad #include <sys/systm.h>
     79        1.2      ad 
     80        1.3      ad #include <uvm/uvm_extern.h>
     81        1.3      ad 
     82        1.2      ad #define	TS_HASH_SIZE	64
     83        1.2      ad #define	TS_HASH_MASK	(TS_HASH_SIZE - 1)
     84        1.2      ad #define	TS_HASH(obj)	(((uintptr_t)(obj) >> 3) & TS_HASH_MASK)
     85        1.2      ad 
     86        1.2      ad tschain_t	turnstile_tab[TS_HASH_SIZE];
     87  1.10.12.1  bouyer pool_cache_t	turnstile_cache;
     88        1.2      ad 
     89        1.2      ad int	turnstile_ctor(void *, void *, int);
     90        1.2      ad 
     91        1.2      ad extern turnstile_t turnstile0;
     92        1.2      ad 
     93        1.2      ad /*
     94        1.2      ad  * turnstile_init:
     95        1.2      ad  *
     96        1.2      ad  *	Initialize the turnstile mechanism.
     97        1.2      ad  */
     98        1.2      ad void
     99        1.2      ad turnstile_init(void)
    100        1.2      ad {
    101        1.2      ad 	tschain_t *tc;
    102        1.2      ad 	int i;
    103        1.2      ad 
    104        1.2      ad 	for (i = 0; i < TS_HASH_SIZE; i++) {
    105        1.2      ad 		tc = &turnstile_tab[i];
    106        1.2      ad 		LIST_INIT(&tc->tc_chain);
    107        1.9    yamt 		mutex_init(&tc->tc_mutex, MUTEX_SPIN, IPL_SCHED);
    108        1.2      ad 	}
    109        1.2      ad 
    110  1.10.12.1  bouyer 	turnstile_cache = pool_cache_init(sizeof(turnstile_t), 0, 0, 0,
    111  1.10.12.1  bouyer 	    "tstilepl", NULL, IPL_NONE, turnstile_ctor, NULL, NULL);
    112  1.10.12.1  bouyer 	KASSERT(turnstile_cache != NULL);
    113        1.2      ad 
    114        1.2      ad 	(void)turnstile_ctor(NULL, &turnstile0, 0);
    115        1.2      ad }
    116        1.2      ad 
    117        1.2      ad /*
    118        1.2      ad  * turnstile_ctor:
    119        1.2      ad  *
    120        1.2      ad  *	Constructor for turnstiles.
    121        1.2      ad  */
    122        1.2      ad int
    123        1.2      ad turnstile_ctor(void *arg, void *obj, int flags)
    124        1.2      ad {
    125        1.2      ad 	turnstile_t *ts = obj;
    126        1.2      ad 
    127        1.2      ad 	memset(ts, 0, sizeof(*ts));
    128        1.2      ad 	sleepq_init(&ts->ts_sleepq[TS_READER_Q], NULL);
    129        1.2      ad 	sleepq_init(&ts->ts_sleepq[TS_WRITER_Q], NULL);
    130        1.2      ad 	return (0);
    131        1.2      ad }
    132        1.2      ad 
    133        1.2      ad /*
    134        1.2      ad  * turnstile_remove:
    135        1.2      ad  *
    136        1.2      ad  *	Remove an LWP from a turnstile sleep queue and wake it.
    137        1.2      ad  */
    138        1.9    yamt static inline void
    139       1.10      ad turnstile_remove(turnstile_t *ts, lwp_t *l, sleepq_t *sq)
    140        1.2      ad {
    141        1.2      ad 	turnstile_t *nts;
    142        1.2      ad 
    143        1.2      ad 	KASSERT(l->l_ts == ts);
    144        1.2      ad 
    145        1.2      ad 	/*
    146        1.2      ad 	 * This process is no longer using the active turnstile.
    147        1.2      ad 	 * Find an inactive one on the free list to give to it.
    148        1.2      ad 	 */
    149        1.2      ad 	if ((nts = ts->ts_free) != NULL) {
    150        1.2      ad 		KASSERT(TS_ALL_WAITERS(ts) > 1);
    151        1.2      ad 		l->l_ts = nts;
    152        1.2      ad 		ts->ts_free = nts->ts_free;
    153        1.2      ad 		nts->ts_free = NULL;
    154        1.2      ad 	} else {
    155        1.2      ad 		/*
    156        1.2      ad 		 * If the free list is empty, this is the last
    157        1.2      ad 		 * waiter.
    158        1.2      ad 		 */
    159        1.2      ad 		KASSERT(TS_ALL_WAITERS(ts) == 1);
    160        1.2      ad 		LIST_REMOVE(ts, ts_chain);
    161        1.2      ad 	}
    162        1.2      ad 
    163        1.9    yamt 	(void)sleepq_remove(sq, l);
    164        1.2      ad }
    165        1.2      ad 
    166        1.2      ad /*
    167        1.2      ad  * turnstile_lookup:
    168        1.2      ad  *
    169        1.2      ad  *	Look up the turnstile for the specified lock.  This acquires and
    170        1.2      ad  *	holds the turnstile chain lock (sleep queue interlock).
    171        1.2      ad  */
    172        1.2      ad turnstile_t *
    173        1.2      ad turnstile_lookup(wchan_t obj)
    174        1.2      ad {
    175        1.2      ad 	turnstile_t *ts;
    176        1.2      ad 	tschain_t *tc;
    177        1.2      ad 
    178        1.2      ad 	tc = &turnstile_tab[TS_HASH(obj)];
    179        1.9    yamt 	mutex_spin_enter(&tc->tc_mutex);
    180        1.2      ad 
    181        1.2      ad 	LIST_FOREACH(ts, &tc->tc_chain, ts_chain)
    182        1.2      ad 		if (ts->ts_obj == obj)
    183        1.2      ad 			return (ts);
    184        1.2      ad 
    185        1.2      ad 	/*
    186        1.2      ad 	 * No turnstile yet for this lock.  No problem, turnstile_block()
    187        1.2      ad 	 * handles this by fetching the turnstile from the blocking thread.
    188        1.2      ad 	 */
    189        1.2      ad 	return (NULL);
    190        1.2      ad }
    191        1.2      ad 
    192        1.2      ad /*
    193        1.2      ad  * turnstile_exit:
    194        1.2      ad  *
    195        1.2      ad  *	Abort a turnstile operation.
    196        1.2      ad  */
    197        1.2      ad void
    198        1.2      ad turnstile_exit(wchan_t obj)
    199        1.2      ad {
    200        1.2      ad 	tschain_t *tc;
    201        1.2      ad 
    202        1.2      ad 	tc = &turnstile_tab[TS_HASH(obj)];
    203        1.9    yamt 	mutex_spin_exit(&tc->tc_mutex);
    204        1.2      ad }
    205        1.2      ad 
    206        1.2      ad /*
    207        1.2      ad  * turnstile_block:
    208        1.2      ad  *
    209        1.2      ad  *	 Enter an object into the turnstile chain and prepare the current
    210        1.2      ad  *	 LWP for sleep.
    211        1.2      ad  */
    212        1.2      ad void
    213        1.4    yamt turnstile_block(turnstile_t *ts, int q, wchan_t obj, syncobj_t *sobj)
    214        1.2      ad {
    215       1.10      ad 	lwp_t *l;
    216       1.10      ad 	lwp_t *cur; /* cached curlwp */
    217       1.10      ad 	lwp_t *owner;
    218        1.2      ad 	turnstile_t *ots;
    219        1.2      ad 	tschain_t *tc;
    220        1.2      ad 	sleepq_t *sq;
    221        1.6    yamt 	pri_t prio;
    222        1.2      ad 
    223        1.2      ad 	tc = &turnstile_tab[TS_HASH(obj)];
    224        1.4    yamt 	l = cur = curlwp;
    225        1.2      ad 
    226        1.2      ad 	KASSERT(q == TS_READER_Q || q == TS_WRITER_Q);
    227        1.9    yamt 	KASSERT(mutex_owned(&tc->tc_mutex));
    228        1.2      ad 	KASSERT(l != NULL && l->l_ts != NULL);
    229        1.2      ad 
    230        1.2      ad 	if (ts == NULL) {
    231        1.2      ad 		/*
    232        1.2      ad 		 * We are the first thread to wait for this object;
    233        1.2      ad 		 * lend our turnstile to it.
    234        1.2      ad 		 */
    235        1.2      ad 		ts = l->l_ts;
    236        1.2      ad 		KASSERT(TS_ALL_WAITERS(ts) == 0);
    237        1.2      ad 		KASSERT(TAILQ_EMPTY(&ts->ts_sleepq[TS_READER_Q].sq_queue) &&
    238        1.2      ad 			TAILQ_EMPTY(&ts->ts_sleepq[TS_WRITER_Q].sq_queue));
    239        1.2      ad 		ts->ts_obj = obj;
    240        1.4    yamt 		ts->ts_inheritor = NULL;
    241        1.9    yamt 		ts->ts_sleepq[TS_READER_Q].sq_mutex = &tc->tc_mutex;
    242        1.9    yamt 		ts->ts_sleepq[TS_WRITER_Q].sq_mutex = &tc->tc_mutex;
    243        1.2      ad 		LIST_INSERT_HEAD(&tc->tc_chain, ts, ts_chain);
    244        1.2      ad 	} else {
    245        1.2      ad 		/*
    246        1.2      ad 		 * Object already has a turnstile.  Put our turnstile
    247        1.2      ad 		 * onto the free list, and reference the existing
    248        1.2      ad 		 * turnstile instead.
    249        1.2      ad 		 */
    250        1.2      ad 		ots = l->l_ts;
    251        1.2      ad 		ots->ts_free = ts->ts_free;
    252        1.2      ad 		ts->ts_free = ots;
    253        1.2      ad 		l->l_ts = ts;
    254        1.2      ad 
    255        1.4    yamt 		KASSERT(ts->ts_obj == obj);
    256        1.2      ad 		KASSERT(TS_ALL_WAITERS(ts) != 0);
    257        1.2      ad 		KASSERT(!TAILQ_EMPTY(&ts->ts_sleepq[TS_READER_Q].sq_queue) ||
    258        1.2      ad 			!TAILQ_EMPTY(&ts->ts_sleepq[TS_WRITER_Q].sq_queue));
    259        1.2      ad 	}
    260        1.2      ad 
    261        1.2      ad 	sq = &ts->ts_sleepq[q];
    262        1.2      ad 	sleepq_enter(sq, l);
    263        1.9    yamt 	LOCKDEBUG_BARRIER(&tc->tc_mutex, 1);
    264  1.10.12.1  bouyer 	l->l_kpriority = true;
    265  1.10.12.1  bouyer 	sleepq_enqueue(sq, obj, "tstile", sobj);
    266        1.4    yamt 
    267        1.4    yamt 	/*
    268        1.4    yamt 	 * lend our priority to lwps on the blocking chain.
    269        1.4    yamt 	 */
    270  1.10.12.1  bouyer 	prio = lwp_eprio(l);
    271        1.4    yamt 	for (;;) {
    272        1.4    yamt 		bool dolock;
    273        1.4    yamt 
    274        1.4    yamt 		if (l->l_wchan == NULL)
    275        1.4    yamt 			break;
    276        1.4    yamt 
    277        1.4    yamt 		owner = (*l->l_syncobj->sobj_owner)(l->l_wchan);
    278        1.4    yamt 		if (owner == NULL)
    279        1.4    yamt 			break;
    280        1.4    yamt 
    281        1.4    yamt 		KASSERT(l != owner);
    282        1.4    yamt 		KASSERT(cur != owner);
    283        1.4    yamt 
    284        1.4    yamt 		if (l->l_mutex != owner->l_mutex)
    285        1.4    yamt 			dolock = true;
    286        1.4    yamt 		else
    287        1.4    yamt 			dolock = false;
    288        1.4    yamt 		if (dolock && !lwp_trylock(owner)) {
    289        1.4    yamt 			/*
    290        1.4    yamt 			 * restart from curlwp.
    291        1.4    yamt 			 */
    292        1.4    yamt 			lwp_unlock(l);
    293        1.4    yamt 			l = cur;
    294        1.4    yamt 			lwp_lock(l);
    295        1.4    yamt 			prio = lwp_eprio(l);
    296        1.4    yamt 			continue;
    297        1.4    yamt 		}
    298  1.10.12.1  bouyer 		if (prio <= lwp_eprio(owner)) {
    299        1.4    yamt 			if (dolock)
    300        1.4    yamt 				lwp_unlock(owner);
    301        1.4    yamt 			break;
    302        1.4    yamt 		}
    303        1.4    yamt 		ts = l->l_ts;
    304        1.4    yamt 		KASSERT(ts->ts_inheritor == owner || ts->ts_inheritor == NULL);
    305        1.4    yamt 		if (ts->ts_inheritor == NULL) {
    306        1.4    yamt 			ts->ts_inheritor = owner;
    307        1.4    yamt 			ts->ts_eprio = prio;
    308        1.4    yamt 			SLIST_INSERT_HEAD(&owner->l_pi_lenders, ts, ts_pichain);
    309        1.4    yamt 			lwp_lendpri(owner, prio);
    310  1.10.12.1  bouyer 		} else if (prio > ts->ts_eprio) {
    311        1.4    yamt 			ts->ts_eprio = prio;
    312        1.4    yamt 			lwp_lendpri(owner, prio);
    313        1.4    yamt 		}
    314        1.4    yamt 		if (dolock)
    315        1.4    yamt 			lwp_unlock(l);
    316        1.4    yamt 		l = owner;
    317        1.4    yamt 	}
    318        1.4    yamt 	LOCKDEBUG_BARRIER(l->l_mutex, 1);
    319        1.4    yamt 	if (cur->l_mutex != l->l_mutex) {
    320        1.4    yamt 		lwp_unlock(l);
    321        1.4    yamt 		lwp_lock(cur);
    322        1.4    yamt 	}
    323        1.4    yamt 	LOCKDEBUG_BARRIER(cur->l_mutex, 1);
    324        1.4    yamt 
    325        1.9    yamt 	sleepq_block(0, false);
    326        1.2      ad }
    327        1.2      ad 
    328        1.2      ad /*
    329        1.2      ad  * turnstile_wakeup:
    330        1.2      ad  *
    331        1.2      ad  *	Wake up the specified number of threads that are blocked
    332        1.2      ad  *	in a turnstile.
    333        1.2      ad  */
    334        1.2      ad void
    335       1.10      ad turnstile_wakeup(turnstile_t *ts, int q, int count, lwp_t *nl)
    336        1.2      ad {
    337        1.2      ad 	sleepq_t *sq;
    338        1.2      ad 	tschain_t *tc;
    339       1.10      ad 	lwp_t *l;
    340        1.2      ad 
    341        1.2      ad 	tc = &turnstile_tab[TS_HASH(ts->ts_obj)];
    342        1.2      ad 	sq = &ts->ts_sleepq[q];
    343        1.2      ad 
    344        1.2      ad 	KASSERT(q == TS_READER_Q || q == TS_WRITER_Q);
    345        1.2      ad 	KASSERT(count > 0 && count <= TS_WAITERS(ts, q));
    346        1.9    yamt 	KASSERT(mutex_owned(&tc->tc_mutex) && sq->sq_mutex == &tc->tc_mutex);
    347        1.4    yamt 	KASSERT(ts->ts_inheritor == curlwp || ts->ts_inheritor == NULL);
    348        1.4    yamt 
    349        1.4    yamt 	/*
    350        1.4    yamt 	 * restore inherited priority if necessary.
    351        1.4    yamt 	 */
    352        1.4    yamt 
    353        1.4    yamt 	if (ts->ts_inheritor != NULL) {
    354        1.4    yamt 		turnstile_t *iter;
    355        1.4    yamt 		turnstile_t *next;
    356        1.4    yamt 		turnstile_t *prev = NULL;
    357        1.6    yamt 		pri_t prio;
    358        1.9    yamt 		bool dolock;
    359        1.4    yamt 
    360        1.4    yamt 		ts->ts_inheritor = NULL;
    361        1.4    yamt 		l = curlwp;
    362        1.8      ad 
    363        1.9    yamt 		dolock = l->l_mutex == &l->l_cpu->ci_schedstate.spc_lwplock;
    364        1.9    yamt 		if (dolock) {
    365        1.9    yamt 			lwp_lock(l);
    366        1.8      ad 		}
    367        1.4    yamt 
    368        1.4    yamt 		/*
    369        1.4    yamt 		 * the following loop does two things.
    370        1.4    yamt 		 *
    371        1.4    yamt 		 * - remove ts from the list.
    372        1.4    yamt 		 *
    373        1.4    yamt 		 * - from the rest of the list, find the highest priority.
    374        1.4    yamt 		 */
    375        1.4    yamt 
    376  1.10.12.1  bouyer 		prio = -1;
    377        1.4    yamt 		KASSERT(!SLIST_EMPTY(&l->l_pi_lenders));
    378        1.4    yamt 		for (iter = SLIST_FIRST(&l->l_pi_lenders);
    379        1.4    yamt 		    iter != NULL; iter = next) {
    380  1.10.12.1  bouyer 			KASSERT(lwp_eprio(l) >= ts->ts_eprio);
    381        1.4    yamt 			next = SLIST_NEXT(iter, ts_pichain);
    382        1.4    yamt 			if (iter == ts) {
    383        1.4    yamt 				if (prev == NULL) {
    384        1.4    yamt 					SLIST_REMOVE_HEAD(&l->l_pi_lenders,
    385        1.4    yamt 					    ts_pichain);
    386        1.4    yamt 				} else {
    387        1.4    yamt 					SLIST_REMOVE_AFTER(prev, ts_pichain);
    388        1.4    yamt 				}
    389  1.10.12.1  bouyer 			} else if (prio < iter->ts_eprio) {
    390        1.4    yamt 				prio = iter->ts_eprio;
    391        1.4    yamt 			}
    392        1.4    yamt 			prev = iter;
    393        1.4    yamt 		}
    394        1.4    yamt 
    395        1.4    yamt 		lwp_lendpri(l, prio);
    396        1.8      ad 
    397        1.9    yamt 		if (dolock) {
    398        1.9    yamt 			lwp_unlock(l);
    399        1.8      ad 		}
    400        1.4    yamt 	}
    401        1.2      ad 
    402        1.2      ad 	if (nl != NULL) {
    403        1.2      ad #if defined(DEBUG) || defined(LOCKDEBUG)
    404        1.2      ad 		TAILQ_FOREACH(l, &sq->sq_queue, l_sleepchain) {
    405        1.2      ad 			if (l == nl)
    406        1.2      ad 				break;
    407        1.2      ad 		}
    408        1.2      ad 		if (l == NULL)
    409        1.2      ad 			panic("turnstile_wakeup: nl not on sleepq");
    410        1.2      ad #endif
    411        1.9    yamt 		turnstile_remove(ts, nl, sq);
    412        1.2      ad 	} else {
    413        1.2      ad 		while (count-- > 0) {
    414        1.2      ad 			l = TAILQ_FIRST(&sq->sq_queue);
    415        1.2      ad 			KASSERT(l != NULL);
    416        1.9    yamt 			turnstile_remove(ts, l, sq);
    417        1.2      ad 		}
    418        1.2      ad 	}
    419        1.9    yamt 	mutex_spin_exit(&tc->tc_mutex);
    420        1.2      ad }
    421        1.2      ad 
    422        1.2      ad /*
    423        1.2      ad  * turnstile_unsleep:
    424        1.2      ad  *
    425        1.2      ad  *	Remove an LWP from the turnstile.  This is called when the LWP has
    426        1.2      ad  *	not been awoken normally but instead interrupted: for example, if it
    427        1.2      ad  *	has received a signal.  It's not a valid action for turnstiles,
    428        1.2      ad  *	since LWPs blocking on a turnstile are not interruptable.
    429        1.2      ad  */
    430        1.2      ad void
    431       1.10      ad turnstile_unsleep(lwp_t *l)
    432        1.2      ad {
    433        1.2      ad 
    434        1.2      ad 	lwp_unlock(l);
    435        1.2      ad 	panic("turnstile_unsleep");
    436        1.2      ad }
    437        1.2      ad 
    438        1.2      ad /*
    439        1.2      ad  * turnstile_changepri:
    440        1.2      ad  *
    441        1.4    yamt  *	Adjust the priority of an LWP residing on a turnstile.
    442        1.2      ad  */
    443        1.2      ad void
    444       1.10      ad turnstile_changepri(lwp_t *l, pri_t pri)
    445        1.2      ad {
    446        1.2      ad 
    447        1.4    yamt 	/* XXX priority inheritance */
    448        1.4    yamt 	sleepq_changepri(l, pri);
    449        1.2      ad }
    450        1.2      ad 
    451        1.2      ad #if defined(LOCKDEBUG)
    452        1.2      ad /*
    453        1.2      ad  * turnstile_print:
    454        1.2      ad  *
    455        1.2      ad  *	Given the address of a lock object, print the contents of a
    456        1.2      ad  *	turnstile.
    457        1.2      ad  */
    458        1.2      ad void
    459        1.2      ad turnstile_print(volatile void *obj, void (*pr)(const char *, ...))
    460        1.2      ad {
    461        1.2      ad 	turnstile_t *ts;
    462        1.2      ad 	tschain_t *tc;
    463        1.2      ad 	sleepq_t *rsq, *wsq;
    464       1.10      ad 	lwp_t *l;
    465        1.2      ad 
    466        1.2      ad 	tc = &turnstile_tab[TS_HASH(obj)];
    467        1.2      ad 
    468        1.2      ad 	LIST_FOREACH(ts, &tc->tc_chain, ts_chain)
    469        1.2      ad 		if (ts->ts_obj == obj)
    470        1.2      ad 			break;
    471        1.2      ad 
    472        1.9    yamt 	(*pr)("Turnstile chain at %p.\n", tc);
    473        1.2      ad 	if (ts == NULL) {
    474        1.2      ad 		(*pr)("=> No active turnstile for this lock.\n");
    475        1.2      ad 		return;
    476        1.2      ad 	}
    477        1.2      ad 
    478        1.2      ad 	rsq = &ts->ts_sleepq[TS_READER_Q];
    479        1.2      ad 	wsq = &ts->ts_sleepq[TS_WRITER_Q];
    480        1.2      ad 
    481        1.2      ad 	(*pr)("=> Turnstile at %p (wrq=%p, rdq=%p).\n", ts, rsq, wsq);
    482        1.2      ad 
    483        1.2      ad 	(*pr)("=> %d waiting readers:", rsq->sq_waiters);
    484        1.2      ad 	TAILQ_FOREACH(l, &rsq->sq_queue, l_sleepchain) {
    485        1.2      ad 		(*pr)(" %p", l);
    486        1.2      ad 	}
    487        1.2      ad 	(*pr)("\n");
    488        1.2      ad 
    489        1.2      ad 	(*pr)("=> %d waiting writers:", wsq->sq_waiters);
    490        1.2      ad 	TAILQ_FOREACH(l, &wsq->sq_queue, l_sleepchain) {
    491        1.2      ad 		(*pr)(" %p", l);
    492        1.2      ad 	}
    493        1.2      ad 	(*pr)("\n");
    494        1.2      ad }
    495        1.2      ad #endif	/* LOCKDEBUG */
    496