Date: Mon, 14 Aug 2006 19:54:58 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 103893 for review Message-ID: <200608141954.k7EJswSa023199@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=103893 Change 103893 by jhb@jhb_mutex on 2006/08/14 19:53:56 Add a mutex cycle. Affected files ... .. //depot/projects/smpng/sys/modules/crash2/crash2.c#12 edit Differences ... ==== //depot/projects/smpng/sys/modules/crash2/crash2.c#12 (text+ko) ==== @@ -88,6 +88,7 @@ static int event[NTHREADS]; static struct rwlock foo; static struct mtx bar; +static struct mtx abc, def, ghi, jkl; static struct sx one, two, three, four; static struct lock fee, fi, fo, fum; @@ -99,6 +100,19 @@ /* Events. */ +static struct mtx *mtxen[] = { &abc, &def, &ghi, &jkl }; + +static void +mtx_deadlock(int thread) +{ + + mtx_lock(mtxen[thread % 4]); + tsleep(mtxen, 0, "mtx_dead", hz/10); + mtx_lock(mtxen[(thread + 1) % 4]); +} +CRASH2_EVENT("mutex cycle", mtx_deadlock, mtx_deadlock, mtx_deadlock, + mtx_deadlock); + static struct lock *locks[] = { &fee, &fi, &fo, &fum }; static struct sx *sxs[] = { &one, &two, &three, &four }; @@ -124,7 +138,7 @@ { lockmgr(locks[thread % 4], LK_EXCLUSIVE, NULL, curthread); - tsleep(sxs, 0, "lk_dead", hz/10); + tsleep(locks, 0, "lk_dead", hz/10); lockmgr(locks[(thread + 1) % 4], LK_EXCLUSIVE, NULL, curthread); } CRASH2_EVENT("lockmgr cycle", lockmgr_deadlock, lockmgr_deadlock, @@ -367,6 +381,10 @@ rw_init(&foo, "foo"); mtx_init(&bar, "bar", NULL, MTX_DEF); + mtx_init(&abc, "abc", NULL, MTX_DEF); + mtx_init(&def, "def", NULL, MTX_DEF); + mtx_init(&ghi, "ghi", NULL, MTX_DEF); + mtx_init(&jkl, "jkl", NULL, MTX_DEF); sx_init(&one, "one"); sx_init(&two, "two"); sx_init(&three, "three"); @@ -414,6 +432,10 @@ sx_destroy(&three); sx_destroy(&two); sx_destroy(&one); + mtx_destroy(&jkl); + mtx_destroy(&ghi); + mtx_destroy(&def); + mtx_destroy(&abc); mtx_destroy(&bar); rw_destroy(&foo); return (0);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608141954.k7EJswSa023199>