Kernel timers infrastructure

Filippo Sironi filippo.sironi at gmail.com
Mon Sep 12 09:58:41 UTC 2011


This is how I modified the module:
--------------------------------------------------------------------------------
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/systm.h>

static struct callout timer_callout;

static void
timer_function(void *arg)
{
	uprintf("timer_function() begin\n");
	if (callout_reset(&timer_callout, hz, timer_function, NULL))
		uprintf("callout_reset() != 0\n");
	uprintf("Hello, World!\n");
	uprintf("timer_function() end\n");
}

static int
timer_event_handler(struct module *mod, int cmd, void *arg)
{
	uprintf("timer_event_handler() begin\n");
	switch (cmd) {
	case MOD_LOAD:
		uprintf("MOD_LOAD\n");
		callout_init(&timer_callout, CALLOUT_MPSAFE);
		if (callout_reset(&timer_callout, hz, timer_function, NULL))
			uprintf("callout_reset() != 0\n");
		break;
	case MOD_UNLOAD:
		uprintf("MOD_UNLOAD\n");
		callout_drain(&timer_callout);
		break;
	case MOD_SHUTDOWN:
		uprintf("MOD_SHUTDOWN\n");
		break;
	default:
		return EOPNOTSUPP;
	}
	uprintf("timer_event_handler() end\n");
	return 0;
}

static struct moduledata timer_moduledata = {
	"timer",
	timer_event_handler,
	NULL
};

DECLARE_MODULE(timer, timer_moduledata, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
--------------------------------------------------------------------------------
and this is the output of load and unload operations:
freebsd# kldload ./timer.ko
timer_event_handler() begin
MOD_LOAD
timer_event_handler() end
freebsd# kldunload timer.ko
timer_event_handler() begin
timer_event_handler() begin
MOD_UNLOAD
timer_event_handler() end

I don't know why "timer_event_handler() begin" is printed twice on unload but the timer doesn't start... and of course it is set on 1 second but I left the module load for 1 minute or so just to be sure. ;)

Thanks again for your help,
Filippo

On 12/set/2011, at 11:48, Marc Lörner wrote:

> Hello,
> what about changing order of callout_reset and uprintf?
> And your timeout isn't 1minute, it's one second!
> 
> Regards,
> Marc
> -- 
> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de



More information about the freebsd-hackers mailing list