Hi everybody !
I've been developing a kernel module and I needed some timer functions. I found init_timer() add_timer() del_timer() etc... but I would ask some questions about them.
1) When I set a timer, it is added to a timer_list chain with add_timer(). If the time is up and the scheduled function is called, should I remove the timer_list struct from the chain via del_timer() ? Or is it removed automatically ?
2) How can a module safely removed if it has some running timers ? I have to call del_timer() in cleanup_module() for each running timer ? And what's the purpose of the timer_pending function ?
thanks
Quoted 4 lines
1) When I set a timer, it is added to a
timer_listchain withadd_timer(). If the time is up and the scheduled function is called, should I remove thetimer_liststruct from the chain viadel_timer()? Or is it removed automatically ?
It will be removed automatically, just before your timer function is called.
Quoted 2 lines
2) How can a module safely removed if it has some running timers ? I have to call
del_timer()incleanup_module()for each running timer ?
You cannot remove a module (safely) if there are outstanding timers. Use del_timer_sync() to get rid of them and ensure they aren't running on another processor.
Chapter 6 of Linux Device Drivers covers this topic; see:
http://www.xml.com/ldd/chapter/book/ch06.html
jon