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

📄 c-basic3.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<div class="Anchor"><a name="83845"> </a><img class="figure" border="0" src="images/c-basic10.gif"></div></dl></div></p><dd><p class="Body"><a name="83850"> </a>The <i class="i">wind </i>kernel has 256 priority levels, numbered 0 through 255. Priority 0 is the highest and priority 255 is the lowest. Tasks are assigned a priority when created; however, while executing, a task can change its priority using <b class="routine"><i class="routine">taskPrioritySet</i></b><b>(&nbsp;)</b>. The ability to change task priorities dynamically allows applications to track precedence changes in the real world.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="83853">Round-Robin Scheduling</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83854"> </a>Preemptive priority scheduling can be augmented with round-robin scheduling. A round-robin scheduling algorithm attempts to share the CPU fairly among all ready tasks of the <i class="emphasis">same priority</i>. Without round-robin scheduling, when multiple tasks of equal priority must share the processor, a single task can usurp the processor by never blocking, thus never giving other equal-priority tasks a chance to run.</p><dd><p class="Body"><a name="83856"> </a>Round-robin scheduling achieves fair allocation of the CPU to tasks of the same priority by an approach known as <i class="term">time slicing. </i>Each task of a group of tasks executes for a defined interval, or <i class="term">time slice</i>; then another task executes for an equal interval, in rotation. The allocation is fair in that no task of a priority group gets a second slice of time before the other tasks of a group are given a slice.</p><dd><p class="Body"><a name="83859"> </a>Round-robin scheduling can be enabled with the routine <b class="routine"><i class="routine">kernelTimeSlice</i></b><b>(&nbsp;)</b>, which takes a parameter for a time slice, or interval. This interval is the amount of time each task is allowed to run before relinquishing the processor to another equal-priority task.</p><dd><p class="Body"><a name="83860"> </a>More precisely, a run-time counter is kept for each task and incremented on every clock tick. When the specified time-slice interval is completed, the counter is cleared and the task is placed at the tail of the queue of tasks at its priority. New tasks joining a priority group are placed at the tail of the group with a run-time counter initialized to zero.</p><dd><p class="Body"><a name="83861"> </a>If a task is preempted by a higher priority task during its interval, its run-time count is saved and then restored when the task is again eligible for execution. <a href="c-basic3.html#83915">Figure&nbsp;2-3</a> shows round-robin scheduling for three tasks of the same priority: <b class="task">t1</b>, <b class="task">t2</b>, and <b class="task">t3</b>. Task <b class="task">t2</b> is preempted by a higher priority task <b class="task">t4</b> but resumes at the count where it left off when <b class="task">t4</b> is finished. <div class="frame"><h4 class="EntityTitle"><a name="83915"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 2-3:&nbsp;&nbsp;Round-Robin Scheduling</font></a></h4><dl class="margin"><div class="Anchor"><a name="83912"> </a><img class="figure" border="0" src="images/c-basic13.gif"></div></dl></div></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="83917">Preemption Locks</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83918"> </a>The <i class="i">wind</i> scheduler can be explicitly disabled and enabled on a per-task basis with the routines <b class="routine"><i class="routine">taskLock</i></b><b>(&nbsp;)</b> and<b class="routine"><i class="routine"> taskUnlock</i></b><b>(&nbsp;)</b><b></b>. When a task disables the scheduler by calling <b class="routine"><i class="routine">taskLock</i></b><b>(&nbsp;)</b>, no priority-based preemption can take place while that task is running.</p><dd><p class="Body"><a name="83921"> </a>However, if the task explicitly blocks or suspends, the scheduler selects the next highest-priority eligible task to execute. When the preemption-locked task unblocks and begins running again, preemption is again disabled.</p><dd><p class="Body"><a name="83922"> </a>Note that preemption locks prevent task context switching but do not lock out interrupt handling.</p><dd><p class="Body"><a name="83923"> </a>Preemption locks can be used to achieve mutual exclusion; however, keep the duration of preemption locking to a minimum. For more information, see <a href="c-basic4.html#84958"><i class="title">2.4.2&nbsp;Mutual Exclusion</i></a>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="83928">2.3.4  &nbsp;&nbsp;Tasking Control</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83929"> </a>The following sections give an overview of the basic VxWorks tasking routines, which are found in the VxWorks library <b class="library">taskLib</b>. These routines provide the means for task creation, control, and information. See the reference entry for <b class="library">taskLib</b> for further discussion. For interactive use, you can control VxWorks tasks from the host-resident shell; see the <i class="title">Tornado User's Guide: Shell</i>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="83930">Task Creation and Activation</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83965"> </a>The routines listed in <a href="c-basic3.html#83938">Table&nbsp;2-3</a> are used to create tasks.<p class="table"><h4 class="EntityTitle"><a name="83938"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 2-3:&nbsp;&nbsp;Task Creation 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="83942"> </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="83944"> </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="83950"> </a><b class="routine"><i class="routine">taskSpawn</i></b><b>(&nbsp;)</b><b> </b>&nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83952"> </a>Spawn (create and activate) a new task.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83954"> </a><b class="routine"><i class="routine">taskInit</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83956"> </a>Initialize a new task.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83958"> </a><b class="routine"><i class="routine">taskActivate</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83960"> </a>Activate an initialized task.&nbsp;</div></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p><dd><p class="Body"><a name="83967"> </a>The arguments to <b class="routine"><i class="routine">taskSpawn</i></b><b>(&nbsp;)</b> are the new task's name (an ASCII string), priority, an "options" word, stack size, main routine address, and 10 arguments to be passed to the main routine as startup parameters:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83968"><i class="textVariable">id</i> = taskSpawn (<i class="textVariable"> name</i>, <i class="textVariable">priority</i>, <i class="textVariable">options</i>, <i class="textVariable">stacksize</i>, <i class="textVariable">main</i>, <i class="textVariable">arg1</i>, <i class="textVariable">arg10 </i>);</a></b></pre></dl><dd><p class="Body"><a name="83970"> </a>The <b class="routine"><i class="routine">taskSpawn</i></b><b>(&nbsp;)</b> routine creates the new task context, which includes allocating the stack and setting up the task environment to call the main routine (an ordinary subroutine) with the specified arguments. The new task begins execution at the entry to the specified routine.</p><dd><p class="Body"><a name="83971"> </a>The <b class="routine"><i class="routine">taskSpawn</i></b><b>(&nbsp;)</b> routine embodies the lower-level steps of allocation, initialization, and activation. The initialization and activation functions are provided by the routines <b class="routine"><i class="routine">taskInit</i></b><b>(&nbsp;)</b> and <b class="routine"><i class="routine">taskActivate</i></b><b>(&nbsp;)</b>; however, we recommend you use these routines only when you need greater control over allocation or activation.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="83976">Task Names and IDs</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83977"> </a>When a task is spawned, you can specify an ASCII string of any length to be the task name. VxWorks returns a task ID, which is a 4-byte handle to the task's data structures. Most VxWorks task routines take a task ID as the argument specifying a task. VxWorks uses a convention that a task ID of 0 (zero) always implies the calling task.</p><dd><p class="Body"><a name="83979"> </a>A task name should not conflict with any existing task name. Furthermore, to use the Tornado development tools to their best advantage, task names should not conflict with globally visible routine or variable names. To avoid name conflicts, VxWorks uses a convention of prefixing all task names started from the target with the letter <i class="i">t</i> and task names started from the host with the letter <i class="i">u</i>.</p><dd><p class="Body"><a name="92541"> </a>You may not want to name some or all of your application's tasks. If a NULL pointer is supplied for the <i class="textVariable">name</i> argument of <b class="routine"><i class="routine">taskSpawn</i></b><b>(&nbsp;)</b>, then VxWorks assigns a unique name. The name is of the form <b class="task">t</b><i class="textVariable">N</i>, where <i class="textVariable">N</i> is a decimal integer that increases by one for each unnamed task that is spawned.</p></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="92558"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE:  </font></b></a>In the shell, task names are resolved to their corresponding task IDs to simplify interaction with existing tasks; see the <i class="title">Tornado User's Guide: Shell</i>.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="84025"> </a>The <b class="library">taskLib</b> routines listed in <a href="c-basic3.html#83989">Table&nbsp;2-4</a> manage task IDs and names.<p class="table"><h4 class="EntityTitle"><a name="83989"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 2-4:&nbsp;&nbsp;Task Name and ID 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="83993"> </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="83995"> </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="84002"> </a><b class="routine"><i class="routine">taskName</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84004"> </a>Get the task name associated with a task ID.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84007"> </a><b class="routine"><i class="routine">taskNameToId</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84009"> </a>Look up the task ID associated with a task name.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84012"> </a><b class="routine"><i class="routine">taskIdSelf</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84014"> </a>Get the calling task's ID.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84017"> </a><b class="routine"><i class="routine">taskIdVerify</i></b><b>(&nbsp;)</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84020"> </a>Verify the existence of a specified task.&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="84028">Task Options</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84029"> </a>When a task is spawned, an option parameter is specified by performing a logical OR operation on the desired options, listed in the following table. Note that <b class="symbol_UC">VX_FP_TASK</b> must be specified if the task performs any floating-point operations.<p class="table"><h4 class="EntityTitle"><a name="84033"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 2-5:&nbsp;&nbsp;Task Options</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="84039"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Name</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84041"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Hex Value</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84043"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th></tr><tr>

⌨️ 快捷键说明

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