Index: sys/ktr.h =================================================================== RCS file: /home/iedowse/CVS/src/sys/sys/ktr.h,v retrieving revision 1.18 diff -u -r1.18 ktr.h --- sys/ktr.h 23 Jun 2002 00:38:04 -0000 1.18 +++ sys/ktr.h 22 Aug 2002 19:24:23 -0000 @@ -71,7 +71,8 @@ #define KTR_VM 0x00100000 /* The virtual memory system */ #define KTR_WITNESS 0x00200000 #define KTR_RUNQ 0x00400000 /* Run queue */ -#define KTR_ALL 0x007fffff +#define KTR_CONTENTION 0x00800000 /* Lock contention */ +#define KTR_ALL 0x00ffffff /* * Trace classes which can be assigned to particular use at compile time Index: sys/lock.h =================================================================== RCS file: /home/iedowse/CVS/src/sys/sys/lock.h,v retrieving revision 1.44 diff -u -r1.44 lock.h --- sys/lock.h 21 Apr 2002 10:42:15 -0000 1.44 +++ sys/lock.h 22 Aug 2002 19:25:43 -0000 @@ -212,6 +212,8 @@ int witness_list(struct thread *); int witness_sleep(int, struct lock_object *, const char *, int); void witness_assert(struct lock_object *, int, const char *, int); +int witness_line(struct lock_object *); +const char *witness_file(struct lock_object *); #ifdef WITNESS #define WITNESS_INIT(lock) \ @@ -245,6 +247,12 @@ #define WITNESS_RESTORE(lock, n) \ witness_restore((lock), __CONCAT(n, __wf), __CONCAT(n, __wl)) +#define WITNESS_FILE(lock) \ + witness_file(lock) + +#define WITNESS_LINE(lock) \ + witness_line(lock) + #else /* WITNESS */ #define WITNESS_INIT(lock) ((lock)->lo_flags |= LO_INITIALIZED) #define WITNESS_DESTROY(lock) ((lock)->lo_flags &= ~LO_INITIALIZED) @@ -256,6 +264,8 @@ #define WITNESS_SAVE_DECL(n) #define WITNESS_SAVE(lock, n) #define WITNESS_RESTORE(lock, n) +#define WITNESS_FILE(lock) ("") +#define WITNESS_LINE(lock) (0) #endif /* WITNESS */ #endif /* _KERNEL */ Index: kern/kern_mutex.c =================================================================== RCS file: /home/iedowse/CVS/src/sys/kern/kern_mutex.c,v retrieving revision 1.104 diff -u -r1.104 kern_mutex.c --- kern/kern_mutex.c 27 Jul 2002 16:54:23 -0000 1.104 +++ kern/kern_mutex.c 22 Aug 2002 19:24:23 -0000 @@ -471,6 +471,7 @@ #if defined(SMP) && defined(ADAPTIVE_MUTEXES) struct thread *owner; #endif + int logged = 0; if ((m->mtx_lock & MTX_FLAGMASK) == (uintptr_t)td) { m->mtx_recurse++; @@ -589,6 +590,15 @@ TAILQ_INSERT_TAIL(&m->mtx_blocked, td, td_blkq); } + if (!logged) { + CTR6(KTR_CONTENTION, + "contention: %p at %s:%d wants %s, taken by %s:%d", + td, file, line, m->mtx_object.lo_name, + WITNESS_FILE(&m->mtx_object), + WITNESS_LINE(&m->mtx_object)); + logged = 1; + } + /* * Save who we're blocked on. */ @@ -613,6 +623,11 @@ mtx_unlock_spin(&sched_lock); } + if (logged) { + CTR4(KTR_CONTENTION, + "contention end: %s acquired by %p at %s:%d", + m->mtx_object.lo_name, td, file, line); + } return; } Index: kern/subr_witness.c =================================================================== RCS file: /home/iedowse/CVS/src/sys/kern/subr_witness.c,v retrieving revision 1.122 diff -u -r1.122 subr_witness.c --- kern/subr_witness.c 15 Jul 2002 02:03:17 -0000 1.122 +++ kern/subr_witness.c 22 Aug 2002 19:25:14 -0000 @@ -929,6 +929,30 @@ return (n); } +const char * +witness_file(struct lock_object *lock) +{ + struct witness *w; + + if (witness_cold || witness_dead || lock->lo_witness == NULL || + panicstr != NULL) + return (NULL); + w = lock->lo_witness; + return (w->w_file); +} + +int +witness_line(struct lock_object *lock) +{ + struct witness *w; + + if (witness_cold || witness_dead || lock->lo_witness == NULL || + panicstr != NULL) + return (0); + w = lock->lo_witness; + return (w->w_line); +} + static struct witness * enroll(const char *description, struct lock_class *lock_class) {