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":
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:
tasklet_schedule()
) wake_up_process()
checks if ksoftirq may preempt current thread TIF_NEED_RESCHED
flag is set ret_from_intr
- in x86) TIF_NEED_RESCHED
flag is checked 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.