WorkQueues as bottom half methods in the Linux kernel

Another bottom half method that is used in the linux kernel is the Workqueue. The work queue is an interface for creating kernel threads to handle work which is queued from elsewhere. The kernel threads so created are called as Worker threads. Work queues allow the kernel driver to create a special worker thread to handle deferred work.

The workqueue subsystem provides a default worker thread for handling work as well. Hence, in its most common form, a work queue is a simple interface for deferring work to a generic kernel thread.

The workqueues run in process context and hence can sleep. In contrast Tasklets/SoftIRQ bottom half methods cannot sleep. There are two types of work defined in the Linux kernel as of kernel 6.2.8 (Refer https://linux-kernel-labs.github.io/refs/heads/master/labs/deferred_work.html).

  1. struct work_struct – it schedules a task to run at a later time
  2. struct delayed_work – it schedules a task to run after at least a given time interval

Snippets of both those structures are provided below from the header file workqueue.h (linux kernel 6.2.8)

Fig courtesy : elixir.Bootlin.com

In the following articles, we see the different APIs that are used in the creation of a workqueue and code examples for workqueues.

Workqueue APIs

Comments

  1. Pingback: Tasklet Example code with dynamically initialized Tasklet | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *