Академический Документы
Профессиональный Документы
Культура Документы
705 RTOS
Module 3
1. Machine layer:
Lowest level and directly interact with hardware.
Written in assembly language.
Not visible to users.
Deals with context switching, interrupt handling, timer handling etc.
Page 1
08.705 RTOS
Module 3
Page 2
08.705 RTOS
Module 3
its period. Such state does not exist in the system, but it continues to occupy processor
bandwidth. An illustration is shown below:
A more complete state transition diagram including all these states is illustrated below:
Page 3
08.705 RTOS
Module 3
In DICK, RECEIVE and DELAY states are not present. It has SLEEP state which is used to
activate or sleep aperiodic tasks.
An aperiodic task enters the SLEEP state by executing the sleep primitive and a task exits the
SLEEP state and goes to the READY state only when an explicit activation is performed by
another task.
Data Structures:
TCB
The information about a task are stored in a data structure, called Task Control Block(TCB).
TCB contains all the parameters specified by the programmer at creation time, and other
temporary information necessary to the kernel for managing the task.
Typical fields of a TCB in real-time system are:
1. Task identifier: It is a character string used by the system to refer the task in messages to the
user,
2. Task address: The memory address corresponding to the first instruction of the task.
3. Task type: The task type (periodic, aperiodic, or sporadic).
4. Task criticalness: The task criticality (hard, soft, or non-real-time).
5. Task priority: The priority (or value), which represents the importance of the task with
respect to the other tasks of the application.
6. Task state: The current state (ready, running, idle, waiting, and so on).
7. Task computation time: The worst-case execution time ( Ci ).
8. The task period: The period of periodic task.
9. The relative deadline: The deadline specified by the user.
10. The absolute deadline: The absolute deadline computed by the kernel at the arrival time.
11. The task utilization factor (only for periodic tasks).
Department of ECE, VKCET
Page 4
08.705 RTOS
SCB
Module 3
In DICK, SCB is an element of the vsem[MAXSEM] array, whose size is equal to the maximum
number of semaphores handled by the kernel.
Kernel Primitives
They are used for implementing the kernel services at different levels.
Different kernel primitives are:
1. Low level primitives
2. List management primitives
3. Scheduling mechanism primitives
4. Task management primitives
5. Semaphores primitives
6. Status enquiry primitives
Page 5
08.705 RTOS
Module 3
Page 6
08.705 RTOS
Module 3
Page 7
08.705 RTOS
Module 3
extract: It extract a task from the queue. Its illustration is shown below:
getfirst: It extract a task from the head of the queue. Its illustration is shown below:
Page 8
08.705 RTOS
Module 3
firstdline: It returns the deadline of the first task. Its illustration is shown below:
Page 9
08.705 RTOS
Module 3
dispatch: It assigns the CPU to the first ready task. Its illustration is:
wake_up: It is the ISR performs the activities for time management. It increments the sys_clock variable,
checks for system lifetime and possible deadline misses, remove those tasks in zombie state and resume
those periodic tasks in idle state at the beginning of their next period. Its illustration is shown below:
Page 10
08.705 RTOS
Module 3
Page 11
08.705 RTOS
Module 3
guarantee: It guarantees the feasibility of a hard task. Its illustration is shown below:
Page 12
08.705 RTOS
Module 3
Page 13
08.705 RTOS
Module 3
Semaphores primitives:
In DICK, synchronization and mutual exclusion are handled by semaphores.
There are four primitives are provided: newsem, delsem, wait and signal
newsem: It allocates a free semaphore control block and initializes the counter field to the value passed as
a parameter.
delsem: It deallocates the semaphore and inserting it in the list of free semaphores.
wait: It is used by a task to wait for an event associated with a semaphore. If the semaphore counter is
positive, it is decremented, and the task continues its execution; if the counter is less than or equal to zero,
the task is blocked, and it is inserted in the semaphore queue. In this case, the first ready task is assigned
to the processor by the dispatch primitive.
signal: It is used by a task to signal an event associated with a semaphore.
Status inquiry primitives:
These primitives are for inquiring the kernel about internal variables and task parameters.
get_time: It returns the system time in milliseconds.
get_state: It returns the state of a task.
Page 14
08.705 RTOS
Module 3
In a pure asynchronous scheme, communicating tasks do not have to wait for each other. The
sender just deposits its message into a channel and continues its execution, independently of the
recipient condition.
Asynchronous communication schemes are more suitable for dynamic real-time systems.
In most commercial RTOS, the asynchronous communication scheme is implemented through a
mailbox mechanism as shown below:
Page 15
08.705 RTOS
Module 3
Two basic operations are provided on a mailbox: send and receive. A send(MX, mes) operation
causes the message mes to be inserted in the queue of mailbox MX. If at least a message is
contained on mailbox MX,a receive(MX, mes) operation extracts the first message from its
queue.
Mailbox provides only a partial solution to the problem of asynchronous communication, since it
has a bounded capacity. Thus, if the queue is full, the sender must be delayed until some message
is received. If the queue is empty, the receiver must wait until some message is inserted.
Cyclic Asynchronous Buffers (CAB)
Avoid the limitation of mailbox for asynchronous communication.
CAB provides a one-to-many communication channel, which at any instant contains the latest
message or data inserted in it.
A message is not consumed by a receiving process but is maintained into the CAB structure until
a new message is overwritten.
As a consequence, once the first message has been put in a CAB, a task can never be blocked
during a receive operation. Similarly, since a new message overwrites the old one, a sender can
never be blocked.
In this a message can be read more than once if the receiver is faster than the sender, while
messages can be lost if the sender is faster than the receiver. This is not a problem in many
control applications; where tasks are require current data rather than previous ones.
CAB primitives are: open_cab for create and initial CAB, delete_cab to remove a CAB from the
system and releases the memory space.
The data structure used to implement a CAB is shown below:
CAB control block contains: max_buf store maximum number of buffers, dim_buff
dimension of buffer, free a pointer to a list of free buffer and mrb pointer to recent buffer.
Each buffer in the CAB can be implemented as a data structure with three field: next a pointer
to maintain a list of free buffers, use stores the current number of task accessing that buffer and
data - a memory area for storing message.
Page 16
08.705 RTOS
Module 3
System overhead
The overhead of an OS represents the time used by the processor for handling all kernel
mechanisms, such as enqueueing tasks, performing context switches, updating the internal data
structures, sending messages to communication channels, servicing the interrupt requests, and so
on.
The time required to perform these operations is usually much smaller than the execution times of
the application tasks. So it can be negligible comparing to execution time of application tasks.
If execution time of tasks is very small and has tight timing constraints, then activities performed
by the kernel may not be so negligible and may create significant interference on the tasks
execution.
In such situations, predictability can be achieved only by considering the effects of the runtime
overhead in the schedulability analysis.
Different overhead factors are:
1. Context switching: One of the most significant overhead factors in any OS. It is an intrinsic
limit of the kernel that does not depend on the specific scheduling algorithm, nor on the
structure of the application tasks.
2. Execution time of ISR: It is another important overhead factor in real-time system. If Q is the
system tick (ie the period of the interrupt request from the timer) and is the worst-case
execution time of the ISR, then timer overhead can be computed as the utilization factor Ut of
an equivalent periodic task.
The illustration shows the execution interval due to the timer routine and execution
intervals necessary for a context switch.
The effect of ISR schedulability of a periodic task also takes for task utilization factor Ut.
The net bound of utilization factor becomes
Page 17
08.705 RTOS
Module 3
The overhead due to other kernel mechanisms can also be taken for the performance. It is like the
context switches during the execution of kernel primitives.
If Ni is the maximum number of preemptions that a periodic task of period Ti and is the time
needed to perform a context switch, the total utilization factor is given as,
Where Up is the utilization factor of the periodic task set and Uov is a correction factor that
considers the effects of thr ISR and the preemption overhead due to context switches.
Case study of RTOS
QNX Neutrino 2 RTOS
It is commercial RTOS with very small kernels (micro kernel) with a memory footprint of a few
kilobytes
It provides support for concurrency through processes and/or threads.
Applications: Mission-critical applications like medical instruments, Internet routers, telematics
devices, process control applications, air traffic control systems etc.
QNX Neutrino microkernel implements only the most fundamental services in the kernel, such as
signals, timers, and scheduling.
All other components file systems, drivers, protocol stacks, applications run outside the kernel, in
a memory-protected user space. Due to this, a faulty component can be automatically restarted
without affecting other components or the kernel.
Some of the real-time features include distributed priority inheritance to eliminate priority
inversion and nested interrupts to allow priority driven interrupt handling.
All components communicate via message passing, which allows the user to dynamically plug in,
or plug out, any component during execution.
Department of ECE, VKCET
Page 18
08.705 RTOS
Module 3
It provides support for transparent distributed processing using standard messages to access
hardware and software resources on remote nodes.
QNX Neutrino also provides advanced graphics features to create visual applications for markets
such as automotive, medical, industrial automation and interactive gaming.
It also support accelerated 3D graphics allows for the creation of sophisticated displays with little
impact on CPU performance.
Micro C/OS II RTOS
COS stands Micro Controller OS. Also known as MUCOS or MicroCOS or UCOS.
Non-commercial use, freeware and available from Micrium.
It is a very small real-time kernel and requires only 20KB memory for a fully functional kernel.
Source code is written mostly in C.
Highly portable, ROMable, very scalable, preemptive real-time, deterministic, multitasking
kernel.
Applications: Automotive, avionics, consumer electronics, medical devices, military, aerospace,
networking, SoC development
An advantage of using this RTOS is full source code availability
It is simple to use and simple to implement but very effective compared to the price/performance
ratio.
It supports all type of processors from 8-bit to 64-bit.
MicroC/OS-II is the second generation of a kernel originally published (with source code)
Page 19