Mohammad Ali Asgar
Mohammad Ali Asgar

Reputation: 734

ksoftirqd's bottom-halves in interrupt or process context?

I have been meticulously reading the book named Linux Kernel Development written by Robert Love.

In my understanding, softirqs and tasklets are run in the interrupt context. Also, ksoftirqd is a kernel thread which runs in the process context. So, I find it quite puzzling and difficult to think how ksoftirqd (process context) is employed in order to run softirqs (interrupt context).

Upvotes: 2

Views: 2421

Answers (2)

XYZ
XYZ

Reputation: 189

Based on my cursory reading of kernel/softirq.c

run_ksoftirqd, just like normal execution of softirq, invokes __do_softirq().

In spite that, in this case, __do_softirq() runs in a task context, it's wrapped in local_irq_disable/enable().

So the code or calls by __do_softirq() will/should not make any distinctions whether it's invoked by ksoftirqd, raised by hw interrupt or run by scheduler.

Since irq is disabled, might_sleep() will complain if you mistakenly violate the rules of softirq even when it's running in a task context

Upvotes: 0

askb
askb

Reputation: 6768

I had similar question on my mind while reading the book, here is a link which should clarify some things: refer to this papar

"ksoftirqd is implemented as a set of threads, each of which is constrained to only run on a specific CPU. They are scheduled (at a very high priority) by the normal task scheduler. This implementation has the advantage that the time spent executing the bottom halves is accounted to a system task. It is thus possible for the user to see that the machine is overloaded with interrupt processing, and maybe take remedial action.

Although the work is now being done in process context rather than bottom half context, ksoftirqd sets up an environment identical to that found in bottom half context. Specifically, it executes the softirq handlers with local interrupts enabled and bottom halves disabled locally. Code which runs as a bottom half does not need to change for ksoftirqd to run it."

Upvotes: 3

Related Questions