2. What are operating systems?
Operating systems are software environments that
provide a buffer between the user and the low level
interfaces to the hardware within a system.
They provide a constant interface and a set of utilities to
enable users to utilise the system quickly and efficiently.
They allow software to be moved from one system to
another and therefore can make application programs
hardware independent.
Many applications do not require any operating system
support at all and run direct on the hardware.
2 Operating Systems Anish Goel
4. Non OS systems
Such software includes its own I/O routines, for example,
to drive serial and parallel ports.
With the addition of mass storage and the complexities
of disk access and file structures, most applications
immediately delegate these tasks to an operating system.
The delegation decreases software development time by
providing system calls to enable application software
access to any of the I/O system facilities.
These calls are typically made by building a parameter
block, loading a specified register with its location and
then executing a software interrupt instruction
4 Operating Systems Anish Goel
5. Typical system call mechanism for the
M680x0 processor family
5 Operating Systems Anish Goel
6. Typical system call mechanism for the
M680x0 processor family…
The TRAP instruction is the MC68000 family equivalent
of the software interrupt and switches the processor into
supervisor mode to execute the required function.
It effectively provides a communication path between the
application and the operating system kernel.
The kernel is the heart of the operating system which
controls the hardware and deals with interrupts, memory
usage, I/O systems etc.
It locates a parameter block by using an address pointer
stored in a predetermined address register
It takes the commands stored in a parameter block and
executes them.
6 Operating Systems Anish Goel
7. Operating system internals
The first widely used operating system was CP/M,
developed for the Intel 8080 microprocessor and 8"
floppy disk systems.
It supported I/O calls by two jump tables — BDOS (basic
disk operating system) and BIOS (basic I/O system)
CP/M is a good example of a single tasking operating
system.
Only one task or application can be executed at any one
time and therefore it only supports one user at a time.
When an application is loaded, it provides the user-
defined part of the total ‘CP/M’ program.
7 Operating Systems Anish Goel
9. Program overlays
Any application program has to be complete and
therefore the available memory often becomes the
limiting factor
Program overlays are often used to solve this problem.
Parts of the complete program are stored separately on
disk and retrieved and loaded over an unused code area
when needed
This allows applications larger than the available memory
to run, but it places the control responsibility on the
application.
9 Operating Systems Anish Goel
12. RTOS Concepts
What Does Real-Time Mean?
Main difference to other computation: time
time means that correctness of system depends
- not only on logical results
- but also on the time the results are produced
real => reaction to external events must occur
during their evolution.
system time ( internal time ) has to be measured
with same time scale as controlled environment
( external time )
12 Operating Systems Anish Goel
13. Foreground/Background.
Systems which do not use an RTOS
An application consist of an infinite loop which calls
application modules to perform the desired operations.
The modules are executed sequentially with interrupt
service routines (ISRs) handling asynchronous events .
Batch process
A process which executes without user interaction.
Interactive process
A process which requires user interaction while
executing
13 Operating Systems Anish Goel
14. Kernel
l Kernel: the smallest portion of the operating system that
provides
l task scheduling, dispatching, and intertask communication.
l Kernel types
n Nanokernel - the dispatcher
n Microkernel - a nanokernel with task scheduling
n Kernel - a microkernel with intertask synchronization
n Executive - a kernel that includes privatized memory blocks,
I/O services, and other complex issues. Most commercial real-
time kernels are in this category.
n Operating system - an executive that also provides generalized
user interface, security, file management system, etc
14 Operating Systems Anish Goel
15. What is RTOS?
A real-time operating system (RTOS) that supports
real-time applications and embedded systems.
Real-time applications have the requirement to meet
task deadlines in addition to the logical correctness of
the results.
– Multiple events handled by a single processor
– Events may occur simultaneously
– Processor must handle multiple, often
competing events
15 Operating Systems Anish Goel
16. Desirable Features of Real-Time Systems
Timeliness
- OS has to provide kernel mechanisms for
- time management
- handling tasks with explicit time constraints
Deterministic
Design for peak load
Predictability
Fault tolerance
Maintainability
16 Operating Systems Anish Goel
17. Multitasking
Must provide mechanisms for scheduling and
switching for several user and kernel tasks
Maximize CPU utilization
Allow for managing of complex and real-time
applications
17 Operating Systems Anish Goel
18. Categories
Hard Real Time System:
failure to meet time constraints leads to system failure
Firm Real Time System:
low occurrence of missing a deadline can be tolerated
Soft Real Time System:
performance is degraded by failure to meet time
constraints
An RTOS differs from common OS, in that the user when
using the former has the ability to directly access the
microprocessor and peripherals.
Such an ability of the RTOS helps to meet deadlines.
18 Operating Systems Anish Goel
19. Real-Time Systems
RTOS is a multitasking system where multiple tasks
run concurrently
– system shifts from task to task
– must remember key registers of each task
• called its context
RTOS responsible for all activities related to a task:
– scheduling and dispatching
– intertask communication
– memory system management
– input/output system management
– timing
– error management
– message management
19 Operating Systems Anish Goel
20. Basic requirements of an RTOS.
(i) Multi-threading and preemptibility
(ii) Thread priority
(iii) Thread synchronization mechanisms
(iv) Priority inheritance
(v) Predefined latencies
Task switching latency: time to save the context of a
currently executing task and switch to another task..
Interrupt latency: time elapsed between the execution
of the last instruction of the interrupted task and the first
instruction in the interrupt handler
Interrupt dispatch latency: This is the time to go
from the last instruction in the interrupt handler to the
next task scheduled to run.
20 Operating Systems Anish Goel
21. Basic requirements of an RTOS
priority inversion
occurs when a higher priority task must wait on a low priority
task to release a resource
Priority Ceiling
Each resource has an assigned priority
Priority of thread is the highest of all priorities of the resources
it’s holding
Priority Inheritance
The thread holding a resource inherits the priority of the thread
blocked on that resource
21 Operating Systems Anish Goel
22. Preemptive scheduling.
In a preemptive kernel, when an event makes a higher priority task ready to
run, the current task is immediately suspended and the higher priority task
is given control of the CPU.
Reentrancy.
reentrant function : can be used by more than one task without fear of data
corruption.
non-reentrant function : cannot be shared by more than one task unless
mutual exclusion to the function is ensured by either using a semaphore, by
disabling interrupts during critical sections of code.
A reentrant function can be interrupted at any time and resumed at a later
time without loss of data.
Reentrant functions either use local variables (CPU registers or variables on
the stack) or protect their data when global variables are used.
Compilers specifically designed for embedded software will generally provide
reentrant run-time libraries.
22 Operating Systems Anish Goel
23. Dynamic Memory Allocation
RTOS uses abstract data types such as record, linked
list, and queue
These data types normally use RAM dynamic memory
allocation techniques
Data structures are created (allocated) on the fly during
program execution and destroyed when no longer
needed
– Requires large RAM memory
Heap is portion of memory used for dynamic memory
allocation
Must allocate separate RAM spaces for the Heap as well
as the Stack
Stack : Last-in-first-out (LIFO) data structure
RTOS requires multiple stacks - one for each task
23 Operating Systems Anish Goel
25. Memory Management
Classic heap
The memory is collected into one giant heap and partitioned
according to the demand from tasks.
There are several “fit” memory allocation algorithms, e.g., best-fit,
first-fit, that also attempt to minimize the memory fragmentation.
Has a big management overhead so is not used in real-time
systems
Priority heap
partitions the memory along priority boundaries, e.g., a high and a
low priority partitions are created
Fixed block heap
partitions the memory into several pools of fixed block length
and upon a request, allocates a single block of memory from the
pool with size equal or larger than the requested amount
25 Operating Systems Anish Goel
26. Stack management:
When multiple tasks share a single processor, their contexts
(volatile information such as the contents of hardware registers,
memory-management registers, and the program counter)
need to be saved and restored so as to switch them.
This can be done using
task-control block model OR one or more run-time stacks
Run-time stacks
- used to keep context
may use only one run-time stack for all the tasks or one run-time
stack in conjunction with several application stacks (or private
stacks), one for each task in memory
Multiple stack case allows tasks to interrupt themselves,
Stack size must be known a priori.
Operating system manages the stacks
26 Operating Systems Anish Goel
27. Task and Task Control Blocks
In RTOS program consists of
independent,asynchronous, and interacting tasks
– Must have capability to store task context
Context is kept in the control block of the task.
Having multiple tasks means multiple control blocks, which are
maintained in a list
• RTOS updates TCB when task is switched
best for full-featured real-time operating systems
Device Control Block (DCB)
– tracks status of system associated devices
27 Operating Systems Anish Goel
28. Priorities
Priority
An ordinal number which represents the relative
importance of a task.
Static priority
A priority which is not automatically adjusted by the
system.
Static priority can typically be changed by user.
Dynamic priority
A priority which is adjusted automatically by the system
according to task behavior and system loading.
Dynamic priority imposes an overhead on the system.
Dynamic priority can improve response times and
eliminate indefinite postponing
28 Operating Systems Anish Goel
29. Scheduling algorithms of RTOS
The most commonly used static scheduling
algorithm is the Rate Monotonic (RM) scheduling
algorithm
The RM algorithm assigns different priorities
proportional to the frequency of tasks.
The task with the shortest period gets the highest
priority, and the task with the longest period gets
the lowest static priority.
Rate monotonic algorithm is a dynamic preemptive
algorithm based on static priorities
RM algorithm provides no support for dynamically
changing task periods and/or priorities and tasks
that may experience priority inversion.
29 Operating Systems Anish Goel