Chapter-1 Introduction to , System Structures Agenda (classes 1-4) v What Operating Systems Do v Computer-System Organization v Computer-System Architecture v Operating-System Structure v Operating-System Operations v Management v Memory Management v Storage Management v Protection and Security v Distributed Systems v Special-Purpose Systems v Computing E nvironments

PHE NOM9 What Operating Systems Do v Operating system is a software that controls and manages the computer hardware. v Operating system acts as an interface between user and hardware of a computer system. v Operating system provides an environment for execution of a program in convenient and efficient way.

PHE NOM9 What Operating Systems Do v A program that acts as an intermediary between a user of a computer and the computer hardware.

PHE NOM9 What Operating Systems Do: Goals v User Computations Execute user programs and make solving user problems easier v Utilization Efficiency To ensure good resource utilization efficiency and provide appropriate corrective actions when it becomes low v User Convenience Make the computer system convenient to use

PHE NOM9 Four Components of a Computer System

PHE NOM9 Four Components of a Computer System v Hardware provides basic computing resources CPU, memory, I/O devices

v Operating system Controls and coordinates use of hardware among various applications and users

PHE NOM9 Four Components of a Computer System v Application programs define the ways in which the system resources are used to solve the computing problems of the users

Word processors, compilers, web browsers, database systems, video games

v Users People, machines, other computers

PHE NOM9 Operating System: Different Views

v User view Personal Computer: Ease of use, performance Mainframe: Resource utilization v System view Resource allocator Control program

PHE NOM9 System View

v OS is a resource allocator Manages all resources Decides between conflicting requests for efficient and fair resource use v OS is a control program Controls execution of programs to prevent errors and improper use of the computer

PHE NOM9 Defining Operating System v “The one program running at all times on the computer” is the kernel. v Everything else is either a system program (ships with the operating system) or an application program

PHE NOM9 Computer System Organization

Computer-system operation Storage Structure  I/O Structure

PHE NOM9 Computer-System Operation

PHE NOM9 Computer-System Operation

v bootstrap program is loaded at power-up or reboot

It is stored in ROM or EEPROM, generally known as firmware It initializes all aspects of system Loads operating system kernel, starts executing first process ‘init’ and waits for some event to occur.

PHE NOM9 Computer-System Operation v One or more CPUs and device controllers are connected through common bus providing access to shared memory I/O devices and the CPU can execute concurrently. v Each device controller is in-charge of a particular device type. v Each device controller has a local buffer. v CPU moves data from/to main memory to/from local buffers

PHE NOM9 Computer-System Operation v The occurrence of an event is signaled by an interrupt from either hardware or software. v Hardware may trigger an interrupt by sending a signal through system bus. v Software may trigger an interrupt through system calls. v When the CPU is interrupted, it stops what it is doing and transfers the execution to a fixed location.

PHE NOM9 Computer-System Operation v The fixed location contains the interrupt vector, which contains the addresses of all the service routines. v Related interrupt service routine is executed. v On completion, CPU resumes the previous interrupted process. v Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt. v An operating system is interrupt driven.

PHE NOM9 Computer-System Operation

PHE NOM9 Storage Structure: H ierarchy

PHE NOM9 Storage Structure: Hierarchy

v Storage systems organized in hierarchy. Speed Cost Volatility v Main memory is only large storage media that the CPU can access directly (semi-conductor) v Secondary storage provides large nonvolatile storage capacity

PHE NOM9 Storage Structure: Main Memory

It is implemented in a semiconductor technology called Dynamic Random Access Memory (DRAM) which forms an array of words. Each word has its own address and can be interacted through Load and Store Load: moves a word from main memory to internal register Store: moves a word from internal register to main memory

PHE NOM9 Storage Structure: Caching

v Information in use is copied from slower to faster storage temporarily v Faster storage (cache) is checked first to determine if information is there If it is, information is used directly from the cache (fast) If not, data is copied to cache and used

PHE NOM9 Storage Structure v Magnetic disks are 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.

PHE NOM9 Storage Structure: E lectronic Disk v Electronic disks can be volatile or non-volatile v It stores data in large DRAM array which is volatile. v Many electronic disk devices contain a hidden magnetic hard disk and battery for back up. v If power is interrupted, electronic disk controller copies the data from RAM to magnetic disc. v When external power is resumed, controller copies data from magnetic disk back to RAM

PHE NOM9 Storage Structure: E lectronic Disk v Another form of Electronic disks is flash memory which is popular in Camera, Robots etc. v NVRAM: DRAM with battery backup

PHE NOM9 I/ O Structure v A computer system may have multiple device controller, each device controller is in-charge of a specific type of device. v A device controller maintains some local buffer storage and a set of special purpose registers. v The device controller is responsible for moving data between the device and local buffer. v OS has a device driver for each device controller.

PHE NOM9 I/ O Structure v To start an I/O operation, the device driver loads the appropriate registers within the device controller. v Device controller examines the contents of these registers and works accordingly. e.g. if action is read a character from keyboard, device controller transfers the character from device to local buffer of the controller v Data transfer is complete, device controller informs the device driver through interrupt.

PHE NOM9 I/ O Structure: Direct Memory Access Structure

v DMA is used for high-speed I/O devices which are able to transmit information faster.

v Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention.

v Only one interrupt is generated per block, rather than the one interrupt per byte.

PHE NOM9 I/ O Structure

PHE NOM9 Operating System Structure

v On the basis of number of general purpose processors used, system can be of two types.

Single-processor systems Multiprocessor systems

PHE NOM9 Operating System Structure: Single-processor systems v Only one general purpose CPU executing general purpose instructions (user’s or system’s) v Systems may have other specific processors like processor for disk, for keyboard which can not execute user’s processes (not considered for general purpose execution) v These specific processors can execute only limited set of instructions.

PHE NOM9 Operating System Structure: Single-processor systems v OS can not communicate with these processors, they do work autonomously. v e.g. A disk-controller microprocessor receives a sequence of requests from the CPU and implements its own disk queue and scheduling algorithm. v Thus CPU is relieved from disk scheduling work.

PHE NOM9 Operating System Structure: Multiprocessor systems

v These are also known as parallel system or tightly coupled system. v Multiprocessor systems are with more than one CPU in close communication. v These processors share computer bus. v They may share memory and a clock and peripheral devices. v Communication takes place through the shared memory.

PHE NOM9 Operating System Structure: Multiprocessor systems v Advantages of parallel system: Increased throughput Economical Increased reliability

PHE NOM9 Operating System Structure: Multiprocessor systems v Increased throughput This speeds up the computation, but speed up ratio with N processors is less than N due to communication overhead and contention with shared resources. v Economical These cost less than multiple single-processor systems because they can share peripherals, mass storage, power supplies etc.

PHE NOM9 Operating System Structure: Multiprocessor systems v Increased reliability Failure of one processor will not halt the system, it will only slow down. Remaining processors will share the work. v Graceful degradation and fail-soft systems v Fault tolerant v It may have mechanism to allow the failure to be detected, diagnosed and corrected. v e.g. HP NonStop System

PHE NOM9 Operating System Structure: Multiprocessor systems v Asymmetric multiprocessing Each processor is assigned a specific task either predefined or instructed by master. Master processor schedules and allocate work to slave processors. This master-slave relationship is more common in extremely large systems

PHE NOM9 Operating System Structure: Multiprocessor systems v Symmetric multiprocessing (SMP) Each processor runs an identical copy of the operating system. All processors are peers. Many processes can run at once Most modern operating systems support SMP

PHE NOM9 Operating System Structure: Multiprocessor systems

Symmetric multiprocessing (SMP) architecture

PHE NOM9 Operating System Structure: Multiprocessor systems

v Symmetric multiprocessing (SMP) e.g. Solaris having dozens of processors N processors: N processes control I/O that data reach the right processor. equal distribution of the work will not allow any processor to be idle.

PHE NOM9 Operating System Structure: Multiprocessor systems v Symmetric and asymmetric multiprocessing v Difference between symmetric and asymmetric may be due to hardware or software Special hardware can differentiate the multiple processors. v Software can be written to allow one master and many slaves v SunOS version4 provided asymmetric whereas Solaris version5 is symmetric on same hardware.

PHE NOM9 Operating System Structure: Multiprocessor systems

v Recent Trends Multi-core chip: High end system Dual core: common in most systems

PHE NOM9 Clustered systems v Clustered systems are the combination of multiple CPUs to accomplish computational work. v Clustering allows two or more systems to share storage and are closely linked via LAN networking. v Provides high reliability & availability. v Some clusters are parallel clusters connected through WAN

PHE NOM9 Clustered systems v Asymmetric clustering one machine is in hot standby and other runs the application if active server fails standby becomes active.

v Symmetric clustering all N hosts are running the application and monitoring each other if one fails, others share the load of failed host.

PHE NOM9 Clustered systems v Oracle Parallel Server is a version of Oracle’s Database designed to run on a parallel cluster. v Each machine runs Oracle, and a layer of software tracks access to the shared data. v Each machine has full access to all data in the database. v To provide the shared access to data, the system supplies access control and locking to ensure that no conflicting operations occur. v This function is known as Distributed Lock Manager (DLM) and included in cluster technology.

PHE NOM9 Operating System Structure: Multiprogramming v Needed for efficiency v Single user cannot keep CPU and I/O devices busy at all times v Multiprogramming organizes jobs (code and data) so CPU always has one to execute v A subset of total jobs in system is kept in memory v One job is selected and run via job scheduling v When it has to wait (for I/O for example), OS switches to another job and so on

PHE NOM9 Operating System Structure: Multiprogramming

PHE NOM9 Operating System Structure: Multiprogramming (E xample)

P1 idle P1 idle P1 P2 idle P2 idle P2 a) Sequential execution

Program 1

Program 2 P1 P2 P1 P2 P1 P2 PHE NOM9 b) Multiprogram Operating System Structure: Multiprogramming

v I/O routine is supplied by system to many programs. v CPU scheduling: the system must choose one job among several jobs ready to run. v Allocation of devices should be done efficiently and fairly.

PHE NOM9 Operating System Structure: Timesharing (multitasking) v Time-Sharing is a logical extension of Multiprogramming where many users share the system simultaneously. v The CPU executes several jobs that are kept in memory by switching among them. v CPU switching is so fast that the user can interact with each program while it is running.

PHE NOM9 Operating System Structure: Timesharing (multitasking) v Response time is < 1 second v Few processes should be available v Several jobs are ready to be brought in memory job scheduling v Several jobs ready to run at the same time CPU scheduling v If processes don’t fit in memory, swapping moves them in and out from the memory memory management v Virtual memory allows execution of processes not completely in memory PHENOM9 Operating-System Operations v OS is interrupt driven v A trap or exception is a software generated interrupt Division by zero or invalid memory access Other process problems include infinite loop Request for operating system service v For each type of interrupt, a service routine is responsible in OS

PHENOM9 Operating-System Operations: Dual mode Operation v As OS and users share hardware and software, they should not interfere in each other operations. v Dual-mode operation allows OS to protect itself and other system components User mode Kernel mode or system mode or privileged mode v A bit, mode bit, is added to computer hardware to indicate the current mode Kernel (0) User (1)

PHENOM9 Operating-System Operations: Dual mode Operation v When a user process requests a service from OS via a system call, it transit from user mode to kernel mode to fulfill the request v At boot time, hardware starts in kernel mode, then OS is loaded (mode bit = 0) v Then OS starts user applications in user mode (mode bit = 1) v Whenever a trap or interrupt occurs, hardware switches from user to kernel mode (mode bit = 0)

PHENOM9 Operating-System Operations: Dual mode Operation v When a user process requests a service from OS via a system call, it transit from user mode to kernel mode to fulfill the request v Mode bit provided by hardware Provides the means for protecting the OS from erroneous programs and erroneous programs from each other. Provides ability to distinguish when system is running user mode or kernel mode Some instructions designated as privileged, only executable in kernel mode

PHENOM9 Operating-System Operations: Dual mode Operation v If any attempt is made to execute privileged instructions in user mode, hardware does not execute these instructions and treats as traps MS-DOS written for Intel 8088 architecture which has no mode bit and therefore no dual mode. A user program may wipe the OS by writing over it. v Pentium provides dual mode; and Windows, Linux, Solaris make use of the feature and provide protection to OS

PHENOM9 Operating-System Operations: Transition from User to Kernel Mode

PHENOM9 Operating-System Operations: Timer v A user program should not stuck in infinite loop i.e. not returning to OS. v Timer can be used to prevent infinite loop or process hogging resources v A timer can be set to interrupt the computer after a specified period. v The period may be fixed (1/60 sec) or variable (from 1 milisecond to 1 second)

PHENOM9 Operating-System Operations: Timer v A variable timer is implemented by a clock and a counter v At each click OS decrements counter v At 0, an interrupt occurs v Set up timer before scheduling process to regain control or terminate program that exceeds allotted time

PHENOM9 Process Management v A program in execution is process v Process is a unit of work within the system. v Program is a passive entity, process is an active entity. v Process needs resources to accomplish its task CPU, memory, I/O, files Initialization data passed (input) v Process termination requires reclaim of any reusable resources

PHENOM9 Process Management v Single-threaded process has one program counter specifying location of next instruction to execute Process executes instructions sequentially, one at a time, until completion v Multi-threaded process has one program counter per v Typically system has many processes,some operating system running concurrently on one or more CPUs

PHENOM9 Process Management: Activities v The operating system is responsible for the following activities in connection with process management Creating and deleting both user and system processes Suspending and resuming processes Providing mechanisms

• Process synchronization

• Process communication

• Deadlock handling

PHENOM9 Memory Management v Memory is large array of bytes, each byte having its address. v CPU reads instructions from main memory during the instruction-fetch cycle. v CPU reads and writes from main memory during data- fetch cycle v All data and instructions should be transferred to memory in order to be processed and executed by CPU v After processing data must be transferred to memory v Once a process is terminated, memory space is declared available for other processes.

PHENOM9 Memory Management v Memory management helps to improve CPU utilization and computer response to multiple users by managing memory needs among multiple processes v Different memory schemes and related hardware are used in memory management. v Memory management activities Deciding which processes are to be loaded when memory space becomes available. Keeping track of parts of memory used by different processes. Allocating and deallocating memory space as needed

PHENOM9 Storage Management: File-System management v OS provides uniform logical view of information storage to make computer system convenient for users Computer can store information on several different physical media like magnetic disk, optical disk etc. Each medium is controlled by device drive (i.e., disk drive, tape drive)

PHENOM9 Storage Management: File-System management

v A file is a collection of related information defined by its creator v Files represent programs (both source and object forms) and data v Files are usually organized into directories

PHENOM9 Storage Management: File-System management v The operating system is responsible for the following activities in connections with file management

Creating and deleting files and directories Primitives to manipulate files and directories Mapping files onto secondary storage Backing up files on stable (non-volatile) storage media

PHENOM9 Storage Management: Mass-Storage Management v Since main memory (primary storage) is volatile and too small to accommodate all data and programs permanently, the computer system must provide secondary storage to back up main memory. v Most modern computer systems use disks as the principle storage medium, for both programs and data. v Proper management is of central importance

PHENOM9 Storage Management: Mass-Storage Management v The operating system is responsible for the following activities in connection with disk management: Storage allocation / deallocation Disk scheduling Free space management v Some storage need not be fast Tertiary storage includes optical storage, magnetic tape but must be managed These vary between WORM (write-once, read-many-times) and RW (read-write)

PHENOM9 Storage Management: Caching v Information in use copied from slower to faster storage temporarily i.e. in cache v Faster storage (cache) checked first to determine if information is present If it is, information used directly from the cache (fast) If not, data copied to cache from memory v Due to limited size cache management is very important. v Selection of appropriate cache size and replacement policy can result in high performance.

PHENOM9 Storage Management: Caching v Internal programmable registers (index registers) also provide a high speed cache for main memory. v The programmer or compiler implements register- allocation and register replacement algorithms to decide which information is to keep in register and which is to keep in main memory. v There are also cache implemented in hardware like instruction cache holding next instruction to be executed

PHENOM9 Storage Management: Caching

Performance of various levels of storage

PHENOM9 Storage Management: Caching v The movement of information between levels of a hierarchy may be either through hardware or through OS like Data transfer from cache to CPU and register is hardware function Data transfer from disk to memory is OS function.

Migration of integer A from disk to register

PHENOM9 Storage Management: Caching v Multitasking environments must be careful to use most recent value of data v Multiprocessor environment must provide cache coherence in hardware such that all CPUs have the most recent value in their cache v Distributed environment situation even more complex Several copies of a datum can exist and must be updated immediately

PHENOM9 Storage Management: I/ O Subsystem v One purpose of OS is to hide peculiarities of hardware devices from the user v I/O subsystem responsible for Memory management of I/O including buffering (storing data temporarily while it is being transferred), caching (storing parts of data in faster storage for performance), spooling (the overlapping of output of one job with input of other jobs) General device-driver interface Drivers for specific hardware devices

PHENOM9 Protection and Security v Protection – any mechanism for controlling access of processes or resources defined by the OS v Security – defense of the system against internal and external attacks denial-of-service, worms, viruses, identity theft, theft of service

PHENOM9 Protection and Security v Systems first distinguish among users, to determine who can do what User identities (user IDs or security IDs) include security number, one per user User ID then associated with all files, processes of that user to determine access control Group identifier (group ID) allows set of users to be defined and controls managed, then also associated with each process, file Privilege escalation allows user to change to effective ID with more rights

PHENOM9 Distributed Systems v A distributed system is a collection of physically separate, heterogeneous computer systems that are connected to provide the access to various resources v These processors that do not share memory or a clock. v Each processor has its own local memory. v The processors in the system are connected through a communication network. v Network vary by the protocol used, distance between nodes and transport media.

PHENOM9 Distributed Systems v These systems distribute the computation among several physical processors. v These systems depend on networking for their functionality. v Require networking infrastructure like Local area networks (LAN) or Wide area networks (WAN) v A network OS provides file sharing across the network and includes a communication scheme that allows different processes on different computers to exchange messages.

PHENOM9 Distributed Systems v Also known as loosely coupled system v Networking Wired: Copper wires, Optic fibers etc. Wireless: Satellite, Microwave etc. v Advantages of distributed systems Resources Sharing Computation speed up due to load sharing Reliability Communications

PHENOM9 Special Purpose Systems: Real-Time E mbedded Systems v Embedded systems provide very specific task. v Systems have very little or no , thus OS generally monitor and manage hardware devices. v OS required for such systems provide limited features.

PHENOM9 Special Purpose Systems: Real-Time E mbedded Systems v A real time system is used to provide rigid time requirements and often used as a control device in a dedicated application. v Sensors bring data to the computer and system control is adjusted accordingly. v Examples: v Microwave oven, robot, car engine v Controlling scientific experiments, medical imaging systems, industrial control systems etc.

PHENOM9 Special Purpose Systems: Multimedia Systems v Multimedia data consists of audio or video. v Frames of video should be delivered under time restriction in a particular sequence. v Multimedia applications: Video clips on internet, video-conferencing Live webcasts over WWW

PHENOM9 Special purpose Systems: Handheld Systems v Personal Digital Assistants (PDAs) v Cellular telephones v Many such systems use special purpose embedded operating system v Issues related to handheld systems: Limited memory Slow processors Small display screens.

PHENOM9 Special purpose Systems: Handheld Systems v Limited memory Mostly between 512 KB and 126 KB, thus OS and applications must manage memory efficiently v Slow processors Not as fast as in PC, (fast processor need more power thus large battery, faster recharge are needed) v Small display screens Small keyboard, output screen v Wireless or Wired connection Web pages through Web clipping

PHENOM9 Computing E nvironments: Traditional computing v Old office environment PCs connected to a network with servers providing files and print services. Remote access was awkward. Portability through laptops. Terminals attached to mainframe with few remote access

PHENOM9 Computing E nvironments: Traditional computing v Now portals allowing networked and remote systems access to same resources v Handheld PDAs can access office information through wireless connection v Home networks Used to be single system with slow modems Now firewalled, networked, high speed

PHENOM9 Computing E nvironments: Client-Server Computing v Centralized architecture moved towards client server architecture v Many systems serve as servers responding to requests generated by clients Compute-server provides an interface to client to request services (e.g. database, server having specific software) File-server provides interface for clients to store and retrieve files (e.g. web server)

PHENOM9 Computing E nvironments: Client-Server Computing

PHENOM9 Computing E nvironments: Peer-to-Peer Computing v Another model of distributed system v P2P does not distinguish nodes as clients and servers All nodes are considered peers Each may act as client or server or both v P2P is advantageous over client-server In client-server, server may be bottleneck In P2P, services can be provided by many nodes avoiding bottleneck at one node.

PHENOM9 Computing E nvironments: Peer-to-Peer Computing v Each node must join P2P network Central lookup Each node registers its service with central lookup service on network Any node desiring a specific service contacts lookup to know the node providing the service. Broadcast Node request for service and respond to requests for service via discovery protocol v Examples include Napster (central lookup) and Gnutella (broadcast)

PHENOM9 Peer-to-Peer Computing: Web based Computing v Web has become very important today. v PCs, PDAs, cell phones are most prevalent access devices to allow web access. v Networking is through wired or wireless. v New category of devices to manage web traffic among similar servers: load balancers. v Operating systems like Windows 95 which acted web client, have evolved into Linux and Windows XP, which can be clients or servers or both

PHENOM9 Questions v What is operating system? Discuss the goals of it. v Discuss the user and system views for an operating system. v What is multiprogramming? What are the main advantages of multiprogramming? v Discuss dual mode operation of operating system. v Differentiate between asymmetric and symmetric multiprocessor systems. v Explain the following: i)Multiprocessor Systems ii) Iii) Time-sharing system

PHENOM9 Questions v Differentiate between single processor and multi- processor systems. v Discuss and differentiate Client-Server and Peer-to-Peer Computing. v Explain various computing environment. Write short notes on the following: v i)Real-Time Embedded Systems v ii)Multimedia Systems iii)Handheld Systems iv)Distributed Systems

PHENOM9 End of the Chapter-1 (part-1)

PHENOM9