The Linux kernel spawns threads which handle background operation. These kernel threads have a PID and also contain a task structure similar to a process. However, the kernel thread does not have a specific address space where they are mapped to. The kernel threads run exclusively in kernel space and take care of asynchronous events […]
Creating a dedicated workqueue
In the previous articles, we created work and we scheduled the work using default worker threads. If a dedicated workqueue is desired specifically to handle specific work for the kernel module that you are developing, a workqueue can be created using “create_workqueue” API. The code block creates a work queue, assigns initialized work and later […]
Workqueue code example using INIT_WORK Macro
The below code snippet shows the code for initializing the work queue separately by using INIT_WORK. The output of the kernel module is placed below Creating a dedicated Workqueue
Workqueue code example using DECLARE_WORK Macro
The code snippet using DECLARE_WORK is provided below The output of the program via “dmesg” output is shown below In the coming example, we will use INIT_WORK to initialize the workqueue. Workqueue code example using INIT_WORK Macro
Workqueue APIs
The below table lists out the different workqueue APIs that are commonly used in the intialization and usage of a workqueue. For a comprehensive list – refer “workqueue.h” in the linux kernel. Workqueue API Description schedule_work Schedule the work to be performed schedule_delayed_work Put work task in global workqueue after delay create_workqueue Creating a new […]
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 […]
Tasklet Example code with dynamically initialized Tasklet
In the previous code example, we discussed a statically assigned Tasklet via the DECLARE_TASKLET_OLD MACRO. In the current code example, a dynamcally memory allocated tasklet structure is intialized for operation via the tasklet_init function. The “dmesg output” is shown below Workqueues as bottom half method in the Linux kernel
Tasklet Example code with statically initialized Tasklet
Tasklet is a bottom half processing method. The Tasklet is scheduled from the ISR in this instance. The below code snippet shows a statically initialized Tasklet and the output of the code block The Makefile for the above code is provided below The output of the tasklet being scheduled and the handler being invoked is […]
Tasklet APIs
There are a number of APIs that are defined for Tasklet operation in the Linux kernel. The below table provides a list of Tasklet APIs with a brief description of the APIs. For a more comprehensive list – refer /linux/interrupt.h file in the Linux kernel Tasklet API Description tasklet_init Initialize the tasklet. Used in dynamic […]