From owner-p4-projects@FreeBSD.ORG Wed Jan 30 20:52:06 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6834416A468; Wed, 30 Jan 2008 20:52:06 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1416D16A41A; Wed, 30 Jan 2008 20:52:06 +0000 (UTC) (envelope-from jb@what-creek.com) Received: from what-creek.com (what-creek.com [66.111.37.70]) by mx1.freebsd.org (Postfix) with ESMTP id B3E5B13C478; Wed, 30 Jan 2008 20:52:05 +0000 (UTC) (envelope-from jb@what-creek.com) Received: by what-creek.com (Postfix, from userid 102) id DF6EF73306; Wed, 30 Jan 2008 20:52:04 +0000 (GMT) Date: Wed, 30 Jan 2008 20:52:04 +0000 From: John Birrell To: John Baldwin Message-ID: <20080130205204.GA68541@what-creek.com> References: <200801272148.m0RLmWdF053919@repoman.freebsd.org> <200801300913.03782.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200801300913.03782.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i Cc: Perforce Change Reviews Subject: Re: PERFORCE change 134245 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: Wed, 30 Jan 2008 20:52:06 -0000 On Wed, Jan 30, 2008 at 09:13:03AM -0500, John Baldwin wrote: > On Sunday 27 January 2008 04:48:32 pm John Birrell wrote: > > http://perforce.freebsd.org/chv.cgi?CH=134245 > > > > Change 134245 by jb@jb_freebsd1 on 2008/01/27 21:47:41 > > > > The linker lock here is private to code in this file. It is > > never a problem with it being locked when any other combination > > of locks are already obtained or even if *no* other locks are > > obtained. Use SX_NOWITNESS to avoid bogus LOR reports. > > If witness reports a LOR it is real, it may just not be obvious. Here is some code that demonstrates the problem: static struct mtx test_mtx; MTX_SYSINIT(test, &test_mtx, "Test", MTX_DEF); static int test_list(linker_file_t lf, void *arg) { printf("Linker file name: '%s'\n", lf->filename); return (0); } static void test_thread_func(void *arg) { printf("\n\nI'm a big bad thread, but I'm going to wait a bit... stay tuned...\n"); pause("Waiting a bit...", 5000); printf("The big bad thread is awake and he wants to list the linker files...\n"); linker_file_foreach(test_list, NULL); printf("Lock my wide scope mutex because I have stuff to protect...\n"); mtx_lock(&test_mtx); printf("I've done some stuff that my wide scope lock protected, but now I need to list some linker files...\n"); linker_file_foreach(test_list, NULL); printf("Unlock my wide scope mutex because I done what I needed to do...\n"); mtx_unlock(&test_mtx); printf("I'm done now.\n"); printf("====================\n"); kthread_exit(); } static int test_modevent(module_t mod __unused, int type, void *data __unused) { int error = 0; switch (type) { case MOD_LOAD: printf("--------------------\n"); printf("I am loaded! I can now list the linker files without grabbing any locks...\n"); linker_file_foreach(test_list, NULL); printf("OK, I'm done listing the linker files.\n"); printf("Now I'll create a thread to do some stuff after I've gone.\n"); kthread_add(test_thread_func, NULL, NULL, NULL, 0, 0, "testme"); printf("OK, the thread is created. I'm out of here.\n"); printf("--------------------\n"); break; case MOD_UNLOAD: printf("I am unloading!\n"); break; case MOD_SHUTDOWN: break; default: error = EOPNOTSUPP; break; } return (error); } DEV_MODULE(test, test_modevent, NULL); MODULE_VERSION(test, 1);