Module 4
Module 4
4.1 INTRODUCTION
Specific computer using a particular language can be hidden from the designer. An operating
system for a given computer converts the hardware of the system into a virtual machine with
characteristics defined by the operating system. Operating systems were developed, as their name
implies, to assist the operator in running a batch processing computer; they then developed to
support both real-time systems and multi-access on-line systems. The traditional approach is to
incorporate all the requirements inside a general purpose operating system as illustrated in Figure
4.1. Access to the hardware of the system and to the I/O devices is through the operating system.
In many real-time and multi-programming systems restriction of access is enforced by hardware
and software traps.
A general purpose operating system will provide some facilities that are not required in a
particular application, and to be forced to include them adds unnecessarily to the system
overheads. Usually during the installation of an operating system certain features can be selected
or omitted. A general purpose operating system can thus be 'tailored' to meet a specific application
requirement. Recently operating systems which provide only a minimum kernel or nucleus have
become popular; additional features can be added by the applications programmer writing in a
high-level language. This structure is shown in Figure 4.2. In this type of operating system the
distinction between the operating system and the application software becomes blurred. The
approach has many advantages for applications that involve small, embedded systems.
Although at any given instance it is not possible to predict which user will have the use of
the CPU, or even if the user's code is in the memory, the operating system ensures that one user
program cannot interfere with the operation of another user program. Each user program runs in its
MITMysore | Dept of Electronics and Communication Engineering
own protected environment. A primary concern of the operating system is to prevent one program,
A real-time multi-tasking operating system has to support the resource sharing and the timing
requirements of the tasks and the functions can be divided as follows:
Task management: the allocation of memory and processor time (scheduling) to tasks.
Memory management: control of memory allocation.
Resource control: control of all shared resources other than memory and CPU time.
Intertask communication and synchronization: provision of support mechanisms to provide
safe communication between tasks and to enable tasks to synchronize their activities.
MITMysore | Dept of Electronics and Communication Engineering
Cyclic
The first of these, cyclic, allocates the CPU to a task in turn. The task uses the CPU for as long as
it wishes. When it no longer requires it the scheduler allocates it to the next task in the list. This is
a very simple strategy which is highly efficient in that it minimizes the time lost in switching
between tasks. It is an effective strategy for small embedded 'systems for which the execution
times for each task run are carefully calculated (often by counting the number of machine
instruction cycles for. the task) and for which the software is carefully divided into appropriate
task
MITMysore segments.
| Dept In general this
of Electronics andapproach is too restrictive
Communication since it requires that the task units have
Engineering
similar execution times. It is also difficult to deal with random events using this method.
When a task requests a delay its status is changed from runnable to suspend and remains
suspended until the delay period has elapsed. One method of implementing the delay function is to
use a queue of task descriptors, say identified by the name DELAYED. This queue is an ordered
list of task descriptors, the task at the front of the by the name DELAYED. This queue is an
ordered list of task descriptors, the task at the front of the queue being that whose next running
time is nearest to the current time.
4.4.3 Base level:
The tasks at the base level are initiated on demand rather than at some predetermined time
interval. The demand may be user input from a terminal, some process event or some particular
requirement of the data being processed. The way in which the tasks at the base level are
scheduled can vary; one the data being processed. The way in which the tasks at the base level are
scheduled can vary; one simple way is to use time slicing on a round-robin basis. In this method
each task in the runnable queue is selected in turn and allowed to run until either it suspends or the
base level scheduler is again entered. For real-time work in which there is usually some element of
priority this is not a particularly satisfactory solution. It would not be sensible to hold up a task,
which had been delayed waiting for a relay to close but was now ready to run, in order to let the
logging task run.
Most
MITMysore | Dept of real-time systems
Electronics and use a priority strategy
Communication even for the base level tasks. This may be
Engineering
either a fixed level of priority or a variable level. The difficulty with a fixed level of priority is
Active (running): this is the task which has control of the CPU. It will normally be
the task with the highest priority of the tasks which are ready to run.
Ready (runnable, on): there may be several tasks in this state. The attribute of the
task and the resources required to run the task must be available for the task to be
placed in the Ready state.
• Suspended (waiting, locked out, delayed): the execution of tasks placed this state
has been suspended because the task requires some resource which is not available or
because the task is waiting for some signal from the plant for example input from the
analog-to-digital converter, or because the task is waiting for the elapse of time.
• Existent (dormant, off): the operating system is aware of the existence of this task,
but the task has not been allocated a priority and has not been made runnable.
• Non-existent (terminated): the operating system has not as yet been made aware of
the existence of this task, although it may be resident in the. Memory of the computer.
MITMysore | Dept of Electronics and Communication Engineering
The range of system commands affecting task status varies with the operating system. Typical
states and commands are shown in Figure 6.12 and fuller details of the commands are given in
Table. Note that this system distinguishes between tasks which are suspended awaiting the passage
of time - these tasks are marked as delayed - and those tasks which are waiting for an event or a
system resource these are marked as locked out. The system does not explicitly support base level
tasks; however, the lowest four priority levels of the clock level tasks can be used to create a base
level system A so - called free time executive (FTX) is provided which if used runs at priority
level n - 3 where n is the lowest-priority task number. The FTX is used to run tasks at priority
levels n - 2, n - I and n; it also provides support for the chaining of tasks. The dispatcher is
unaware of the fact that tasks at these three priority levels are being changed; it simply treats
whichever tasks are in the lowest three priority levels as low-priority tasks. Tasks run under the
MITMysore
FTX| Dept ofhave
do not Electronics andsystem
access to the Communication Engineering
commands (except OFFCO1 that is turn task off).
In response to the first condition the scheduler searches for work starting with the highest-
priority task and checking each task in priority order (see Figure 6.14). Thus if tasks with a high
repetition rate are given a high priority they will be treated as if they were clock level tasks, that is
they will be run first during each system clock period. In response to the second condition a search
for work is started at the task with the next lowest priority to the task which has just been running.
There cannot be another higher-priority task ready to run since a higher-priority task becoming
ready always pre-empts a lower-priority-running task. The system commands for task management
are issued as calls from the assembly level language and the parameters are passed either in the
MITMysore
CPU| Dept of Electronics
registers and
or as a control Communication
word Engineering
immediately following the call statement.
The available memory is divided into predetermined segments and the tasks are loaded
individually into the various segments. The load operation would normally be carried out using to
command processor. With this type of system the entries in the TD (or the operation system tables)
have to be made from the console using a memory examine as change facility. Divided
(partitioned) memory was widely used in many early real-time operating systems and it was
frequently extended to allow several tasks to share on:
partition; the tasks were kept on the backing store and loaded into the appropriate partition
when required. There was of course a need to keep any tasks in which timing was crucial (hard
time constraint tasks) in fast access memory permanent other tasks could be swapped
between fast memory and backing store. The difficulty with this method is, of course, in choosing
the best mix of partition sizes. The partition size and boundaries have to be determined at system
generation.
As shown in Figure, some form of lock mechanism is placed at the beginning of the routine
such that if any task is already using the routine the calling task will not be allowed entry until the
task which is using the routine unlocks it. The use of a lock mechanism to protect a subroutine is
an example of the need for mechanisms to support mutual exclusion when constructing an
operating system.
If the subroutine-can be coded such that it does not hold within it any data that is it is
purely code - any intermediate results are stored in the calling task or in a stack associated with the
task - then the subroutine is said to be re-entrant. Figure shows an arrangement which can be used:
the task descriptor for each task contains a pointer to a data area - usually a stack area - which is
used for the storage of all information relevant to that task when using the subroutine. Swapping
between tasks while they are using the subroutine will not now cause any problems since the
contents of the stack pointer will be saved with the volatile environment of the task and will be
restored when the task resumes.
All accesses to data by the subroutine will be through the stack and hence it will
automatically manipulate the correct data. Re-entrant routines can be shared between several tasks
since they contain no data relevant to a particular task and hence can be stopped and restarted at a
different point in the routine without any loss of information. The data held in the working
registers of the CPU is stored in the relevant task descriptor when task swapping takes place.
Device drivers in conventional operating systems are frequently implemented using re-entrant
code. The PID control1er code segment uses the information in the LOOP descriptor and the T
ASK to calculate the control value and to send it to the control1er. The actual task is made up of
the LOOP descriptor, the TASK segment and the PID control code segment. The addition of
another loop to the system requires the provision of new loop descriptors; the actual PID control
code remains unchanged.
2. Real-Time Systems Design and Analysis, Phillip. A. Laplante, Second Edition, PHI,
2005.