[英]is there a workqueue feature in xnu kernel?
I need to use workqueue-like feature on Mac OSX (kernel mode driver) and am looking for a way to add work into a queue to be processed by a kernel thread later. 我需要在Mac OSX(内核模式驱动程序)上使用类似于工作队列的功能,并且正在寻找一种将工作添加到队列中以供稍后由内核线程处理的方法。 Conceptually this is the same thing as workqueue feature available in Linux kernel. 从概念上讲,这与Linux内核中可用的工作队列功能相同。 Is there something similar on XNU kernel as well? XNU内核上也有类似的东西吗?
I don't think there's a direct equivalent as such, although I admit I'm not intimately familiar with the Linux side, so I'll avoid comparing and just tell you about what's available on macOS/xnu. 尽管我承认我对Linux方面并不十分熟悉,但我不认为有这样的直接对等物,因此我将避免进行比较,而只是告诉您macOS / xnu上的可用功能。
I/O Kit IOWorkLoops I / O套件IOWorkLoops
If you're building an I/O Kit driver, and especially if you're writing a secondary interrupt handler, you'll be using IOWorkLoops . 如果要构建I / O Kit驱动程序,尤其是在编写辅助中断处理程序时,将使用IOWorkLoops 。 Interrupts are abstracted by IOEventSource objects, which schedule secondary interrupt handlers to run on the driver's IOWorkLoop . 中断由IOEventSource对象抽象,该对象计划辅助中断处理程序在驱动程序的IOWorkLoop上运行 。
Each IOWorkLoop
wraps one kernel thread and also provides a serialisation/locking mechanism for resources shared with that thread. 每个IOWorkLoop
包装一个内核线程,并为与该线程共享的资源提供序列化/锁定机制。 All jobs submitted to a workloop either explicitly through an IOCommandGate
or the workloop object directly, or as a result of an IOEventSource
event will be serialised. 通过IOCommandGate
或直接通过工作循环对象显式提交到工作循环的所有作业,或由于IOEventSource
事件而提交给工作循环的所有作业,都将被序列化。 Note that IOCommandGate
jobs will run synchronously on the calling thread, not the workloop thread. 请注意, IOCommandGate
作业将在调用线程而非工作循环线程上同步运行。
As always with macOS/OSX internals, you will want to look at the header file comments and possibly the implementation in the xnu source for details. 与macOS / OSX内部一样,您将需要查看头文件注释以及xnu源中的实现以获取详细信息。 I personally find IOWorkLoop
sa bit clumsy for some tasks, but if you're dealing with PCI devices, etc. you don't really have a choice. 我个人发现IOWorkLoop
对于某些任务而言有些笨拙,但是如果您要处理PCI设备等,则实际上别无选择。
thread_call thread_call
A more lightweight background work mechanism is the thread_call API . 一个更轻量的后台工作机制是thread_call API 。 It's defined in <kern/thread_call.h>
and supports running functions on an OS-managed background thread, optionally after a delay or with a specific priority. 它在<kern/thread_call.h>
定义,并支持在OS管理的后台线程上运行功能,可以选择在延迟或具有特定优先级之后运行。 This is probably closer to what you know from Linux, has a fairly straightforward API, but is not suitable for secondary interrupt handlers. 这可能更接近您从Linux所了解的知识,具有相当简单的API,但不适用于辅助中断处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.