1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Data Which Mostly Used By An IRQ Handler</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Locking"><link rel="up" href="Efficiency.html" title="Chapter&#160;9.&#160;Locking Speed"><link rel="prev" href="per-cpu.html" title="Per-CPU Data"><link rel="next" href="sleeping-things.html" title="Chapter&#160;10.&#160;What Functions Are Safe To Call From Interrupts?"></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">Data Which Mostly Used By An IRQ Handler</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="per-cpu.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;9.&#160;Locking Speed</th><td width="20%" align="right">&#160;<a accesskey="n" href="sleeping-things.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="mostly-hardirq"></a>Data Which Mostly Used By An IRQ Handler</h2></div></div></div><p>
2      If data is always accessed from within the same IRQ handler, you
3      don't need a lock at all: the kernel already guarantees that the
4      irq handler will not run simultaneously on multiple CPUs.
5    </p><p>
6      Manfred Spraul points out that you can still do this, even if
7      the data is very occasionally accessed in user context or
8      softirqs/tasklets.  The irq handler doesn't use a lock, and
9      all other accesses are done as so:
10    </p><pre class="programlisting">
11	spin_lock(&amp;lock);
12	disable_irq(irq);
13	...
14	enable_irq(irq);
15	spin_unlock(&amp;lock);
16</pre><p>
17      The <code class="function">disable_irq()</code> prevents the irq handler
18      from running (and waits for it to finish if it's currently
19      running on other CPUs).  The spinlock prevents any other
20      accesses happening at the same time.  Naturally, this is slower
21      than just a <code class="function">spin_lock_irq()</code> call, so it
22      only makes sense if this type of access happens extremely
23      rarely.
24    </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="per-cpu.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="Efficiency.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="sleeping-things.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Per-CPU Data&#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;10.&#160;What Functions Are Safe To Call From Interrupts?</td></tr></table></div></body></html>
25