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

📄 real-time experiment #6 preemptive priority based task scheduling.htm

📁 该文档是学习在Vxworks上进行编程开发的入门教材。
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0077)http://www.rt.db.erau.edu/experiments/vx/priorityScheduling/Experiment-6.html -->
<HTML><HEAD><TITLE>Real-Time Experiment #6: Preemptive Priority Based Task Scheduling</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<BODY>
<CENTER>
<H1>Embry-Riddle Real-Time Laboratory Experiment<BR>Experiment #6<BR>Preemptive 
Priority Based Task Scheduling </H1></CENTER>
<HR SIZE=3>

<H2>Introduction</H2>Task scheduling is the assignment of starting and ending 
times to a set of tasks, subject to certain constraints. Constraints are 
typically either time constraints or resource constraints. On a time-sharing 
operating system, running each active process in turn for its share of time (its 
"timeslice"), thus creating the illusion that multiple processes are running 
simultaneously on a single processor. 
<P></P><EM>Wind</EM> task scheduling uses a priority based preemptive scheduling 
algorithm as default, but it can also accommodate round-robin scheduling.
<P></P>
<HR SIZE=3>

<H2>Objectives</H2>The following are the primary objectives of this experiment: 
<UL>
  <LI>To demonstrate the use of VxWorks preemptive priority based task 
  scheduling facilities. </LI></UL>
<P></P>
<HR SIZE=3>

<H2>Description</H2>
<UL>
  <LI><B>Preemptive Priority Based Scheduling</B>
  <P></P>With a preemptive priority based scheduler, each task has a priority 
  and the kernel insures that the CPU is allocated to the highest priority task 
  that is ready to run. This scheduling method is <EM>preemptive</EM> in that if 
  a task that has a higher priority than the current task becomes ready to run, 
  the kernel immediately saves the current tasks's context and switches to the 
  context of the higher priority task.
  <P></P>The <EM>Wind</EM> kernel has 256 priority levels(0-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 
  <EM>taskPrioritySet()</EM>. </LI></UL>
<P></P><B>1. Example: Preemptive Priority Based Scheduling</B>
<P></P>One of the arguments to <EM>taskSpawn()</EM> is the priority at which the 
task is to execute:
<P></P><EM>id</EM> = taskSpawn(<EM>name, <B>priority</B>, options, stacksize, 
function, arg1,.. , arg10);</EM>
<P></P>By varying the priority(0-255) of the task spawned, you can affect the 
priority of the task. <EM>Priority</EM> 0 is the highest and priority 255 is the 
lowest.The Note the priority of a task is relative to the priorities of other 
tasks. In other words, the task priority number itself has no particular 
significance by itself.
<P></P>In addition a task's priority can be changed after its spawned using the 
following routine: 
<UL>
  <LI><EM>taskPrioritySet(int tid, int newPriority)</EM>: Change the priority of 
  a task. </LI></UL>
<P></P>In the example below, there are three tasks with different 
priorities(HIGH,MID,LOW). The result of running the program is that the task 
with the highest priority, "taskThree" will run to completion first, followed by 
the next highest priority task, "taskTwo", and the finally the task with the 
lowest priority which is "taskOne."
<P></P><PRE>------------------------------------------------------------------------------------
/* includes */
#include "vxWorks.h"
#include "taskLib.h"
#include "logLib.h"

/* function prototypes */
void taskOne(void);
void taskTwo(void);
void taskThree(void);

/* globals */
#define ITER1 100
#define ITER2 1
#define LONG_TIME 1000000
#define HIGH 100 /* high priority */
#define MID 101 /* medium priority */
#define LOW 102 /* low priority */

void sched(void) /* function to create the two tasks */
{
int taskIdOne, taskIdTwo, taskIdThree;

printf("\n\n\n\n\n");
/* spawn the three tasks */
if((taskIdOne = taskSpawn("task2",LOW,0x100,20000,(FUNCPTR)taskOne,0,0,0,0,0,0,0,
	0,0,0)) == ERROR)
	printf("taskSpawn taskOne failed\n");
if((taskIdTwo = taskSpawn("task2",MID,0x100,20000,(FUNCPTR)taskTwo,0,0,0,0,0,0,0,
	0,0,0)) == ERROR)
	printf("taskSpawn taskTwo failed\n");
if((taskIdThree = taskSpawn("task3",HIGH,0x100,20000,(FUNCPTR)taskThree,0,0,0,0,0,0,0,
	0,0,0)) == ERROR)
	printf("taskSpawn taskThree failed\n");

}

void taskOne(void) 
{
int i,j;
for (i=0; i &lt; ITER1; i++)
	{
	for (j=0; j &lt; ITER2; j++)
		logMsg("\n",0,0,0,0,0,0);
		for (j=0; j &lt; LONG_TIME; j++);	
	}
}

void taskTwo(void) 
{
int i,j;
for (i=0; i &lt; ITER1; i++)
	{
	for (j=0; j &lt; ITER2; j++)
		logMsg("\n",0,0,0,0,0,0);
		for (j=0; j &lt; LONG_TIME; j++);
	}
}

void taskThree(void) 
{
int i,j;
for (i=0; i &lt; ITER1; i++)
	{ 
	for (j=0; j &lt; ITER2; j++)
		logMsg("\n",0,0,0,0,0,0);
		for (j=0; j &lt; LONG_TIME; j++);
	}
}
------------------------------------------------------------------------------------
</PRE>
<P></P>
<HR SIZE=3>

<H2>Procedures</H2>1. Copy the source code in the example and compile it. 
<P></P>2. Load the object file onto the target machine.
<P></P>3. Execute the following command on the WindSh terminal: "logFdSet 1". 
This will direct the <EM>logMsg()</EM> output to the virtual console.
<P></P>4. Run the examples by executing the main routine("sched") of the example 
on WindSh terminal. 
<P></P>Note: Make sure you have redirected I/O, otherwise you won't see the 
results of the <EM>logMsg()</EM> commands. 
<HR SIZE=3>

<H2>Follow On Experiment</H2>Experiment 1. Modify the program such that the 
order of execution is "taskOne" first, then "taskTwo", and then "taskThree."
<P></P>Experiment 2. Modify the program so that "taskOne" has the highest 
priority and "taskOne" and "taskTwo" are running at the same priority. Is there 
a difference in the output when compared with the output of Experiment 1 of the 
Follow On Experiment in this section.
<P></P>
<HR SIZE=3>

<H2>Additional Information</H2>Refer to VxWorks User's Manual and Reference 
Manual.
<P></P>
<HR SIZE=3>

<CENTER>
<H4><A 
href="http://www.rt.db.erau.edu/experiments/vx/toc/TableOfContents.html">Return 
to Primary Table of Contents </A></H4></CENTER>
<HR SIZE=3>

<CENTER>Last Updated: 21 March 1997<BR><EM>Created by: Dan Eyassu</EM><BR><A 
href="mailto:eyassud@db.erau.edu">eyassud@db.erau.edu</A><BR></CENTER></BODY></HTML>

⌨️ 快捷键说明

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