Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > 98e91bc877e03cf3582cd163550eb7e3 > files > 601

kernel-doc-html-2.4.19-16mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><TITLE
>Software Interrupt Context: Bottom Halves, Tasklets, softirqs</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Unreliable Guide To Hacking The Linux Kernel"
HREF="book1.html"><LINK
REL="UP"
TITLE="The Players"
HREF="c26.html"><LINK
REL="PREVIOUS"
TITLE="Hardware Interrupts (Hard IRQs)"
HREF="x54.html"><LINK
REL="NEXT"
TITLE="Some Basic Rules"
HREF="c84.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Unreliable Guide To Hacking The Linux Kernel</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x54.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>The Players</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="c84.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="BASICS-SOFTIRQS"
></A
>Software Interrupt Context: Bottom Halves, Tasklets, softirqs</H1
><P
>    Whenever a system call is about to return to userspace, or a
    hardware interrupt handler exits, any `software interrupts'
    which are marked pending (usually by hardware interrupts) are
    run (<TT
CLASS="FILENAME"
>kernel/softirq.c</TT
>).
   </P
><P
>    Much of the real interrupt handling work is done here.  Early in
    the transition to <SPAN
CLASS="ACRONYM"
>SMP</SPAN
>, there were only `bottom 
    halves' (BHs), which didn't take advantage of multiple CPUs.  Shortly 
    after we switched from wind-up computers made of match-sticks and snot,
    we abandoned this limitation.
   </P
><P
>    <TT
CLASS="FILENAME"
>include/linux/interrupt.h</TT
> lists the 
    different BH's.  No matter how many CPUs you have, no two BHs will run at 
    the same time. This made the transition to SMP simpler, but sucks hard for
    scalable performance.  A very important bottom half is the timer
    BH (<TT
CLASS="FILENAME"
>include/linux/timer.h</TT
>): you 
    can register to have it call functions for you in a given length of time.
   </P
><P
>    2.3.43 introduced softirqs, and re-implemented the (now
    deprecated) BHs underneath them.  Softirqs are fully-SMP
    versions of BHs: they can run on as many CPUs at once as
    required.  This means they need to deal with any races in shared
    data using their own locks.  A bitmask is used to keep track of
    which are enabled, so the 32 available softirqs should not be
    used up lightly.  (<I
CLASS="EMPHASIS"
>Yes</I
>, people will
    notice).
   </P
><P
>    tasklets (<TT
CLASS="FILENAME"
>include/linux/interrupt.h</TT
>) 
    are like softirqs, except they are dynamically-registrable (meaning you 
    can have as many as you want), and they also guarantee that any tasklet 
    will only run on one CPU at any time, although different tasklets can 
    run simultaneously (unlike different BHs).  
   </P
><DIV
CLASS="CAUTION"
><P
></P
><TABLE
CLASS="CAUTION"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="./stylesheet-images/caution.gif"
HSPACE="5"
ALT="Caution"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>     The name `tasklet' is misleading: they have nothing to do with `tasks', 
     and probably more to do with some bad vodka Alexey Kuznetsov had at the 
     time.
    </P
></TD
></TR
></TABLE
></DIV
><P
>    You can tell you are in a softirq (or bottom half, or tasklet)
    using the <TT
CLASS="FUNCTION"
>in_softirq()</TT
> macro 
    (<TT
CLASS="FILENAME"
>include/asm/softirq.h</TT
>).  
   </P
><DIV
CLASS="CAUTION"
><P
></P
><TABLE
CLASS="CAUTION"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="./stylesheet-images/caution.gif"
HSPACE="5"
ALT="Caution"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>     Beware that this will return a false positive if a bh lock (see below)
     is held.
    </P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x54.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="c84.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Hardware Interrupts (Hard IRQs)</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c26.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Some Basic Rules</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>