📄 tasklets.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="level2"><div class="li"><span class="li"><a href="#tasklets" class="toc">Tasklets</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#tasklet_details" class="toc">Tasklet Details</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#tasklet_examples" class="toc">Tasklet Examples</a></span></div></li></ul></li></ul></li></ul></div></div><h2><a name="tasklets" id="tasklets">Tasklets</a></h2><div class="level2"><p> Kernel Tasklets are functions that can be added to a list of operations a kernel thread has to perform at the next “return from exception”.</p><p>They execute in the context of the Soft IRQ Thread and cannot perform any actions that may sleep.</p><p>They are very useful for performing activities that need to be triggered or scheduled at one time and have the actual execution deferred until a later time.</p><p>An interrupt action is one example where a deferred process may need to complete the data processing started by the Interupt service routiune.</p></div><!-- SECTION [1-565] --><h3><a name="tasklet_details" id="tasklet_details">Tasklet Details</a></h3><div class="level3"><p> To use tasklets you will need to include the header file <strong>linux/interrupt.h</strong></p><p>The following fiunctions are available: </p><ul><li class="level1"><div class="li"> DECLARE_TASKLET(tlname, func, data);</div></li></ul><pre class="code"> This will declare an enabled tasklet structure called tlname.</pre><pre class="code"> struct tasklet_struct tlname = { NULL, 0, ATOMIC_INT(0), func, data }</pre><pre class="code"> The function will be called with (unsigned long)data as a parameter</pre><ul><li class="level1"><div class="li"> DECLARE_TASKLET_DISABLED(tlname, function, data);</div></li></ul><pre class="code"> This will declare a disabled tasklet structure called tlname.</pre><pre class="code"> struct tasklet_struct tlname = { NULL, 0, ATOMIC_INT(1), func, data }</pre><pre class="code"> The function will be called with (unsigned long)data as a parameter</pre><ul><li class="level1"><div class="li"> void tasklet_schedule(&tlname)</div></li></ul><pre class="code"> This will cause the tasklet to be scheduled. If the tasklet is enabled it will be run.</pre><ul><li class="level1"><div class="li"> void tasklet_disable(&tlname);</div></li></ul><pre class="code"> This will disable the tasklet. The tasklet may still be scheduled with tasklet_schedule, but it will not execute until it is enabled.</pre><ul><li class="level1"><div class="li"> void tasklet_enable(&tlname);</div></li></ul><pre class="code"> This will enables a previously disabled taskled. If the tasklet had already been scheduled, it will be run after the return from tasklet_enable.</pre><ul><li class="level1"><div class="li"> void tasklet_kill(&tlname);</div></li></ul><pre class="code"> This function may be used on to remove the tasklet from any queue that it is on. It will wait until the tasklet executes, then removes it from the queue. The tasklet will not be interrupted during its execution. However the function may hang if the tasklet is not running and it may not be called from an interrupt routine.</pre></div><!-- SECTION [566-2157] --><h3><a name="tasklet_examples" id="tasklet_examples">Tasklet Examples</a></h3><div class="level3"><p> The keyboard driver (in the drivers/char directory) makes use of tasklets.</p><pre class="code c"><span class="co1">// from drivers/char/keyboard.c</span> DECLARE_TASKLET_DISABLED<span class="br0">(</span>keyboard_tasklet, kbd_bh, <span class="nu0">0</span><span class="br0">)</span>; <span class="coMULTI">/* * This allows a newly plugged keyboard to pick the LED state. */</span><span class="kw4">static</span> <span class="kw4">void</span> kbd_refresh_leds<span class="br0">(</span><span class="kw4">struct</span> input_handle *handle<span class="br0">)</span><span class="br0">{</span> <span class="kw4">unsigned</span> <span class="kw4">char</span> leds = ledstate; tasklet_disable<span class="br0">(</span>&keyboard_tasklet<span class="br0">)</span>; <span class="kw1">if</span> <span class="br0">(</span>leds != 0xff<span class="br0">)</span> <span class="br0">{</span> input_event<span class="br0">(</span>handle->dev, EV_LED, LED_SCROLLL, !!<span class="br0">(</span>leds & 0x01<span class="br0">)</span><span class="br0">)</span>; input_event<span class="br0">(</span>handle->dev, EV_LED, LED_NUML, !!<span class="br0">(</span>leds & 0x02<span class="br0">)</span><span class="br0">)</span>; input_event<span class="br0">(</span>handle->dev, EV_LED, LED_CAPSL, !!<span class="br0">(</span>leds & 0x04<span class="br0">)</span><span class="br0">)</span>; input_sync<span class="br0">(</span>handle->dev<span class="br0">)</span>; <span class="br0">}</span> tasklet_enable<span class="br0">(</span>&keyboard_tasklet<span class="br0">)</span>;<span class="br0">}</span> <span class="co1">// the keyboard event handler</span> <span class="kw4">static</span> <span class="kw4">void</span> kbd_event<span class="br0">(</span><span class="kw4">struct</span> input_handle *handle, <span class="kw4">unsigned</span> <span class="kw4">int</span> event_type, <span class="kw4">unsigned</span> <span class="kw4">int</span> event_code, <span class="kw4">int</span> value<span class="br0">)</span><span class="br0">{</span> <span class="kw1">if</span> <span class="br0">(</span>event_type == EV_MSC && event_code == MSC_RAW && HW_RAW<span class="br0">(</span>handle->dev<span class="br0">)</span><span class="br0">)</span> kbd_rawcode<span class="br0">(</span>value<span class="br0">)</span>; <span class="kw1">if</span> <span class="br0">(</span>event_type == EV_KEY<span class="br0">)</span> kbd_keycode<span class="br0">(</span>event_code, value, HW_RAW<span class="br0">(</span>handle->dev<span class="br0">)</span>, handle->dev->regs<span class="br0">)</span>; tasklet_schedule<span class="br0">(</span>&keyboard_tasklet<span class="br0">)</span>; do_poke_blanked_console = <span class="nu0">1</span>; schedule_console_callback<span class="br0">(</span><span class="br0">)</span>;<span class="br0">}</span> </pre></div><!-- SECTION [2158-] --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -