From owner-freebsd-current Mon Aug 7 14:56:34 2000 Delivered-To: freebsd-current@freebsd.org Received: from mailgate.originative.co.uk (mailgate.originative.co.uk [194.217.50.228]) by hub.freebsd.org (Postfix) with ESMTP id 789CD37BC09; Mon, 7 Aug 2000 14:56:27 -0700 (PDT) (envelope-from paul@originative.co.uk) Received: from originative.co.uk (lobster.originative.co.uk [194.217.50.241]) by mailgate.originative.co.uk (Postfix) with ESMTP id 63AA01D13D; Mon, 7 Aug 2000 22:56:25 +0100 (BST) Message-ID: <398F3089.416DEA1@originative.co.uk> Date: Mon, 07 Aug 2000 22:56:25 +0100 From: Paul Richards Organization: Originative Solutions Ltd X-Mailer: Mozilla 4.74 [en] (X11; U; Linux 2.2.12 i386) X-Accept-Language: en MIME-Version: 1.0 To: dg@root.com Cc: Poul-Henning Kamp , Alfred Perlstein , Matt Dillon , Mike Smith , Stephen McKay , freebsd-current@FreeBSD.ORG, dillon@FreeBSD.ORG Subject: Re: Ugly, slow shutdown References: <200008071903.MAA03649@implode.root.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG David Greenman wrote: > > >>Can you give a reason why we'll have to now start coding defensively > >>because our arguments to tsleep() are just "advisory" now? > > > >It is not something we "suddenly have to do" it's been The Right Way > >even since I first sharpened my teeth on unix kernels many years ago. > > Uh, Poul, I think you're full of it. The previous behavior of tsleep where > you can make assumptions about who wakes you and under what conditions is a > long and well established idiom. We (the kernel developers of BSD) have always > coded to the established kernel programming interface and most of us consider > it bad form to check for conditions which can't happen because the kernel > API doesn't allow it. For example, we don't check for a NULL return from malloc > in the case of !NO_WAIT, because we knew that the code would never do that. > There are many other examples of similar assumptions in the kernel. We write > the code to be efficient and only check for bogus conditions that might > happen. The only exception to this is programatic ASSERTs that do internal > consistency checks, but the purpose of those is quite different. In the particular case of sleeping though, a woken process does need to check the condition that it slept on because one of the other processes sleeping on that resource may have had a chance to run first and changed some state. So as a general rule, you shouldn't assume that everything is fine when you return from being asleep because it might not be. I agree with your sentiment about defensive coding in the kernel though. Defensive coding should only be used on the boundary of your interface, i.e. if you're getting non-deterministic data from somewhere, most commonly user behaviour. Everything inside the kernel implementation should be deterministic and therefore there shouldn't be any need for defensive programming. Any cause of errors that defensive programming catches in the kernel can only be caused by bugs and therefore falls into the category of diagnostics. There's actually a lot of defensive programming creeping into the kernel which should really be wrapped in an #ifdef INVARIANTS. Paul. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message