Task Scheduling in Operating System Kernel

Its quite important for all of us to clean up our systems just like we clean our houses in a 'house-keeping' job. A process carries out any task which is placed in the crontab file . The same task can be carried out by a kernel module in two different ways:
1) In first way, the process is put in the crontab file which wakes up the module by a system call, for example by accessing a file or writing to a file. I personally don't refer this mode, however -- we run a new process off of crontab, read a new executable to memory, and all this just to wake up a kernel module which is in memory anyway.

2) The other way would be to create a function that which can be called once for every interrupt. The way we can do this is by creating a task initially held in a struct tq_struct, which holds a pointer to the function. Then, we can use queue_task to put that task on a 'task list' called tq_timer, which is the list of tasks that are to be executed on the next interrupt. Because we want the function to keep on being executed, we need to put it back on tq_timer whenever it is called, for the next timer interrupt.

Another thing to be kept in mind is this: When we remove a module by the command rmmod, its reference count is checked first. If it is zero, module_cleanup is called. Next, the module is removed from memory with all its functions. Nobody checks to see if the timer's task list happens to contain a pointer to one of those functions, which will no longer be available. Ages later (from the computer's perspective, from a human perspective it's nothing, less than a hundredth of a second), the kernel has a timer interrupt and tries to call the function on the task list. Unfortunately, the function is no longer there. In most cases, the memory page where it sat is unused, and you get an ugly error message. But if some other code is now sitting at the same memory location, things could get very ugly. Unfortunately, we don't have an easy way to unregister a task from a task list.

Since cleanup_module can't return with an error code (it's a void function), the solution is to not let it return at all. Instead, it calls sleep_on or module_sleep_on to put the rmmod process to sleep. Before that, it informs the function called on the timer interrupt to stop attaching itself by setting a global variable. Then, on the next timer interrupt, the rmmod process will be woken up, when our function is no longer in the queue and it's safe to remove the module. ;)
thanks. wait for more

View AdSense Ads For:

Brought to you by Digital Point Solutions

Page copy protected against web site content infringement by Copyscape

No comments: