Date: Wed, 4 Mar 2009 13:52:27 -0500 From: John Baldwin <jhb@freebsd.org> To: barney_cordoba@yahoo.com Cc: current@freebsd.org Subject: Re: MTX Lock implementation question Message-ID: <200903041352.27709.jhb@freebsd.org> In-Reply-To: <440962.16587.qm@web63902.mail.re1.yahoo.com> References: <440962.16587.qm@web63902.mail.re1.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday 04 March 2009 1:45:43 pm Barney Cordoba wrote: > > --- On Wed, 3/4/09, John Baldwin <jhb@freebsd.org> wrote: > > > From: John Baldwin <jhb@freebsd.org> > > Subject: Re: MTX Lock implementation question > > To: barney_cordoba@yahoo.com > > Cc: current@freebsd.org > > Date: Wednesday, March 4, 2009, 1:05 PM > > On Wednesday 04 March 2009 12:34:40 pm Barney Cordoba wrote: > > > > > > --- On Wed, 3/4/09, John Baldwin > > <jhb@freebsd.org> wrote: > > > > > > > From: John Baldwin <jhb@freebsd.org> > > > > Subject: Re: MTX Lock implementation question > > > > To: freebsd-current@freebsd.org, > > barney_cordoba@yahoo.com > > > > Cc: current@freebsd.org > > > > Date: Wednesday, March 4, 2009, 10:13 AM > > > > On Wednesday 04 March 2009 7:54:32 am Barney > > Cordoba wrote: > > > > > > > > > > Suppose the following: > > > > > > > > > > Module foo.c > > > > > > > > > > foo_getlock(sc) > > > > > { > > > > > FOO_LOCK(sc); > > > > > } > > > > > foo_unlock(sc) > > > > > { > > > > > FOO_UNLOCK(sc); > > > > > } > > > > > foo_dosomething(sc) > > > > > { > > > > > MTX_LOCK_ASSERT(sc); > > > > > foo_dooit(); > > > > > } > > > > > > > > > > Module bar.c > > > > > > > > > > bar_dofoo() > > > > > { > > > > > foo_getlock(sc); > > > > > foo_dosomething(sc); > > > > > foo_unlock(sc); > > > > > } > > > > > > > > This works fine. > > > > > > > > > Is this something that shouldn't work? I > > need to > > > > access functions > > > > > that require locks in a different module, > > but this > > > > code barfs on > > > > > ASSERT with witness enabled. Is this a > > deflugalty in > > > > WITNESS, or do > > > > > I need to create functions within foo that > > do the > > > > locking? Its been > > > > > working ok for awhile (its not a high volume > > function) > > > > but when I > > > > > fired up witness to debug something else I > > encountered > > > > witness panics. > > > > > > > > You probably have a real bug that WITNESS is > > warning about > > > > however. > > > > > > > > -- > > > > John Baldwin > > > > > > It seems that theres a problem when the mutex is > > initialized with a type > > > of NULL. Changing it to a non-null string eliminated > > the issue. I'm > > > running a 7.0 base system. > > > > Hmm, mutexes are required to be named. The > > "type" argument is optional, but > > the name is not. So you can't do: > > > > mtx_init(&m, NULL, NULL, MTX_DEF); > > > > > > You can, however do: > > > > mtx_init(&m, "foo", NULL, MTX_DEF); > > > There seems to be an issue when the type is set to NULL. I got > panics in strcpy and strlen functions when displaying warning > traces that cleared up when the type was set to a string. There are literally thousands of mutexes in the kernel with a NULL type. Are you only seeing panics after doing a kldlunload? Alternatively, if you are not destroying your mutexes using mtx_destroy() and you are using dynamically created strings for your mutex name that could cause what you see. -- John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903041352.27709.jhb>