Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 62

RTOS TASK SCHEDULING MODELS,INTERRUPT LATENCY AND RESPONSE TIMES OF THE TASKS AS PERFORMANCE METRICS.

The three common model stratergies that a scheduler may adopt are:

Control flow strategy


Data Flow Strategy
Control-Data Flow Strategy
Control flow Strategy

• There is a complete control of sequencing of the inputs and outputs.


• Control steps are deterministic
• The worst case interrupt latencies are well defined.
• The scheduler programs such that is states are predetermined by the
programming codes.
• The cooperative scheduler adopt this strategy.
• Scheduler program can be modeled by FSM and petri net
model,where transition from only one node place to a specific next
place.
Data flow strategy

• Interrupt and task control occurrences are not deterministic.


• EXAMPLE : NETWORK
• Packets arrival is not deterministic,when the client demands a
service,it is not known prior.
• Worst case latency is not well defined.
• Sequencing of input and output is not feasible
• Preemptive scheduler use this stratergy.
• Scheduler program modeled by petri nets,as there are transition from
one or more node places to one or several node places.
Control-Data flow strategy
• A task design and scheduler functions may provide for the time out
delay features with deterministic delays.
• Deterministic petri net model is used.
• The worst case latencies are now deterministic because maximum
delays are deterministic.
Scheduling models used by RTOS schedulers.
• Cyclic Cooperative Scheduling of ready tasks in a circular queue.It closely relates
to function queue scheduling.
• Cooperative Scheduling with precedence Constraints.
• Cyclic Cooperative Scheduling with Time slicing
• Preemptive Scheduling
• Fixed Times Scheduling
• Scheduling of periodic, sporadic and aperiodic Tasks.
• Dynamic Real time scheduling using ‘Earliest Deadline First’(EDF) precedence.
• Advanced scheduling algorithms using the probabilistic Timed petri
nets(Stochastic) or Multi Thread Graphs.
The Cooperative Round Robin Scheduling
Using a circular Queue of Ready Tasks
Contd..
• Cooperative means that each ready task cooperates to let a running
one finish. None of the tasks does a block anywhere during the ready
to finish states.
• Round robin means that each ready task runs in turn only from the
circular queue.
The Cooperative Round Robin Scheduling
Using a circular Queue of Ready Tasks
Contd..
The cooperative scheduling of Ready Tasks using an Ordered list as per
Precedence Constraints.(Fig a)
Contd…(Fig b)
Contd…
Fig a shows a cooperative Priority based scheduling of the ISRs
executed in the first layer and Priority based ready tasks at an ordered
list executed in the second layer.

Fig b shows the program counter switch at different times,when the


scheduler calls the ISRs and the corresponding tasks at an ordered list
one by one.
The ordering of a list of the tasks is done by the RTOS using a priority
parameter,task Priority.
Contd…
• The RTOS scheduler first executes only the first task at the ordered
list.
• Tcycle is equals to the period taken by the first task on the list.
• It is deleted from the list after the first task is executed and the next
task becomes the first.
• If the task is in the ordered list is executed in a cyclic order it is called
cyclic priority based cooperative scheduler.
• The insertion and deletion for forming the ordered list are made only
at the beginning of each cycle.
Contd…
• ISR has a set of short codes that have to be executed immediately.
• The ISR run in first layer(top –right in figure) according to their assigned
prioirities.
• It sends a flag or token and its priority parameter for the task to be initiated.This
is the task that is inserted into the ready task list.
• There is cooperative scheduling and each ready task cooperates to let the
running one finish.
• None of the tasks does a block any where from the start to finish.
• The round robin is among the ready task that run in turn only from a priority
wise ordered list. Ordering is according to the precedence of the interrupt source
and task.
Contd…
Cyclic scheduling with time scheduling(Rate
Monotonic Cooperative Scheduling)
Contd…
Contd…
• When a p-th task has high execution time,etp,the worst case latency
of the lowest priority task can exceed its deadline.
• To overcome this problem,it is better that the RTOS defines a time
slice for each task to finish and if it does not finish,then blocks it and
finishes its remaining codes during the succeeding cycle(next after the
lowest priority task is attended and new cycle starts from the first
highest assigned priority task only.
• There is no insertion or deletion into the queue or list.
Disadvantage of cooperative scheduling
• Cooperative schedulers schedule such that each ready task cooperates to let
the running one finish.
• Let there be N tasks from task 1 to task N and let the assigned order of
priority for interrupt servicing from 1(highest) to N (lowest).
• Assume that interrupt occurs in the time slicing cooperative scheduling just
after the cycle starts.
• It means task 1 misses by a flick the chance of running from start to finish as
task 1 will not get serviced till the cycle upto task N finishes or till the defined
period tslice expires.
• Long execution time of a low priority task makes a high priority task wait at
least until it finishes.
Preemptive Scheduling Model Strategy by a
scheduler
Contd…
Contd…
Let the priority of task_1 > task_2 > task_3 >task_4….>task N.
1)The highest priority task_1 is initiated as follows. Task 2 blocks and sends
a messages to the RTOS.
2)The RTOS now sends a message to task_1 to go to a ready state and run.
3)A message is sent to RTOS after task_1 finishes and the task_1 context
becomes the same as it starts.An RTOS then reads the task2.task2 now runs.
A message will be sent to RTOS after task_2 finishes and task_2 context
becomes same as it starts.An RTOS message readies the task_3.Task_3 will
run now.
Contd…
The condition in which an event ,the preemption event,is generated for a task to
undergo transition from running place to ready place.
• The preemption event takes place when an interrupt occurs and just before the return
from the interrupt, there is a service call to the RTOS by the ISR. on this call to the RTOS,a
token,the preemption event,is set.The task then undergoes transition to the
place,readyTaskPlace,and runs only when asked by the scheduler.
• Each RTOS uses a system clock ticking an RTCSWT.The preemption event takes place
when an RTCSWT interrupt occurs at the RTOS.On this event RTOS takes control of the
processor and checks whether it should let currently executing task to continue or to
pre-empt it to make way for the higher priority task.
• The preemption event takes place when any call to the RTOS occurs to enter the critical
section or for sending the task message to the RTOS,and if another higher priority task
then needs to be served.
Critical section service by a preemptive
Scheduler
• For servicing of a critical section,a Preemptive scheduler,
• on arising out of service need of the higher priority task,should not
preempt a lower priority task in certain cases.
• The blocking should not occur in the critical section of any lower priority
task. This is to prevent the occurrence of shared data problem.
• Before a critical section ,the running task takes a semaphore from the
scheduler and releases the semaphore at the exit from the critical section.
• Petri net which models and helps in designing the codes for a task that has
a critical section in its running.
Contd…
Contd…
• The RTOS initiates idle to ready transition by executing a function ,task
create().For the present case it is done by executing a function,task_J_create().A
transition from the idle state of the task is fired as follows.RTOS sends two
tokens,RTOS_CREATE Event and taskJSwitchFlag.The output token from the
transition is taskSwitchFlag = true.Each task is in idl state to start with,and a
token to the RTOS is taskSwitchFlag = reset.
• Consider the task_J_Idle place,which currently has highest priority among the
ready tasks.After the RTOS creates task_J,the place task_J_Idle undergoes a
transition to the ready state.
• When after task J finishes and when it is no longer needed under RTOS
control,the RTOS sends a RTOS_DELETE event task,it returns to the task_J_Idle
place and its corresponding taskJSwitchFlag resets.
Contd..
• At task_J_Ready place,the scheduler takes the priority parameter into
account.if the current task happens to be of highest priority,the
scheduler sets two tokens,taskJSwitchFlag=true and higher Priority
Event = false for the transition to the running task J
place,task_J_Running.The scheduler also resets and sends the
tokens,task switch flags,for all other tasks that are of lesser
priority.This is because the system has only one CPU to process at an
instant.
• From the task_J_Running place,the transition to the task_J_Ready
place will be fired when the task finish flag sets.
• At task_J_Running place,the codes of the switched task J are executed.
• At the RunningTaskPlace,the transition for preempting will be fired when
RTOS sends a token,SuspendEvent.Another enabling token if present,is
time_out_event will also fire the transition.
• An enabling token for both situations is the semaphore release flag,which
must be set.Semaphore release flag is set on finishing the codes of task J
critical sections.On firing,the next place is task_J Blocked.Blocking is in two
situations.one situation is of preemption.It happens when the
suspendEvent occurs on a call at the runningTaskPlace asking the RTOS to
suspend the running.Another situation is a time-out of an SWT that
associates with the running task place.
Contd…
• On a resumeEvent the transition to task_J_Running place occurs.
• At the task_J_Running place,there is another transition that fires so
that the task J is back at the to task_J_running place when the RTOS
sends a token,take_Semaphore_Event to ask the task J to take the
semaphore.
• There can be none or one or several critical sections.During the
execution of a critical section,the RTOS resets the semaphore release
flag and sets the take semaphore event token.
Fixed Real Time scheduling of tasks
• A scheduler is said to be using a fixed time scheduling method when
the schedule is static and deterministic.
• The working environment is unaltered when the processes are
scheduled on the single cpu of the system.
• Schedules are deterministic as the worst case latencies for all the
interrupts and tasks are predeterminable.
• RTOS Scheduler can thus schedule each task at fixed times so that
none misses its deadline.
Contd…
• Fixed schedules can be defined by one of three methods.
• Simulated annealing method : Here the different schedules can be fixed and
the performance simulated.Now,schedules for the tasks are gradually
incremented by changing the RTCSWT timer settings(using a corresponding
OS functions) till the simulation result shows that none is missing its deadline
or number of deadline misses are too few to impact the system performance.
• Heuristic method : Here, reasoning or past experience helps to define and
fixing the schedules
• Dynamic programming model: A specific running program first determines
the schedules for each task and then the RTCSWTs loads the timer settings
from the outputs from that program.
Dynamic scheduling model using EDF
model.
• The software design may be such that priorities can be rescheduled and fixed
times redefined when a message or error message is received during the run.

Precedence Assignment in the scheduling algorithm.

The best strategy is one, which is based on EDF(Earliest Deadline First)


precedence.
Precedence is made the highest for a task that corresponds to an interrupt
source, which occurs at the earliest times and which deadline will finish
earliest.
How is the precedence assigned in case of variable
CPU loads for the different tasks and EDFs
• Let t1 be the instance when task I needs preemption the first time
and t2 be the next instance.
• A task with minimum (t2-t1) is inserted at the top of the task priority
list.It is assigned the highest precedence.
• The list is dynamically ordered according to (t2–t1).
Advanced Scheduling Algorithms using the
Probabilistic Timed Petri nets(Stochastic) and
Multi Thread Graph(MTG)
• The scheduling needs to be dynamic as well as stochastic.
• The scheduler has to use the probabilistic scheduling stratergy in a
non deterministic environment.
Performance metric in scheduling models
for Periodic, Sporadic and Aperiodic tasks
• Three performance Metrics are as follows
i) Ratio of the sum of Interrupt Latencies with respect to the sum of
the execution times.(Refer worst case latency formulas)
ii) CPU load
iii) Worst –case Execution time with respect to mean execution time.
CPU Load as Performance Metric
• Each task gives a load to the CPU that equals the task execution time
divided by the task period.
• Consider Task Period is 172 ms. If the task execution time is is also 172
ms .Then what is cpu load?
• The maximum load of the CPU is 1.
• For multiple task ,the sum of CPU loads for all the tasks and ISRs should
be less than 1.
• The timeouts and fixed time limit definitions for the tasks reduce the
cpu load for the highest priority tasks so that even the lower priority
tasks can run before deadlines.
Contd…
• Suppose if the CPU load is 0.1 ? What is the conclusion ?
• When a task needs to run only once, then it is aperiodic in an application.
Example for aperiodic task Interactive commands issued by users are handled by
aperiodic tasks
• When a task that need to run periodically with the fixed period can be periodic
in an application ,achieved by making CPU load very close to 1.
Example for periodic task : There may be inputs at a port with predetermined
periods, and inputs are in succession without any time gap.
• When a task cannot be scheduled at fixed periods,its schedule is called sporadic.
Example for Sporadic : Packets from the router in the network
A Preemptive scheduler must take into
account three types of tasks
i) An aperiodic task needs to be preempted only once.
ii) A periodic tasks needs to be preempted after the fixed periods and
it must be executed before its next preemption is needed.
iii) A sporadic task needs to be checked for preemption after a
minimum time period of its occurrence.
Sporadic Task Model
IEEE STANDARD POSIX 1003.1B FUNCTIONS
FOR STANDARDISATION OF RTOS AND
INTER_TASK COMMUNICATION FUNCTIONS
• A note on POSIX
• Portable operating system Interface
• Set of standards under ISO/IEEE Chapter
• POSIX standard 1003.1b,(formerly called 1003.4) for RTOS
• Makes it easier to move applications from one operating system to
another.
The POSIX 1003.1b defines the standard
for the following
1.Portability of the application and system implementation
2.Definations for the RTOS service interfaces,subroutines,environment
variables,headers and structures.
3.Ensuring portability,deadlock recovery,error reporting and error
recovery
4.Timer setting and reading with a high resolution using POSIX timer
and clock interface.
5.Sharing the memory using POSIX memory management
6.Priority scheduling and priority based preemptive scheduling
Contd…
7.Creating and accessing the real time files, and their deterministic
performance.
8.Locking a memory block to a process.
9.Synchronizing I/Os
10.Asynchronous I/Os using POSIX for asynchronous IO
11.Defining the performance of a real-time system with a performance
matrix.
12.Defining the context switch times, interrupt latency[time interval between
the interrupt occurrences and first instruction execution] and process dispatch
latency[time interval between interrupt occurrence and return to the process]
Contd..
13.Language specific services by the RTOS
14. Synchronus and asynchronous inter process communication using
POSIX signals,POSIX semaphores,POSIX message queues.
15.It contains the definations for threads and threading mechanisms.
Synchronization(FIFTEEN POINT STRATERGY FOR
SYNCHRONIZATION BETWEEN THE PROCESSES,ISRs,OS FUNCTIONS
AND TASKS AND FOR RESOURCE MANAGEMENT)

An embedded system with a single CPU can run only one process at an
instance,process may be either ISR,Scheduler or task.
For designing the codes for synchronization between the
processes,the following fifteen points must be taken into account.
Contd…
1.Use appropriate precedence assignment stratergy
2.The ISR can only write the messages for an RTOS and parameters for the tasks. No
ISR instruction should not block any task apart from RTOS.The variables and task
switching flags must always be under the RTOS control.
3.The ISR coding should be like a reentrant function with no shared data problems.
The ISR should be short and execute the codes that should not wait for actions by
the RTOS and tasks.
4.A task should not call another task as each task has to be under the RTOS
control.Such an attempt should generate an error.
5.A task can get the messages and send the messages using the RTOS calls only.
Contd..
6.While executing the critical section codes,if possible,instead of
disabling the interrupts only the task switching flag changes should be
prevented.Disabling preemption may be better than disabling
interrupts.Howeever,both increase worst case interrupt latencies.
7. Resource locking using the mutex semaphores may be better than
disabling preemption or interrupts.
8.A task should take the semaphore only during a short period in which
critical section alone is executed.Disabling of running of other tasks for
a longer period increases the worst case interrupt latency periods for
all interrupts.
Contd..
9.Relative response times improve on multitasking but a limited number of
multiple tasks should be preferred.It reduces the context switching intervals
and stack needs.Otherwise,the response time advantages are lost and sum of
the stacks for each task needs a larger memory.
10.Get a semaphore takes the least CPU time.
11.Create a tasks at start-up only and avoid creating and deleting task
later.The only advantage of deleting is the availability of additional memory
space.
12.Semaphores,queues,and messages should not be globally shared
variables,and each should be shared between a set of tasks only and
encapsulated later.
Contd…
13.Use idle CPU time for internal functions.Often,the CPU may not be
running any task.All tasks may be waiting for preemption .The CPU at
that instant may associate the RTOS for the following .Read the internal
queue.Manage the memory.Search for a free block of memory.Delete
or dispatch a task.Perform the internal and inter process
communication functions.
14.If memory allocation and dellocation is done by the task the number
of RTOS functions is reduced.This reduces the interrupt-latency periods
as execution of these function takes significant time by the RTOS
whenever the RTOS preempts a task.
Contd…
13.Use idle CPU time for internal functions.Often,the CPU may not be
running any task.All tasks may be waiting for preemption .The CPU at
that instant may associate the RTOS for the following .Read or a free
block of memory.Delete or dispatch a task.Perform the internal and
inter process communication functions.
14.If memory allocation and dellocation is done by the task the number
of RTOS functions is reduced.This reduces the interrupt-latency periods
as execution of these function takes significant time by the RTOS
whenever the RTOS preempts a task.
Contd…
15.Use a configurable or hierarchial RTOS ,which can put only the
needed functions from the scheduler with the rest outside.

A fifteen point stratergy is suggested for real time programming for an


embedded system.
Embedded Linux Internals
• Linux is increasingly used in embedded systems besides being a
freeware ,because of its :
• powerful device driver features,
• expandability of the kernel codes at run time
• provision of registering and deregistering device driver modules thus
facilitating their scheduling like the processes.
• These are essential in complex embedded system.
LINUX KERNEL FOR THE DEVICE
DRIVERS AND EMBEEDED SYSTEM
• Is it possible to define classes of devices other than block devices
such as files, in an OS?
• Linux gives the answer for this question.
• Linux OS facilitates definitions of classes of devices and thus device
driver modules.
• A module may be for the USB class of devices or SCSI(small computer
System Interface)
Contd…
• A linux kernel can insert a module by registering and remove it by de-
registering.
• Linux kernel also permits the scheduling of device drivers and
modules.
• Therefore,the different task or programs can send the bytes
concurrently or sequentially to a device through its driver registered
at kernel.
• Linux kernel enforces the use of sequential accesses,and to specific
memory addresses only, by the registering and deregistering
mechanism.
Registering and De-registering and related
functions of Linux for Device Driver
Modules Function Action
insmod Insert module into the Linux kernel
rmmod A module is deleted from the kernel
cleanup A kernel level void function,which performs the action
on an rmmod call from the execution of the module
Register_capability A kernel level function for registering
Unregister capability A kernel level function for degistering

Register_symtab A symbol table function support,which exists as an


alternative to declaring functions and variable static.
Linux/time.h Supports the timing function in the kernel for
scheduling
Linux/delay.h Supports the delay function in the kernel for
scheduling

Linux/tqueue.h Support the task queue.


OS SECURITY ISSUES
• The OS security issue is a critical issue.
• When an OS has to supervise multiple process and their access to the
resources, protection of memory and resources from any
unauthorized writes into the PCB .
Important Security Functions
Function Activities
Controlled resource sharing Controlling read and write of the resources and
parameters by user processes. For example,Some
resources read only for a set of process.
Confinement Mechanism Mechanism that restricts sharing of parameters to a
set of processes only.
Security policy(Stratergy) Rules for authorizing access to the OS, system and
information. A policy example is a communication
system having a policy of peer –peer communication
Authentication Mechanism User or process allowed using the system resources as
per the security policy.
Encryption A tool to change information to make it unusable by
any other user or process without the appropriate key
for deciphering it.
Need of a well tested and debugged real-time
operating system
• When designing a complex embedded system,one needs the thoroughly
tested bug-free codes for the following software components.
1. Multiple task functions in embedded c or embedded c++.
2. Real-time clock based software timers(RTCSWT codes)employing the
system(hardware) clock.
3. Software for cooperative scheduler.
4. Device drivers and device managers
5. Functions for interprocess communications using the task switching
flags, semaphore handling functions and functions for the
signals,queues,mailboxes,pipe and sockets.
Contd…
• Networking functions
• Error handling functions and Exception handling functions
• Testing and system debugging software.
Conclusion: Therefore a lot of coding is needed in a complex embedded system and that
too within a reasonable amount of time that might be assigned to develop a product.
A readily available RTOS package provides an advantage that the previously tested and
debugged RTOS functions and error and exception handling functions can be ported
directly as these are already well tested by thousands of users.Tools for the source
code engineering,testing,simulating and debugging may also be available with the
RTOS package.
IT helps in building a product fast.
Vxworks
• VxWorks is created as proprietary software by Wind River Systems, a completely
owned subsidiary of Aptiv. It was firstly launched in 1987.
• It is mainly intended for embedded systems that require real-time and deterministic
performance.
• In many cases, it needs safety and security certification in aerospace and robotics,
medical devices, industrial equipment, energy, transportation, defence, automotive,
network infrastructure, and consumer electronics.
• VxWorks is a proprietary and customizable real-time operating system (RTOS).
VxWorks is designed for distributed computing on most central processing units
(CPU) with embedded systems.
Basic features of vxWorks
• Multitasking environment using standard Posix scheduler
• Ability to run two concurrent Operating systems on a single process
layer.
• Multiple file systems and systems that enable advanced multimedia
functionality.
• Synchronization using a full range of IPC options
• Different context saving mechanism for the task and ISR
• Virtual IO devices includes pipes and sockets
• Virtual memory management functions.
Contd…
• Processor abstraction layer to enable application system design by
user when using a new versions of processor architecture.
• Ram disk drivers for memory resident files.
• Network drivers for shared memory and Ethernet.
• Power management functions to enhance the ability to control
power consumption.

You might also like