Date: Thu, 27 Oct 2005 08:00:27 -0600 From: Scott Long <scottl@samsco.org> To: Dinesh Nair <dinesh@alphaque.com> Cc: freebsd-hackers@freebsd.org Subject: Re: locking in a device driver Message-ID: <4360DD7B.20900@samsco.org> In-Reply-To: <4360B8EE.4070605@alphaque.com> References: <435EEC56.9080708@samsco.org> <200510261130.45506.jhb@freebsd.org> <435FA6A9.4000600@samsco.org> <200510261324.03790.jhb@freebsd.org> <4360B8EE.4070605@alphaque.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Dinesh Nair wrote: > > carrying on this discussion, what would be a good locking mechanism to > use to protect tsleep() and other sensitive areas in a driver in freebsd > 4.x ? > > the current code for the driver in 5.x uses mtx_lock and mtx_unlock with > some parts even being protected by mtx_lock(&Giant). > > would the use of simple_lock() or s_lock() do, given that > SIMPLELOCK_DEBUG was defined in the 4.x kernel ? > > the mechanism is actually a pseudo device driver which communicates with > the real device driver. the pseudo device driver creates a bunch of > /dev/ devices which the userland reads/writes to, and the pseudo device > driver then places data in a few buffers. > > the real device driver then reads these buffers and uses busdma to send > the data to the device. reading is done by using busdma to read from the > device and then placing the data in these buffers for the pseudo device > to return to the userland process. > > locking in the real device driver uses splhigh/splx, but what locking > should be used in the pseudo device driver ? > If you need to protect your pseudodriver from being interrupted by the real driver then you'll need to use the same spl() as the driver. Note that you shouldn't be using splhigh() unless you really know what you are doing. Other than that, there likely isn't anything that you need to do for 'locking' in 4.x. The kernel is non-reentrant there, so you don't need to worry about synchronizing multiple threads. Scott
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4360DD7B.20900>