Re: msleep() on recursivly locked mutexes

2007-05-02 Thread Attilio Rao
Matthew Dillon wrote: The real culprit here is passing held mutexes to unrelated procedures in the first place because those procedures might have to block, in order so those procedures can release and reacquire the mutex. That's just bad coding in my view. The unrelated

Re: msleep() on recursivly locked mutexes

2007-05-02 Thread Attilio Rao
Julian Elischer wrote: Hans Petter Selasky wrote: First of all: Where is FreeBSD's locking strategy document? It is just started.. man 9 locking. it needs a lot of work still. I'm working with rwatson@ about a document that can nicely fit in locking(9), but we are a little bit stuck in

Re: msleep() on recursivly locked mutexes

2007-05-02 Thread Attilio Rao
Sergey Babkin wrote: From: Julian Elischer [EMAIL PROTECTED] Basically you shouldn't have a recursed mutex FULL STOP. We have a couple of instances in the kernel where we allow a mutex to recurse, but they had to be hard fought, and the general rule is Don't. If you are recursing on a mutex

Re: msleep() on recursivly locked mutexes

2007-05-02 Thread Julian Elischer
Attilio Rao wrote: Julian Elischer wrote: Hans Petter Selasky wrote: First of all: Where is FreeBSD's locking strategy document? It is just started.. man 9 locking. it needs a lot of work still. I'm working with rwatson@ about a document that can nicely fit in locking(9), but we are a

Re: msleep() on recursivly locked mutexes

2007-04-30 Thread John Baldwin
On Friday 27 April 2007 02:32:20 pm Hans Petter Selasky wrote: P0 unlock(1); P0 unlock(2); this looks interesting. Can you give a more concrete example of this? what work is done in the upcall? WHo is upcalling to who? For example an USB device driver might be up-calling to the

Re: msleep() on recursivly locked mutexes

2007-04-28 Thread Robert Watson
On Thu, 26 Apr 2007, Julian Elischer wrote: Further the idea that holding a mutex except for when we sleep is a generally bright idea is also a bit odd to me.. If you hold a mutex and release it during sleep you probably should invalidate all assumptions you made during the period before you

Re: msleep() on recursivly locked mutexes

2007-04-28 Thread Robert Watson
On Fri, 27 Apr 2007, Julian Elischer wrote: Basically you shouldn't have a recursed mutex FULL STOP. We have a couple of instances in the kernel where we allow a mutex to recurse, but they had to be hard fought, and the general rule is Don't. If you are recursing on a mutex you need to

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Hans Petter Selasky
On Thursday 26 April 2007 23:50, Attilio Rao wrote: 2007/4/26, Julian Elischer [EMAIL PROTECTED]: The reason that mutexes ever recurse in the first place is usually because one piece of code calls itself (or a related piece of code) in a blind manner.. in other words, it doesn't know it is

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Hans Petter Selasky
On Thursday 26 April 2007 23:52, Bosko Milekic wrote: On 4/26/07, Hans Petter Selasky [EMAIL PROTECTED] wrote: Hi, In the new USB stack I have defined the following: Could you perhaps describe some of the codepaths in the USB stack that require this behavior? There are no requirements

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread John-Mark Gurney
Hans Petter Selasky wrote this message on Fri, Apr 27, 2007 at 07:50 +0200: On Thursday 26 April 2007 23:52, Bosko Milekic wrote: On 4/26/07, Hans Petter Selasky [EMAIL PROTECTED] wrote: Hi, In the new USB stack I have defined the following: Could you perhaps describe some of the

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Attilio Rao
Hans Petter Selasky wrote: On Thursday 26 April 2007 23:50, Attilio Rao wrote: 2007/4/26, Julian Elischer [EMAIL PROTECTED]: The reason that mutexes ever recurse in the first place is usually because one piece of code calls itself (or a related piece of code) in a blind manner.. in other

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Bosko Milekic
On 4/26/07, Hans Petter Selasky [EMAIL PROTECTED] wrote: Hi, In the new USB stack I have defined the following: Could you perhaps describe some of the codepaths in the USB stack that require this behavior? -- Bosko Milekic [EMAIL PROTECTED] http://www.crowdedweb.com/

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Daniel Eischen
On Fri, 27 Apr 2007, Hans Petter Selasky wrote: On Thursday 26 April 2007 23:50, Attilio Rao wrote: 2007/4/26, Julian Elischer [EMAIL PROTECTED]: The reason that mutexes ever recurse in the first place is usually because one piece of code calls itself (or a related piece of code) in a blind

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Julian Elischer
Hans Petter Selasky wrote: On Thursday 26 April 2007 23:50, Attilio Rao wrote: 2007/4/26, Julian Elischer [EMAIL PROTECTED]: The reason that mutexes ever recurse in the first place is usually because one piece of code calls itself (or a related piece of code) in a blind manner.. in other

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Matthew Dillon
The real culprit here is passing held mutexes to unrelated procedures in the first place because those procedures might have to block, in order so those procedures can release and reacquire the mutex. That's just bad coding in my view. The unrelated procedure has no clue as to

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Julian Elischer
Hans Petter Selasky wrote: First of all: Where is FreeBSD's locking strategy document? It is just started.. man 9 locking. it needs a lot of work still. We should have a global strategy when we write device drivers, so that various modules can be connected together without races and

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Julian Elischer
Matthew Dillon wrote: The real culprit here is passing held mutexes to unrelated procedures in the first place because those procedures might have to block, in order so those procedures can release and reacquire the mutex. That's just bad coding in my view. The unrelated

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Julian Elischer
Julian Elischer wrote: I think trying to sleep with a recursed mutex should be an instant panic, even if the mutex IS marked as being allowed to sleep. I mean marked as being able to recurse. ___ freebsd-hackers@freebsd.org mailing list

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Hans Petter Selasky
On Friday 27 April 2007 19:39, Matthew Dillon wrote: The real culprit here is passing held mutexes to unrelated procedures in the first place because those procedures might have to block, in order so those procedures can release and reacquire the mutex. That's just bad coding

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Hans Petter Selasky
On Friday 27 April 2007 15:14, Daniel Eischen wrote: On Fri, 27 Apr 2007, Hans Petter Selasky wrote: On Thursday 26 April 2007 23:50, Attilio Rao wrote: 2007/4/26, Julian Elischer [EMAIL PROTECTED]: The reason that mutexes ever recurse in the first place is usually because one piece of

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Daniel Eischen
On Fri, 27 Apr 2007, Hans Petter Selasky wrote: On Friday 27 April 2007 15:14, Daniel Eischen wrote: When you hold a mutex, it should be for a very short time. And I agree with the other comment that all drivers should be multi-thread safe, so we shouldn't add cruft to allow for non MT-safe

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread John Baldwin
On Thursday 26 April 2007 03:36:33 pm Hans Petter Selasky wrote: Are there any comments on integrating this functionality into msleep(), and adding mtx_drop_recurse() and mtx_pickup_recurse() to the FreeBSD kernel? Nope. Fix the code to not recurse instead, or to know it has a recursed mutex

Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Hans Petter Selasky
On Friday 27 April 2007 20:01, Julian Elischer wrote: Hans Petter Selasky wrote: First of all: Where is FreeBSD's locking strategy document? It is just started.. man 9 locking. it needs a lot of work still. Excellent. We should have a global strategy when we write device drivers, so

Re: Re: msleep() on recursivly locked mutexes

2007-04-27 Thread Sergey Babkin
From: Julian Elischer [EMAIL PROTECTED] Basically you shouldn't have a recursed mutex FULL STOP. We have a couple of instances in the kernel where we allow a mutex to recurse, but they had to be hard fought, and the general rule is Don't. If you are recursing on a mutex you need to switch to

msleep() on recursivly locked mutexes

2007-04-26 Thread Hans Petter Selasky
Hi, In the new USB stack I have defined the following: u_int32_t mtx_drop_recurse(struct mtx *mtx) { u_int32_t recurse_level = mtx-mtx_recurse; u_int32_t recurse_curr = recurse_level; mtx_assert(mtx, MA_OWNED); while(recurse_curr--) {

Re: msleep() on recursivly locked mutexes

2007-04-26 Thread Julian Elischer
Hans Petter Selasky wrote: Hi, In the new USB stack I have defined the following: u_int32_t mtx_drop_recurse(struct mtx *mtx) { u_int32_t recurse_level = mtx-mtx_recurse; u_int32_t recurse_curr = recurse_level; mtx_assert(mtx, MA_OWNED); while(recurse_curr--)

Re: msleep() on recursivly locked mutexes

2007-04-26 Thread Attilio Rao
2007/4/26, Hans Petter Selasky [EMAIL PROTECTED]: Hi, In the new USB stack I have defined the following: u_int32_t mtx_drop_recurse(struct mtx *mtx) { u_int32_t recurse_level = mtx-mtx_recurse; u_int32_t recurse_curr = recurse_level; mtx_assert(mtx, MA_OWNED);

Re: msleep() on recursivly locked mutexes

2007-04-26 Thread M. Warner Losh
In message: [EMAIL PROTECTED] Hans Petter Selasky [EMAIL PROTECTED] writes: : Are there any comments on integrating this functionality into msleep(), and : adding mtx_drop_recurse() and mtx_pickup_recurse() to the FreeBSD kernel? This is generally a bad idea. We allow it for Giant

Re: msleep() on recursivly locked mutexes

2007-04-26 Thread Attilio Rao
2007/4/26, Julian Elischer [EMAIL PROTECTED]: The reason that mutexes ever recurse in the first place is usually because one piece of code calls itself (or a related piece of code) in a blind manner.. in other words, it doesn't know it is doing so. The whole concept of recursing mutexes is a

Re: msleep() on recursivly locked mutexes

2007-04-26 Thread Hans Petter Selasky
On Thursday 26 April 2007 23:18, Julian Elischer wrote: Hans Petter Selasky wrote: Hi, In the new USB stack I have defined the following: u_int32_t mtx_drop_recurse(struct mtx *mtx) { u_int32_t recurse_level = mtx-mtx_recurse; u_int32_t recurse_curr =