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

📄 c-basic3.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title>     Basic OS   </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-basic.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-basic2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-basic4.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="83567">2.3  &nbsp;&nbsp;Tasks</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83568"> </a>It is often essential to organize applications into independent, though cooperating, programs. Each of these programs, while executing, is called a <i class="term">task</i>. In VxWorks, tasks have immediate, shared access to most system resources, while also maintaining enough separate context to maintain individual threads of control.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="83570">2.3.1  &nbsp;&nbsp;Multitasking</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83571"> </a><i class="term">Multitasking</i> provides the fundamental mechanism for an application to control and react to multiple, discrete real-world events. The VxWorks real-time kernel, <i class="i">wind</i>, provides the basic multitasking environment. Multitasking creates the appearance of many threads of execution running concurrently when, in fact, the kernel interleaves their execution on the basis of a scheduling algorithm. Each apparently independent program is called a <i class="term">task</i>. Each task has its own <i class="term">context</i>, which is the CPU environment and system resources that the task sees each time it is scheduled to run by the kernel. On a context switch, a task's context is saved in the task control block (TCB). A task's context includes:</p></dl><dl class="margin"><ul class="DashSingle" type="circle"><li><a name="83575"> </a>a thread of execution, that is, the task's program counter</li></ul><ul class="DashSingle" type="circle"><li><a name="83576"> </a>the CPU registers and (optionally) floating-point registers</li></ul><ul class="DashSingle" type="circle"><li><a name="83577"> </a>a stack for dynamic variables and function calls</li></ul><ul class="DashSingle" type="circle"><li><a name="83578"> </a>I/O assignments for standard input, output, and error</li></ul><ul class="DashSingle" type="circle"><li><a name="83580"> </a>a delay timer</li></ul><ul class="DashSingle" type="circle"><li><a name="83581"> </a>a timeslice timer</li></ul><ul class="DashSingle" type="circle"><li><a name="83582"> </a>kernel control structures</li></ul><ul class="DashSingle" type="circle"><li><a name="83583"> </a>signal handlers</li></ul><ul class="DashSingle" type="circle"><li><a name="83584"> </a>debugging and performance monitoring values</li></ul></dl><dl class="margin"><dd><p class="Body"><a name="83585"> </a>In VxWorks, one important resource that is <i class="emphasis">not</i> part of a task's context is memory address space: all code executes in a single common address space. Giving each task its own memory space requires virtual-to-physical memory mapping, which is available only with the optional product VxVMI; for more information, see <a href="c-vm.html#84369"><i class="title">7.&nbsp;Virtual Memory Interface</i></a>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="83590">2.3.2  &nbsp;&nbsp;Task State Transition </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83591"> </a>The kernel maintains the current state of each task in the system. A task changes from one state to another as the result of kernel function calls made by the application. When created, tasks enter the <i class="term">suspended</i> state. Activation is necessary for a created task to enter the <i class="term">ready</i> state. The activation phase is extremely fast, enabling applications to pre-create tasks and activate them in a timely manner. An alternative is the <i class="term">spawning</i> primitive, which allows a task to be created and activated with a single function<i class="term">. </i>Tasks can be deleted from any state.</p><dd><p class="Body"><a name="83595"> </a>The<i class="i"> wind</i> kernel states are shown in the state transition diagram in <a href="c-basic3.html#93407">Figure&nbsp;2-1</a>, and a summary of the corresponding <i class="term">state symbols</i> you will see when working with Tornado development tools is shown in <a href="c-basic3.html#93568">Table&nbsp;2-1</a>.<p class="table"><h4 class="EntityTitle"><a name="93568"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 2-1:&nbsp;&nbsp;Task State Transitions</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="93572"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">State Symbol</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="93574"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93577"> </a><b>READY</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93579"> </a>The state of a task that is not waiting for any resource other than the CPU.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93582"> </a><b>PEND</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93584"> </a>The state of a task that is blocked due to the unavailability of some resource.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93587"> </a><b>DELAY</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93590"> </a>The state of a task that is asleep for some duration.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93593"> </a><b>SUSPEND</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93595"> </a>The state of a task that is unavailable for execution. This state is used primarily for debugging. Suspension does not inhibit state transition, only task execution. Thus <i class="term">pended-suspended</i> tasks can still unblock and<i class="term"> delayed-suspended </i>tasks can still awaken. &nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93599"> </a><b>DELAY + S</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93601"> </a>The state of a task that is both delayed and suspended.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93603"> </a><b>PEND + S</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93605"> </a>The state of a task that is both pended and suspended.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93607"> </a><b>PEND + T</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93609"> </a>The state of a task that is pended with a timeout value.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93611"> </a><b>PEND + S + T</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93613"> </a>The state of a task that is both pended with a timeout value and suspended.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="93615"> </a><i class="textVariable">state</i><b> + I</b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="93618"> </a>The state of task specified by <i class="textVariable">state</i>, plus an inherited priority.&nbsp;</div></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div class="frame"><h4 class="EntityTitle"><a name="93407"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 2-1:&nbsp;&nbsp;Task State Transitions</font></a></h4><dl class="margin"><div class="Anchor"><a name="93492"> </a><img class="figure" border="0" src="images/c-basica4.gif"></div></dl></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="83757">2.3.3  &nbsp;&nbsp;Wind Task Scheduling</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83758"> </a>Multitasking requires a scheduling algorithm to allocate the CPU to ready tasks. Priority-based preemptive scheduling is the default algorithm in <i class="i">wind</i>, but you can select round-robin scheduling for your applications as well. The routines listed in <a href="c-basic3.html#83765">Table&nbsp;2-2</a> control task scheduling.<p class="table"><h4 class="EntityTitle"><a name="83765"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 2-2:&nbsp;&nbsp;Task Scheduler Control Routines</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="83769"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Call</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="83771"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83778"> </a><b class="routine"><i class="routine">kernelTimeSlice</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83780"> </a>Control round-robin scheduling.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83783"> </a><b class="routine"><i class="routine">taskPrioritySet</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83785"> </a>Change the priority of a task.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83788"> </a><b class="routine"><i class="routine">taskLock</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83790"> </a>Disable task rescheduling.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83793"> </a><b class="routine"><i class="routine">taskUnlock</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83795"> </a>Enable task rescheduling.&nbsp;</div></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="83800">Preemptive Priority Scheduling</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83802"> </a>With a preemptive priority-based scheduler, each task has a priority and the kernel ensures that the CPU is allocated to the highest priority task that is ready to run. This scheduling method is <i class="term">preemptive</i> in that if a task that has higher priority than the current task becomes ready to run, the kernel immediately saves the current task's context and switches to the context of the higher priority task. In <a href="c-basic3.html#83848">Figure&nbsp;2-2</a>, task <b class="task">t1</b> is preempted by higher-priority task <b class="task">t2</b>, which in turn is preempted by <b class="task">t3</b>. When <b class="task">t3</b> completes, <b class="task">t2</b> continues executing. When <b class="task">t2</b> completes execution, <b class="task">t1</b> continues executing. <div class="frame"><h4 class="EntityTitle"><a name="83848"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 2-2:&nbsp;&nbsp;Priority Preemption</font></a></h4><dl class="margin">

⌨️ 快捷键说明

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