<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <HTML ><HEAD ><TITLE >Hard IRQ Context</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Unreliable Guide To Locking" HREF="book1.html"><LINK REL="PREVIOUS" TITLE="Locking Between Softirqs" HREF="x165.html"><LINK REL="NEXT" TITLE="Common Techniques" HREF="c196.html"></HEAD ><BODY CLASS="CHAPTER" 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 Locking</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x165.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="c196.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="CHAPTER" ><H1 ><A NAME="HARDIRQ-CONTEXT" ></A >Hard IRQ Context</H1 ><P > Hardware interrupts usually communicate with a bottom half, tasklet or softirq. Frequently this involves putting work in a queue, which the BH/softirq will take out. </P ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="HARDIRQ-SOFTIRQ" ></A >Locking Between Hard IRQ and Softirqs/Tasklets/BHs</H1 ><P > If a hardware irq handler shares data with a softirq, you have two concerns. Firstly, the softirq processing can be interrupted by a hardware interrupt, and secondly, the critical region could be entered by a hardware interrupt on another CPU. This is where <TT CLASS="FUNCTION" >spin_lock_irq()</TT > is used. It is defined to disable interrupts on that cpu, then grab the lock. <TT CLASS="FUNCTION" >spin_unlock_irq()</TT > does the reverse. </P ><P > This works perfectly for UP as well: the spin lock vanishes, and this macro simply becomes <TT CLASS="FUNCTION" >local_irq_disable()</TT > (<TT CLASS="FILENAME" >include/asm/smp.h</TT >), which protects you from the softirq/tasklet/BH being run. </P ><P > <TT CLASS="FUNCTION" >spin_lock_irqsave()</TT > (<TT CLASS="FILENAME" >include/linux/spinlock.h</TT >) is a variant which saves whether interrupts were on or off in a flags word, which is passed to <TT CLASS="FUNCTION" >spin_lock_irqrestore()</TT >. This means that the same code can be used inside an hard irq handler (where interrupts are already off) and in softirqs (where the irq disabling is required). </P ></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="x165.html" ACCESSKEY="P" ><<< 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="c196.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Locking Between Softirqs</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" > </TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Common Techniques</TD ></TR ></TABLE ></DIV ></BODY ></HTML >