Exactly when tasklet runs after it is schedule by

2019-04-09 15:56发布

I written my ISR and my tasklet ran immediately. BUT, I have seen people saying that tasklet runs only when it gets CPU attention. This is a very generic term CPU attention so i recite for those responders. I mean exactly which moment cpu attention goes to tasklet execution and what happen to the state of CPU ?

Secondly, if suppose that i am keep on getting hard interrupt then when will tasklet get chance to run? Is it possible that tasklet may not get chance to run? How does kernel take care these things ?

1条回答
smile是对你的礼貌
2楼-- · 2019-04-09 16:50

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.

查看更多
登录 后发表回答