0% found this document useful (0 votes)
93 views35 pages

RTOS-Components: Network Stack

This document discusses key concepts related to tasks and scheduling in real-time operating systems. It defines tasks as the smallest unit of execution that can compete independently for system resources. Tasks can be in various states like ready, running, waiting, and blocked. The kernel tracks each task using a task control block that stores the task's context and state. Scheduling algorithms like priority-based preemptive and round-robin are used to allocate the CPU to tasks based on priorities and time slices. Preemptive scheduling allows higher priority tasks to interrupt lower priority tasks currently running.

Uploaded by

ashishshuklabs
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views35 pages

RTOS-Components: Network Stack

This document discusses key concepts related to tasks and scheduling in real-time operating systems. It defines tasks as the smallest unit of execution that can compete independently for system resources. Tasks can be in various states like ready, running, waiting, and blocked. The kernel tracks each task using a task control block that stores the task's context and state. Scheduling algorithms like priority-based preemptive and round-robin are used to allocate the CPU to tasks based on priorities and time slices. Preemptive scheduling allows higher priority tasks to interrupt lower priority tasks currently running.

Uploaded by

ashishshuklabs
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

RTOS-Components

Network Stack

Kernel

Kernel Target
s Kernel

Kernel

RT File Systems
A Real Time Kernel
Tasks / Timers/
Interrupts

Memory Target Scheduler

Communication/
Synchronization
Kernel-Services
Tasks
Scheduler
Memory
Inter Task Communication
Inter Task Synchronization
Interrupts
Timers
Task Concept

What is a task?

A task is usually thought of as some amount of


work which is started and finished within a short
period of time. It is normally part of a larger job.
Contd..

A software task is usually defined to be one pass


through a particular section of code which
accomplishes part of a job.

However, in modern multitasking systems, this


definition is too simple. Tasks frequently wait for
more work when they finish and, in fact, they may
never end.
Task - Definition
Task is a smallest unit of execution that can compete on its
own for system resources.

A task can execute concurrently with, and independent of


other tasks.

RTOS Kernel simply switches tasks on events.

Although tasks are independent, they need to co-ordinate


and synchronize itself with actions in other tasks.
Tasks,Processes and Threads
A task could be either a process or a thread.It simply refers to
a sequence of related computations that all work together to
achieve some end.

A process is an independent program, complete with its own


data space and code space in memory.

A thread is a separate execution path within a process; that is


threads exist in processes.
Task States
A task may be in one of the following states at
any instant of time.During the execution time
transition of task occurs among the different
States. Some important states are as follows,

Null
Ready
Running
Waiting/Blocked
Task State Transitions

n e e d e d re s o u rc e
b e c o m e s a v a i la b le R u n n in g A h ig h e r p r io r ity
N o h ig h e r p r io r ity ta s k b e c o m e s
re a d y re a d y

n e e d e d re s o u rc e n o h ig h e r
u n a v a i la b le p r io r ity ta s k is
re a d y

B lo c k e d
R eady
n e e d e d re s o u rc e
b e c o m e s a v a i la b le
N o h ig h e r p r io r ity
re a d y
Task-Control Block

All the Tasks are defined in the data structure


called Task Control Blocks (TCB).

During the transition time of a task the


corresponding TCB is updated.This is very
important for the multi-tasking operations.

The block diagram of a TCB is given below,

Contd..,
Task-Control Block

P ro g ra m C o u n te r

T a s k S ta tu s

T a s k # id

C o n te n t s o f R e g is t e r s

P o in t e r t o n e x t T C B

..

..

o th e r C o n te x ts
How does RTOS handle tasks?

Tasks are system objects which are regulated by task control


blocks (TCBs).

The kernel keeps track of the state of each task by using a data
structure, TCB. The TCB contains the status of the task (Ready,
Delayed or Waiting for an event), the task priority, the pointer to
the task’s top-of-stack and other kernel related information.

 Following Figure shows the relationship between the task stacks,


the TCBs and the CPU registers in more detailed manner.
Task Control Block - more detailed description
Queues – States

All the states of a task are actually implemented as


queues of TCBs.

For Eg., A ready queue is a queue of all the tasks which


are ready for immediate execution.

It is a doubly linked list of all the tcb’s. In some RTOS’s it


is implemented as a single level queue where as in others
it is implemented as a multi level queues based on the
priority of the tasks thereby increasing the speed of
operation.
Context Switching

 During the task switching (State transitions) the following are


saved in the TCB.

 Context (current status of the task) Saving rule


 Contents of registers
 Contents of the program counter
 contents of co-processor registers
 memory page registers
 memory-mapped I/O location mirror images
 special variables
Task : The basic building block
 Tasks must first be created and started

 Guideline to create tasks:


 Tasks should be collections of software functions

 Worst Possible Design:


 Each software function is a task
 Too many tasks
 Operating system execution at each task switch overwhelms

capacity of your CPU


Assigning Priorities
 Criterion of Urgency
Task with Shorter Time Deadline should be given
Higher Priority

 Criterion of Criticality
Task whose Failure to meet its time deadline will be
harmful, should be given Higher Priority Irrespective
of length of time deadline

 Trade off Urgency vs.Criticality


Most often, Urgency is the major factor
Assigning Priorities
Problem with hard real-time deadline

Use Separate tasks for separate deadlines


One missed deadline is a failure of a real-time program.

 Use PRIORITY to strive for on-time execution

 Activities must execute at the expense of other activities “PRE-


EMPTION”

 CPU cycles needed to ensure all activities to meet their


deadlines
Scheduling

It is a mechanism used to achieve the desired objective of


multitasking .This is achieved by SCHEDULER which is
the heart and soul of the Real time Operating System. It is
responsible for allocating the processor among various
tasks based on whatever scheduling algorithm it’s using.
Various scheduling algorithms are available to perform
multitasking as follows,
Scheduling Types

Scheduling

Co-Operative Pre-Emptive

Round-Robin (RR) Priority based

Dynamic priority
RR-Time slice EDF

RR-Priority based
Static priority
Pre-emptive
RM
Co-operative versus Preemptive Multitasking

In Co-operative multitasking, Tasks co-operate in terms of sharing processor


timing .Each task gives-up its use of CPU by making a call to the OS’s scheduler.
the tasks voluntarily gives the kernel a chance to perform a task switch.

In Preemptive Multitasking, Tasks are preempted by a portion of the OS


called the scheduler.This is made possible with the aid of scheduling points like
timer interrupt. Tasks are allowed to run for a fixed length of time called Time-
Slice.At the end of each Time-Slice, the timer interrupt awakens an ISR that in turn
transfers control to the scheduler that determined the next task to be run, according
to the scheduling algorithm used.

Contd..
Contd..
Draw- backs of co-operative scheduling

Failure to make task switch call affects all other tasks in the
system

More impartantly, if a task fails (crashes), the call to the


scheduler is never made and the system locks up.

The only advantage of co-operative scheduling is fewer


reentrance problems are encountered than in preemptive
scheduling because tasks can be interrupted only at positions
permitted by the programmer(by kernel call).
How does a Scheduler Work?

A scheduler always selects a task from the head of the ready


queue for allocating the processor.

Scheduling of tasks is based on the current state of the tasks


and their respective priorities.

A task Must be in ready state and the priority should be


higher or equal among the other tasks in ready queue.
Round Robin Scheduling

In the round robin all the tasks have equal priorities and they
share the processor co-operatively.That means each task calls the
scheduler to give –up the CPU for the other.

The tasks are scheduled for execution in the order which they
enter the ready queue.

 E.g : If the tasks enter the ready queue in the order

T1, T2 & T3 then the order of execution would be T1,T2 and T3.
Round-robin -Time Slice based

This time slicing is similar to round-robin


except that the scheduler forces tasks to
give up the processor based on the timer
interrupt. It does so by preempting the
current task (i.e. the task actually running)
at the end of each time slice. The task is
moved to the end of the priority level.
Round-Robin (Pre-emptive based)
Tasks t1, t2, & t3 having same priorities. Round-robin scheduling. Task t4 has
higher priority. So it preempts t2.

t4
tim e
s lic e p re e m p ts

t1 t2 t3 t1 t2 t2
Pre-emption

Pre-emption means while a lower priority task is


executing on the processor another task higher in
priority than comes up in the ready queue , it preempts
the lower priority task.
Priority Based Preemptive

In case priority based preemptive algorithm if a higher


priority tasks becomes ready while a lower priority task is
executing it immediately preempts the lower priority task
from the processor.

These kind of systems work on the urgency of a particular


task so there is no place for fairness.

 Hence it is widely used method for embedded systems s/w.


Pre-emption – among tasks with different priorities

p r io r it y
t a s k c o m p le t io n

t3 ta s k
c o m p le tio n
p re e m p ts
t2 t2

p re e m p ts
t1 t1

t im e
Based on the priority type (Dynamic or Static)
we have two advanced Priority based pre-
emptive scheduling techniques called,

Rate Monotonic Scheduling Algorithm


(Static Priority Algorithm)

Earliest DeadLine First Scheduling Algorithm


(Dynamic Priority Algorithm)
RM Scheduling Algorithm

RM scheduling Algorithm is a Priority Driven Scheduling


Algorithm, where highest Priority is assigned to the Task
with the Shortest Period.

RM is an optimal static priority uni-processor scheduling


Algorithm.

Contd.,
Issues in Preemptive Schedulers

 Which tasks should a given task be allowed to preempt if


they are running, and which tasks should a given task not
be allowed to preempt ?

 The answer to this question is given by assigning a priority


number to each task. Tasks of higher priority can preempt
tasks of lower priority. But tasks with lower priority can not
preempt tasks of higher priority.

 A preemptive scheduler needs to be told what is the priority


of each task that it can schedule.
Remember 

Tasks which can be preempted and which can preempt


others, cannot be allowed to pass information to one
another by simply writing and reading shared data.

Simple methods for passing information between tasks


which worked for non-preemptive schedulers, no longer
work for preemptive schedulers.
Deadline Scheduler (EDF)

 This kind of scheduler tries to give execution time to the


task that is most quickly approaching its deadline. This
is typically done by the scheduler changing priorities of
tasks on-the-fly as they approach their individual
deadlines.

 The popular commercially-available off-the-shelf real-


time operating systems don’t offer deadline scheduling.
But you can build one of your own.
Conclusion

 Depending on the nature of our application and our I/O


requirements, we can choose from a wide spectrum of
scheduling methods.

 They range from a simple cyclic executive (RR) to full-


featured, priority-based preemptive schedulers and to
more sophisticated schedulers beyond the commercially
available.

You might also like