0% found this document useful (0 votes)
7 views

W5.1 Embedded Operating System

The document provides an overview of Embedded Operating Systems, focusing on Real-Time Operating Systems (RTOS) and their internal workings, including task states and task control blocks. It explains how an OS manages multiple tasks through context switches and discusses scheduling methods such as Round Robin and Pre-emptive Priority. The need for embedded OS is highlighted, emphasizing their efficiency, configurability, and predictability in resource management.

Uploaded by

Andrew Koh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

W5.1 Embedded Operating System

The document provides an overview of Embedded Operating Systems, focusing on Real-Time Operating Systems (RTOS) and their internal workings, including task states and task control blocks. It explains how an OS manages multiple tasks through context switches and discusses scheduling methods such as Round Robin and Pre-emptive Priority. The need for embedded OS is highlighted, emphasizing their efficiency, configurability, and predictability in resource management.

Uploaded by

Andrew Koh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Embedded Operating System

Agenda

• Introduction to Embedded Operating System → RTOS

• Internal workings of an RTOS

• Context Switches

• A few examples of Scheduling


What is an Operating Systems

• An organized collection of software extensions


(or libraries) that serve to:
• control common routines
• Printing to terminal
• Allocating memory
• Access rights to a peripheral
• a standard environment for execution of programs across various
platform or processors
Operating System Hierarchy

APPLICATIONS

OS USER INTERFACE
Extends the basic kernel more complex
functionalities, e.g. UI,
network stack, etc. FILE AND DISK SUPPORT

This is typically found in full-


Kernel on an embedded

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

BASIS FOR COMPARISON MICROKERNEL MONOLITHIC KERNEL


Basic In microkernel user services and In monolithic kernel, both user services
kernel, services are kept in separate and kernel services are kept in the same
address space. address space.
Size Microkernel are smaller in size. Monolithic kernel is larger than
microkernel.
Execution Slow execution. Fast execution.
Extendible The microkernel is easily extendible. The monolithic kernel is hard to extend.
Security If a service crashes, it does effect on If a service crashes, the whole system
working of microkernel. crashes in monolithic kernel.
Code To write a microkernel, more code is To write a monolithic kernel, less code is
required. required.
Why the need for Embedded Operating System

• OS is just a “collection” of commonly used libraries


• Common for applications to re-use existing code or libraries
• These libraries are common across most/all applications
• Typically these libraries have been tested and verified
• Share limited resources (e.g. processor, memory, etc)
• Schedule the various request for a shared resource
• Kernels used in desktop OS are often:
• Not modular (not configurable)
• Not fault‐tolerant (Not designed for mission‐critical applications)
• Resource hungry
• Timing uncertainty makes designing a real-time system challenging.
What is an Embedded Operating Systems

• Minimal Embedded OS → OS Kernel


• An embedded system is designed for a single purpose (we talked about this in Lecture 1)
• Does not need a user interface and file access (most of the time)
• Only contain libraries that are necessary (reduce overhead)
• Configurability is important feature
• Embedded OS gives you control over your resources
• Every process is scheduled (no accidental runs)
• The timing behavior of the OS must be predictable
• Number of tasks is known (bounded)
• Embedded OS allows control over timing by
• managing the timing and scheduling
• being aware of deadlines and have mechanism to take them into account during scheduling
• providing precise timing services with a high resolution.

An Embedded OS that supports the construction of real‐time


systems is called a Real‐time Operating System (RTOS)
Basic Functions of RTOS Kernel
Task synchronization (critical sections,
Execution of “parallel” tasks on a semaphores, monitors, mutual exclusion)
processor by scheduling them to
ensure fairness in sharing the Inter‐task communication
resources (queuing of request)

Critical component in RTOS to


ensure the device works indefinitely
An embedded system comprises without needing a reboot, e.g.
of various components other memory leaks, memory
then the CPU and memory that fragmentation, etc.
needs to be managed by the OS
as a resource.

Managing and servicing


Support of real‐time clocks, timers, delays, etc.
real-time events
Task States

startup

task is placed in queue


READY
A task goes through several states
task is deleted

during its life in a multitasking


pre-emption
system.
RUNNING

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

task is placed in queue


READY
State of tasks that are ready to execute but cannot as
task is deleted

the processor is assigned to another task, i.e. another


run pre-emption task has the state “running”.

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.

startup When the scheduler decides the current task has

task is placed in queue


READY had enough time on the processor, either because
it finished, its time slice is up or its being pre-
task is deleted

empted, the “running" task is moved to the “ready


run pre-emption queue”. Then the first task on the “ready queue” is
selected to run.
RUNNING

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

• Typically, an application will have a separate tasks for each


distinct activity.
• Tasks Control Block (TCB) stores information needed to
manage and schedule a task

A task is the smallest sequence of instructions that can


be managed independently by a scheduler; e.g., a task
is a basic unit of processor utilization.
Task Control Block (TCB)

• 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?

• Separate tasks share one processor (or processors)


• Each task executes within its own context
• Owns processor
• Sees its own variables
• May be interrupted
• Tasks may interact to execute as a whole program
• OS needs to switch one context (task) to another context (task)

Context Switch
Context Switch

• When the processor switches from one task to another task.


• Save the minimum information to restore the interrupted task
• stored in the stack
• contents of registers
• contents of the program counter
• contents of coprocessor registers (if applicable)
• memory page registers
• memory-mapped I/O
• special variables
• Interrupts are often disabled during a context switching
• Minimal times for context switches are required for Real-time Systems.
Context Switch: An Example

Task T0 Task T1

TCB

TCB

TCB

TCB
How do many tasks share the same processor?

• Different ways of scheduling a task in a multitasking


environment such as:
• Round Robin Systems
• Pre-emptive Priority Systems
Round Robin

• Several processes execute sequentially to completion


• Each task is assigned a fixed time slice
• Fixed rate clock initiates an interrupt at a rate corresponding to the time slice
• Task executes until it completes, or its execution time expires
• Context saved if task does not complete

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

TASK 1 TASK 2 TASK 3


time
TASK Nm

task iteration, m 1 time slice 1.5 time slice 2 time slice


Pre-emptive Priority

• 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

• Overview of Embedded Operating System


• Briefly discussed the internal workings of an RTOS
• Task States
• Task Control Block
• Illustrate how OS manages multiple tasks via Context Switches
• Went through two examples of Scheduling
• Round Robin
• Pre-emptive Priority

You might also like