Re: Kernel timers infrastructure
This is what I wrote for FreeBSD 7.2 and it does not work: #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) { if (callout_reset(timer_callout, hz, timer_function, NULL)) uprintf(callout_reset() != 0\n); uprintf(Hello, World!\n); } static int timer_event_handler(struct module *mod, int cmd, void *arg) { switch (cmd) { case MOD_LOAD: callout_init(timer_callout, CALLOUT_MPSAFE); if (callout_reset(timer_callout, hz, timer_function, NULL)) uprintf(callout_reset() != 0\n); break; case MOD_UNLOAD: callout_drain(timer_callout); break; case MOD_SHUTDOWN: break; default: return EOPNOTSUPP; } return 0; } static struct moduledata timer_moduledata = { timer, timer_event_handler, NULL }; DECLARE_MODULE(timer, timer_moduledata, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); but I do not know why... I basically run through many different examples I found within the kernel and they are not different from this module. Does anyone see any clear issue? Filippo On 10/set/2011, at 19:39, Riccardo Cattaneo wrote: Hi all, Me in the same situation: university project, freebsd os, required to call a certain function X times/second (say, uprintf). Got no luck till now :( Thanks Riccardo___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
How about adding some printfs() to the functions to ensure they're being called? Adrian ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
I already did that to ensure timer_event_handler would be called correctly. The result follows: freebsd# kldload ./timer.ko timer_event_handler() with MOD_LOAD freebsd# kldunload ./timer.ko timer_event_handler() with MOD_UNLOAD and I maintained the module load for about 1 minute so the timer printing Hello, World! should have been run. Filippo On 12/set/2011, at 11:24, Adrian Chadd wrote: How about adding some printfs() to the functions to ensure they're being called? Adrian ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
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 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Re: Kernel timers infrastructure
Hello, what about changing order of callout_reset and uprintf? And your timeout isn't 1minute, it's one second! Regards, Marc I already did that to ensure timer_event_handler would be called correctly. The result follows: freebsd# kldload ./timer.ko timer_event_handler() with MOD_LOAD freebsd# kldunload ./timer.ko timer_event_handler() with MOD_UNLOAD and I maintained the module load for about 1 minute so the timer printing Hello, World! should have been run. Filippo On 12/set/2011, at 11:24, Adrian Chadd wrote: How about adding some printfs() to the functions to ensure they're being called? Adrian ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org -- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Re: Kernel timers infrastructure
On Mon, Sep 12, 2011 at 11:48:42AM +0200, 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 I already did that to ensure timer_event_handler would be called correctly. The result follows: freebsd# kldload ./timer.ko timer_event_handler() with MOD_LOAD freebsd# kldunload ./timer.ko timer_event_handler() with MOD_UNLOAD and I maintained the module load for about 1 minute so the timer printing Hello, World! should have been run. Filippo On 12/set/2011, at 11:24, Adrian Chadd wrote: How about adding some printfs() to the functions to ensure they're being called? The callouts are executed in the context that does not have the controlling terminal. uprintf(9) tries to use the ctty for output. Use printf(9) to get something on console. pgpMi02zI4Bux.pgp Description: PGP signature
Re: Re: Kernel timers infrastructure
Besides I'd also suggest to have the callout rearming as the very last step of you callback in order to avoid buffering interleaving issues. Attilio 2011/9/12 Kostik Belousov kostik...@gmail.com: On Mon, Sep 12, 2011 at 11:48:42AM +0200, 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 I already did that to ensure timer_event_handler would be called correctly. The result follows: freebsd# kldload ./timer.ko timer_event_handler() with MOD_LOAD freebsd# kldunload ./timer.ko timer_event_handler() with MOD_UNLOAD and I maintained the module load for about 1 minute so the timer printing Hello, World! should have been run. Filippo On 12/set/2011, at 11:24, Adrian Chadd wrote: How about adding some printfs() to the functions to ensure they're being called? The callouts are executed in the context that does not have the controlling terminal. uprintf(9) tries to use the ctty for output. Use printf(9) to get something on console. -- Peace can only be achieved by understanding - A. Einstein ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
Hello again, it seems that uprintf needs a tty to put output to. I tried your code with printf instead of uprintf and got output to root-console ttyu0 every second. HTH, Marc Original-Nachricht Datum: Mon, 12 Sep 2011 11:58:37 +0200 Von: Filippo Sironi filippo.sir...@gmail.com An: Marc Lörner loer...@gmx.de CC: freebsd-hackers@freebsd.org Betreff: Re: Kernel timers infrastructure 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 -- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
Thanks a lot guys, it didn't even think about the tty problem... shame on me, I should have read the man pages. :( Filippo ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
On Monday, September 12, 2011 4:42:40 am Filippo Sironi wrote: This is what I wrote for FreeBSD 7.2 and it does not work: callout_reset() is always going to return false here as you are never rescheduling an existing callout (it is either idle or has already fired each time you invoke callout_reset()). However, you are calling uprintf() from the kernel softclock thread and that thread is not attached to your tty, so the uprintf() is going to nowhere. Just use a regular printf and you will get your Hello, World! output once a second. -- John Baldwin ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
Hi all, Me in the same situation: university project, freebsd os, required to call a certain function X times/second (say, uprintf). Got no luck till now :( Thanks Riccardo___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
You can use the callout API to schedule timed events in the kernel. Adrian ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
Of course, the module from which I'm calling them must be already loaded and initialized, isn't it? Riccardo On Sep 11, 2011, at 2:57 AM, Adrian Chadd wrote: You can use the callout API to schedule timed events in the kernel. Adrian ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
On 11 September 2011 09:02, Riccardo Cattaneo cattaneo.ricca...@gmail.com wrote: Of course, the module from which I'm calling them must be already loaded and initialized, isn't it? Riccardo Well, yes - but then, you can just add something to the module load code to start off the callout. There are race conditions to keep in mind though - the callout may just about to be in-play when you go to remove it. The callout manpage points out these situations under Avoiding Race Conditions. Adrian ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Kernel timers infrastructure
Hi everyone, 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? Thanks, Filippo ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
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 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: Kernel timers infrastructure
Hi. On 25.07.2011 17:13, 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? Have you read callout(9) manual page? That API is right if you need to call some function. Also in some cases (if you need to make your kernel thread wait for something) you may use sleep(9) API. -- Alexander Motin ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org