What’s a workqueue?
Workqueue is an asynchronous execution mechanism which is widely used across the kernel. A work item queued on a workqueue is asynchronously executed by a worker task (kworker/* in ps output). It’s used for various purposes from simple context bouncing to hosting a persistent in-kernel service thread. Each workqueue has one or more dedicated processes (“kthreads”), which run functions submitted to the queue.
What are the types of workqueues?
Well. There are 2 types: dedicated and system_wq.
A dedicated workqueue has a dedicated thread- a single thread in some cases, one thread per CPU in others. You might want to use these if the work items hosted by a workqueue are dependent on memory reclaim or require high priority.
A device driver, in many cases, does not need its own workqueue. If you only submit tasks to the queue occasionally, it may be more efficient to simply use the shared, default workqueue ie system_wq. system_wq has been able to handle high level of concurrency for a long time now and there’s no reason to use dedicated workqueues just to gain concurrency.
Cool. How do I create a workqueue?
Well, if you want to create a dedicated workqueue then alloc_workqueue is what you’re looking for.
alloc_workqueue(@name, @flags, @max_active)
If you want to use system_wq, then there’s no “creation” involved. You can begin queuing right away…
I want to read more..
Sure. Check out the docs.