Rename printf -> kprintf in sys/ and add some defines where necessary
[dragonfly.git] / sys / kern / kern_lock.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Copyright (C) 1997
6 * John S. Dyson. All rights reserved.
7 *
8 * This code contains ideas from software contributed to Berkeley by
9 * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating
10 * System project at Carnegie-Mellon University.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)kern_lock.c 8.18 (Berkeley) 5/21/95
41 * $FreeBSD: src/sys/kern/kern_lock.c,v 1.31.2.3 2001/12/25 01:44:44 dillon Exp $
6ea70f76 42 * $DragonFly: src/sys/kern/kern_lock.c,v 1.25 2006/12/23 00:35:04 swildner Exp $
984263bc
MD
43 */
44
45#include "opt_lint.h"
46
47#include <sys/param.h>
46a3f46d
MD
48#include <sys/systm.h>
49#include <sys/kernel.h>
984263bc
MD
50#include <sys/proc.h>
51#include <sys/lock.h>
46a3f46d 52#include <sys/sysctl.h>
16523a43 53#include <sys/spinlock.h>
e43a034f 54#include <sys/thread2.h>
16523a43 55#include <sys/spinlock2.h>
46a3f46d
MD
56
57/*
58 * 0: no warnings, 1: warnings, 2: panic
59 */
60static int lockmgr_from_int = 1;
61SYSCTL_INT(_debug, OID_AUTO, lockmgr_from_int, CTLFLAG_RW, &lockmgr_from_int, 0, "");
984263bc
MD
62
63/*
64 * Locking primitives implementation.
65 * Locks provide shared/exclusive sychronization.
66 */
67
68#ifdef SIMPLELOCK_DEBUG
dadab5e9 69#define COUNT(td, x) (td)->td_locks += (x)
984263bc 70#else
dadab5e9 71#define COUNT(td, x)
984263bc
MD
72#endif
73
74#define LOCK_WAIT_TIME 100
75#define LOCK_SAMPLE_WAIT 7
76
77#if defined(DIAGNOSTIC)
78#define LOCK_INLINE
79#else
80#define LOCK_INLINE __inline
81#endif
82
83#define LK_ALL (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE | \
84 LK_SHARE_NONZERO | LK_WAIT_NONZERO)
85
86static int acquire(struct lock *lkp, int extflags, int wanted);
984263bc
MD
87
88static LOCK_INLINE void
89sharelock(struct lock *lkp, int incr) {
90 lkp->lk_flags |= LK_SHARE_NONZERO;
91 lkp->lk_sharecount += incr;
92}
93
e3332475
MD
94static LOCK_INLINE int
95shareunlock(struct lock *lkp, int decr)
96{
97 int dowakeup = 0;
984263bc
MD
98
99 KASSERT(lkp->lk_sharecount >= decr, ("shareunlock: count < decr"));
100
101 if (lkp->lk_sharecount == decr) {
102 lkp->lk_flags &= ~LK_SHARE_NONZERO;
103 if (lkp->lk_flags & (LK_WANT_UPGRADE | LK_WANT_EXCL)) {
e3332475 104 dowakeup = 1;
984263bc
MD
105 }
106 lkp->lk_sharecount = 0;
107 } else {
108 lkp->lk_sharecount -= decr;
109 }
e3332475 110 return(dowakeup);
984263bc
MD
111}
112
16523a43
MD
113/*
114 * lock acquisition helper routine. Called with the lock's spinlock held.
115 */
984263bc 116static int
8a8d5d85 117acquire(struct lock *lkp, int extflags, int wanted)
984263bc 118{
e43a034f 119 int error;
984263bc
MD
120
121 if ((extflags & LK_NOWAIT) && (lkp->lk_flags & wanted)) {
122 return EBUSY;
123 }
124
984263bc
MD
125 while ((lkp->lk_flags & wanted) != 0) {
126 lkp->lk_flags |= LK_WAIT_NONZERO;
127 lkp->lk_waitcount++;
16523a43
MD
128
129 /*
ab6f251b 130 * Atomic spinlock release/sleep/reacquire.
16523a43 131 */
ab6f251b 132 error = msleep(lkp, &lkp->lk_spinlock,
f2770c70
MD
133 ((extflags & LK_PCATCH) ? PCATCH : 0),
134 lkp->lk_wmesg,
135 ((extflags & LK_TIMELOCK) ? lkp->lk_timo : 0));
984263bc
MD
136 if (lkp->lk_waitcount == 1) {
137 lkp->lk_flags &= ~LK_WAIT_NONZERO;
138 lkp->lk_waitcount = 0;
139 } else {
140 lkp->lk_waitcount--;
141 }
16523a43 142 if (error)
984263bc 143 return error;
16523a43 144 if (extflags & LK_SLEEPFAIL)
984263bc 145 return ENOLCK;
984263bc 146 }
984263bc
MD
147 return 0;
148}
149
150/*
151 * Set, change, or release a lock.
152 *
153 * Shared requests increment the shared count. Exclusive requests set the
154 * LK_WANT_EXCL flag (preventing further shared locks), and wait for already
155 * accepted shared locks and shared-to-exclusive upgrades to go away.
16523a43
MD
156 *
157 * A spinlock is held for most of the procedure. We must not do anything
158 * fancy while holding the spinlock.
984263bc
MD
159 */
160int
161#ifndef DEBUG_LOCKS
df4f70a6 162lockmgr(struct lock *lkp, u_int flags)
984263bc 163#else
df4f70a6 164debuglockmgr(struct lock *lkp, u_int flags,
056f4388 165 const char *name, const char *file, int line)
984263bc
MD
166#endif
167{
df4f70a6 168 thread_t td;
984263bc 169 int error;
984263bc 170 int extflags;
e3332475 171 int dowakeup;
c8741453 172 static int didpanic;
984263bc
MD
173
174 error = 0;
e3332475 175 dowakeup = 0;
984263bc 176
46a3f46d 177 if (lockmgr_from_int && mycpu->gd_intr_nesting_level &&
5adac495 178 (flags & LK_NOWAIT) == 0 &&
46a3f46d 179 (flags & LK_TYPE_MASK) != LK_RELEASE && didpanic == 0) {
03aa8d99 180#ifndef DEBUG_LOCKS
46a3f46d
MD
181 if (lockmgr_from_int == 2) {
182 didpanic = 1;
183 panic(
184 "lockmgr %s from %p: called from interrupt",
185 lkp->lk_wmesg, ((int **)&lkp)[-1]);
186 didpanic = 0;
187 } else {
6ea70f76 188 kprintf(
46a3f46d
MD
189 "lockmgr %s from %p: called from interrupt\n",
190 lkp->lk_wmesg, ((int **)&lkp)[-1]);
191 }
03aa8d99 192#else
46a3f46d
MD
193 if (lockmgr_from_int == 2) {
194 didpanic = 1;
dae8fa2c
MD
195 panic(
196 "lockmgr %s from %s:%d: called from interrupt",
46a3f46d
MD
197 lkp->lk_wmesg, file, line);
198 didpanic = 0;
199 } else {
6ea70f76 200 kprintf(
dae8fa2c 201 "lockmgr %s from %s:%d: called from interrupt\n",
46a3f46d
MD
202 lkp->lk_wmesg, file, line);
203 }
03aa8d99
MD
204#endif
205 }
206
d666840a 207 spin_lock_wr(&lkp->lk_spinlock);
984263bc
MD
208
209 extflags = (flags | lkp->lk_flags) & LK_EXTFLG_MASK;
df4f70a6 210 td = curthread;
984263bc
MD
211
212 switch (flags & LK_TYPE_MASK) {
984263bc
MD
213 case LK_SHARED:
214 /*
215 * If we are not the exclusive lock holder, we have to block
216 * while there is an exclusive lock holder or while an
217 * exclusive lock request or upgrade request is in progress.
218 *
219 * However, if P_DEADLKTREAT is set, we override exclusive
220 * lock requests or upgrade requests ( but not the exclusive
221 * lock itself ).
222 */
dadab5e9
MD
223 if (lkp->lk_lockholder != td) {
224 if (td->td_flags & TDF_DEADLKTREAT) {
984263bc
MD
225 error = acquire(
226 lkp,
227 extflags,
228 LK_HAVE_EXCL
229 );
230 } else {
231 error = acquire(
232 lkp,
233 extflags,
234 LK_HAVE_EXCL | LK_WANT_EXCL |
235 LK_WANT_UPGRADE
236 );
237 }
238 if (error)
239 break;
240 sharelock(lkp, 1);
7b95be2a 241 COUNT(td, 1);
984263bc
MD
242 break;
243 }
244 /*
245 * We hold an exclusive lock, so downgrade it to shared.
246 * An alternative would be to fail with EDEADLK.
247 */
248 sharelock(lkp, 1);
7b95be2a 249 COUNT(td, 1);
984263bc
MD
250 /* fall into downgrade */
251
252 case LK_DOWNGRADE:
16523a43 253 if (lkp->lk_lockholder != td || lkp->lk_exclusivecount == 0) {
d666840a 254 spin_unlock_wr(&lkp->lk_spinlock);
984263bc 255 panic("lockmgr: not holding exclusive lock");
16523a43 256 }
984263bc
MD
257 sharelock(lkp, lkp->lk_exclusivecount);
258 lkp->lk_exclusivecount = 0;
259 lkp->lk_flags &= ~LK_HAVE_EXCL;
dadab5e9 260 lkp->lk_lockholder = LK_NOTHREAD;
984263bc 261 if (lkp->lk_waitcount)
e3332475 262 dowakeup = 1;
984263bc
MD
263 break;
264
265 case LK_EXCLUPGRADE:
266 /*
267 * If another process is ahead of us to get an upgrade,
268 * then we want to fail rather than have an intervening
269 * exclusive access.
270 */
271 if (lkp->lk_flags & LK_WANT_UPGRADE) {
e3332475 272 dowakeup = shareunlock(lkp, 1);
7b95be2a 273 COUNT(td, -1);
984263bc
MD
274 error = EBUSY;
275 break;
276 }
277 /* fall into normal upgrade */
278
279 case LK_UPGRADE:
280 /*
281 * Upgrade a shared lock to an exclusive one. If another
282 * shared lock has already requested an upgrade to an
283 * exclusive lock, our shared lock is released and an
284 * exclusive lock is requested (which will be granted
285 * after the upgrade). If we return an error, the file
286 * will always be unlocked.
287 */
16523a43 288 if ((lkp->lk_lockholder == td) || (lkp->lk_sharecount <= 0)) {
d666840a 289 spin_unlock_wr(&lkp->lk_spinlock);
984263bc 290 panic("lockmgr: upgrade exclusive lock");
16523a43 291 }
e3332475 292 dowakeup += shareunlock(lkp, 1);
7b95be2a 293 COUNT(td, -1);
984263bc
MD
294 /*
295 * If we are just polling, check to see if we will block.
296 */
297 if ((extflags & LK_NOWAIT) &&
298 ((lkp->lk_flags & LK_WANT_UPGRADE) ||
299 lkp->lk_sharecount > 1)) {
300 error = EBUSY;
301 break;
302 }
303 if ((lkp->lk_flags & LK_WANT_UPGRADE) == 0) {
304 /*
305 * We are first shared lock to request an upgrade, so
306 * request upgrade and wait for the shared count to
307 * drop to zero, then take exclusive lock.
308 */
309 lkp->lk_flags |= LK_WANT_UPGRADE;
310 error = acquire(lkp, extflags, LK_SHARE_NONZERO);
311 lkp->lk_flags &= ~LK_WANT_UPGRADE;
312
313 if (error)
314 break;
315 lkp->lk_flags |= LK_HAVE_EXCL;
dadab5e9 316 lkp->lk_lockholder = td;
16523a43 317 if (lkp->lk_exclusivecount != 0) {
d666840a 318 spin_unlock_wr(&lkp->lk_spinlock);
984263bc 319 panic("lockmgr: non-zero exclusive count");
16523a43 320 }
984263bc
MD
321 lkp->lk_exclusivecount = 1;
322#if defined(DEBUG_LOCKS)
323 lkp->lk_filename = file;
324 lkp->lk_lineno = line;
325 lkp->lk_lockername = name;
326#endif
7b95be2a 327 COUNT(td, 1);
984263bc
MD
328 break;
329 }
330 /*
331 * Someone else has requested upgrade. Release our shared
332 * lock, awaken upgrade requestor if we are the last shared
333 * lock, then request an exclusive lock.
334 */
335 if ( (lkp->lk_flags & (LK_SHARE_NONZERO|LK_WAIT_NONZERO)) ==
e3332475
MD
336 LK_WAIT_NONZERO) {
337 ++dowakeup;
338 }
984263bc
MD
339 /* fall into exclusive request */
340
341 case LK_EXCLUSIVE:
dadab5e9 342 if (lkp->lk_lockholder == td && td != LK_KERNTHREAD) {
984263bc
MD
343 /*
344 * Recursive lock.
345 */
16523a43 346 if ((extflags & (LK_NOWAIT | LK_CANRECURSE)) == 0) {
d666840a 347 spin_unlock_wr(&lkp->lk_spinlock);
984263bc 348 panic("lockmgr: locking against myself");
16523a43 349 }
984263bc
MD
350 if ((extflags & LK_CANRECURSE) != 0) {
351 lkp->lk_exclusivecount++;
7b95be2a 352 COUNT(td, 1);
984263bc
MD
353 break;
354 }
355 }
356 /*
357 * If we are just polling, check to see if we will sleep.
358 */
359 if ((extflags & LK_NOWAIT) &&
360 (lkp->lk_flags & (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE | LK_SHARE_NONZERO))) {
361 error = EBUSY;
362 break;
363 }
364 /*
365 * Try to acquire the want_exclusive flag.
366 */
367 error = acquire(lkp, extflags, (LK_HAVE_EXCL | LK_WANT_EXCL));
368 if (error)
369 break;
370 lkp->lk_flags |= LK_WANT_EXCL;
371 /*
372 * Wait for shared locks and upgrades to finish.
373 */
374 error = acquire(lkp, extflags, LK_WANT_UPGRADE | LK_SHARE_NONZERO);
375 lkp->lk_flags &= ~LK_WANT_EXCL;
376 if (error)
377 break;
378 lkp->lk_flags |= LK_HAVE_EXCL;
dadab5e9 379 lkp->lk_lockholder = td;
16523a43 380 if (lkp->lk_exclusivecount != 0) {
d666840a 381 spin_unlock_wr(&lkp->lk_spinlock);
984263bc 382 panic("lockmgr: non-zero exclusive count");
16523a43 383 }
984263bc
MD
384 lkp->lk_exclusivecount = 1;
385#if defined(DEBUG_LOCKS)
386 lkp->lk_filename = file;
387 lkp->lk_lineno = line;
388 lkp->lk_lockername = name;
389#endif
7b95be2a 390 COUNT(td, 1);
984263bc
MD
391 break;
392
393 case LK_RELEASE:
394 if (lkp->lk_exclusivecount != 0) {
dadab5e9
MD
395 if (lkp->lk_lockholder != td &&
396 lkp->lk_lockholder != LK_KERNTHREAD) {
d666840a 397 spin_unlock_wr(&lkp->lk_spinlock);
dadab5e9
MD
398 panic("lockmgr: pid %d, not %s thr %p unlocking",
399 (td->td_proc ? td->td_proc->p_pid : -99),
400 "exclusive lock holder",
984263bc
MD
401 lkp->lk_lockholder);
402 }
dadab5e9 403 if (lkp->lk_lockholder != LK_KERNTHREAD) {
7b95be2a 404 COUNT(td, -1);
984263bc
MD
405 }
406 if (lkp->lk_exclusivecount == 1) {
407 lkp->lk_flags &= ~LK_HAVE_EXCL;
dadab5e9 408 lkp->lk_lockholder = LK_NOTHREAD;
984263bc
MD
409 lkp->lk_exclusivecount = 0;
410 } else {
411 lkp->lk_exclusivecount--;
412 }
413 } else if (lkp->lk_flags & LK_SHARE_NONZERO) {
e3332475 414 dowakeup += shareunlock(lkp, 1);
7b95be2a 415 COUNT(td, -1);
984263bc
MD
416 }
417 if (lkp->lk_flags & LK_WAIT_NONZERO)
e3332475 418 ++dowakeup;
984263bc
MD
419 break;
420
984263bc 421 default:
d666840a 422 spin_unlock_wr(&lkp->lk_spinlock);
984263bc
MD
423 panic("lockmgr: unknown locktype request %d",
424 flags & LK_TYPE_MASK);
425 /* NOTREACHED */
426 }
d666840a 427 spin_unlock_wr(&lkp->lk_spinlock);
e3332475
MD
428 if (dowakeup)
429 wakeup(lkp);
984263bc
MD
430 return (error);
431}
432
df4f70a6
MD
433void
434lockmgr_kernproc(struct lock *lp)
435{
436 struct thread *td = curthread;
437
ccc65d15
MD
438 if (lp->lk_lockholder != LK_KERNTHREAD) {
439 KASSERT(lp->lk_lockholder == td,
440 ("lockmgr_kernproc: lock not owned by curthread %p", td));
441 COUNT(td, -1);
442 lp->lk_lockholder = LK_KERNTHREAD;
443 }
df4f70a6
MD
444}
445
e3332475
MD
446/*
447 * Set the lock to be exclusively held. The caller is holding the lock's
448 * spinlock and the spinlock remains held on return. A panic will occur
449 * if the lock cannot be set to exclusive.
450 */
451void
452lockmgr_setexclusive_interlocked(struct lock *lkp)
453{
454 thread_t td = curthread;
455
456 KKASSERT((lkp->lk_flags & (LK_HAVE_EXCL|LK_SHARE_NONZERO)) == 0);
457 KKASSERT(lkp->lk_exclusivecount == 0);
458 lkp->lk_flags |= LK_HAVE_EXCL;
459 lkp->lk_lockholder = td;
460 lkp->lk_exclusivecount = 1;
461 COUNT(td, 1);
462}
463
464/*
465 * Clear the caller's exclusive lock. The caller is holding the lock's
466 * spinlock. THIS FUNCTION WILL UNLOCK THE SPINLOCK.
467 *
468 * A panic will occur if the caller does not hold the lock.
469 */
470void
471lockmgr_clrexclusive_interlocked(struct lock *lkp)
472{
473 thread_t td = curthread;
474 int dowakeup = 0;
475
476 KKASSERT((lkp->lk_flags & LK_HAVE_EXCL) && lkp->lk_exclusivecount == 1
477 && lkp->lk_lockholder == td);
478 lkp->lk_lockholder = LK_NOTHREAD;
479 lkp->lk_flags &= ~LK_HAVE_EXCL;
480 lkp->lk_exclusivecount = 0;
481 if (lkp->lk_flags & LK_WAIT_NONZERO)
482 dowakeup = 1;
483 COUNT(td, -1);
484 spin_unlock_wr(&lkp->lk_spinlock);
485 if (dowakeup)
486 wakeup((void *)lkp);
487}
488
984263bc
MD
489/*
490 * Initialize a lock; required before use.
491 */
492void
f2770c70 493lockinit(struct lock *lkp, char *wmesg, int timo, int flags)
984263bc 494{
16523a43 495 spin_init(&lkp->lk_spinlock);
984263bc
MD
496 lkp->lk_flags = (flags & LK_EXTFLG_MASK);
497 lkp->lk_sharecount = 0;
498 lkp->lk_waitcount = 0;
499 lkp->lk_exclusivecount = 0;
984263bc
MD
500 lkp->lk_wmesg = wmesg;
501 lkp->lk_timo = timo;
dadab5e9 502 lkp->lk_lockholder = LK_NOTHREAD;
984263bc
MD
503}
504
3446c007
MD
505/*
506 * Reinitialize a lock that is being reused for a different purpose, but
5adac495 507 * which may have pending (blocked) threads sitting on it. The caller
3446c007
MD
508 * must already hold the interlock.
509 */
510void
f2770c70 511lockreinit(struct lock *lkp, char *wmesg, int timo, int flags)
3446c007 512{
ae5cd5cd 513 spin_lock_wr(&lkp->lk_spinlock);
ca2e1d01 514 lkp->lk_flags = (lkp->lk_flags & ~LK_EXTFLG_MASK) |
3446c007 515 (flags & LK_EXTFLG_MASK);
3446c007
MD
516 lkp->lk_wmesg = wmesg;
517 lkp->lk_timo = timo;
ae5cd5cd 518 spin_unlock_wr(&lkp->lk_spinlock);
3446c007
MD
519}
520
984263bc
MD
521/*
522 * Determine the status of a lock.
523 */
524int
dadab5e9 525lockstatus(struct lock *lkp, struct thread *td)
984263bc
MD
526{
527 int lock_type = 0;
528
d666840a 529 spin_lock_wr(&lkp->lk_spinlock);
984263bc 530 if (lkp->lk_exclusivecount != 0) {
dadab5e9 531 if (td == NULL || lkp->lk_lockholder == td)
984263bc
MD
532 lock_type = LK_EXCLUSIVE;
533 else
534 lock_type = LK_EXCLOTHER;
8a8d5d85 535 } else if (lkp->lk_sharecount != 0) {
984263bc 536 lock_type = LK_SHARED;
8a8d5d85 537 }
d666840a 538 spin_unlock_wr(&lkp->lk_spinlock);
984263bc
MD
539 return (lock_type);
540}
541
542/*
543 * Determine the number of holders of a lock.
b265bae0
MD
544 *
545 * The non-blocking version can usually be used for assertions.
984263bc
MD
546 */
547int
5adac495 548lockcount(struct lock *lkp)
984263bc
MD
549{
550 int count;
551
d666840a 552 spin_lock_wr(&lkp->lk_spinlock);
984263bc 553 count = lkp->lk_exclusivecount + lkp->lk_sharecount;
d666840a 554 spin_unlock_wr(&lkp->lk_spinlock);
984263bc
MD
555 return (count);
556}
557
b265bae0 558int
5adac495 559lockcountnb(struct lock *lkp)
b265bae0
MD
560{
561 return (lkp->lk_exclusivecount + lkp->lk_sharecount);
562}
563
984263bc
MD
564/*
565 * Print out information about state of a lock. Used by VOP_PRINT
566 * routines to display status about contained locks.
567 */
568void
5adac495 569lockmgr_printinfo(struct lock *lkp)
984263bc 570{
dadab5e9
MD
571 struct thread *td = lkp->lk_lockholder;
572 struct proc *p;
573
574 if (td && td != LK_KERNTHREAD && td != LK_NOTHREAD)
575 p = td->td_proc;
576 else
577 p = NULL;
984263bc
MD
578
579 if (lkp->lk_sharecount)
6ea70f76 580 kprintf(" lock type %s: SHARED (count %d)", lkp->lk_wmesg,
984263bc
MD
581 lkp->lk_sharecount);
582 else if (lkp->lk_flags & LK_HAVE_EXCL)
6ea70f76 583 kprintf(" lock type %s: EXCL (count %d) by td %p pid %d",
dadab5e9
MD
584 lkp->lk_wmesg, lkp->lk_exclusivecount, td,
585 p ? p->p_pid : -99);
984263bc 586 if (lkp->lk_waitcount > 0)
6ea70f76 587 kprintf(" with %d pending", lkp->lk_waitcount);
984263bc
MD
588}
589