Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 May 2008 01:59:57 +0300
From:      Ilya Bobir <ilya@po4ta.com>
To:        Alexander Popov <aopopov@yahoo.com>
Cc:        freebsd-drivers@freebsd.org
Subject:   Re: Synchronization in drivers (after SMP improvements)
Message-ID:  <483C926D.50104@po4ta.com>
In-Reply-To: <730729.32628.qm@web51410.mail.re2.yahoo.com>
References:  <730729.32628.qm@web51410.mail.re2.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Alexander Popov wrote:
> Hello all,
>
> [...]
>
> It has been suggested everywhere that mutexes shall be used to protect top and bottom halves of the driver. So I've tried. The following is the pseudo-code that I've used:
> int driver_read(...)
> {
>    mtx_lock(&sc->mtx);
>    
>    if (no data is available) => tsleep(..)
>    
>    mtx_unlock(&sc->mtx);
> }
>
> First it worked very well, but under relatively heavy load I started getting kernel panic, all the time related to one error: a thread holding a non-sleepable lock. Which means that user process has been suspended somewhere during execution in the read() function (probably awaiting data, but not necessary) and its thread has been holding mutex that I've used for synchronization, but that it apparently not allowed (look in man page on mutex).
> [...]
>   

Do you really need to hold the mutex while sleeping?
Maybe you need to mtx_sleep instead?



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?483C926D.50104>