Unit 5 Real Time Operating System
Unit 5 Real Time Operating System
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.
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).
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).
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.
Types of devices
1. Char devices and
2. Block devices
3. Network devices
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.
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.
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.
8|P ag e
ADIT Embedded systems
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.
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
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
11 | P a g e
ADIT Embedded systems
12 | P a g e
ADIT Embedded systems
13 | P a g e