From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 25 15:26:51 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E225F106564A for ; Mon, 25 Jul 2011 15:26:51 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id BE4278FC08 for ; Mon, 25 Jul 2011 15:26:51 +0000 (UTC) Received: from fledge.watson.org (fledge.watson.org [65.122.17.41]) by cyrus.watson.org (Postfix) with ESMTPS id 4767846B39; Mon, 25 Jul 2011 11:26:51 -0400 (EDT) Date: Mon, 25 Jul 2011 16:26:51 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Filippo Sironi In-Reply-To: <3AD5705F-0C4E-43CB-8A9C-3416171AEA30@gmail.com> Message-ID: References: <3AD5705F-0C4E-43CB-8A9C-3416171AEA30@gmail.com> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-hackers@freebsd.org Subject: Re: Kernel timers infrastructure 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: Mon, 25 Jul 2011 15:26:52 -0000 On Mon, 25 Jul 2011, Filippo Sironi wrote: > I'm working on a university project that's based on FreeBSD and I'm > currently hacking the kernel... but I'm a complete newbie. My question is: > what if I have to call a certain function 10 times per second? I've seen a > bit of code regarding callout_* functions but I can't get through them. Is > there anyone who can help me? Hi Filippo: I'm not sure if you've found the callout(9) man page yet, but it talks about the KPI in some detail. The basic idea, though, is that you describe a regular "callout" using a function pointer, an opaque data pointer, and how long until it should be invoked. In its more complex incantations, you can also specify locks for it to acquire, etc. The key aspect of the API that some people find confusing is that the time interval is described in ticks of length 1/hz seconds. Unless software really wants one invocation per tick (generally unlikely), you will want to pass in some constant times/divided by hz so that it's appropriately scaled. You can find two fairly straight-forward examples in kern/uipc_domain.c, which are respectively the "fast" and "slow" timers Robert