📄 traps8.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Quadralay WebWorks Publisher Professional Edition 6.0.5">
<meta name="TEMPLATEBASE" content="book_html">
<meta name="LASTUPDATED" content="08/22/03 10:13:21">
<title>8.7 Scheduler traps</title>
<STYLE TYPE="text/css">
<!--
span.Signal { text-transform: uppercase; font-family: Verdana }
-->
</STYLE>
</head>
<body link="#3366CC" vlink="#9999CC" text="#000000" alink="#0000CC" bgcolor="#FFFFFF"
background="images/backgrnd.gif">
<p><img src="images/stlogo.gif" width="106" height="83" align="left"
alt="logo here!"> </p>
<table width="331" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td><a href="c2isetto.htm"><img src="images/navtoc.gif" width="84" height="23"
border="0" alt="TOC"> </a></td>
<td><a href="traps7.htm"><img src="images/navprev.gif" width="80" height="23"
border="0" alt="PREV"> </a></td>
<td><a href="interrup.htm"><img src="images/navnext.gif" width="83" height="23"
border="0" alt="NEXT"> </a></td>
<td><a href="c2isetix.htm"><img src="images/navidx.gif" width="84" height="23"
border="0" alt="INDEX"> </a></td>
</tr>
</table>
<p><br clear="all">
</p>
<hr align="left">
<blockquote>
<h2>
<a name="1204717"> </a><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">8.7 Scheduler traps</font>
</h2><hr>
<p>
<a name="1204718"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Scheduler traps are different from the other traps, because rather than trapping `exceptional' behavior in a process, they intercept and replace activities in the ST20-C2 micro-scheduler. Scheduler traps are designed to support software scheduling systems where a collection of software priorities are multiplexed onto a single ST20-C2 priority. In this situation, all attempts to schedule a process must be intercepted to ensure that the process is scheduled at the right software priority (which in turn may require a software priority pre-emption). Similarly the kernel must trap the event where the hardware scheduler finds no further processes at the current (software) priority and, in the handler, find a new software priority with processes waiting to run.</font>
</p>
<p>
<a name="1204719"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Scheduler traps trap the ST20-C2 microscheduler rather than the current process, therefore the only value of interest in the trapped process structure is the trap bit that has been set which indicates the source of the trap. All other states refers to the process which has been pre-empted by the handler.</font>
</p>
<p>
<a name="1204720"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">It is essential that a scheduler trap handler saves and restores <span class=Signal>Areg</span>, <span class=Signal>Breg</span> and <span class=Signal>Creg</span> as these are the current values for the process that has been pre-empted.</font>
</p>
<p>
<a name="1204721"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">There are three subclasses of scheduler traps which all share the same handler.</font>
</p>
<ol type="1">
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li value="1"><a name="1204722"> </a>Process schedule traps. The placing of a process onto a scheduler queue is trapped.</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li value="2"><a name="1204723"> </a>Process interrupt. The transfer from low to high priority by priority pre-emption (that is, by a high priority process become ready while executing at low priority) is trapped;</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li value="3"><a name="1204724"> </a>Queue empty or idle trap. The processor attempted to find more work by taking a process off the queue but found it was empty, that is, the priority has become idle.</font></p>
</ol>
<h3>
<a name="1204725"> </a><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">Process schedule traps</font>
</h3>
<p>
<a name="1204726"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Processes can be added to the scheduler queue by:</font>
</p>
<ul>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li ><a name="1204727"> </a>the current process scheduling a new process or synchronizing with a waiting process,</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li ><a name="1204728"> </a>a timer alarm becoming ready causing the associated process to be scheduled,</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li ><a name="1204729"> </a>a subsystem requesting that a process be rescheduled due to completion of an activity such as data transfer.</font></p>
</ul>
<p>
<a name="1204730"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">The first of these cases is caused by an instruction from the current process, however the second two are from the micro-kernel built into the ST20-C2`s microcode. In all cases the actions are as follows.</font>
</p>
<ol type="1">
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li value="1"><a name="1204731"> </a>The <span class=Signal>TrapEnablesReg</span> at the priority of the process to be scheduled are examined to see if the relevant scheduler trap has been enabled.</font></p>
<dl>
<dt> <a name="1204732"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">If the trap is not enabled then the process is simply placed on the queue and execution continues as normal.</font>
</dl>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li value="2"><a name="1204733"> </a>If the trap is enabled then CPU priority is switched to the priority of the process to be scheduled. The relevant trap bit is then set in <span class=Signal>Status</span> along with a record of the priority the machine was at when the trap condition occurred. The process descriptor of the process to be scheduled is written to location <span class=Signal>Wptr</span>+0 of the trap handler workspace.</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li value="3"><a name="1204734"> </a>The processor then runs the scheduler trap handler.</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li value="4"><a name="1204735"> </a>Inside the handler the process to be scheduled is obtained from the workspace.</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li value="5"><a name="1204736"> </a>On exit, the handler executes a <strong>tret</strong> instruction which, since it is exiting from a scheduler trapgroup handler, switches the CPU priority to the one recorded in <span class=Signal>Status</span> to return to the state before the trap condition.</font></p>
</ol>
<p>
<a name="1205593"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif"><em>Note: The scheduler trap always runs at its own priority regardless of the priority of the machine when the trap condition occurred. This can lead to a handler running at low priority when there is an active process still at high priority, however the restrictions suggested in <a href="traps8.htm#1204748"><font color="#0000ff" face="Verdana, Arial, Helvetica, sans-serif"><i>Restrictions on scheduler traps</i></font></a> ensure that priority pre-emption does not take place.</em></font>
</p>
<h3>
<a name="1205597"> </a><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">ProcessInterrupt traps</font>
</h3>
<p>
<a name="1204739"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">A <em>ProcessInterrupt</em> trap condition occurs when the machine is switched from low to high priority by pre-emption, that is, when the machine was at low priority and a high priority process becomes ready.</font>
</p>
<p>
<a name="1204740"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">In this case, if the trap is enabled then it is taken after the machine has switched to high priority but before the process that has become ready has been dequeued. That is, the trap is being taken over an idle high priority machine.</font>
</p>
<p>
<a name="1204741"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">On exit, the handler returns to this idle high priority machine and then the microcoded kernel takes the process of the queue and runs it.</font>
</p>
<p>
<a name="1204742"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">This trap has no meaning at low priority.</font>
</p>
<h3>
<a name="1204743"> </a><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">QueueEmpty traps</font>
</h3>
<p>
<a name="1204744"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Whenever a process stops or deschedules, the <em>QueueEmpty</em> trap condition occurs if the scheduler queue of that priority is empty, that is, it occurs when the machine has become idle at that priority.</font>
</p>
<p>
<a name="1204745"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">If the trap is enabled then the handler is run at the current machine priority.</font>
</p>
<p>
<a name="1204746"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif"><em>Note: If a trap handler exits via <strong>tret</strong> to an idle priority (no valid process and empty queues) then a <em>QueueEmpty</em> trap is not triggered. This avoids the danger of the <em>QueueEmpty</em> trap livelocking the machine by restarting itself every time it exits. However, this does mean that if trap handlers can change the trapped machine state to cause it to become idle, then the handler must `handle' this case itself rather than relying on the <em>QueueEmpty</em> trap to be triggered.</em></font>
</p>
<p>
<a name="1204747"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">By definition, a <em>QueueEmpty</em> trap traps any running process which needs to be stored in the trapped process structure (as by definition there is no running process when it is triggered), it also still saves the relevant register values into this structure. In particular, the saved value of <span class=Signal>Wptr</span> is the value of <span class=Signal>Wptr</span> of the last process to stop causing the <em>QueueEmpty</em> condition to occur.</font>
</p>
<h3>
<a name="1204748"> </a><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">Restrictions on scheduler traps</font>
</h3>
<p>
<a name="1204749"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Various additional restrictions are placed on what scheduler traps may perform.</font>
</p>
<ul>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li ><a name="1204750"> </a>In general, scheduler traps are only used at low priority to implement a software scheduling regime. </font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li ><a name="1204751"> </a>Scheduler trap handlers should be seen as replacing `atomic' events in the microcoded kernel, hence they should run `atomically' (that is, no other process/event should interrupt them). This can be achieved through the <span class=Signal>Enables</span> mask in the handler state which can be preset to cause all traps, external events, timer alarms and priority pre-emption to be disabled for the duration of the handler.</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li ><a name="1204752"> </a>The <em>QueueEmpty</em> trap must be disabled if a <em>QueueEmpty</em> trap is handled and the handler leaves the priority in a still idle state, if not then the system livelocks.</font></p>
</ul>
<p>
<a name="1204353"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif"></font>
</p>
</blockquote>
<hr>
<table width="331" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td><a href="c2isetto.htm"><img src="images/navtoc.gif" width="84" height="23"
border="0" alt="TOC"> </a></td>
<td><a href="traps7.htm"><img src="images/navprev.gif" width="80" height="23"
border="0" alt="PREV"> </a></td>
<td><a href="interrup.htm"><img src="images/navnext.gif" width="83" height="23"
border="0" alt="NEXT"> </a></td>
<td><a href="c2isetix.htm"><img src="images/navidx.gif" width="84" height="23"
border="0" alt="INDEX"> </a></td>
</tr>
</table>
<font size=1 face="Verdana, Arial, Helvetica, sans-serif"> © 1997, 2001, 2002, 2003 STMicroelectronics. All Rights Reserved.<br>
ADCS 7301761C</font>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -