Bonus Assignment, COSC 4351
Due:
Midnight 5-3-2004
Task scheduling in real-time systems is to determine an execution order such that all task can meet the corresponding deadlines. To do this, we often need an estimate of the worst-case execution time (WCET) and then reserve CPU time accordingly. An overrun occurs if the real execution time exceeds the estimate WCET. When it is undetected, subsequent tasks may miss their deadline as a consequence of overspending CPU time. One solution to the task overrun problem is to lower the priority of the overrunning task once it consumes the reserved CPU time and only execute it in the background mode. This requires a measurement of task execution time at run time.
In real-time systems, a task may be preempted (by high priority tasks) or blocked (due to unavailable resources locked by low priority tasks). The measurement of execution time at user application level is difficult, since we cannot predict the instances of preemption and blocking. On the other hand, it can be done easily at kernel level. As shown in the following diagram, a task is created, dispatched to run, switched off to waiting or ready state, and deleted (terminated). The measurement of execution time can be done once we mark the instances it is dispatched and accumulate the time it has spent when it is switched off or terminated.
vxWorks allows user tasks to add callback functions (hooks) to kernel at the instances of task creation, task deletion, and context switching. When a hook is called, the pointer to the task’s TCB is passed as a parameter. Thus, we can access TCB and use the spare space in TCB to record additional task information.
You need to develop a task to run in vxWorks environment at the target Intel ARM - Xcale processor. The task will
1. add vxWorks hooks for task execution time measurement.
2. report the accumulated execution times of terminated tasks (the execution times should be printed out on console, and a host task should be developed to inquire the task execution time measured at the target.)
Also, you need to develop a test case which contains multiple concurrent tasks to test you measurement and reporting facility. Note that you can design your own format of reporting and how it is done. Please make reasonable assumptions and don’t use any excessive buffers.
The
vxWorks' libraries are more than the followings for the given purpose and of
course you're not restricted to use just those. They are listed to give you a
basic idea for the project.
· Generating tasks: taskSpawn() with task's name, a priority etc as arguments can be used to create new task.
· Delaying tasks: taskDelay() or nanosleep() may be used to put a task into the delayed state.
· Checking an execution time: You may need to handle a timer or times to measure the execution time. However, a simple way would be using tickSet() and tickGet() to check a relative time elapse.
· Tracking an execution time of a task: There might be diverse ideas regarding how to keep track of the execution time for a task which is preempted in multiple times. One could be to use VxWorks' task hooks which allow additional routines to be invoked whenever a task is created, switched and deleted. Those libraries are taskCreateHookAdd(), taskCreateHookDelete(), taskSwitchHookAdd(), taskSwitchHookDelete(), taskDeleteHookAdd(), taskDeleteHookDelete() etc. that are included in taskHookLib. You must be careful to use hook routines since there is a limit of facilities that can be called in Hook routines.
· TCB(Task Control Block) which keeps a context of a task has spare fields for these extensions. TCB's data structure is defined in taskLib.h.
Your
report should contain:
Turn in a hardcopy of your listing and any description. Also, you need to email a zipped file to lgoel@cs.uh.edu. The zipped file should contain all files and subdirectories in your project directory. This assignment is adapted from the ASU CSE 494/598 curriculum.