From owner-freebsd-drivers@FreeBSD.ORG Tue May 27 23:21:25 2008 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3C0F5106564A for ; Tue, 27 May 2008 23:21:25 +0000 (UTC) (envelope-from ilya@po4ta.com) Received: from tom.kiev.farlep.net (tom.kiev.farlep.net [213.130.24.4]) by mx1.freebsd.org (Postfix) with ESMTP id EEBD58FC1E for ; Tue, 27 May 2008 23:21:24 +0000 (UTC) (envelope-from ilya@po4ta.com) Received: from ilya.kiev.farlep.net ([62.221.47.37]:2101 helo=[10.0.0.3]) by tom.kiev.farlep.net with esmtps (TLSv1:AES256-SHA:256) (Exim 4.66 (FreeBSD)) (envelope-from ) id 1K189B-00010i-4B; Wed, 28 May 2008 02:00:01 +0300 Message-ID: <483C926D.50104@po4ta.com> Date: Wed, 28 May 2008 01:59:57 +0300 From: Ilya Bobir User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Alexander Popov References: <730729.32628.qm@web51410.mail.re2.yahoo.com> In-Reply-To: <730729.32628.qm@web51410.mail.re2.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Farlep-Data: Cc: freebsd-drivers@freebsd.org Subject: Re: Synchronization in drivers (after SMP improvements) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 May 2008 23:21:25 -0000 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?