From owner-freebsd-hackers Mon Nov 20 12:53:40 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id MAA05716 for hackers-outgoing; Mon, 20 Nov 1995 12:53:40 -0800 Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id MAA05707 for ; Mon, 20 Nov 1995 12:53:34 -0800 Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id NAA01979; Mon, 20 Nov 1995 13:51:25 -0700 From: Terry Lambert Message-Id: <199511202051.NAA01979@phaeton.artisoft.com> Subject: Re: Notion of time in kernel + malloc To: Andres.Vega_Garcia@sophia.inria.fr (Andres Vega Garcia) Date: Mon, 20 Nov 1995 13:51:25 -0700 (MST) Cc: hackers@FreeBSD.org In-Reply-To: <199511201935.UAA16241@fun.inria.fr> from "Andres Vega Garcia" at Nov 20, 95 08:35:33 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Length: 950 Sender: owner-hackers@FreeBSD.org Precedence: bulk > Hello, I'm adding some code to the kernel in order to modify the > packet scheduling policy (currently FIFO) to Fair Queueing, and I > need to have a notion of time (seconds (or tens of seconds) elapsed > since ...). > > => Can I use just gettimeofday?, or there is a better way? > (The #ifdef in sys/time.h disables the prototype for gettimeofday > when KERNEL is defined) Look at /sys/ufs/ufs/ufs_vnops.c. Probably accessing the global timeval struct "time" is the correct way to do what you want with the least expense. It should be good to 10ms, at least. Actually, note that SMP and portability concerns should drive this to be macroed at some time in the future, so don't overuse it. [ ... ] Your malloc code is not happy. Grep for malloc in /sys/kern/* for better examples of its use. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.