From owner-p4-projects@FreeBSD.ORG Thu Dec 8 22:23:53 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6384616A420; Thu, 8 Dec 2005 22:23:53 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0952E16A425 for ; Thu, 8 Dec 2005 22:23:53 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id C709A43D9E for ; Thu, 8 Dec 2005 22:23:39 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id jB8MNSwG023003 for ; Thu, 8 Dec 2005 22:23:28 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id jB8MNSA4023000 for perforce@freebsd.org; Thu, 8 Dec 2005 22:23:28 GMT (envelope-from jhb@freebsd.org) Date: Thu, 8 Dec 2005 22:23:28 GMT Message-Id: <200512082223.jB8MNSA4023000@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 87908 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Dec 2005 22:23:54 -0000 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 +#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. */