From owner-freebsd-hackers@FreeBSD.ORG Sun Feb 4 06:57:55 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 82B2516A402 for ; Sun, 4 Feb 2007 06:57:55 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 4391813C481 for ; Sun, 4 Feb 2007 06:57:55 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.13.4/8.13.4) with ESMTP id l146uocX004650; Sat, 3 Feb 2007 23:56:50 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sat, 03 Feb 2007 23:57:22 -0700 (MST) Message-Id: <20070203.235722.1973608952.imp@bsdimp.com> To: luping.nju@gmail.com From: "M. Warner Losh" In-Reply-To: References: X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Sat, 03 Feb 2007 23:56:50 -0700 (MST) Cc: freebsd-hackers@freebsd.org Subject: Re: "sleep" in freebsd kernel X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Feb 2007 06:57:55 -0000 In message: "lu ping" writes: : I have a kernel thread running as a daemon, and I want to make it sleep for : a while in an infinite loop. I guess I can use "tsleep" but it only timeout : after intergal system ticks, which only has millisecond granularity, but I : want to make it sleep in some microsecond. Is there any way I can do this in : the kernel? Make HZ=10000 and you get 100us timeouts. :-) However, there are issues with that... There's presently no easy way to sleep for microseconds without some kind of hardware assist. Maybe the daemon you are running can access custom hardware, which you could use to schedule your interrupt in the near future. There is DELAY which will delay things by a number of microseconds, but it isn't that useful if you are doing it a lot because it is a busy wait, not a scheduling event. Warner