In the previous example character driver code <character driver sample>, we used the “mknod command” to create the device file instance. it is possible to create a device file instance via code in the driver itself allowing the code to come up “on the go”. The below code snippet provides an example implementation of the […]
Character device driver sample user space code
The character device driver code can be looked at in the article placed at this location – <character device driver example>. The below user space sample code is to invoke the device file via the device driver. The output of the sample code is provided below The dmesg output indicates that the open, read, write […]
Device drivers – character device driver Example
Device driver – as the name suggests – it controls a device. It could a physical resource or a non-physical resource. In the following articles, we will ook through some device The character device driver is the most basic device driver that an interested developer will see and needs to learn in the Linux kernel. […]
Kernel Thread Code example
The below code block provides a sample implementation for kernel threads. the sample implementation only indicates a single operation for the thread. normally the a kernel thread will be performing cleanup operations or other background tasks continuously the output for the kernel thread code is shown below Device drivers – Character device driver example
Kernel Threads
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 […]