The SoftIRQ Daemon

The task of the softIRQ daemon is to execute softIRQs asynchronously to remaining kernel code. To this end, each system processor is allocated its own daemon named ksoftirqd.

wakeup_softirqd is invoked at two points in the kernel to wake up the daemon:

□ In do_softirq, as just mentioned.

□ At the end of raise_softirq_irqoff. This funtion is called by raise_softirq internally, and can also be used directly if the kernel has interrupts turned off at the moment.

The wake-up function itself can be dealt with in a few lines. A pointer to the task_struct of the softIRQ daemon is read from a per-CPU variable by means of a few macros. If the current task state is not already task_running, it is put back in the list of processes ready to run by means of wake_up_process (see Chapter 2). Although this does not immediately start servicing of all pending software interrupts, the daemon (which runs with priority 19) is selected as soon as the scheduler has nothing better to do.

The softIRQ daemons of the system are generated shortly after init is called at system startup using the initcall mechanism described in Appendix D. After initialization, each daemon executes the following endless loop17:

kernel/softirq.c static int ksoftirqd(void * _bind_cpu)


while (local softirq pendinq()) { do_softirq(); cond_resched();


Each time it is awakened, the daemon first checks whether marked softIRQs are pending, as otherwise control can be passed to another process by explicitly invoking the scheduler.

If there are marked softIRQs, the daemon gets on with servicing them. In a while loop the two functions do_softirq and cond_resched are invoked repeatedly until no marked softIRQS remain. cond_resched ensures that the scheduler is called if the tif_need_resched flag was set for the current process (see Chapter 2). This is possible because all functions execute with enabled hardware interrupts.

Continue reading here: Tasklets

Was this article helpful?

0 0