Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use kernel threads vs workqueues in the linux kernel

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?

like image 821
Jamey Hicks Avatar asked Jan 27 '10 13:01

Jamey Hicks


People also ask

What is kernel threads and why it is used?

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.

What is Workqueue in Linux?

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.

What is the difference between Softirq Tasklet and Workqueue?

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.

What is deferred Jobs & recurring job in Linux?

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.


1 Answers

 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 
like image 79
user361697 Avatar answered Oct 03 '22 16:10

user361697