From owner-freebsd-hackers Thu Jan 28 20:00:42 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id UAA13454 for freebsd-hackers-outgoing; Thu, 28 Jan 1999 20:00:42 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from smtp01.primenet.com (smtp01.primenet.com [206.165.6.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAA13448 for ; Thu, 28 Jan 1999 20:00:40 -0800 (PST) (envelope-from tlambert@usr07.primenet.com) Received: (from daemon@localhost) by smtp01.primenet.com (8.8.8/8.8.8) id VAA05534; Thu, 28 Jan 1999 21:00:39 -0700 (MST) Received: from usr07.primenet.com(206.165.6.207) via SMTP by smtp01.primenet.com, id smtpd005238; Thu Jan 28 21:00:24 1999 Received: (from tlambert@localhost) by usr07.primenet.com (8.8.5/8.8.5) id UAA17862; Thu, 28 Jan 1999 20:59:54 -0700 (MST) From: Terry Lambert Message-Id: <199901290359.UAA17862@usr07.primenet.com> Subject: Re: rules to allocate buffers in device drivers To: archie@whistle.com (Archie Cobbs) Date: Fri, 29 Jan 1999 03:59:46 +0000 (GMT) Cc: Emmanuel.Duros@sophia.inria.fr, freebsd-hackers@FreeBSD.ORG In-Reply-To: <199901282019.MAA03434@bubba.whistle.com> from "Archie Cobbs" at Jan 28, 99 12:19:41 pm X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > u_char *buffer; > > buffer = malloc( SIZE, M_DEVBUF, M_NOWAIT); > > Yes this works.. you also have to make sure buffer != NULL > after calling malloc, as it can be with M_NOWAIT. > > M_DEVBUF is the type. You must free it with the same type argument. > > M_NOWAIT or M_WAITOK are the latter choices. Don't use M_WAITOK > from within an interrupt context, because it can put you to sleep. > > Also, you should use the MALLOC() and FREE() macros in > instead. Just to add to what Archie has correctly pointed out here... you probably don't want to allocate things at interrupt, in any case, since it makes the interrupt servicing much slower. A better plan is to pre-allocate one resource at instantiation, and then use a mechanism (like NETISR) to preallocate the next resource to replace the one that was used. It'd be real nice if FreeBSD could be a little more deterministic about the time it takes to process an interrupt to completion before leaving interrupt mode... Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message