Exactly when tasklet runs after it is schedule by ISR?

不打扰是莪最后的温柔 提交于 2019-12-04 10:41:18

TL;DR: Tasklets are run by ksoftirq threads who are handled by Scheduler.


Tasklet is just a form of softirq (it is handled by them with TASKLET_SOFTIRQ priority), so rules on when running tasklets applies to them. Here they are according to Robert Love's book "Linux Kernel Development":

  1. In the return from hardware interrupt code path
  2. In the ksoftirq kernel thread
  3. In any code that explicitly checks for and executes pending softirqs, such as the networking subsystem

It seems that case (1) will not work if threadirqs=true (kernel boot parameter) which is default value.


UPD: Some notes on ksoftirq relation with Scheduler.

That is what seem to happen:

  1. In hardirq handler you wake up ksoftirq (due to tasklet_schedule())
  2. Thus wake_up_process() checks if ksoftirq may preempt current thread
  3. If (2) is true TIF_NEED_RESCHED flag is set
  4. On the return from hardirq (ret_from_intr - in x86) TIF_NEED_RESCHED flag is checked
  5. If (4) is true, schedule() is called trying to pick next thread to be executed.

There is high chance that ksoftirq will be considered as preempt candidate in (2-3) and it will be picked in (5), but if there are competitors, ksoftirq have to wait till next schedule() cycle - current thread surrenders (i.e. sleeping), clock tick happens, syscall or new interrupt.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!