Sophie

Sophie

distrib > CentOS > 6 > i386 > by-pkgid > 2c51d8eb79f8810ada971ee8c30ce1e5 > files > 2205

kernel-doc-2.6.32-71.14.1.el6.noarch.rpm

<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>Chapter&#160;5.&#160;Cheat Sheet For Locking</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="Unreliable Guide To Locking" /><link rel="up" href="index.html" title="Unreliable Guide To Locking" /><link rel="prev" href="ch04s02.html" title="Locking Between Two Hard IRQ Handlers" /><link rel="next" href="ch06.html" title="Chapter&#160;6.&#160;The trylock Functions" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;5.&#160;Cheat Sheet For Locking</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s02.html">Prev</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch06.html">Next</a></td></tr></table><hr /></div><div class="chapter" title="Chapter&#160;5.&#160;Cheat Sheet For Locking"><div class="titlepage"><div><div><h2 class="title"><a id="cheatsheet"></a>Chapter&#160;5.&#160;Cheat Sheet For Locking</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch05.html#minimum-lock-reqirements">Table of Minimum Requirements</a></span></dt></dl></div><p>
     Pete Zaitcev gives the following summary:
   </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
          If you are in a process context (any syscall) and want to
	lock other process out, use a mutex.  You can take a mutex
	and sleep (<code class="function">copy_from_user*(</code> or
	<code class="function">kmalloc(x,GFP_KERNEL)</code>).
      </p></li><li class="listitem"><p>
	Otherwise (== data can be touched in an interrupt), use
	<code class="function">spin_lock_irqsave()</code> and
	<code class="function">spin_unlock_irqrestore()</code>.
	</p></li><li class="listitem"><p>
	Avoid holding spinlock for more than 5 lines of code and
	across any function call (except accessors like
	<code class="function">readb</code>).
	</p></li></ul></div><div class="sect1" title="Table of Minimum Requirements"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="minimum-lock-reqirements"></a>Table of Minimum Requirements</h2></div></div></div><p> The following table lists the <span class="emphasis"><em>minimum</em></span>
	locking requirements between various contexts.  In some cases,
	the same context can only be running on one CPU at a time, so
	no locking is required for that context (eg. a particular
	thread can only run on one CPU at a time, but if it needs
	shares data with another thread, locking is required).
   </p><p>
	Remember the advice above: you can always use
	<code class="function">spin_lock_irqsave()</code>, which is a superset
	of all other spinlock primitives.
   </p><div class="table"><a id="id3050387"></a><p class="title"><b>Table&#160;5.1.&#160;Table of Locking Requirements</b></p><div class="table-contents"><table summary="Table of Locking Requirements" border="1"><colgroup><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><tbody><tr><td>&#160;</td><td>IRQ Handler A</td><td>IRQ Handler B</td><td>Softirq A</td><td>Softirq B</td><td>Tasklet A</td><td>Tasklet B</td><td>Timer A</td><td>Timer B</td><td>User Context A</td><td>User Context B</td></tr><tr><td>IRQ Handler A</td><td>None</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td></tr><tr><td>IRQ Handler B</td><td>SLIS</td><td>None</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td></tr><tr><td>Softirq A</td><td>SLI</td><td>SLI</td><td>SL</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td></tr><tr><td>Softirq B</td><td>SLI</td><td>SLI</td><td>SL</td><td>SL</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td></tr><tr><td>Tasklet A</td><td>SLI</td><td>SLI</td><td>SL</td><td>SL</td><td>None</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td></tr><tr><td>Tasklet B</td><td>SLI</td><td>SLI</td><td>SL</td><td>SL</td><td>SL</td><td>None</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td></tr><tr><td>Timer A</td><td>SLI</td><td>SLI</td><td>SL</td><td>SL</td><td>SL</td><td>SL</td><td>None</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td></tr><tr><td>Timer B</td><td>SLI</td><td>SLI</td><td>SL</td><td>SL</td><td>SL</td><td>SL</td><td>SL</td><td>None</td><td class="auto-generated">&#160;</td><td class="auto-generated">&#160;</td></tr><tr><td>User Context A</td><td>SLI</td><td>SLI</td><td>SLBH</td><td>SLBH</td><td>SLBH</td><td>SLBH</td><td>SLBH</td><td>SLBH</td><td>None</td><td class="auto-generated">&#160;</td></tr><tr><td>User Context B</td><td>SLI</td><td>SLI</td><td>SLBH</td><td>SLBH</td><td>SLBH</td><td>SLBH</td><td>SLBH</td><td>SLBH</td><td>MLI</td><td>None</td></tr></tbody></table></div></div><br class="table-break" /><div class="table"><a id="id3050680"></a><p class="title"><b>Table&#160;5.2.&#160;Legend for Locking Requirements Table</b></p><div class="table-contents"><table summary="Legend for Locking Requirements Table" border="1"><colgroup><col /><col /></colgroup><tbody><tr><td>SLIS</td><td>spin_lock_irqsave</td></tr><tr><td>SLI</td><td>spin_lock_irq</td></tr><tr><td>SL</td><td>spin_lock</td></tr><tr><td>SLBH</td><td>spin_lock_bh</td></tr><tr><td>MLI</td><td>mutex_lock_interruptible</td></tr></tbody></table></div></div><br class="table-break" /></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s02.html">Prev</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="ch06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Locking Between Two Hard IRQ Handlers&#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;6.&#160;The trylock Functions</td></tr></table></div></body></html>