Exactly when tasklet runs after it is schedule by ISR?

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 ?


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":

  • In the return from hardware interrupt code path
  • In the ksoftirq kernel thread
  • 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:

  • In hardirq handler you wake up ksoftirq (due to tasklet_schedule() )
  • Thus wake_up_process() checks if ksoftirq may preempt current thread
  • If (2) is true TIF_NEED_RESCHED flag is set
  • On the return from hardirq ( ret_from_intr - in x86) TIF_NEED_RESCHED flag is checked
  • 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 (ie sleeping), clock tick happens, syscall or new interrupt.

    链接地址: http://www.djcxy.com/p/84802.html

    上一篇: 为什么同一个TASKLET不能同时在两个内核上执行?

    下一篇: ISR计划之后,tasklet是否正确运行?