c - tasklet 和 workqueue 有什么区别

标签 c linux-kernel linux-device-driver tasklet workqueue

我是一个 Linux 设备驱动新手,想知道 taskletworkqueue 之间的确切区别。我有以下疑问:

  1. Which kernel stack do interrupts, tasklet and workqueue use when running in interrupt/process context?
  2. At what priority would tasklet and workqueue run and can we modify it's priority?
  3. 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/

相关文章:

C:读取MCU整个Flash存储器的值

c - 为什么我会在 hackerrank "~ no response on stdout ~"中收到此消息?我不知道我错过了什么>

c - 在内核中高效分配内存

c - 如何防止 MMAP 缓存值?

linux - 使用 devicetree 配置的 davinci-spi 设备驱动程序是否支持 DMA 传输?

c - Linux : direct access to the hard-disk in C

c - C语言中的内存管理错误。为什么会出现这些错误?

c - C 编程中的 pragmapack() 除了结构打包之外还有其他用途吗?

c - 内核模块无法在某个语句之后执行语句

linux-kernel - 从 x86 交叉编译 arm