|
Traditional
Task v/s Supertask
Traditional
Task
·
Consists of several Subtasks
·
Has unique Entry Point via Mailbox
·
Priority is same for all Subtasks
·
Has a dedicated Stack

Supertask
·
Consists of several Subtasks
·
Each Subtask is a Priority Function
·
Each Subtask has its own Entry Point
·
No Mailbox
·
Subtasks can have different Priority Levels
·
Has a dedicated Stack

More
Efficient Context Switch
·
Traditional Tasks: Full Context Switch only
·
Supertasks: 5 types of Context Switches

Priority
Functions
·
Any Function that has been assigned a Priority Level
·
Preempts Lower Priority Functions
·
Is preempted by Higher Priority Functions
·
Can execute outside Supertasks (more lightweight and
more flexible than a Software Interrupt)
Traditional
Tasks v/s Priority Functions
Click here for a serial
port DMA implementation comparison between Traditional Tasks and PORTOS
Below
is a modem implemented with traditional tasks (left side) and with
priority functions (right side). Layer L2 transmits data to Layer L1 and
starts a timer. A timeout occurs, which calls the retransmission code. In
the traditional tasks implementation, each layer is usually a task (with
different priority level). In the priority functions implementation,
layers L2, L3 and the Timer utility layer execute outside any Tasks or
Supertasks (note: alternatively, they could execute inside one shared
Supertask).

Priority
Objects
·
Any Object (Structure) that has been assigned a
Priority Level
·
Priority Level is inherited by functions or methods
·
Allows very flexible prioritization (every Object can
have a different priority level)
Example
of Inter-Task Calls and Context Switches
F0
calls F1. F1 returns but in the meantime F2 and F3 were scheduled. First
F2 is called. It suspends without returning. F3 takes over. When F3
returns, F0 proceeds.

Some
Advantages of Supertasks
·
Lighter, more Powerful and more Efficient than
traditional Tasks
·
No need to create messages. As simple as calling a
normal function
·
No need for Event Flags because a Supertask has
Multi-Entry Points
·
Priority Inversion is mitigated by assigning higher Priority
Levels to critical “Subtasks”
·
More efficient Context Switch could result in less
Interrupt Response Jitter
·
Creating a Real Time product from Simulation Software
is far quicker with Supertasks: No Mailbox, No Messages, No Message
Dispatchers, No Events, No Task Entry Point
·
During debugging time, temporary Supertasks can be
defined to achieve memory protection between various libraries. Once the
product has been debugged, the Supertasks can be turned off to improve
performance and decrease stack space usage (the product can mainly run on
Priority Functions)
Some
Advantages of Priority Functions
·
The most efficient and clean way to design a Real
Time product
·
Stack space is not wasted. Priority Functions
share the same Stack
·
Zero Context Switching
·
No need to create messages. As simple as calling a
normal function. Hence:
o
No Inter-Task messages
o
No Intra-Task messages
o
No message packing and unpacking
o
No message dispatching
·
Programming with Priority Functions preserves the
modularity of the software:
o
Priority functions are inherently independent from
each other. When writing a function or a software module, the programmer
can forget about the rest of the system. The focus is on the function
itself. Once ready, the function can be called from anywhere. The software
module can be reused, unchanged, in a future project.
o
Traditional Tasks are not so independent since
they are heavy and they tend to execute several subtasks. Various
functions from one software module can end up on different tasks (e.g.,
low priority and high priority tasks). The software module and the
programmer have to be aware of the overall system architecture when
writing each function. The module written for project A may have to be
rewritten for project B (since the tasks of projects A and B are not the
same). Messages exchanged between the functions of one module have to be
correctly routed via dispatchers embedded in each task. The dispatchers
have to be updated each time a function is moved from one task to
another.
·
Easy to integrate in a programming language
compiler, interpreter or preprocessor
·
Can be quickly assembled inside Supertasks when
memory protection or time-slicing is desirable
·
Priority Functions “Scheduler” is highly portable
across platforms: it does not need any information on registers or stacks
More examples using
traditional tasks and priority functions
Passing
Arguments to a Function Running in a Different Supertask
·
Traditional Tasks have only one option to pass
arguments to a function running in a different task: via Memory Heap.
Task A allocates memory in Heap, creates message, stores arguments, sends
message to task B. Task B dispatches message to recipient function.
Recipient function unpacks arguments from message and de-allocates it.
·
Supertasks have a faster option directly via Stack
and Registers1:
o
Arguments on Stack are copied from Stack A to Stack B
(or directly written to Stack B with compiler’s help)
o
Arguments in Registers are automatically available to
supertask B
1 Option not always
available, depending on when the function will be called.

|