1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Software Interrupt Context: Softirqs and Tasklets</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="up" href="basic-players.html" title="Chapter&#160;2.&#160;The Players"><link rel="prev" href="basics-hardirqs.html" title="Hardware Interrupts (Hard IRQs)"><link rel="next" href="basic-rules.html" title="Chapter&#160;3.&#160;Some Basic Rules"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Software Interrupt Context: Softirqs and Tasklets</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="basics-hardirqs.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;2.&#160;The Players</th><td width="20%" align="right">&#160;<a accesskey="n" href="basic-rules.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="basics-softirqs"></a>Software Interrupt Context: Softirqs and Tasklets</h2></div></div></div><p>
2    Whenever a system call is about to return to userspace, or a
3    hardware interrupt handler exits, any 'software interrupts'
4    which are marked pending (usually by hardware interrupts) are
5    run (<code class="filename">kernel/softirq.c</code>).
6   </p><p>
7    Much of the real interrupt handling work is done here.  Early in
8    the transition to <acronym class="acronym">SMP</acronym>, there were only 'bottom
9    halves' (BHs), which didn't take advantage of multiple CPUs.  Shortly 
10    after we switched from wind-up computers made of match-sticks and snot,
11    we abandoned this limitation and switched to 'softirqs'.
12   </p><p>
13    <code class="filename">include/linux/interrupt.h</code> lists the
14    different softirqs.  A very important softirq is the
15    timer softirq (<code class="filename">include/linux/timer.h</code>): you can
16    register to have it call functions for you in a given length of
17    time.
18   </p><p>
19    Softirqs are often a pain to deal with, since the same softirq
20    will run simultaneously on more than one CPU.  For this reason,
21    tasklets (<code class="filename">include/linux/interrupt.h</code>) are more
22    often used: they are dynamically-registrable (meaning you can have
23    as many as you want), and they also guarantee that any tasklet
24    will only run on one CPU at any time, although different tasklets
25    can run simultaneously.
26   </p><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3><p>
27     The name 'tasklet' is misleading: they have nothing to do with 'tasks',
28     and probably more to do with some bad vodka Alexey Kuznetsov had at the 
29     time.
30    </p></div><p>
31    You can tell you are in a softirq (or tasklet)
32    using the <code class="function">in_softirq()</code> macro 
33    (<code class="filename">include/linux/interrupt.h</code>).
34   </p><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3><p>
35     Beware that this will return a false positive if a bh lock (see below)
36     is held.
37    </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="basics-hardirqs.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="basic-players.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="basic-rules.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Hardware Interrupts (Hard IRQs)&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Chapter&#160;3.&#160;Some Basic Rules</td></tr></table></div></body></html>
38