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

Unit 5 Real Time Operating System

This document discusses operating system services and real-time operating systems. It defines an operating system and lists its main goals which include facilitating resource sharing and scheduling, optimizing performance, and providing management functions. It describes the user mode and kernel mode structure, with the kernel having complete control and running in protected memory space. Key kernel services are listed such as process, memory, file, and device management. Process management functions like creation, scheduling, and control are explained. The timer functions of an OS are also outlined, including setting system clock ticks and using interrupts to switch between user and kernel modes.

Uploaded by

smit patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views

Unit 5 Real Time Operating System

This document discusses operating system services and real-time operating systems. It defines an operating system and lists its main goals which include facilitating resource sharing and scheduling, optimizing performance, and providing management functions. It describes the user mode and kernel mode structure, with the kernel having complete control and running in protected memory space. Key kernel services are listed such as process, memory, file, and device management. Process management functions like creation, scheduling, and control are explained. The timer functions of an OS are also outlined, including setting system clock ticks and using interrupts to switch between user and kernel modes.

Uploaded by

smit patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

ADIT Embedded systems

Unit 5 Real time operating systems


Q. Operating system services
 OS definition: Operating system is a program that controls that execution of application
program. It is an interface between the application and hardware.

 Goals of operating system


1. Facilitating easy sharing of resources as per schedule and allocations:
Resources mean processor, memory, IOs, devices, virtual memory devices (pipes,
socket), system timer, keyboard, displays, printer, and other such resource. No processing
task or thread uses any resource until it has been allocated by the OS at a given instance.
2. Facilitating easy implementation of the application program with the given system-
hardware through the system software.
3. Optimally scheduling the processes on one (or more CPUs if available) by providing an
appropriate context switching mechanism.
4. Maximizing the system performance to let different processes (or tasks or threads) share
the resources most efficiently with protection and without any security breach.
5. Providing management functions for the processes (tasks or threads), memory, file,
physical and virtual devices and I/Os and for other functions for which it is designed
6. Providing management and organisation functions for the I/Os, devices and files and file -
like devices.
7. Providing interoperability of the application on different networks.
8. Providing a common set of interfaces that integrates various devices and applications
through standard and open systems.
9. Providing easy interfacing and management functions for the network protocols and
network.
10. Providing portability of the application on different hardware configurations.

 User mode and supervisory mode(Kernel mode) structure in OS


1. User mode
 User process is permitted to run and use only a subset of functions and instructions in OS.
Use of OS functions in user mode either by sending a message to the waiting process
associated in the OS kernel space or by system call (calling an OS function).
 The use of hardware resources including memory is not permitted without OS making the
call to the OS functions, called system call.
 User function call, which is not a system call, is not permitted to read and write into the
protected memory allotted to the OS functions, data, stack and heap
 That protected memory space is also called kernel space. Hence execution of user
functions calls is slower than the execution of the OS functions (on system call) due to
need to spend time in first checking the access permission to the protected space.
2. Supervisory mode
 It is also called kernel mode. OS runs in protected mode the privileged functions and
instructions in protected mode that are the privileged ones and the OS (more specifically,
the kernel) is only one permitted to access the hardware resources and protected area
memory

1|P ag e
ADIT Embedded systems

 Kernel space functions and processes execute faster than the user space functions and
processes. Only a system call is permitted to read and write into the protected memory
allotted to the OS functions, data, stack and heap.
 Kernel and its services
 Kernel:
The kernel is software code that resides in the central core of operating system. It has
complete control over the system. In which, the memory space of function, data and stack are
protected from excess by any call other than system call. It is secured unit of OS and operates
in supervisory mode.

 Kernel services in operating system


Functions Actions
Process Creation to Enables process creation, activation, running,
management deletion of blocking, resumption, deactivation and deletion
process
Process Enables process structure maintenance and its
structure information at PCB
maintenance
Process Resource request made by the system call or sending
structure request message
Scheduling of Handling of scheduling Eg. Cyclic scheduling or
process priority scheduling etc.
IPC (Between Process synchronization by sending message from
task) one task to another task. It manages shared memory
by using IPC function such as semaphore, queues,
mailbox, pipes and socket.
Memory Memory allocation and deallocation and management. It also restricts
management the memory access region for a task.
File File management provides management of the creation, deletion, read,
management write to the files on the secondary memory disk.
Device A physical device management is such that devices are accessible to one
management task only at an instant.
Device Facilitates the use of number of physical devices like keyboard, display,
drivers disk, parallel port, network interface card, network device, virtual
devices.
IO Character or block IO management. It ensures that parallel or serial port
management is accessible to one task at a time.
Interrupt Facilitates running of the ISR.
control
mechanism

Q. Process management

 Process creation
At reset of processor in a computer system an OS is initialized first, and then a
process which can be called initial process, it created. Then the OS is started that runs an
initial process. Process can be created hierarchically. The initial process creates subsequent

2|P ag e
ADIT Embedded systems

processes. OS schedule the processes and provides for context switching between the process
and threads.
Creation of process means specifying the resources for the process and address space for
created process, stack, data, heap and placing the process initial information at a PCB. The
process manager allocates the PCB (Process control block) or TCB (Task control block).

PCB describes the following


1. Context
2. Process stack pointer
3. Current state [Is it created, activated or spawned? Is it running? Is it blocked?]
4. Addresses that are allocated and that are presently in use
5. Pointer for the parent process
6. Pointer to a list of child processes.
7. Pointer to a list of resources, which are usable (consumed) only once. For examples, input
data, memory buffer or pipe, mailbox message, semaphore
8. Pointer to a list of resources, which are usable (consumed) only once
9. Pointer to queue of messages.
10. Pointer to Access-permissions descriptor
11. Process ID

 Management of the created processes


Process manager is a unit of the OS that is responsible for controlling a process
execution. Process management enables process creation, activation, running, blocking,
resumption, deactivation and deletion. It continuously changes their states during the
execution.
The process manager executes a process request for resource or OS service and then
grants that request to let the process share the resources. The resource can be used by one task
at a time.
 Resource management method
Request method Explanation
Message A process running on user mode generates and put a message so
that OS lets the requested resource use or run an OS service
function.
For example, a message can be sent for the OS to let the LCD
display be used by a task or thread for sending the output. An
ISR sends a message to a waiting thread to start on return from
the ISR.
System call A call to a function defined at the OS.
For example OStaskcreate() is a system call to create a task. It
switches to supervisory mode. On finishing the instruction of
called function, the processor switches back from supervisory
mode to user mode and lets the calling process run further.

3|P ag e
ADIT Embedded systems

Q. Timer function
 OS timer function
1. OS_TICK_PER_SEC─to set the system clock ticks and hence SysClkIntr interrupts per
second.
2. OSTickInit( )─to initiate system clock ticks.
3. OSTimeDelay( )─to delay the process making call by a fixed number of system clock
ticks specified in argument.
4. OSTimeDelay-Resume ( )─to resume a delayed process specified in the argument
5. OSTimeSet( )─to set the counts of system clock ticks.
6. OSTimeGet( ) ─to read the counts of system clock ticks to find the time interval from the
previous read or write of the counts.
7. OSSemPend(semVal, twait, *semErr)─to wait for a semaphore release.
8. OSMboxPend(semVal, twait, *mboxErr) ─to wait for a message in mailbox.

The periodic SysClkIntr interrupt on this tick is used by the system to switch to the
supervisory mode from the user mode on every tick. The following are the steps.
1. Before servicing of SysClkIntr, the presently running task or thread or process context
saves on the TCB or thread stack or PCB data structure.
2. SysClkIntr service routine call the OS to increment the system tick time.
3. The OS finds the new messages or IPCs, which the OS event control blocks received
from the system call for the IPC functions.
4. Then OS either selects the same task or selects new task or thread (by preemption in case
of preemptive scheduling) and switches the context to the new one.
5. Then after return from the interrupt the new task runs from the code, which was blocked
from running earlier.

Q. Event function
 Wait for only one event (semaphore or mailbox-message posting event).
 Event related OS functions can wait for number of events before initiating an action or
wait for any of the predefined set of events.
 Events for wait can be from different tasks or the ISRs.
 Some OS support and some don’t support event functions for a group of event.
 OS event function
1. OSEventCreate ( )
Creates an event register, which has a set of 8 or 16 or 32 flag-bits. Event register is for
defining the information of occurrences of the events in an event register. Event register
is for clearing the defined occurrences of the events in an event register. Each bit
corresponds to an event flag.
2. OSEventQuery( )─to query an event register to find the event register existence and its
contents.
3. OSEventDelete( ) ─delete the event register.
4. SET (event_flag) to set one of the bits at the event register. Event flag in the register can
be set by an ISR or Task using SET (event_flag) function.

4|P ag e
ADIT Embedded systems

Q. Memory management

 When a process is created, the memory manager allocates the memory addresses (blocks)
to it by mapping the process-address space.
 Threads of a process share the memory space of the process. Memory manager of the
OS─secure, robust and well protected.
 No memory leaks and stack overflows. Memory leaks means attempts to write in the
memory block not allocated to a process or data structure. Stack overflow means that the
stack exceeding the allocated memory block(s).

 Memory managing strategy


1. Fixed-blocks allocation: Memory address space is divided into block with process
having small address space getting a lesser number of blocks and process with big address
space getting a larger number of blocks.
2. Dynamic -blocks Allocation: memory address space is divided into fixed as above and
then later memory manager later allocates variable size blocks dynamically allocated
from a free list of memory.
3. Dynamic Page-Allocation: Memory has fixed sized blocks called pages and the memory
manager MMY (Memory management unit) allocates the page dynamically with a page
descriptor table.
4. Dynamic Data memory Allocation: The manager allocates memory dynamically to
different data structure like the nodes of list, queue and stacks.
5. Dynamic address-relocation: The manager dynamically allocates the address initially
bound to the relative addresses. It adds the relative address to address with relocation
register. It also takes into account limit register so that the reallocated address is within
the limit of available addresses.
6. Multiprocessor Memory Allocation: Memory is shared with two or more processor.
7. Memory Protection to OS functions: Memory protection to the OS functions means that
the system call and function call in user space are distinct. The OS function code, data
and stack are in the protected memory area. It means that when user function call attempts
to write or read exclusive memory space allocated to the OS functions, it is blocked and
the system generates error.
8. Memory protection among the tasks: Memory protection to the tasks means that a task
function call cannot attempt to write or read in the exclusive area of memory space
allocated to another task.

 Memory management functions


The memory mangers manages the following,
1. Use of memory addresses space by a process.
2. Specific mechanisms to share the memory space.
3. Specific mechanisms to restrict sharing of a given memory space.
4. Optimization of the access periods of a memory by using a hierarchy of memory.

5|P ag e
ADIT Embedded systems

Q. Device management
 Software that manages the device drivers of each device. Provides and executes the
modules for managing the devices and their drivers ISRs.
 Effectively operates and adopts appropriate strategy for obtaining optimal performance
for the devices. Coordinates between application-process, driver and device-controller.
 Process sends a request to the driver by an interrupt; and the driver provides the actions
by executing an ISR.
 Device manager polls the requests at the devices and the actions occur as per their
priorities.
 Manages IO Interrupts (requests) queues. Creates an appropriate kernel interface and API
and that activates the control register specific actions of the device. Manages the physical
as well as virtual devices like the pipes and sockets through a common strategy.

Three types of device drivers:


1. Programmed I/Os by polling from each device its the service need from each device.
2. Interrupt(s) from the device drivers device ISR and
3. Device uses DMA operation used by the devices to access the memory.

 Device manager function


1. Device Detection and Addition
2. Device Deletion
3. Device Allocation and
4. Registration
5. Detaching and Deregistration
6. Restricting Device to a specific process
7. Device Sharing
8. Device control
9. Device Access Management
10. Device Buffer Management
11. Device Queue, Circular-queue or blocks of queues Management
12. Device drivers updating and upload of new device-functions
13. Backup and restoration

 Types of devices
1. Char devices and
2. Block devices
3. Network devices

 Command for device


1. Create and open: It creates and opens devices and configuring and initializing the device.
2. Write: Write into the device buffer or send output from the device.
3. Read: Read from the device buffer or read from the device.
4. Ioctl: Specified device configured for specific functions and given specific parameter

6|P ag e
ADIT Embedded systems

5. close and delete: close is for de-registering the deice from the system and delete is for the
close and detaching the device.

Q. RTOS task scheduling Models


There are two types of scheduler.
 Cooperative scheduling algorithm (Non preemptive scheduling algorithm)
 Cooperative Scheduling in the cyclic order
Each task cooperates to let the running task finish. Cooperative means that each task
cooperates to let the running one finish. None of the tasks does block in-between anywhere
during the ready to finish states. The service is in the cyclic order.
 Worst Worst-case latency
 Same for every task
 Tworst= {(sti+ eti)1+ (sti+ eti)2+...+ (sti+ eti)N-1+ (sti+ eti)N} + tISR.
 tISR is the sum of all execution times for the ISRs.
 For an ith task, switching time from one task to another be is sti and task execution time
be is eti, Where, i = 1, 2, …, N −1 , N, when number of task.s = N

 Program counter assignments (switch) at different times, when the on the scheduler calls
the tasks from the list one by one in the circular queue from the list.

First three tasks among N-tasks in washing machine tasks scheduling.

 Cooperative Scheduling of Ready Tasks in List


None of the tasks does block in-between anywhere during the ready to finish states. The
service is in the order in which a task is initiated on interrupt.
 Worst Worst-case latency
 Same for every task in the ready list
 Tworst= {(dti+ sti+ eti)1+ (dti+ sti+ eti)2+...+ (dti+ sti+ eti)n-1+ (dti+ sti+ eti)n} + tISR.
 tISR is the sum of all execution times for the ISRs

7|P ag e
ADIT Embedded systems

 For an ith task, let the event detection time with when an event is brought into a list be is
dti, switching time from one task to another be is sti and task execution time be is eti,
Where, i = 1, 2, …, n −1 , n
 Scheduler in which the scheduler inserts into a list the ready tasks for a sequential
execution in a cooperative mode.

 Cooperative Scheduling of Ready Tasks Using an Ordered List as per precedence


Constraints
 Scheduler using a priority parameter, task Priority does the ordering of list of the tasks
ordering according to the precedence of the interrupt sources and tasks.
 The scheduler first executes only the first task at the ordered list, and the total, equals to
period taken by the first task on at the list. It is deleted from the list after the first task is
executed and the next task becomes the first.
 The insertions and deletions for forming the ordered list are made only at the beginning of
the cycle for each list.
 Worst-case latency
 Not Same for every task. Varies from (dti+ sti+ eti) p(m)} + tISR to {(dti+ sti+ eti)p1+
(dti+ sti+ eti) p2+...+ (dti+ sti + eti) p(m-1) + (dti + sti + eti ) p(m)} + tISR.
 tISR is the sum of all execution times for the ISRs.
 For an ith task, let the event detection time with when an event is brought into a list be is
dti, switching time from one task to another be is sti and task execution time be is eti.,
Where, i = 1, 2, …, m −1 , m; m is number of ISRs and tasks in the list.

 Cyclic and round robin scheduling


 Cyclic Scheduling Periodic tasks

8|P ag e
ADIT Embedded systems

 Time Periodic Scheduling in the cyclic order


Assume periodically occurring three tasks. Let in time-frames allotted to the,
 first task, the task executes at t1, t1 + Tcycle, t1+ 2 ×Tcycle, ..,
 second task frames at t2, t2 + Tcycle, t2+ 2 ×Tcycle and
 third task at t3, t3 + Tcycle, t3+ 2 ×Tcycle, ….

 Start of a time frame is the scheduling point for the next task in the cycle. Tcycle is the
cycle for repeating cycle of execution of tasks in order 1, 2 and 3 and equals start of task
1 time frame to end of task 3 frame. Tcycle is period after which each task time frame
allotted to that repeats.
 Then each task is executed once and finishes in one cycle itself. When a task finishes the
execution before the maximum time it can takes, there is a waiting period in-between
period between two cycles.
 The worst-case latency for any task is then N ×Sum of the maximum times for each task.
A task may periodically need execution. A task period for the its need of required repeat
execution of a task is an integral multiple of tcycle.
Example of Video and audio signals,
 Signals reaching at the ports in a multimedia system and processed. The video frames
reach at the rate of 25 in one second. The cyclic scheduler is used in this case to process
video and audio with Tcycle= 40 ms or in multiples of 40 ms.

 Round robin with time slicing scheduling


 Round robin means that each ready task runs turn by in turn only in a cyclic queue for a
limited time slice. Widely used model in traditional OS.
 Round robin is a hybrid model of clock-driven model (for example cyclic model) as well
as event driven (for example, preemptive).
 A real time system responds to the event within a bound time limit and within an explicit
time.
 Tasks programs contexts at the five instances in the Time Scheduling Scheduler for C1 to
C5

 Program counter assignments on the scheduler call to tasks at two consecutive time slices.
Each cycle takes time = N ×tslice

9|P ag e
ADIT Embedded systems

 Same for every task = Tcycle


 Tcycle={Tslice)}×N + tISR.
 tISR is the sum of all execution times for the ISRs
 For an ith task, switching time from one task to another be is stand task execution time be
is et
 Number of tasks = N

 Worst case latency


 Same for every task in the ready list
 Tworst= {N ×(Tslice)} + tISR.
 tISRis the sum of all execution times for the ISRs where, i = 1, 2, …, N −1 , N

 Preemptive scheduling model


 Difficulties in cooperative and cyclic scheduling of tasks
 Cooperative schedulers schedule such that each ready task cooperates to let the running
one finish.
 However, a difficulty in case of the cooperative scheduling is that a long execution time
of a low-priority task lets a high priority task waits at least until that that finishes.
 Difficulty when the cooperative scheduler is cyclic but without a predefined
tslice─Assume that an interrupt for service from first task occurs just at the beginning of
the second task. The first task service waits till all other remaining listed or queued tasks
finish. Worst case latency equals the sum of execution times of all tasks.
 Preemptive scheduling
 OS schedules such that higher priority task, when ready, preempts a lower priority by
blocking.
 Solves the problem of large worst case latency for high priority tasks.
 Processes execute such that scheduler provides for preemption of lower priority process
by higher priority process.
 Assume priority of task_1 > task_2> task_3 > task_4…. > task N
 Each task has an infinite loop from start (Idle state) up to finish.
 Task 1 last instruction points to the next pointed address, *next. In case of the infinite
loop, *next points to the same task 1 start.

10 | P a g e
ADIT Embedded systems

 Program counter assignments on the a scheduler call to preempt task 2. when priority of
task_1 > task_2 > task_3

 Worst-case latency
 Not Same for every task
 Highest priority task latency smallest
 Lowest priority task latency highest

 RTOS method for Preemptive Scheduling of tasks


 Each task design is like as an independent program, in an infinite loop between the task
ready place and the finish place.
 The task does not return to the scheduler, as a function does.
 Within the loop, the actions and transitions are according to the events or flags or tokens.

When priority of task_1 > task_2 > task_3


1. At RTOS start, scheduler sends a message (Task_Switch_Flag) to task 1 to go to un-
blocked state and run, and thus highest priority task 1 runs at start.
2. When task 1 blocks due to need of some input or wait for IPC or delay for certain period,
a message (Task_Switch_Flag) will be sent to RTOS, task 1 context saves and the RTOS
now sends a message (Task_Switch_Flag) to task 2 to go to un-blocked state and run.
3. Task 2 now runs on retrieving the context of task 2. When it blocks due to need of some
input or wait for IPC or delay for certain period, a message (Task_Switch_Flag) will be
sent to RTOS, task 2 context saves and an RTOS message (Task_Switch_Flag) makes the
task 3 in un-blocked state. Task 3 will run now after retrieving the context of task 3.
4. If during running of task 3, either task 2 or task 1 becomes ready with the required input
or IPC or delay period is over, task 3 is preempted, a message (Task_Switch_Flag) will
be sent to RTOS, task 3 context saves, and task 1, and if task 1 not ready, then task 2 runs
after retrieving the context of task 2.
5. A message (Task_Switch_Flag) is sent to RTOS after task 2 blocks due to wait of IPC or
need of sum input and task 2 context saves and task 1 if ready then task 1 runs on
retrieving the context of task 1
6. task 1 if not ready then task 3 runs on retrieving the context of task 3
7. Task 1 when ready to run preempts tasks 2 and 3, and Task 2 when ready to run preempts
task 3

 Earlier deadline first (EDF) and Rate monolithic scheduling


 It is given in hand written lecture notes.

11 | P a g e
ADIT Embedded systems

 Fixed (Static) real time scheduling


Every task is allotted fixed schedules to run. Let, there m task and m real time clock
interrupts, the scheduler can thus assign each task a fixed schedule. The OS is supposed to
define hard real time schedules for each task.
A scheduler is said to be using fixed time scheduling method when the schedule is static and
deterministic. The working environment is unaltered when processes are scheduled on the
single CPU of the system.
The OS scheduler can thus schedule each task at fixed times so that none misses its deadline.
Schedules once defined remain static in fixed time scheduler.

 Fixed schedules can be defined by one of the three methods.


1. 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 interrupt timer setting till the simulation result shows that none is missing its
deadline.
2. Heuristic method: Here, reasoning or past experience helps to define and fix the
schedules.
3. Dynamic programming model: A specific running program first determines the
schedules for each task and then the timer interrupt load the timer setting from the outputs
from that program.

Q. OS security issue and security function


When an OS has to supervise multiple process and their access to the resource,
protection f memory and resources from any unauthorized writes into the PCB or resources or
mix up of accesses of one by another become imperative. The OS security issue is a critical
issue.
The OS should provide protection mechanism and implement a system administration
defined security policy.
Functions Activities
Controlled resource sharing Controlling read and writes of the resource and parameters by
user processes.
For example, some resources write only for a process and
some read only for a set of processes
Another example, memory buffer to which one process writes
at an instant till that buffer is emptied by other process
Confinement mechanism Mechanism that restricts sharing of parameters to a set of
processes only .
Security policy Rules for authorizing access to the OS, system and
information.
A policy example is that a communication system may having
a policy of peer-to-peer communication (connection
establishment preceding the data packets flow).
Authentication mechanism External authentication mechanism for the user and a
mechanism meant to prevent an application run unless the user
registers and the system administrator (software) authorizes.
Internal authentication for the process, and the process should

12 | P a g e
ADIT Embedded systems

not appear (impersonate) as some like other processes.


User authentication can become difficult if the user
disseminates password passwords or other authentication
methods.
Authorization mechanism User or process (s) allowed to use the system resources as per
the security policy.
Encryption A tool to change information to make it unusable by any other
user or process unless without the appropriate key is used for
deciphering it.

13 | P a g e

You might also like