Kernel timers infrastructure
Robert Watson
rwatson at FreeBSD.org
Mon Jul 25 15:26:52 UTC 2011
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
More information about the freebsd-hackers
mailing list