processing order: cooperative vs. preemptive process b2 process a process c process b1 process d...

8
Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cycl Process C (high priority, cyc Process B (low priority) Process D (high priority) OS Preemptive Multitasking Cooperative 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 Copyright © 2011 DSR Corporation Corporation 1

Upload: lily-keene

Post on 26-Mar-2015

262 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cyclic) Process C (high priority,

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

Page 2: Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cyclic) Process C (high priority,

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

Page 3: Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cyclic) Process C (high priority,

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

Page 4: Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cyclic) Process C (high priority,

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

Page 5: Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cyclic) Process C (high priority,

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?
Page 6: Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cyclic) Process C (high priority,

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?
Page 7: Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cyclic) Process C (high priority,

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

Page 8: Processing Order: Cooperative vs. Preemptive Process B2 Process A Process C Process B1 Process D Process A (low priority, cyclic) Process C (high priority,

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