I've been studying about interrupts
in Linux and softirq
in particular (I'm interested in networking subsystem of the kernel). I understand the concept of top-half and bottom-half, but what's not clear to me is -- how far does the softirq
context last? Until what point in the kernel stack we deal with softirq
? For example, when the ingress path hits ip_rcv()
, are we still in soft interrupt mode?
Rudely speaking, softirq context lasts until the softirq-handler returns.
ip_rcv(), are we still in soft interrupt mode
Yep, we are in softirq context. We're inside call-stack of function, that was raised as NET_RX_SOFTIRQ
.
Let's talk about receive path considering NAPI.
____napi_schedule()
raises NET_RX_SOFTIRQ
(it in turn modifies per-CPU data structure by accessing irq_stat.__softirq_pending
). Then the softirq handler moves packet up to the stack. All these actions are in softirq context. So here are two different directions: 1) this is forward packet - so the softirq context lasts until this packet will be added to some output queue and the handler will return. 2) this is local input packet - so the softirq lasts until this packet will be added (enqueued) to local socket receive queue, after which the handler returns. Such things are in case of dropping anywhere in the network stack. It all terminates when the basic softirq-function/handler terminates.