Single core Demo #2 & #3 Description

See starvation protection, mutex priority inheritance, round-robin, safe task suspension in action!

Demonstration #3 consists of a six task system: a high priority task ("High"), three mid-priority tasks in a round-robin configuration ("RR-x"), and two lower priority tasks to demonstrate the starvation protection mechanism ("ST-x"). The High task runs for 10.0s every 30.0s.

Download Video:  [Stellaris] MP4 Ogg [Olimex MSP430-5438STK] MP4 Ogg

If a task owns the Mutex when it is time to Suspend, the Deadlock prevention mechanism will defer the suspension until the mutex is released. Also, if a task owns the Mutex and no other ready-to-run task wants it, then it holds the mutex indefinitely. Otherwise, the demo state machine informs the task to release the mutex after 5.0s.

     Abassi Demo

High  00.0s  P2  R M
RR-A  00.0s  P4   A
RR-B  00.0s  P4    b
RR-C  00.0s  P4
ST-A  00.0s  P7
ST-B  00.0s  P9

      00:00:00

In addition to the task names, there are three additional columns that give information about the individual tasks. One displays the duration the task was in the running state. The next displays the task priority ("Px"), or if the task is Pending Suspension ("PS"; because it currently holds the lock on a Mutex), or is Suspended ("S"). The final column provides internal state information, as follows:

R   Running Task
A   Task currently under Starvation Protection ("Priority Aging")
M   Task that has acquired the Mutex
m   Task that will acquire the Mutex next
B   Task that is blocked on the Mutex
b   Task that will block on the Mutex next
I   Task that has had its priority changed due to Priority Inheritance

The demonstration has been configurated with a Timer Tick of 10,000μs (10.0ms), and each task has its own programmable Round-Robin timeslice, to slow down the system enough to give the user an opportunity to view the state changes.

The tasks in the round-robin queue have been allocated different numbers of ticks, to illustrate the asymetric round-robin capability; Task RR-A has been given 400 ticks, RR-B 600 ticks, and RR-C 800 ticks.

Starvation Protection has been configured for a default Run time of 200 timer ticks (2.0s), Wait time of 500 timer ticks (5.0s), and Priority of 3. Tasks ST-A and ST-B override these defaults and use Run and Wait times of 5.0s and 2.5s, and 5.0s and 1.0s, respectively.

The following are numerous snapshots of the beginning of the demonstration execution, accompanied by explanations of the feature being illustrated. The demonstration highlights asymetric Round-Robin, Starvation Protection ("Priority Aging"), and Priority Inheritance.

     Abassi Demo

High  05.0s  P2  R M
RR-A  00.0s  P3   A
RR-B  00.0s  P4    b
RR-C  00.0s  P4
ST-A  00.0s  P7
ST-B  00.0s  P9

      00:00:05
     Abassi Demo

High  10.0s  PS  R M
RR-A  00.0s  P3   A
RR-B  00.0s  P4    b
RR-C  00.0s  P4
ST-A  00.0s  P7
ST-B  00.0s  P9

      00:00:10
     Abassi Demo

High  15.0s  S
RR-A  00.0s  P3  RA
RR-B  00.0s  P4    b
RR-C  00.0s  P4
ST-A  00.0s  P7
ST-B  00.0s  P9

      00:00:15

Step 1. After the initial Wait time (5.0s), the task under Starvation Protection (RR-A) has its priority increased by one step from P4 to P3.

Step 2. At time 10.0s High attempts to Suspend, but since it still owns the Mutex, the Deadlock prevention mechanism defers the suspension. Also, since RR-A has already reached the Starvation Priority (P3), its priority does not increase.

Step 3. Finally, after High releases the Mutex, it enters the Suspended state and RR-A enters the Running state.

     Abassi Demo

High  15.0s  S
RR-A  02.0s  P4
RR-B  00.0s  P4  RAM
RR-C  00.0s  P4
ST-A  00.0s  P7
ST-B  00.0s  P9

      00:00:17
     Abassi Demo

High  15.0s  S
RR-A  02.0s  P4
RR-B  02.0s  P4    M
RR-C  00.0s  P4  RA
ST-A  00.0s  P7
ST-B  00.0s  P9

      00:00:19
     Abassi Demo

High  15.0s  S
RR-A  02.0s  P4  R
RR-B  02.0s  P4    M
RR-C  02.0s  P4
ST-A  00.0s  P7   A
ST-B  00.0s  P9

      00:00:21

Step 4. RR-A has run for the Starvation Run duration (2.0s) and returned to its original priority (P4). RR-B is now under Starvation Protection, and since it is also next in the round-robin queue and the highest priority ready-to-run task, it enters the Running state. RR-B was also wanting to acquire the mutex, and now that it is running, it does.

Step 5. RR-C is now under Starvation Protection, and since it is also next in the round-robin queue and the highest priority ready-to-run task, it enters the Running state. RR-B still has the mutex and will hold it until it begins running again and has held the mutex for a total of 5.0s.

Step 6. All RR-x tasks have progressed through the Starvation Protection, and ST-A is now under Starvation Protection. Since the RR-x tasks are still the highest priority ready-to-run tasks, they will be serviced according to their round-robin configuration. RR-A receives a 4.0s timeslice, RR-B a 6.0s timeslice, and RR-C a 8.0s timeslice. ST-A will have its priority increased by 1 every 2.5s, according to its custom Starvation Protection configuration.

     Abassi Demo

High  00.0s  P2  R
RR-A  04.0s  P4
RR-B  05.5s  P4
RR-C  02.0s  P4    m
ST-A  00.0s  P4   A
ST-B  00.0s  P9

      00:00:30
     Abassi Demo

High  10.0s  S
RR-A  04.0s  P4
RR-B  05.5s  P4
RR-C  02.0s  P4    m
ST-A  00.0s  P3  RA
ST-B  00.0s  P9

      00:00:40
     Abassi Demo

High  10.0s  S
RR-A  04.0s  P4
RR-B  05.5s  P4  R
RR-C  02.0s  P4    m
ST-A  05.0s  P7
ST-B  00.0s  P9   A

      00:00:45

Step 7. RR-A has run for its 4.0s timeslice, and RR-B was 5.5s through its 6.0s timeslice when High awoke and became the Running task because of its higher priority. ST-A has now reached priority P4 due to Starvation Protection.

Step 8. High runs for 10.0s before Suspending, and during that time ST-A has had its priority increased to P3. Once High suspends, ST-A enters the Running state and remains there until it has completed its configured 5.0s Run time.

Step 9. ST-A returns to its original priority (P7) and ST-B is now under Starvation Protection. RR-B resumes execution for 0.5s, until it completes its configured 6.0s round-robin timeslice.

     Abassi Demo

High  10.0s  S     b
RR-A  04.0s  P4
RR-B  06.0s  P4
RR-C  00.5s  P4  R M
ST-A  05.0s  P7
ST-B  00.0s  P9   A

      00:00:46
     Abassi Demo

High  10.0s  S     b
RR-A  04.0s  P4
RR-B  06.0s  P4
RR-C  05.7s  P4    M
ST-A  05.0s  P7
ST-B  00.0s  P3  RA

      00:00:51
     Abassi Demo

High  10.0s  S     b
RR-A  04.0s  P4   A
RR-B  06.0s  P4
RR-C  05.8s  P4  R M
ST-A  05.0s  P7
ST-B  05.0s  P9

      00:00:55

Step 10. RR-C is now the Running task, and will execute until ST-B attains a higher priority due to under Starvation Protection. RR-B resumes execution for 0.5s, until it completes its configured 6.0s round-robin timeslice.

Step 11. ST-B has reached priority P3 and is now the highest priority ready-to-run task in the system, so it becomes the Running task.

Step 12. ST-B will run for its configured Run time (5.0s), after which it returns to its original priority, and RR-C again becomes the Running task. All tasks in the Starvation Protection queue have progressed through the protection stage, so the cycle starts again at task RR-A.

     Abassi Demo

High  10.0s  S     b
RR-A  00.1s  P4  RA
RR-B  06.0s  P4
RR-C  08.0s  P4    M
ST-A  05.0s  P7
ST-B  05.0s  P9

      00:00:58
     Abassi Demo

High  00.0s  P2    B
RR-A  02.0s  P4
RR-B  06.0s  P4   A
RR-C  00.5s  P2  R MI
ST-A  05.0s  P7
ST-B  05.0s  P9

      00:01:00
     Abassi Demo

High  00.1s  P2  R M
RR-A  02.0s  P4
RR-B  06.0s  P3   A
RR-C  05.5s  P4
ST-A  05.0s  P7
ST-B  05.0s  P9

      00:01:05

Step 13. RR-C has completed its configured round-robin timeslice and RR-A, again under Starvation Protection and next in the round-robin queue, becomes the Running task.

Step 14. High exits the Suspended state and is the highest priority (P2) ready-to-run task. It enters the Running state and attempts to acquire the Mutex, but becomes Blocked. RR-B already has the Mutex, so the Priority Inheritance mechanism causes RR-B to have its priority increased to that of High.

Step 15. RR-B remains in the Running state until it releases the Mutex. It then returns to its original priority (P4) and High returns to the Running state.

The demonstration code continues indefintely.

If you wish to modify the demonstration parameters, this can be done in real-time using the command line interface over the (virtual) serial port. Your port settings should be 115,200 baud 8-N-1.

Abassi Demo Console

The display the task list and configuration, issue the ? command.

The task list and configuration shows:

name --> RR xxx | SP x | SR xxx | SW xxx | P x

where:

name Task name
RR   Round-robin timeslice
SP   Starvation Priority
SR   Starvation Run time
SW   Starvation Wait time
P    Task Priority

The parameters can be changed by issuing a command of the form:

name param value

For example, to change the priority of the task named HI to 3:

hi p 3

Abassi Demo Console