Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D...

Post on 26-Mar-2015

255 views 3 download

Tags:

Transcript of Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D...

Processing Order: Cooperative vs. Preemptive

Process B2Process B2

Process AProcess A

Process CProcess C

Process B1Process B1

Process DProcess D

Process A (low priority, cyclic)Process A (low priority, cyclic)

Process C (high priority, cyclic)Process C (high priority, cyclic)

Process B (low priority)Process B (low priority)

Process D (high priority)Process D (high priority)

OS

Preemptive MultitaskingCooperative Multitasking

Processes (tasks) are run in an infinite loop

If task takes too much time (B), need to divide it

No overhead occurs

Scheduling is performed by the OS Long task is suspended if needed Overhead: caused by OS internals

Copyright © 2011 DSR CorporationCopyright © 2011 DSR Corporation 11

Task States (ITRON Case)

Ready: could run but the CPU is busy

Executing: running on the CPU

Blocked: waits for something (I/O, signal, resource, etc.)

Dormant (hibernation): created task that is not started

NON-EXISTENT: deleted or not created task

The RTOS implements a Finite State Machine for each task and manages its transitions.

Copyright © 2011 DSR CorporationCopyright © 2011 DSR Corporation 22

Task State Transitions

Ready Executing

Dormant state

Task scheduled

Preemption

Wait state

Wait for the event

Task can be executed at any time

unlock waiting

resuming

waiting

suspend

Execution is suspended

Only one task running

Copyright © 2011 DSR CorporationCopyright © 2011 DSR Corporation 33

Preemption

1 2 3 A

Ready to run Executing

A 1 3 2

12

3 ATime

High Priority

ready-to-run state Executing

dormant state

dispatch

pre-emption

waiting state

A1 2 3

waiting

unlock waiting

suspend

resuming

Task is in the ready state Task is scheduled to run – running state

Priority of some task is changed to high

Copyright © 2011 DSR CorporationCopyright © 2011 DSR Corporation 44

Close

Example: the task runs until finishing the function

Execution of tasks to complete

TASK(…) { ………… ………… …………} Hibernation

Ready to run Executing

2 3

ready-to-run state Executing

dormant state

dispatch

pre-emption

waiting state

A1 2 3

waiting

unlock waiting

suspend

resuming

Copyright © 2011 DSR CorporationCopyright © 2011 DSR Corporation 55

step
Can't understand this slide. Does task A finish its execution? Or does only one function in task finish?

Starting

Start task executing from the beginning.

Task was executing, then it was suspended

TASK(…) { ………… ………… …………}

Hibernation

Ready to run Executing

2 3

A1

ready-to-run state Executing

dormant state

Dispatch

pre-emption

waiting state

A1 2 3

waiting

unlock waiting

suspend

resuming

Copyright © 2011 DSR CorporationCopyright © 2011 DSR Corporation 66

step
Does task A start from very beginning? why? If it was suspended, maybe it should start from the point when it was suspended?

Wait

Example: Wait for an event for 40 msec.

Running task is waiting for an event. When AN event rises, task gets ready for execution.

TASK(…) { ………… 40msec Wait …………}

Wait state

Ready to run Executing

2 3

ready-to-run state Executing

dormant state

Dispatch

pre-emption

waiting state

A1 2 3

waiting

unlock waiting

suspend

resuming

Copyright © 2011 DSR CorporationCopyright © 2011 DSR Corporation 77

Wait Release

Start execution of the task from the last point.

Waiting task becomes ready to run.

TASK(…) { ………… 40msec Wait …………}

Wait state

Ready to run Executing

2 3

A1

ready-to-run state Executing

dormant state

Dispatch

pre-emption

waiting state

A1 2 3

waiting

unlock waiting

suspend

resuming

Copyright © 2011 DSR CorporationCopyright © 2011 DSR Corporation 88