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

Module 4 - 1

RTOS allows for multitasking by scheduling tasks to run concurrently using scheduling algorithms like round robin. It discusses round robin scheduling where each task gets a time slice to run before being preempted. An example is given of tasks in a washing machine like filling with water, starting motor, etc passing messages between each other using flags. Priority scheduling is also covered where higher priority tasks preempt lower priority ones. An example of message processing tasks with different priorities is provided.

Uploaded by

Darshan Babu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Module 4 - 1

RTOS allows for multitasking by scheduling tasks to run concurrently using scheduling algorithms like round robin. It discusses round robin scheduling where each task gets a time slice to run before being preempted. An example is given of tasks in a washing machine like filling with water, starting motor, etc passing messages between each other using flags. Priority scheduling is also covered where higher priority tasks preempt lower priority ones. An example of message processing tasks with different priorities is provided.

Uploaded by

Darshan Babu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 47

Module 4

RTOS
Course :Embedded systems(EC6C04)
Course Instructor : Bhavana k
Syllabus
Introduction -What is an operating system
What is an operating system
1. It is a software layer between hardware and the application
software.
2. Has direct access to Hardware
3.Manage the hardware according to predefined rules and policies
4.Hide hardware complexity from the application software
5.Offers multitasking/Resource and data Management.
Examples of operating system
• Microsoft windows
• Linux
• Mac OS
• Android
• IOS
• Embedded os
Real Time operating System
• RTOS Designed specially to Run Applications with very precise
timing and high degree of reliability

Operating
RTOS Real time
system
What are Real Time Systems
• Real Time systems are those systems which responds to external
events in a timely fashion.
• A real-time system is characterized by the need to meet deadlines.
• Real Time performance does not mean faster performance.
Types of RTOS
• 1. Hard real time system
• 2.Soft real time system
Hard Real Time Systems
• A System that meets the deadline all the times(100 %),even under a
worst case system load.
• Missing a deadline even a single time may result in fatal
consequences.
• Hard Real Time systems are used in Life safety systems, where a task
needed to be performed within a particular time frame otherwise
catastrophic event will occur.
• Example : Air bag system.
Soft Real Time Systems
• Missing a deadline does not result in fatal consequences.
• Missing a deadline, at the Maximum, it may lower the quality of
service provided but are not catastrophic.
• Example : DVD player
HARD VS SOFT REAL TIME SYSTEMS
Hard real time
• Tasks have to be performed on time
• Missing a deadline results in fatal Consequences.
• EXAMPLE : Flight control system.

Soft real time


• Late completion of jobs is undesirable but not fatal.
• Missed deadlines may lower the quality of service provided but are not catastrophic.
• Example : Music Systems.
RTOS Characteristics
Single tasking v/s Multitasking

• Without RTOS,Only one task can . RTOS allows the execution of


be Executed by the cpu at a time. Multiple tasks on a single cpu .
This is called Single –task System All tasks execute as if they
completely own the entire cpu.
Single tasking v/s Multitasking
• Interrupt service routine(ISRs) Multitasking is done by a
are used for the real time parts of Scheduler in RTOS Kernel.
the application(critical operation) The task are scheduled for
execution,according to priority
Single task system(Super loop)
Multitasking system
• In a multitasking system,cpu time is distributed among different tasks.
Single task Systems
• Superloop Designs is the classic way of designing embedded systems
does not use the service of RTOS.
• No real time kernel is used,so interrupt service routine are used for the
real time parts of the applications(Critical operation).
• However super loops can become difficult to maintain if the program
becomes too large or uses complex interactions.
• Reaction time depend on the execution time of the entire
sequence,resulting in a poor real time behavior.
• This type of system is typically used in small,simple system or if real
time behavior is not critical.
Scheduling in RTOS
• Scheduling is the process of distributing the cpu time amongst different tasks.

• Number of tasks
• Resources Requirements
• Execution time
• Deadline
• Priority
Round Robin Scheduling Algorithm
• What is Round-Robin Scheduling?
• The name of this algorithm comes from the round-robin principle,
where each process gets an equal share of something in turns. It is
the oldest, simplest scheduling algorithm, which is mostly used for
multitasking.
• In Round-robin scheduling, each ready task runs turn by turn only in a
cyclic queue for a limited time slice
Characteristics of Round-Robin
Scheduling
• Round robin is a pre-emptive algorithm
• The CPU is shifted to the next process after fixed interval time, which is
called time quantum/time slice.
• The process that is preempted is added to the end of the queue.
• Time slice should be minimum, which is assigned for a specific task that
needs to be processed. However, it may differ OS to OS.
• It is a real time algorithm which responds to the event within a specific time
limit.
• Round robin is one of the oldest, fairest, and easiest algorithm.
• Widely used scheduling method in traditional OS.
Example of Round-robin Scheduling
Contd…
Contd…
Contd…
Contd..
Contd…
Contd…
Advantage of Round-robin Scheduling
• All the jobs get a fair allocation of CPU.
• Once a process is executed for a specific set of the period, the process
is preempted, and another process executes for that given time
period.
• Allows OS to use the Context switching method to save states of
preempted processes.
• It gives the best performance in terms of average response time.
Disadvantages of Round-robin Scheduling
• If slicing time of OS is low, the processor output will be reduced.
• This method spends more time on context switching
• Finding a correct time quantum is a quite difficult task in this system.
Schedule Management for Multiple tasks by
an RTOS.
Contd…
• Consider a Round Robin scheduling by a cyclic schedule
• Consider an embedded system-an automatic washing machine where
all tasks are independent to each other.
• First three tasks A1,A2,A3 in a set of tasks A1 to AN.
Contd..
• Task A1 : The task is to reset the system and switch on the power if
the door of the machine is closed and power switched pressed once
and released to start the system.
• Task 1 waiting loop terminates after detection of two events
i) door closed ii) Power switch pressed by the user.
At the end,task1 sets a flag start_F,which is a message ,messag A1 ,to
the scheduler for task A2 to start executing its code.
Contd..
• Task A2 :The scheduler waits for the message A1 for start_F setting
and if that event occurs task A2 starts.
• A bit is set to signal water into the wash tank and repeatedly checks
for the water level.
• When the water level is adequate the flag Water-stage1_F is
set,which is a message,message A2,to scheduler for task A3 to start
executing its code.
Contd..
• Task A3 : The scheduler waits for the message A2 for the stage1_F
setting and if that event occurs task A3 starts.A bit is set to stop water
inlet and another bit sets to start the wash tank motor.
• Then a flag ,motor-stage1_Fis set,which is a message,message A3,to
the scheduler for the next task to start executing its code.
Priority scheduling algorithm
• Priority scheduling algorithm executes the processes depending upon
their priority.
• Each process is allocated a priority and the process with the highest
priority is executed first.
• Priorities can be defined internally as well as externally. Internal priorities
are decided by the system depending upon the number of resources
required, time needed etc.
• whereas external priorities are based upon the time in which the work is
needed or the amount being paid for the work done or the importance
of process. Priority scheduling can be preemptive or non- preemptive
Priority scheduling algorithm
Priority scheduling algorithm
• Suppose there is a stream of coded messages reaching at port A of an
embedded system.
• It then decrypts and re-transmits to the port B after encoding each
decrypted message.
• The order of priorities as follows.
1.Task B1 : Check for a message at port A
2.Task B2 : Read Port A
3.Task B3 : Decrypt the Message
4. Task B4 : Encode the Message
5. Task B5 : Transmit the encoded message to port.
Contd…
• A higher priority task takes control from the lower priority task.
• A higher priority task switches into the running state after blocking
the low priority task.
Contd…
1. At the first instance the context is B3 and task B3 is running.
2.At the second instance the context switches to B1 as context B3 saves
on interrupt at port A and task B1 is of highest priority.Now task B1 is in
a running state and task B3 is in a blocked state.Context B3 is at the
task B3 Stack.
3. At the third instance the context switches to B2 on interrupt,which
occurs only after task B1 finishes.Task B1 is in a finished state,B2 in
running state and task B3 is still in the blocked state.Context B3 is still at
the task B3 Stack.
Contd…
4.At the fourth instance context B3 is retrieved and the context
switches to B3.Tasks B1 and B2,both of higher priorities than B3,are
finished.Tasks B1 and B2 are in finished states.Therefore,Task B3
blocked state changes to running state and B3 is now in running state.
5.At the fifth instance the context switches to B4.Tasks B1,B2 and B3,all
of higher priorities than B4,are finished.Tasks,B1,B2,B3 ,are in finished
states.B4 is now in a running state.
6.At the sixth instance the context switches to B5.Tasks B1,B2,B3 and
B4,all of higher priorities than B5,are finished.Tasks,B1,B2,B3,B4 are in
finished states.B5 is now in a running state.
Contd…
7. At the seventh instance the context switches to B1 as context B5 is
saved on interrupt at port A,and task B1 is of highest priority.Now task
B1 is in a running state and task B5 is in a blocked state.Context B5 is at
the task B5 stack.
8. At the eighth instance the context switches to B2 on interrupt,Which
occurs only after task B1 finishes.Task B1 is in a finished state,B2 in
running state and task B5 is still in the blocked state.Context B5 is still at
the task B5 stack.
9.At the last instance the context B3 and task B3 is running. The tasks
B1,B2 and B5 are in the finished state.
Scheduling of Multiple Tasks in Real Time by
RTOS
Contd…
• Task C1 : Check for a message at port A at every 10 ms.
• Task C2 : Read Port A and put the message in a message queue.
• Task C3 : Decrypt the Message from message queue.
• Task C4 : Encode the Message from the queue.
• Task C5 : Transmit the encoded message from the queue to port B.
Contd..
RTOS initiate C1 to C5.
• Consider RTC tick interrupts at each ms.
• Task C1 is scheduled by RTOS to bring it in running state from its
blocked state as soon as a timer trigger an event.
• If it is known that every ten millisecond a byte reaches port A ,let a
timer,RTCSWT,trigger an event every 10 ms.
• Task c1 finishes after 10 ms ,c2 starts running
Scheduling of Multiple Tasks in Real Time
by RTOS
Schedule Management conclusion

•An RTOS Scheduling management may


be in cyclic (round robin),preemptive
and time slicing modes when
processing multiple tasks.

You might also like