From owner-freebsd-hackers Sun Dec 20 22:01:03 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id WAA09460 for freebsd-hackers-outgoing; Sun, 20 Dec 1998 22:01:03 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from allegro.lemis.com (allegro.lemis.com [192.109.197.134]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id WAA09455 for ; Sun, 20 Dec 1998 22:00:59 -0800 (PST) (envelope-from grog@freebie.lemis.com) Received: from freebie.lemis.com (freebie.lemis.com [192.109.197.137]) by allegro.lemis.com (8.9.1/8.9.0) with ESMTP id QAA27009; Mon, 21 Dec 1998 16:30:44 +1030 (CST) Received: (from grog@localhost) by freebie.lemis.com (8.9.1/8.9.0) id QAA68193; Mon, 21 Dec 1998 16:30:43 +1030 (CST) Message-ID: <19981221163041.C24125@freebie.lemis.com> Date: Mon, 21 Dec 1998 16:30:41 +1030 From: Greg Lehey To: Alfred Perlstein , hackers@FreeBSD.ORG Subject: Re: question about re-entrancy. References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.91.1i In-Reply-To: ; from Alfred Perlstein on Sun, Dec 20, 1998 at 04:36:51PM -0500 WWW-Home-Page: http://www.lemis.com/~grog Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-41-739-7062 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sunday, 20 December 1998 at 16:36:51 -0500, Alfred Perlstein wrote: > > I'm a bit confused. I've been watching the discussions going on about > SMP. The issue of kernel re-entrancy has been brought up many times. > > So here's the question: > > I thought the kernel was re-entrant, when a process makes a syscall it's > thread of execution enters the kernel where its arguments are validated > and careful checks are done to ensure security then the syscall is done. Well, those are two different things. AFAIK the kernel is *not* reentrant, in the sense that only one process can be executing in the kernel at any one point. Certainly the classical UNIX kernel is not, anyway, but it makes sense to allow concurrent execution on SMP machines. I believe that at the moment, though, the kernel does not allow this. On the other hand, of course the kernel checks parameters for validity and protects itself. > If during the system call the process is put to sleep or rescheduled, > another process may enter the kernel. Right. That's the only way, but then the process isn't executing. > As long as the splxxx() calls do not interfere with each other you > have 2 processes excuting in the kernel at that point. (more can > enter as well) You seem to be confused here. splxxx() is an interrupt-level mechanism, and it's not needed for resources which are accessed by processes (i.e. non-interrupt environments) alone. > Or.... what i'm now thinking is that once a process enters the kernel it > must run until it exits the system call. Or it gets suspended. > I have a problem with this though, processes such as nfsiod/nfsd > enter the kernel through a syscall and never exit (according to > design and implementation) how then are other processes allowed into > the kernel? The normal state of all daemons is sleeping. > Can anyone explain this a bit better? > > I understand deadlock can occur if something like this happens: > > process 1 process 2 > syscall() > splbio() > rescheduled -----> This can't happen, not inside splbio(). How can it get rescheduled? > syscall() > splimp() > <----- rescheduled > splimp()? -no,reschedule-> > <-no,reschedule- splbio()? > splimp()? -no,reschedule-> > splbio()? > > some sorta flipflop deadlock happens at this point as nested locks are > held and won't be released as two in kernel processes never relinquish > resources. > > Or are the spl calls simply there to diable interupts? Yes, that's exactly what they do. > but that brings me back to the question about "well how do nfsd and > nfsiod do it?" They don't sleep inside spl()s. > Perhaps once an spl is initiated the process can not block? Right. > the more I thought about this, the more my head ached :) You'd probably find ``The Design and Implementation'' a useful read. It'll give you a better understanding of the issues. But it seems to me that you're attributing more importance to the splxxx() functions than they deserve. To recap: you don't need to synchronize between processes, because the kernel (currently) guarantees that only one process will be doing something in the kernel at any one time. On the other hand, non-process activity (interrupts, bottom halves of device drivers) can execute at just about any time. You resolve conflicts between interrupt handlers and possibly the process currently running by locking out specific interrupts in critical sections of code. That's what the splxxx() routines do. In the PDP-11, they set the processor priority level (which is why you'll occasionally see the System Visms spl4(), spl5(), spl6() and spl7()). On the i386, they mask specific interrupts relating to the function (for example, splbio() masks disk controller/host adaptor interrupts). Greg -- See complete headers for address, home page and phone numbers finger grog@lemis.com for PGP public key To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message