Unit-2 Os
Unit-2 Os
Interrupt Handling
The occurrence of an event is usually signaled by an interrupt from either the hardware or
the software.
Hardware may trigger an interrupt at any time by sending a signal to the CPU,usually by
way of the systembus.
Software may trigger an interrupt by executing a special operation called a system call
(also called a monitor call).
Interrupt transfers control to the interrupt service routine generally, through the
interrupt vector, which contains the addresses of all the service routines
Interrupt architecture must save the address of the interrupted instruction
The operating system preserves the state of the CPU by storing registers and the program
counter
After the interrupt is serviced, the saved return address is loaded into the program
counter, and the interrupted computation resumes as though the interrupt had not
occurred.
A trap or exception is a software-generated interrupt caused either by an error or a user
request
An operating system is interrupt driven
2
Storage Structure
Main memory – only large storage media that the CPU can access directly
o Random access
o Typically volatile
Secondary storage – extension of main memory that provides large nonvolatile storage
capacity
o Hard disks – rigid metal or glass platters covered with magnetic recording material
Disk surface is logically divided into tracks, which are subdivided into
sectors
The disk controller determines the logical interaction between the device
and the computer
Storage systems organized based
o Speed
o Cost
o Volatility
Caching – copying information into faster storage system; main memory can be viewed as
a cache for secondary storage
Information in use copied from slower to faster storage temporarily
I/O Structure
I/O devices and the CPU can execute concurrently
3
Each device controller has a local buffer
The device controller is responsible for moving the data between the peripheral
Typically, operating systems have a device driver for each device controller
To start an I/O operation, the device driver loads the appropriate registers within the
device controller. The device controller, in turn, examines the contents of these registers to
determine what action to take (such as “read a character from the keyboard”).
The controller starts the transfer of data from the device to its local buffer. Once the
transfer of data is complete, the device controller informs the device driver via an interrupt
that it has finished its operation. The device driver then returns control to the operating
system, possibly returning the data or a pointer to the data if the operation was a read.
This form of interrupt-driven I/O is fine for moving small amounts of data but can
Transfers an entire block of data directly to or from its own buffer storage to memory, with
While the device controller is performing these operations, the CPU is available to
4
Computer-System Architecture
Most systems use a single general-purpose processor
o Most systems have special-purpose processors as well
Single-Processor Systems
On a single processor system, there is one main CPU capable of executing a general-
purpose instruction set, including instructions from user processes.
Almost all single processor systems have other special-purpose processors as well.
They may come in the form of device-specific processors, such as disk, keyboard, and
graphics controllers; or, on mainframes, they may come in the form of more general-
purpose processors, such as I/O processors that move data rapidly among the components
of the system.
For example : PCs contain a microprocessor in the keyboard to convert the keystrokes into
codes to be sent to the CPU.
The use of special-purpose microprocessors is common and does not turn a single-
processor system into a multiprocessor. If there is only one general-purpose CPU,
then the system is a single-processor system.
Multiprocessors systems
Multiprocessors systems growing in use and importance
o Also known as parallel systems, tightly-coupled systems
o Advantages include:
Increased throughput
Economy of scale
Increased reliability – graceful degradation or fault tolerance
o Two types:
Asymmetric Multiprocessing –in which each processor is assigned a specific task. A boss
processor controls the system; the other processors either look to the boss for instruction or
have predefined tasks. This scheme defines a boss–worker relationship. The boss processor
schedules and allocates work to the worker processors.
Symmetric Multiprocessing – which each processor performs all tasks within the operating
system. SMP means that all processors are peers; no boss–worker relationship exists between
processors.
Multiprocessing can cause a system to change its memory access model from uniform memory
access UMA) to non-uniform memory access(NUMA).
UMA is defined as the situation in which access to any RAM from any CPU takes the
same amount of time.
5
With NUMA, some parts of memory may take longer to access than other parts, creating a
performance penalty
Symmetric Multiprocessing Architecture
A Dual-Core Design
o Multi-chip and multicore
o Systems containing all chips
Chassis containing multiple separate systems
Clustered Systems
Like multiprocessor systems, but multiple systems working together
o Usually sharing storage via a storage-area network (SAN)
Clustered systems :they are composed of two or more individual systems—or nodes—
joined together. Such systems are considered loosely coupled. Each node may be a
single processor system or a multicore system.
In symmetric clustering: two or more hosts are running applications and are
monitoring each other. This structure is obviously more efficient, as it uses all of the
available hardware.
Some clusters are for high-performance computing (HPC) :Such systems can supply
significantly greater computational power than single-processor or even SMP systems
because they can run an application concurrently on all computers in the cluster.
6
The application must have been written specifically to take advantage of the
cluster, however. This involves a technique known as parallelization, which
divides a Program into separate components that run in parallel on individual
computers in the cluster.
Operating-System Operations
Operating systems are interrupt driven
Events are almost always signaled by the occurrence of an interrupt or a trap
(hardware and software)
Hardware interrupt by one of the devices
Software interrupt (exception or trap):
Software error (e.g., division by zero)
Request for operating system service
Other process problems include infinite loop, processes modifying each
other or the operating system
Dual-mode operation allows OS to protect itself and other system components
User mode and kernel mode
A bit, called the mode bit, is added to the hardware of the computer to indicate
the current mode: kernel (0) or user (1).
At system boot time, the hardware starts in kernel mode.
Whenever a trap or interrupt occurs, the hardware switches from user mode to
kernel mode
The system always switches to user mode (by setting the mode bit to 1) before
passing control to a user program.
protecting the operating system from users—and users from one another.
7
Transition from User to Kernel Mode
Timer to prevent infinite loop / process hogging resources
Timer is set to interrupt the computer after some time period
Keep a counter that is decremented by the physical clock.
Operating system set the counter (privileged instruction)
When counter zero generate an interrupt
Set up before scheduling process to regain control or terminate program that
exceeds allotted time
8
Debugging facilities can greatly enhance the user’s and programmer’s
abilities to efficiently use the system
o Resource allocation - When multiple users or multiple jobs running concurrently,
resources must be allocated to each of them
Many types of resources - CPU cycles, main memory, file storage, I/O
devices.
o Accounting - To keep track of which users use how much and what kinds of
computer resources
o Protection and security - The owners of information stored in a multiuser or
networked computer system may want to control use of that information,
concurrent processes should not interfere with each other
Protection involves ensuring that all access to system resources is
controlled
Security of the system from outsiders requires user authentication, extends
to defending external I/O devices from invalid access attempts
A View of Operating System Services
SYSTEM CALLS
System provides interface between the process & the OS.
The calls are generally available as assembly language instruction & certain system allow system
calls to be made directly from a high level language program.
Several language have been defined to replace assembly language program.
A system call instruction generates an interrupt and allows OS to gain control of the processors.
PASSING PARAMETERS TO OS
9
Three general methods are used to pass the parameters to the OS.
The simplest approach is to pass the parameters in registers. In some there can be more
parameters than register. In these the parameters are generally in a block or table in m/y
and the address of the block is passed as parameters in register. This approach used by
Linux.
Parameters can also be placed or pushed onto stack by the program & popped off the
stack by the OS.
Some OS prefer the block or stack methods, because those approaches do not limit the
number or length of parameters being passed.
System calls may be grouped roughly into 5 categories
1. Process control.
2. File management.
3. Device management.
4. Information maintenance.
5. Communication.
Process control
o create process, terminate o wait event, signal event
process o allocate and free memory
o end, abort o Dump memory if error
o load, execute o Debugger for determining
o get process attributes, set bugs, single step execution
process attributes o Locks for managing access to
o wait for time shared data between processes
File management
o create file, delete file o read, write, reposition
o open, close file o get and set file attributes
Device management
o request device, release device o logically attach or detach
o read, write, reposition devices
o get device attributes, set
device attributes
Information maintenance
o get time or date, set time or date
o get system data, set system data
10
o get and set process, file, or device attributes
Communications
o create, delete communication connection
o send, receive messages if message passing model to host name or process name
From client to server
o Shared-memory model create and gain access to memory regions
o transfer status information
o attach and detach remote devices
Protection
o Control access to resources
o Get and set permissions
o Allow and deny user access
Examples of Windows and Unix System Calls
program invoking printf() library call, which calls write() system call
11
Operating System Structure
A system as large and complex as a modern operating system must be engineered carefully
if it is to function properly and be modified easily.
A common approach is to partition the task into small components, or modules,
Each of these modules should be a well- defined portion of the system, with carefully
defined inputs, outputs, and functions
Various ways to structure ones
o Simple structure – MS-DOS
o More complex -- UNIX
o Layered – an abstraction
o Microkernel -Mach
Simple Structure -- MS-DOS
Many operating systems do not have well-defined structures such systems started as
small, simple, and limited system
MS-DOS is an example of such a system
The interfaces and levels of functionality are not well separated
Application programs are able to access the basic I/O routines to write directly to the
display and disk drives
MS-DOS vulnerable to errant (or malicious) programs, causing entire system crashes
when user programs fail.
MS-DOS was also limited by the hardware
Intel 8088 for which it was written provides no dual mode and no hardware protection
12
Layered Approach
The operating system is divided into a number of layers (levels),
The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface.
The main advantage of the layered approach is simplicity of construction and
debugging and System verification
The design and implementation of the system are simplified.
Each layer hides the existence of certain data structures, operations, and hardware from
higher-level layers.
The major difficulty with the layered approach involves appropriately defining the
various layers. Because a layer can use only lower-level layers, careful planning is
necessary.
Microkernel
This method structures the operating system by removing all nonessential components
from the kernel and implementing them as system and user-level programs.
The result is a smaller kernel.
There is little consensus regarding which services should remain in the kernel and which
should be implemented in user space.
13
Microkernels provide minimal process and memory management, in addition to a
communication facility.
messages messages
microkernel
hardware
The main function of the microkernel is to provide communication between the client
program and the various services that are also running in user space.
Communication takes place between user modules using message passing
Benefits:
Easier to extend a microkernel without modification of the kernel
Portable from one hardware design to another
The microkernel also provides more security and reliability, since most services are
running as user—rather than kernel— processes.
If a service fails, the rest of the operating system remains untouched.
Detriments:
Performance of microkernels can suffer due to increased system-function overhead.
Modules
The best current methodology for operating-system design involves using loadable kernel
modules ,the kernel has a set of core components and links in additional services via
modules, either at boot time or during run time.
CPU scheduling and memory management algorithms directly into the kernel and
then add support for different file systems by way of loadable modules.
The Solaris operating system structure, is organized around a core kernel with seven
types of loadable kernel modules:
o Scheduling classes
o File systems
o Loadable system calls
14
o Executable formats
o STREAMS modules
o Miscellaneous
o Device and bus drivers
Hybrid Systems
Most modern operating systems are actually not one pure model
o Hybrid combines multiple approaches to address performance, security, usability
needs
o Linux and Solaris kernels in kernel address space, so monolithic, plus modular for
dynamic loading of functionality
o Windows mostly monolithic, plus microkernel for different subsystem
personalities
Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming environment
o Below is kernel consisting of Mach microkernel and BSD Unix parts, plus I/O kit
and dynamically loadable modules (called kernel extensions)
Mac OS X Structure
graphical user interface
Aqua
kernel environment
BSD
Mach
iOS
Apple mobile OS for iPhone, iPad
o Structured on Mac OS X, added functionality
o Does not run OS X applications natively
Also runs on different CPU architecture (ARM vs. Intel)
o Cocoa Touch Objective-C API for developing apps
o Media services layer for graphics, audio, video
15
o Core services provides cloud computing, databases
o Core operating system, based on Mac OS X kernel
Android
Developed by Open Handset Alliance (mostly Google)
o Open Source
Similar stack to IOS
Based on Linux kernel but modified
o Provides process, memory, device-driver management
o Adds power management
Runtime environment includes core set of libraries and Dalvik virtual machine
o Apps developed in Java plus Android API
Java class files compiled to Java bytecode then translated to executable than
runs in Dalvik VM
Libraries include frameworks for web browser (webkit), database (SQLite), multimedia,
smaller libc
Applications
Android Architecture
Application Framework
surface media
Dalvik
manager framework
virtual machine
webkit libc
Linux kernel
Operating System Generation
Operating systems are designed to run on any of a class of machines; the system must be
configured for each specific computer site
SYSGEN program obtains information concerning the specific configuration of the
hardware system
Used to build system-specific compiled kernel or system-tuned
16
Can general more efficient code than one general kernel
The following kinds of information must be determined.
What CPU is to be used? What options (extended instruction sets, floating point
arithmetic, and so on) are installed? For multiple CPU systems, each CPU may be
described.
How will the boot disk be formatted? How many sections, or “partitions,” swill
it be separated into, and what will go into each partition?
How much memory is available? Some systems will determine this value
themselves by referencing memory location after memory location until an “illegal
address” fault is generated. This procedure defines the final legal address and hence
the amount of available memory.
What devices are available? The system will need to know how to address each
device (the device number), the device interrupt number, the device’s type and model, and any
special device characteristics.
What operating-system options are desired, or what parameter values are to
be used? These options or values might include how many buffers of which sizes should be
used, what type of CPU-scheduling algorithm is desired, what the maximum number of
processes to be supported is, and so on.
System Boot
The procedure of starting a computer by loading the kernel is known as booting
the system.
Small piece of code known as the bootstrap program or bootstrap loader locates
the kernel, loads it into main memory, and starts its execution.
At that location is the initial bootstrap program. This program is in the form of
17
Run diagnostics to determine the state of the machine. If the diagnostics pass,
It can also initialize all aspects of the system, from CPU registers to device
CASE 1
Storing the operating system in ROM is suitable for small operating systems,
A problem with this approach is that changing the bootstrap code requires
changing the ROM hardware chips.
CASE 2:
is on disk.
In this case, the bootstrap runs diagnostics and has a bit of code that can read
a single block at a fixed location (say block zero) from disk into memory and
The program stored in the boot block may be enough to load the
18