From: brad@huey.Jpl.Nasa.GOV (Brad Hines)
Subject: another controller technique
Keywords: vxworks controller
Reply-To: brad@huey.Jpl.Nasa.GOV
Organization: JPL Spatial Interferometry Group
Date: Tue, 8 Sep 1992 22:43:22 GMT

I initially mailed this to Terry concerning a technique we use for
implementing controllers, and he suggested that it might be worth
posting.

===========


From brad Tue Sep  8 14:34:06 1992
To: doctor@kronos.arc.nasa.gov
Subject: periodic task execution


I just saw your summary of responses to how to periodically schedule
tasks, and I thought you might be interested in my 2 cents about how we
do it in our lab.

We use a technique related to the semGive scheme.  We use an external
clock (from an IRIG time code reader card to get microsecond timing
resolution) hooked to an ISR.  Rather than calling semGive to resume
the desired controller task, which then has to go through system tables
to find out who's waiting on the semaphore and then make a taskResume
call, we just call the taskResume ourselves (after all, you get the
task id for the task when you first spawn it).  Basically, the thinking
is why go through the extra layer of abstraction of the semaphore when
all you really want to do is resume a specific task (semaphores are
more appropriate when there may be more than one task waiting on a
given resource).  At the end (or beginning) of each task iteration,
there is a taskSuspend(0) call (so the taskResume/taskSuspend pair
replaces the semGive/semTake pair), which is also faster than the
semTake.  Finally, the taskResume is naturally deterministic; the
semGive probably isn't since the OS has to deal with the bookkeeping
involved when multiple tasks wait for the same semaphore.  (As an
aside, my personal opinion is that WRS recommends semaphores for this
kind of thing because WRS is proud of their semaphores, and heck, it
just sounds more like real computer science.)

If there are several periodic tasks to run, you have a couple of
options.  For example, I have written a deterministic high-speed
periodic task scheduling library for use in a project here which
supplies the ISR and routines to add and delete tasks from the queue of
tasks to run periodically, as well as lots of ways of manipulating the
task queues.  In addition, it allows for one task which runs at
interrupt level.

We ended up using this in one part of the project, but in another part
that needs very high speed, we instead chained the various controller
tasks together, combining the do-it-in-the-ISR and the taskResume
techniques.  In our system, the ISR runs at 5-10 kHz depending on base
CPU speed, and there are three standard VxWorks tasks that run at lower
speeds (800 Hz, 200 Hz, and 2 Hz).  The tasks are chained together -
i.e, if the ISR runs at 8 kHz, it calls taskResume to resume the 800 Hz
task on every 10th iteration.  The 800 Hz task calls taskResume to
resume the 200 Hz task on every 4th iteration, and the 200 Hz task
calls taskResume to resume the 2 Hz task every 100th time through.
It's not as elegant as some of the other techniques, but it is the
fastest of all the techniques mentioned for this kind of system, and
it's also the simplest and most direct.

Hope this is helpful or at least interesting.

-Brad



-- 
Brad Hines
Internet: brad@huey.jpl.nasa.gov
Jet Propulsion Lab, Pasadena, California