我是一个 Linux 设备驱动新手,想知道 tasklet
和 workqueue
之间的确切区别。我有以下疑问:
- Which kernel stack do interrupts, tasklet and workqueue use when running in interrupt/process context?
- At what priority would tasklet and workqueue run and can we modify it's priority?
- If I implement my own work queue list, can I schedule/prioritize it independently?
最佳答案
小任务:
- 年龄大(我相信大约 2.3)
- 有一个直接、简单的 API
- 专为低延迟而设计
- 无法 sleep (在软 IRQ 上下文中以原子方式运行,并且保证永远不会在给定处理器的多个 CPU 上运行,对于给定的 tasklet)
工作队列:
- 较新(在 2.5 中引入)
- 拥有灵活的 API(支持更多选项/标志)
- 专为更高的延迟而设计
- 可以 sleep
底线是:将 tasklet 用于高优先级、低延迟的原子任务,这些任务仍必须在硬 IRQ 上下文之外执行。
您可以使用 tasklet_hi_enable
/tasklet_hi_schedule
(而不是它们各自的 no-_hi
版本)控制 tasklet 的某种优先级。来自 this IBM page :
The normal-priority schedule is performed through the TASKLET_SOFTIRQ-level softirq, where high priority is through the HI_SOFTIRQ-level softirq.
...
Tasklets from the high-priority vector are serviced first, followed by those on the normal vector. Note that each CPU maintains its own normal and high-priority softirq vectors.
对于工作队列,在创建工作队列时,您将使用alloc_workqueue
(create_workqueue
已弃用)和can pass a flag要求更高的优先级:
WQ_HIGHPRI:
Work items of a highpri wq are queued to the highpri thread-pool of the target gcwq. Highpri thread-pools are served by worker threads with elevated nice level.
Note that normal and highpri thread-pools don't interact with each other. Each maintain its separate pool of workers and implements concurrency management among its workers.
我无法回答您所有的问题,但无论如何我希望这对您有所帮助。
关于c - tasklet 和 workqueue 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18321858/