⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wait_queues.html

📁 ADI 公司blackfin系列的用户使用文挡。
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head>  <title></title>  <link rel="stylesheet" media="screen" type="text/css" href="./style.css" />  <link rel="stylesheet" media="screen" type="text/css" href="./design.css" />  <link rel="stylesheet" media="print" type="text/css" href="./print.css" />  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><div class="toc"><div class="tocheader toctoggle" id="toc__header">Table of Contents</div><div id="toc__inside"><ul class="toc"><li class="clear"><ul class="toc"><li class="clear"><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#wait_queues" class="toc">Wait Queues</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#exclusive_functions" class="toc">Exclusive Functions</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#bit_functions" class="toc">Bit Functions</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#sync_functions" class="toc">Sync Functions</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#interruptible_functions" class="toc">Interruptible Functions</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#out_of_line_functions" class="toc">Out of Line Functions</a></span></div></li></ul></li></ul></li></ul></div></div><h3><a name="wait_queues" id="wait_queues">Wait Queues</a></h3><div class="level3"><p>The Wait Queue mechanism is the main method for one process to tell another  process that it can continue running.</p><p>For example An I/O Read  Process is waiting for data to arrive. It suspends itself on a wait queue. When the I/O Device receives data it wakes up any tasks waiting for the data.</p><p>If you have more than one task waiting for the data then you have to stop one task &ldquo;stealing&rdquo; data for the other task.</p><p>Most device drivers use this process to handle I/O events.</p><p> Here is an example of setting up, suspending and waking a task on a wait queue</p><pre class="code c">&nbsp;<span class="co2">#include &lt;linux/wait.h&gt;</span>&nbsp;<span class="co1">// wait queues</span><span class="kw4">static</span> wait_queue_head_t myreadq;<span class="kw4">static</span> wait_queue_head_t mywriteq;&nbsp;&nbsp;                                      <span class="co1">// inside the module_init function</span>    init_waitqueue_head<span class="br0">&#40;</span>&amp;myreadq<span class="br0">&#41;</span>;     init_waitqueue_head<span class="br0">&#40;</span>&amp;mywriteq<span class="br0">&#41;</span>;.................................................................    <span class="co1">//inside the read function</span>   ...   <span class="kw1">if</span> <span class="br0">&#40;</span> wait_event_interruptible<span class="br0">&#40;</span> myreadq, <span class="br0">&#40;</span>bytes_read &lt;= bytes_in<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>            printk<span class="br0">&#40;</span><span class="st0">" read signal ...<span class="es0">\n</span>"</span><span class="br0">&#41;</span>;            <span class="kw1">return</span> -ERESTARTSYS;        <span class="br0">&#125;</span>    <span class="co1">// read count bytes from the device                         </span>    space_left+=count;    bytes_read+=count;&nbsp;    <span class="co1">//wake up any writers we now have space</span>    wake_up_interruptible<span class="br0">&#40;</span>&amp;mywriteq<span class="br0">&#41;</span>;&nbsp;.................................................................     <span class="co1">//inside the write function</span>    <span class="kw1">if</span> <span class="br0">&#40;</span> wait_event_interruptible<span class="br0">&#40;</span> mywriteq, <span class="br0">&#40;</span>bytes_in &gt;= space_left<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>            <span class="kw1">return</span> -ERESTARTSYS;        <span class="br0">&#125;</span>    <span class="co1">// once we have space write bytes</span>    space_left-=count;    bytes_in+=count;&nbsp;    <span class="co1">//wake up any readers </span>    wake_up_interruptible<span class="br0">&#40;</span>&amp;myreadq<span class="br0">&#41;</span>;&nbsp;.................................................................     <span class="co1">// or if data arrives via an Interrupt</span>&nbsp;    space_left-=count;    bytes_in+=count;&nbsp;       <span class="co1">//wake up any readers </span>    wake_up_interruptible<span class="br0">&#40;</span>&amp;myreadq<span class="br0">&#41;</span>;&nbsp;&nbsp;</pre></div><!-- SECTION [1-1900] --><h3><a name="exclusive_functions" id="exclusive_functions">Exclusive Functions</a></h3><div class="level3"><p> When a wait queue is &ldquo;woken up&rdquo; all tasks on the wait queue are  enabled for the scheduler. If a task is added to a wait queue using an exclusive function then the wake up call will  only wake up one exclusive task leaving the others still waiting. If a mixture of exclusive tasks and non exclusive tasks are added to the queue then the wake up function will wake up any non exclusive tasks until it wakes up the exclusive task. The wakeup order is normally the reverse of the order in which tasks are added to the queue.  </p></div><!-- SECTION [1901-2455] --><h3><a name="bit_functions" id="bit_functions">Bit Functions</a></h3><div class="level3"><p>These functions allow the user to wait / wake up on the value of a designated bit in a word. The combination of the word address plus the bit number is used to pick a queue from a hash tabel for the task to wait on. The corresponding wake up call only needs to refer to the word address and the bit. The bit should be cleared before the wakeup will succeed.</p></div><!-- SECTION [2456-2837] --><h3><a name="sync_functions" id="sync_functions">Sync Functions</a></h3><div class="level3"><p>Thes options can be used when you do not want the scheduler called when waking up the task. The rules are that you can wake up &ldquo;sync&rdquo; but you have to agree to call the scheduler yourself.  </p></div><!-- SECTION [2838-3051] --><h3><a name="interruptible_functions" id="interruptible_functions">Interruptible Functions</a></h3><div class="level3"><p>These do <strong>NOT</strong> refer to interrupts. An <strong>UNINTERRUPTIBLE</strong> task will not respond to signals whereas an <strong>INTERRUPTIBLE</strong> task will return early from a wait request should it get a signal.</p></div><!-- SECTION [3052-3275] --><h3><a name="out_of_line_functions" id="out_of_line_functions">Out of Line Functions</a></h3><div class="level3"><p>A lot of kernel functions are inserted inline into the calling function. Out of Line functions are avaialble should you wish to explicitly call the function.</p><p>Other Kernel wait queue functions </p><table class="inline">	<tr>		<td colspan="2">add_wait_queue_exclusive</td>	</tr>	<tr>		<td colspan="2">remove_wait_queue</td>	</tr>	<tr>		<td>prepare_to_wait</td><td>helper function to set up a process to wait for a condition</td>	</tr>	<tr>		<td colspan="2">prepare_to_wait_exclusive</td>	</tr>	<tr>		<td>finish_wait</td><td>clean up after a prepare_to_wait</td>	</tr>	<tr>		<td>wait_on_bit</td><td>given a word and a bit number wait until the bit is cleared</td>	</tr>	<tr>		<td>out_of_line_wait_on_bit</td><td>same but not inlined</td>	</tr>	<tr>		<td colspan="2">wait_on_bit_lock</td>	</tr>	<tr>		<td colspan="2">out_of_line_wait_on_bit_lock</td>	</tr>	<tr>		<td>wake_up_bit</td><td>wake up a task waiting on a bit</td>	</tr>	<tr>		<td>wake_up_exclusive</td><td>wake all the non-exclusive tasks and one exclusive task</td>	</tr></table><br /></div><!-- SECTION [3276-] --></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -