有关内核中工作队列的一些标志 [英] some flags about workqueue in kernel

查看:175
本文介绍了有关内核中工作队列的一些标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理linux内核2.6.36中的并发管理工作队列.但是我对某些标志感到困惑.

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
  • WQ_HIGHPRI
  • WQ_UNBOUND
  • WQ_RESCUER
  • WQ_CPU_INTENSIVE

我创建一个带有标志WQ_HIGHPRI的工作队列,并向其中排队一些工作项(例如w1 w2 w3 w4,按顺序),这4个工作项都不会进入睡眠状态.

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. 这4个工作项是否由同一线程执行,在这种情况下,是否创建了任何线程?

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

在上述情况下,如果使用WQ_UNBOUND有什么区别?因为如果设置WQ_UNBOUND,则内核将设置WQ_HIGHPRI.

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

先谢谢您

推荐答案

以下摘录解释了

在原始wq实现中,每个wq维护自己的单独工作池.一个MT wq每个CPU只能提供一个执行上下文,而一个ST wq可以为整个系统提供一个执行上下文.工作项必须竞争那些导致各种问题的非常有限的执行上下文.

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.

为消除这些问题,开发了并发管理工作队列(cmwq)框架.顾名思义,重点在于提供最大的并发性,即以最小的可能开销最小地阻塞工作项.

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.

1. WQ_HIGHPRI

  • 高优先级工作队列的工作项排队到高优先级线程池,该线程池包含具有较高尼斯级别的工作线程.普通线程池和高优先级线程池不会相互影响.每个维护自己的工人池,并在工人之间实施并发管理.

2. WQ_UNBOUND

  • 不参与工作队列并发管理.该工作项未绑定到特定的CPU,可以安排它在任何可用的CPU上运行.如果需要,还可以唤醒其他工作线程.

3. WQ_RESCUER

4. WQ_CPU_INTENSIVE

  • 不参与工作队列并发管理.而是像其他任何任务一样,这是CPU调度程序的责任.

每个标志的详细说明和当前工作队列设计背后的原理可在

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. 所有4个工作项都在绑定到特定CPU的高优先级线程上排队.

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

使用WQ_UNBOUND将允许在多个运行中的任何可用CPU上执行工作项.

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

这篇关于有关内核中工作队列的一些标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆