There are many ways to schedule work in the linux kernel: timers, tasklets, work queues, and kernel threads. What are the guidelines for when to use one vs another?
There are the obvious factors: timer functions and tasklets cannot sleep, so they cannot wait on mutexes, condition variables, etc.
What are the other factors in choosing which mechanism to us in a driver?
Which are the preferred mechanisms?
A kernel thread is the schedulable entity, which means that the system scheduler handles kernel threads. These threads, known by the system scheduler, are strongly implementation-dependent. To facilitate the writing of portable programs, libraries provide user threads.
A "workqueue" is a list of tasks to perform, along with a (per-CPU) kernel thread to execute those tasks. Since a kernel thread is used, all tasks are run in process context and may safely sleep.
Workqueue functions run in the context of a kernel process, but tasklet functions run in the software interrupt context. This means that workqueue functions must not be atomic as tasklet functions. Tasklets always run on the processor from which they were originally submitted.
Deferred work is a class of kernel facilities that allows one to schedule code to be executed at a later timer. This scheduled code can run either in the process context or in interruption context depending on the type of deferred work.
softirqs : deferred work runs in interrupt context tasklets : deferred work runs in interrupt context work queues : deferred work runs in process context softirqs : Softirqs of the same type can run concurrently on several CPUs. tasklets : Tasklets of different types can run concurrently on several CPUs, but tasklets of the same type cannot. work queues : can run simultaneously on different CPU's softirqs : cannot go to sleep tasklets : cannot go to sleep work queues : can go to sleep softirqs : cannot be preempted/schedule tasklets : cannot be preempted/schedule work queues : maybe be preempted/schedule softirqs : not easy to use tasklets : easy to use work queues : easy to use
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With