In order to use a kernel timer, you must follow a few steps. Here's what to do in a nutshell (we'll discuss this in more detail afterward):
- Initialize the timer metadata structure (struct timer_list) with the timer_setup() macro. The key items that get initialized here are as follows:
- The time to expire by (that value that jiffies should reach for the timer to expire)
- The function to invoke when the timer expires – in effect, the timer "callback" function
- Write the code for your timer callback routine.
- When appropriate, "arm" the timer – that is, have it start – by invoking the add_timer() (or mod_timer()) function.
- When the timer times out (expires), the OS will automatically invoke your timer's callback function (the one you set up in step 2); remember, it will be running in the timer softirq or an atomic or interrupt context.
- (Optional)Â Timers are not cyclic, they are one-time by...