Operating systems
Transcript of Operating systems
Basics of Operating Systems
Prof. Anish Goel
What are operating systems? Operating systems are software environments that
provide a buffer between the user and the low levelinterfaces to the hardware within a system.
They provide a constant interface and a set of utilities toenable users to utilise the system quickly and efficiently.
They allow software to be moved from one system toanother and therefore can make application programshardware independent.
Many applications do not require any operating systemsupport at all and run direct on the hardware.
2 Operating Systems Anish Goel
Hardware independence through the use of an operating system
3 Operating Systems Anish Goel
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 applicationsimmediately delegate these tasks to an operating system.
The delegation decreases software development time byproviding system calls to enable application softwareaccess to any of the I/O system facilities.
These calls are typically made by building a parameterblock, loading a specified register with its location andthen executing a software interrupt instruction
4 Operating Systems Anish Goel
Typical system call mechanism for the M680x0 processor family
5 Operating Systems Anish Goel
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 intosupervisor mode to execute the required function.
It effectively provides a communication path between theapplication and the operating system kernel.
The kernel is the heart of the operating system whichcontrols the hardware and deals with interrupts, memoryusage, I/O systems etc.
It locates a parameter block by using an address pointerstored in a predetermined address register
It takes the commands stored in a parameter block andexecutes them.
6 Operating Systems Anish Goel
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 (basicdisk operating system) and BIOS (basic I/O system)
CP/M is a good example of a single tasking operatingsystem.
Only one task or application can be executed at any onetime 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
Program overlays
8 Operating Systems Anish Goel
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
What is OS ?
Operating Systems Anish Goel10
Basic structure of OS
Operating Systems Anish Goel11
RTOS Concepts
Operating Systems Anish Goel12
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 )
Foreground/Background.
Operating Systems Anish Goel13
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 processA process which executes without user interaction.
Interactive processA process which requires user interaction while executing
Kernel
Operating Systems Anish Goel14
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 schedulingn Kernel - a microkernel with intertask synchronizationn 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
What is RTOS?
Operating Systems Anish Goel15
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
Desirable Features of Real-Time Systems
Operating Systems Anish Goel16
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
Multitasking
Operating Systems Anish Goel17
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
Categories
Operating Systems Anish Goel18
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.
Real-Time Systems
Operating Systems Anish Goel19
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
Basic requirements of an RTOS.
Operating Systems Anish Goel20
(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.
Basic requirements of an RTOS
Operating Systems Anish Goel21
priority inversionoccurs 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
Operating Systems Anish Goel22
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.
Dynamic Memory Allocation
Operating Systems Anish Goel23
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 StackStack : Last-in-first-out (LIFO) data structure
RTOS requires multiple stacks - one for each task
Memory Management
Operating Systems Anish Goel24
Two issues Heap management Stack management
Heap management Classic heap Priority heap Fixed block heap
Memory Management
Operating Systems Anish Goel25
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
Stack management:
Operating Systems Anish Goel26
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
Task and Task Control Blocks
Operating Systems Anish Goel27
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
Priorities
Operating Systems Anish Goel28
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
Scheduling algorithms of RTOS
Operating Systems Anish Goel29
The most commonly used static schedulingalgorithm is the Rate MonotonicRate 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.