Date: Thu, 8 Dec 2005 22:23:28 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 87908 for review Message-ID: <200512082223.jB8MNSA4023000@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=87908 Change 87908 by jhb@jhb_slimer on 2005/12/08 22:23:18 Add a function pointer to lock_class for displaying information about a lock in ddb and use that to collapse show mtx, show mutex, and show sx into a generic 'show lock' command. Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#111 edit .. //depot/projects/smpng/sys/kern/kern_sx.c#27 edit .. //depot/projects/smpng/sys/sys/lock.h#33 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#111 (text+ko) ==== @@ -94,16 +94,26 @@ #define mtx_owner(m) (mtx_unowned((m)) ? NULL \ : (struct thread *)((m)->mtx_lock & MTX_FLAGMASK)) +#ifdef DDB +static void db_show_mtx(struct lock_object *lock); +#endif + /* * Lock classes for sleep and spin mutexes. */ struct lock_class lock_class_mtx_sleep = { "sleep mutex", - LC_SLEEPLOCK | LC_RECURSABLE + LC_SLEEPLOCK | LC_RECURSABLE, +#ifdef DDB + db_show_mtx +#endif }; struct lock_class lock_class_mtx_spin = { "spin mutex", - LC_SPINLOCK | LC_RECURSABLE + LC_SPINLOCK | LC_RECURSABLE, +#ifdef DDB + db_show_mtx +#endif }; /* @@ -942,22 +952,35 @@ } #ifdef DDB -DB_SHOW_COMMAND(mutex, db_show_mutex) +/* XXX: This function is not mutex-specific. */ +DB_SHOW_COMMAND(lock, db_show_lock) +{ + struct lock_object *lock; + + if (!have_addr) + return; + lock = (struct lock_object *)addr; + if (lock->lo_class != &lock_class_mtx_sleep && + lock->lo_class != &lock_class_mtx_spin && + lock->lo_class != &lock_class_sx) { + db_printf("Unknown lock class\n"); + return; + } + db_printf(" class: %s\n", lock->lo_class->lc_name); + db_printf(" name: %s\n", lock->lo_name); + if (lock->lo_type && lock->lo_type != lock->lo_name) + db_printf(" type: %s\n", lock->lo_type); + lock->lo_class->lc_ddb_show(lock); +} + +void +db_show_mtx(struct lock_object *lock) { struct thread *td; struct mtx *m; - if (!have_addr) - return; - m = (struct mtx *)addr; + m = (struct mtx *)lock; - if (m->mtx_object.lo_class != &lock_class_mtx_sleep && - m->mtx_object.lo_class != &lock_class_mtx_spin) - return; - db_printf(" name: %s\n", m->mtx_object.lo_name); - if (m->mtx_object.lo_type && - m->mtx_object.lo_type != m->mtx_object.lo_name) - db_printf(" type: %s\n", m->mtx_object.lo_type); db_printf(" flags: {"); if (m->mtx_object.lo_class == &lock_class_mtx_spin) db_printf("SPIN"); @@ -979,7 +1002,4 @@ db_printf(" recursed: %d\n", m->mtx_recurse); } } - -/* Make 'show mtx' an alias for 'show mutex'. */ -DB_SET(mtx, db_show_mutex, db_show_cmd_set, 0, NULL); #endif ==== //depot/projects/smpng/sys/kern/kern_sx.c#27 (text+ko) ==== @@ -50,9 +50,16 @@ #include <ddb/ddb.h> +#ifdef DDB +static void db_show_sx(struct lock_object *lock); +#endif + struct lock_class lock_class_sx = { "sx", - LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE + LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, +#ifdef DDB + db_show_sx +#endif }; #ifndef INVARIANTS @@ -375,18 +382,14 @@ #endif /* INVARIANT_SUPPORT */ #ifdef DDB -DB_SHOW_COMMAND(sx, db_show_sx) +void +db_show_sx(struct lock_object *lock) { struct thread *td; struct sx *sx; - if (!have_addr) - return; - sx = (struct sx *)addr; + sx = (struct sx *)lock; - if (sx->sx_object.lo_class != &lock_class_sx) - return; - db_printf(" name: %s\n", sx->sx_object.lo_name); db_printf(" locked: "); if (sx->sx_cnt < 0) { td = sx->sx_xholder; ==== //depot/projects/smpng/sys/sys/lock.h#33 (text+ko) ==== @@ -50,6 +50,7 @@ struct lock_class { const char *lc_name; u_int lc_flags; + void (*lc_ddb_show)(struct lock_object *lock); }; #define LC_SLEEPLOCK 0x00000001 /* Sleep lock. */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200512082223.jB8MNSA4023000>