2

i am dealing with the concurrency managed workqueues in linux kernel 2.6.36.But i am confused about the some flags.

  • WQ_HIGHPRI
  • WQ_UNBOUND
  • WQ_RESCUER
  • WQ_CPU_INTENSIVE

I create a workqueue with flag WQ_HIGHPRI and queue some work items(eg w1 w2 w3 w4,by order) to it, none of the 4 work items will sleep.

  1. Whether the 4 work items are executed by the same thread and in this situation, is any thread created?

  2. In above situation, is there any difference if WQ_UNBOUND is used? Because if you set WQ_UNBOUND, then kernel will set WQ_HIGHPRI.

thank you in advance.

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
Olyd Olyd
  • 33
  • 1
  • 5

1 Answers1

1

Following excerpt explains the very basics of the workqueue design in the Linux kernel.

In the original wq implementation, each wq maintained its own separate worker pool. A MT wq could provide only one execution context per CPU while a ST wq one for the whole system. Work items had to compete for those very limited execution contexts leading to various problems.

In order to ease the asynchronous execution of functions a new abstraction, the work item, is introduced.

A work item is a simple struct that holds a pointer to the function that is to be executed asynchronously. Whenever a driver or subsystem wants a function to be executed asynchronously it has to set up a work item pointing to that function and queue that work item on a workqueue.

Special purpose threads, called worker threads, execute the functions off of the queue, one after the other. If no work is queued, the worker threads become idle. These worker threads are managed in so called thread-pools.

To eliminate these problems the Concurrency Managed Workqueue (cmwq) framework has been developed. As the name suggests, the emphasis is on providing maximum concurrency i.e. least blocking of work items with minimal possible overhead.


The various "WQ_*" flags

1. WQ_HIGHPRI

  • Work items of a high-priority workqueues are queued to the high priority thread-pool which contains worker threads with elevated nice level. The normal and high-priority thread-pools don't interact with each other. Each maintains its separate pool of workers and implements concurrency management among its workers.

2. WQ_UNBOUND

  • Does NOT participate in the workqueue concurrency management. The work item is NOT bound to a particular CPU and it can be scheduled to run on any available CPU. Also additional worker thread may be woke-up if required.

3. WQ_RESCUER

  • Deprecated (in latest kernel). Superseded by WQ_MEM_RECLAIM. Read this answer for details.

4. WQ_CPU_INTENSIVE

  • Does NOT participate in the workqueue concurrency management. Instead it is the responsibility of the CPU scheduler just like any other task.

Detailed description of each flag and the philosophy behind current workqueue design is available in Linux-kernel-src/Documentation/workqueue.txt


With the above info in mind, the answers to your queries are :

  1. All 4 work items are queued on high-priority threads which are bound to a particular CPU.

  2. Using WQ_UNBOUND will allow the work items to be executed on any available CPU across multiple runs.

Community
  • 1
  • 1
TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
  • Sincerely Thank you very much for your answer. I see the kernel has change the way of workqueues with the WQ_HIGHPRI flag.But what's the meaning of this word about WQ_UNBOUND:"Does NOT participate in the workqueue concurrency management"?Also about WQ_CPU_INTENSIVE? By the way,could you use some simple words summarizing the thread-pool management of the concurrency workqueue? – Olyd Olyd Aug 06 '13 at 07:48
  • Added details. Explained the emphasis on "concurrency" in the new workqueue framework. – TheCodeArtist Aug 06 '13 at 08:04