Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tasklet, taskqueue, work-queue -- which to use?

I am going through ldd3 for last few months. I read first few chapters many times.

These two links are using diffrent way, one is using work queue other is using task-queue. To implement a bottom half.
http://www.tldp.org/LDP/lkmpg/2.4/html/x1210.html http://www.linuxtopia.org/online_books/linux_kernel/linux_kernel_module_programming_2.6/x1256.html

I have some doubt about tasklet, taskqueue, work-queue all seems to be doing some task at free time :--

a) What exactly the diffrence between these three ?

b) Which should be used for interrupt handler bottom half ?

confused ...???

like image 524
user2090434 Avatar asked Feb 20 '13 14:02

user2090434


2 Answers

Tasklet and work-queue are normally used in bottom half but they can be used anywhere, their is no limitation on them

Regarding the difference.

1) The Tasklet are used in interrupt context. All the tasklet code must be atomic,so all rules that are applied on atomic context are applied to it. For eg. They cannot sleep(as they cannot be reschecduled) or hold a lock for long time.

2) Unlike Tasklet work-queue executes is in process context means they can sleep and hold the lock for longtime.

In short tasklet are used for fast execution as they cannot sleep where as workqueue are used in case of normal execution of bottom half. Both are executed at later time by the kernel.

like image 115
duck Avatar answered Sep 22 '22 17:09

duck


Softirq and tasklet both are interrupt context tasklet which is executed in interrupt context and workques are executed in process context code.Process context code is allowed to sleep in execution but interrupt context code is not allowed to sleep while execution (Only another interrupt can preempt scheduled interrupt context bottom half. )

Which bottom half mechanism you use is totally depend on driver you are writing and its requirement.

For Ex. If you are writing nw driver which is sending packets to and from HW on interrupt basis you would like to complete this activity without any delay so only options available is softirq or tasklets.

Note: Better you go through Linux Kernel Development by Robert Love chapter 8.I have also read LDD but still Linux Kernel Development by Robert Love is better for interrupt related understanding.

like image 23
Nishith Goswami Avatar answered Sep 21 '22 17:09

Nishith Goswami