tasklet, taskqueue, work-queue -- which to use?
Solution 1
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.
Solution 2
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.
user2090434
Updated on August 22, 2022Comments
-
user2090434 over 1 year
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.htmlI 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 ...???
-
duck about 11 yearsIt is a wrong assumption that people generally have, by miscalling softirq as tasklet or even bottom half. Tasklet are implemented over softirq (priority 5 and 0) as you said. But They both are different in working and registration. They have seperate interface to register themself Their are 4 ways to defer work in Bottom Half 1. softirq 2. tasklet 3. workqueue (replacement of task queues) 4. Kernel Timer
-
duck about 11 yearsSoftirq are like tasklet they run in interrupt context. But Softirq needed to be registered at compile time whereas tasklet are dynamically registered. Morever two softirq of same type can run simoltaneously whereas two tasklet of same type cannot.