Reputation: 1767
I am implementing a timeout for some parameters in my kernel module.
So I am using struct timer_list
and Associated API's to implement a 12 sec timer.
So as mentioned in the IBM developer Works guide for kernel timers I use:
struct timer_list my_timer;
init_timer_on_stack(&my_timer);
void tick_timer()
{
my_timer.expires = jiffies + delay * HZ; //delay is global variable int = 12.
my_timer.data=0;
my_timer.function = my_timer_func;
add_timer(&my_timer);
}
So each time my timer expires I do my work in my_timer_func
and call tick_timer
again to reset the timer.
Next, I would like to implement the delay
as a sysctl entry.
But the change should immediately call the tick_timer
function and reset the timer with new delay
. SO how can I detect this change and remove any current timer or reset it.
Should there be any kernel thread to detect the change in delay
Upvotes: 1
Views: 456
Reputation: 66288
Kernel has no mechanism for detect changes in variables. Instead, you should perform corresponded actions before/after your code changes your variable.
When you add sysctl entry, you also set handler for it(ctl_table->proc_handler
). This handler defines actions, which are executed when read/write method for entry is called. Standard proc_do*
functions only set/get value of variable, so you should define your handler. Something like this:
int my_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
// Call standard helper..
int res = proc_dointvec(table, write, buffer, lenp, ppos);
if(write && !res) {
// Additional actions on successfull write.
}
return res;
}
Modification of the timer's timeout can be performed using mod_timer
function.
Upvotes: 1