W5.1 Embedded Operating System
W5.1 Embedded Operating System
Agenda
• Context Switches
APPLICATIONS
OS USER INTERFACE
Extends the basic kernel more complex
functionalities, e.g. UI,
network stack, etc. FILE AND DISK SUPPORT
simple
featured commercial OS. OS KERNEL processor implements the most
basic of OS functionalities
HARDWARE
Microkernel vs Monolithic Kernel
The user services and kernel services Both user services and kernel services
are kept in separate address space. are kept in the same address space.
Difference Between Microkernel and Monolithic Kernel
startup
task task is
Tasks are moved from one state to
exits blocked another in response to the stimuli
TERMINATED BLOCKED
marked on the arrows.
task is deleted
Task State Diagram
ready queue
startup
RUNNING
task task is
exits blocked A task enters this state when it starts executing on
TERMINATED BLOCKED the processor. Only one task can be in this state in
the system at any one time.
task is deleted
block queue
A task will only be removed A task enters the blocked state when it executes a
when it is explicitly deleted. synchronization primitive to wait for an event,
e.g. a wait primitive on a semaphore or timer.
Task State Diagram Any tasks that are ready to run sit on the ready
queue. The queue may be prioritized so the most
ready queue important task runs next.
task task is
exits blocked If the “running” task needs I/O or needs a
TERMINATED BLOCKED
resource that is currently unavailable, it is
task is deleted inserted in a “blocked” queue when its waiting on
block queue a semaphore. When its resource becomes
available, it goes back to “ready” and inserted
into the “ready queue”.
Tasks vs Functions
TASK post
• A function is a set of program instruction,
signal
then exits and may return a value, e.g.
“process data”
• A task is a process that repeats itself
• Essential software building block in a real
time systems “block”
signal
• Loop forever while waiting for a signal received
• When a task is “blocked”, lower priority
tasks can run
• Another task can “post” a signal, to FUNCTION
“unblock” this task that would execute it
“process data” function process data
• Loops back and “block” again
“loop”
Tasks advantages and characteristics
• The operating system maintains for each task a data structure that contains its current
status such as program counter, priority, state, scheduling information, task name.
• Typically, these TCBs are managed using linked lists (as shown below)
• Other implementation are double-link-list, array, etc.
What is Multitasking?
Context Switch
Context Switch
Task T0 Task T1
TCB
TCB
TCB
TCB
How do many tasks share the same processor?
TASK
TASK 11 TASK 21 TASK 31 TASK 12 TASK 31 TASK 13 TASK 22 TASK 32
21
time
1 time slice
Round Robin Systems - Time Slicing of 3 Tasks
which task, N
• Higher priority task can pre-empt a lower priority task if it interrupts the lower-priority task
• Priorities assigned to each interrupt are typically based upon the urgency of the task
associated with the interrupt
• Priorities can be fixed or dynamic
TASK 1
TASK 2
High
TASK 3
TASK 31
priority
TASK
TASK 21
21
TASK TASK
Low
11 11
time
time
Round Robin Systems – Pre-emptive Scheduling of 3 Tasks
Other Priority Driven Scheduling Algorithm
• Fixed-Priority
• Rate Monotonic Scheduling (RMS)
• static priorities are assigned according to the cycle duration of the job
• a shorter cycle duration results in a higher job priority.
• Deadline Monotonic Scheduling (DMS)
• Dynamic-Priority
• Earliest Deadline First (EDF)
• place processes in a priority queue
• when a task finishes or a new task is started, this queue will be searched for the task closest to its
deadline
• this chosen task is next to be scheduled for execution
• Least Slack Time (LST)
• assigns priority based on the slack time of a task
• slack time is defined as the temporal difference between the deadline, the ready time and the run
time.
Summary