简体   繁体   English

工作队列的这些标志是什么意思?

[英]What are these flags for workqueue means?

While studying workqueue, I came across WorkQueue flags & constants defined in kernel.在研究工作队列时,我遇到了内核中定义的工作队列标志和常量。 I have following doubts which i could not understand.我有以下疑问,我无法理解。

  1. What exactly draining & rescuer mean here?排水和救援人员在这里到底是什么意思?

     WQ_DRAINING = 1 << 6, /* internal: workqueue is draining */ WQ_RESCUER = 1 << 7, /* internal: workqueue has rescuer */
  2. The number of CPUs defined for unbound workqueues is 4. What if I have an octa core processor.为未绑定工作队列定义的 CPU 数量是 4。如果我有一个八核处理器会怎样。 How the unbounded wq will be bounded to cpus.无界 wq 将如何绑定到 cpus。 How they decided which CPUs to run as they have now 8 cpus not 4 cpus.他们如何决定运行哪些 CPU,因为他们现在有 8 个 cpu 而不是 4 个 cpu。 Is it that, they can run on any of 8 or only 4 specific cpus?是这样,它们可以在 8 个或仅 4 个特定 cpu 中的任何一个上运行吗?

    WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */

WQ_DRAINING WQ_DRAINING

This flag is used to indicate that the kernel is currently flushing the workqueue and new work items cannot be queued on it.此标志用于指示内核当前正在刷新工作队列并且新的工作项不能在其上排队。 Only currently pending or running work items are allowed to so during this phase until the entire workqueue is completely empty.在此阶段只允许当前挂起或正在运行的工作项,直到整个工作队列完全清空为止。

For details, check out the implementation of drain_workqueue() in kernel/workqueue.c .有关详细信息,请查看kernel/workqueue.c drain_workqueue()实现。


WQ_RESCUER WQ_RESCUER

This flag is already deprecated in the latest Kernel by this patch and the behaviour is now determined by the WQ_MEM_RECLAIM flag.这个标志在最新的内核中已经被这个补丁弃用了,行为现在由WQ_MEM_RECLAIM标志决定。

As far as the "rescuer" functionality is concerned, here is the relevant section of documentation from kernel/workqueue.c ,就“救援”功能而言,这里是kernel/workqueue.c文档的相关部分,

Workqueue rescuer thread function.工作队列救援线程函数。 There's one rescuer for each workqueue which has WQ_MEM_RECLAIM set.每个设置了 WQ_MEM_RECLAIM 的工作队列都有一个救援者。

Regular work processing on a pool may block trying to create a new worker which uses GFP_KERNEL allocation which has slight chance of developing into deadlock if some works currently on the same queue need to be processed to satisfy the GFP_KERNEL allocation.池上的常规工作处理可能会阻止尝试创建使用 GFP_KERNEL 分配的新工作线程,如果需要处理当前在同一队列上的某些工作以满足 GFP_KERNEL 分配,则极有可能发展为死锁。 This is the problem rescuer solves.这是救援人员解决的问题。

When such condition is possible, the pool summons rescuers of all workqueues which have works queued on the pool and let them process those works so that forward progress can be guaranteed.当这种情况可能发生时,池会召集所有在池中排队的工作队列的救援人员,让他们处理这些工作,以保证前进的进度。


WQ_MAX_UNBOUND_PER_CPU WQ_MAX_UNBOUND_PER_CPU

(Contrary to how you have interpreted it, WQ_MAX_UNBOUND_PER_CPU is NOT the number of cpus. It is the number of workqueues that can be associated with a cpu.) (与您的解释相反, WQ_MAX_UNBOUND_PER_CPU不是 CPU 的数量。它是可以与 CPU 关联的工作队列的数量。)

Workqueues have been traditionally per-cpu ie each workqueue was associated with a particular cpu, resulting in better performance due to cache-locality.工作队列传统上是每个 CPU 的,即每个工作队列都与一个特定的 CPU 相关联,由于缓存局部性导致更好的性能。 The kernel scheduler does NOT have a choice but to schedule it always on the cpu it was defined on.内核调度程序别无选择,只能在定义它的 cpu 上调度它。 On current architectures, this leads to increased power consumption as even a single workqueue can prevent a cpu from idling and being turned off.在当前架构中,这会导致功耗增加,因为即使是单个工作队列也可以防止 CPU 空闲和关闭。 Hence unbound workqueues have been introduced.因此引入了未绑定的工作队列。 The scheduler is free to re-schedule unbound workqueues on any cpu as it sees fit.调度程序可以自由地在任何 cpu 上重新调度未绑定的工作队列,因为它认为合适。

The total number of such workqueues is limited to WQ_UNBOUND_MAX_ACTIVE which is defined as num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPU (upto a limit of total workqueues in the system determined by WQ_MAX_ACTIVE ).此类工作队列的总数限制为WQ_UNBOUND_MAX_ACTIVE ,其定义为num_possible_cpus() * WQ_MAX_UNBOUND_PER_CPUWQ_MAX_ACTIVEWQ_MAX_ACTIVE确定的系统中总工作队列的限制)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM