Tuesday, March 6, 2012

When to use the workqueue in driver code / What is workqueue

Hey guys,
Here is one more post about kernel, As I am going through Kernel code, I feel this doubt. Theoretically it is assumed that workqueue increased the performance. As you are allowing the interrupt to be enabled. So it means you are ready to handle another interrupt while putting the previous interrupt handler code in workqueue.
But is it a good way to put all the interrupt handler code in the workqueue function, The Answer is NO. Why ? To be part of my belief first you have to understand the basic functionality of workqueue. Linux Kernel developer came with this concept, because they want to reduce the overhead of unnecessary execution of code at the cost of performance(As no other interrupt will be allowed during that time). So what they do is, they divided the functionality in two parts, crucial part and the normal part. With this approach they decided which code should be executed before enabling the interrupt and which part should be executed later.
In summary,what developer should do is, decide the importance of the code in terms of functionality and performance and accordingly put the rest of the Not-so-Crucial part in the work function.
Hope it will help.

Thursday, March 1, 2012

Difference between schedule_work() and queue_work()

Hi Guys,
If you are newbie in Linus Kernel, you may have this doubt that what is the difference between these two methods,basically it is related to the choice that whether you want a dedicated workqueue(which in turn will need dedicated kernel thread) for your driver or you just want to use the default workqueue provided by kernel.
So if you want to control the workfunction in terms of scheduling independently,
you should go for create_workqueue method to create a workqueue. This function will create a workqueue and which in turn will create a seperate Kernel Thread on each and every processor available. Here I would also like to introduce a different version of same method which iscreate_singlethread_workqueue(), you should use this function only when you want to create only a single thread for all the processor.