From owner-p4-projects@FreeBSD.ORG Mon Apr 2 13:42:09 2007 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 5C7D316A409; Mon, 2 Apr 2007 13:42:09 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 00B1A16A401 for ; Mon, 2 Apr 2007 13:42:09 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id E5E0B13C48A for ; Mon, 2 Apr 2007 13:42:08 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l32Dg85H051768 for ; Mon, 2 Apr 2007 13:42:08 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l32Dg8nw051765 for perforce@freebsd.org; Mon, 2 Apr 2007 13:42:08 GMT (envelope-from jhb@freebsd.org) Date: Mon, 2 Apr 2007 13:42:08 GMT Message-Id: <200704021342.l32Dg8nw051765@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 117183 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: Mon, 02 Apr 2007 13:42:09 -0000 http://perforce.freebsd.org/chv.cgi?CH=117183 Change 117183 by jhb@jhb_mutex on 2007/04/02 13:41:44 Merge in fixes and new sx tests from jhb_lock. Affected files ... .. //depot/projects/smpng/sys/modules/crash/crash.c#37 integrate .. //depot/projects/smpng/sys/modules/crash2/crash2.c#21 integrate Differences ... ==== //depot/projects/smpng/sys/modules/crash/crash.c#37 (text+ko) ==== @@ -87,6 +87,23 @@ /* Events. */ static void +cv_sx(void) +{ + struct cv blah; + + cv_init(&blah, "blah"); + sx_slock(&foo); + cv_timedwait(&blah, &foo, hz/10); + if (sx_try_upgrade(&foo) == 0) + printf("bad juju, upgrade failed\n"); + else { + cv_timedwait(&blah, &foo, hz/10); + sx_xunlock(&foo); + } +} +CRASH_EVENT("test cv_wait() with sx", cv_sx); + +static void sleep_sx_recurse(void) { sx_slock(&foo); @@ -660,7 +677,7 @@ kdb_enter("order should be test1 then test2"); printf("Check order of test1 -> test2 should succeed.\n"); mtx_lock(&test1_mtx); - witness_check_mutex(&test2_mtx); + witness_check(&test2_mtx); mtx_unlock(&test1_mtx); status = WITNESS_DEFINEORDER(&test2_mtx, &test1_mtx); printf("Status of test2 -> test1 set order should be EDOOFUS: %d\n", ==== //depot/projects/smpng/sys/modules/crash2/crash2.c#21 (text+ko) ==== @@ -94,6 +94,7 @@ static struct sx one, two, three, four; static struct lock fee, fi, fo, fum; static int crash2_wait = 1; +static volatile int lots = 50000; static int mod_event(struct module *module, int cmd, void *arg); static int load(void *arg); @@ -131,6 +132,111 @@ static struct sx *sxs[] = { &one, &two, &three, &four }; static void +one_grades(int dummy) +{ + + switch (arc4random() % 10) { + case 0: + sx_xlock(&one); + DELAY(30); + sx_xunlock(&one); + break; + case 1: + case 2: + sx_slock(&one); + DELAY(40); + if (!sx_try_upgrade(&one)) { + sx_sunlock(&one); + sx_xlock(&one); + DELAY(40); + } + DELAY(10); + sx_xunlock(&one); + break; + case 3: + case 4: + case 5: + case 6: + sx_xlock(&one); + DELAY(30); + sx_downgrade(&one); + DELAY(20); + sx_sunlock(&one); + break; + default: + sx_slock(&one); + DELAY(50); + sx_sunlock(&one); + } +} + +static void +one_grades_lots(int dummy) +{ + int i; + + for (i = 0; i < lots; i++) + one_grades(dummy); +} + +CRASH2_EVENT("lots of one up/downgrades", one_grades_lots, one_grades_lots, + one_grades_lots, one_grades_lots); +CRASH2_EVENT("one up/downgrades", one_grades, one_grades, one_grades, + one_grades); + +static void +whack_one(int dummy) +{ + switch (arc4random() % 10) { + case 0: + case 1: + case 2: + sx_xlock(&one); + DELAY(30); + sx_xunlock(&one); + break; + default: + sx_slock(&one); + DELAY(150); + sx_sunlock(&one); + } +} + +static void +whack_one_lots(int dummy) +{ + int i; + + for (i = 0; i < lots; i++) + whack_one(dummy); +} + +static void +xlock_one(int dummy) +{ + + sx_xlock(&one); + DELAY(1000); + sx_xunlock(&one); +} + +static void +slock_one(int dummy) +{ + + sx_slock(&one); + DELAY(1000); + sx_sunlock(&one); +} + +CRASH2_EVENT("whack one repeatedly", whack_one_lots, whack_one_lots, + whack_one_lots, whack_one_lots); +CRASH2_EVENT("whack one", whack_one, whack_one, whack_one, whack_one); +CRASH2_EVENT("one 2 each", slock_one, xlock_one, slock_one, xlock_one); +CRASH2_EVENT("one writers", xlock_one, xlock_one, xlock_one, xlock_one); +CRASH2_EVENT("one readers", slock_one, slock_one, slock_one, slock_one); + +static void sleep_deadlock(int thread) { @@ -212,7 +318,7 @@ { int i; - for (i = 0; i < 50000; i++) + for (i = 0; i < lots; i++) foo_grades(dummy); } @@ -254,7 +360,7 @@ { int i; - for (i = 0; i < 50000; i++) + for (i = 0; i < lots; i++) whack_foo(dummy); } @@ -341,6 +447,9 @@ SYSCTL_PROC(_debug_crash2, OID_AUTO, test, CTLTYPE_INT | CTLFLAG_RW, 0, 0, sysctl_debug_crash2_test, "I", ""); +SYSCTL_INT(_debug_crash2, OID_AUTO, lots, CTLFLAG_RW, + __DEVOLATILE(int *, &lots), 0, "Iterations for 'lots' tests"); + static void crash_thread(void *arg) { @@ -355,14 +464,15 @@ while ((ev = event[i]) == 0) cv_wait(&event_cv, &event_mtx); event[i] = 0; + mtx_unlock(&event_mtx); if (ev == -1) { printf("crash2[%d]: exiting\n", i); - mtx_unlock(&event_mtx); kthread_exit(0); break; } /* Give sysctl time to finish. */ pause("delay", hz / 5); + mtx_lock(&event_mtx); if (ev < 0 || ev >= MAX_EVENT) { printf("crash2[%d]: event %d is not defined!\n", i, ev); continue;