UNIT I OPERATING SYSTEMS OVERVIEW · Organization-Operating System Structure and Operations- System...

18
CS6401- Operating Systems 1 UNIT I OPERATING SYSTEMS OVERVIEW Computer System Overview-Basic Elements, Instruction Execution, Interrupts, Memory Hierarchy, Cache Memory, Direct Memory Access, Multiprocessor and Multicore Organization. Operating system overview-objectives and functions, Evolution of Operating System- Computer System Organization-Operating System Structure and Operations- System Calls, System Programs, OS Generation and System Boot. INTRODUCTION Definition of OS An operating system (OS) is a software program designed to act as an interface between the user and the computer. It is a collection of program and utilities. It controls the computer hardware, manages the system resources, and supervises the interaction between the system and the user. Example: DOS, LINUX, Windows etc., Computer System Overview-Basic Elements I/O Modules Moves data between the computer and external environments such as: storage (e.g. hard drive) communications equipment terminals System Bus Provides for communication among processors, main memory, and I/O modules Instruction Execution A program consists of a set of instructions stored in memory Two steps: Processor Controls the operation of the computer Performs the data processing functions Referred to as the Central Processing Unit (CPU) Main Memory Volatile Contents of the memory is lost when the computer is shut down Referred to as real memory or primary memory

Transcript of UNIT I OPERATING SYSTEMS OVERVIEW · Organization-Operating System Structure and Operations- System...

CS6401- Operating Systems

1

UNIT I OPERATING SYSTEMS OVERVIEW

Computer System Overview-Basic Elements, Instruction Execution, Interrupts, Memory Hierarchy, Cache Memory, Direct Memory Access, Multiprocessor and Multicore Organization. Operating system overview-objectives and functions, Evolution of Operating System- Computer System Organization-Operating System Structure and Operations- System Calls, System Programs, OS Generation and System Boot. INTRODUCTION Definition of OS An operating system (OS) is a software program designed to act as an interface between the user and the computer. It is a collection of program and utilities. It controls the computer hardware, manages the system resources, and supervises the interaction between the system and the user. Example: DOS, LINUX, Windows etc., Computer System Overview-Basic Elements

I/O Modules

• Moves data between the computer and external environments such as: • storage (e.g. hard drive) • communications equipment • terminals

System Bus • Provides for communication among processors, main memory, and I/O modules

Instruction Execution

• A program consists of a set of instructions stored in memory Two steps:

Processor • Controls the operation of the computer • Performs the data processing functions • Referred to as the Central Processing Unit

(CPU) Main Memory

• Volatile • Contents of the memory is lost when the

computer is shut down • Referred to as real memory or primary

memory

CS6401- Operating Systems

2

• processor reads (fetches) instructions from memory • processor executes each instruction

Basic Instruction Cycle

Instruction Fetch and Execute

• The processor fetches the instruction from memory • Program counter (PC) holds address of the instruction to be fetched next

• PC is incremented after each fetch Instruction Register (IR) Fetched instruction is loaded into Instruction Register (IR)

• Processor interprets the instruction and performs required action: • Processor-memory • Processor-I/O • Data processing • Control

Characteristics of a Hypothetical Machine

CS6401- Operating Systems

3

Example of Program Execution

Three instructions, which can be described as three fetch and three execute stages, are required: 1. The PC contains 300, the address of the first instruction. This instruction (the value 1940 in hexadecimal) is loaded into the IR and the PC is incremented. 2. The first 4 bits (first hexadecimal digit) in the IR indicate that the AC is to be loaded from memory. The remaining 12 bits (three hexadecimal digits) specify the address, which is 940. 3. The next instruction (5941) is fetched from location 301 and the PC is incremented. 4. The old contents of the AC and the contents of location 941 are added and the result is stored in the AC. 5. The next instruction (2941) is fetched from location 302 and the PC is incremented. 6. The contents of the AC are stored in location 941. Interrupts

• Interrupt the normal sequencing of the processor • Provided to improve processor utilization

• most I/O devices are slower than the processor • processor must pause to wait for device • wasteful use of the processor

CS6401- Operating Systems

4

Flow of Control Without Interrupts

The user program performs a series of WRITE calls interleaved with processing. Code segments 1, 2, and 3 refer to sequences of instructions that do not involve I/O. The WRITE calls are to an I/O routine The I/O program consists of three sections: • A sequence of instructions, labeled 4 in the figure, to prepare for the actual I/O operation. • The actual I/O command. Without the use of interrupts, once this command is issued, the program must wait for the I/O device to perform the requested function (or

CS6401- Operating Systems

5

periodically check the status, or poll, the I/O device). The program might wait by simply repeatedly performing a test operation to determine if the I/O operation is done. • A sequence of instructions, labeled 5 in the figure, to complete the operation. This may include setting a flag indicating the success or failure of the operation.

The dashed line represents the path of execution followed by the processor. Thus, after the first WRITE instruction is encountered, the user program is interrupted and execution continues with the I/O program. After the I/O program execution is complete, execution resumes in the user program immediately following the WRITE instruction.

Because the I/O operation may take a relatively long time to complete, the I/O program is hung up waiting for the operation to complete; hence, the user program is stopped at the point of the WRITE call for some considerable period of time. Without interrupts the user program reaches a point at which it makes a system call in the form of a WRITE call. The I/O program that is invoked in this case consists only of the preparation code and the actual I/O command. After these few instructions have been executed, control returns to the user program. With interrupts, the processor can be engaged in executing other instructions while an I/O operation is in progress. When the external device becomes ready to be serviced, that is, when it is ready to accept more data from the processor, the I/O module for that external device sends an interrupt request signal to the processor. The processor responds by suspending operation of the current program; branching off to a routine to service. Transfer of Control via Interrupts

For the user program, an interrupt suspends the normal sequence of execution. When the interrupt processing is completed, execution resumes. Thus, the user program does not have to contain any special code to accommodate interrupts; the processor and the OS are responsible for suspending the user program and then resuming it at the same point.

CS6401- Operating Systems

6

Instruction cycle with Interrupts

In the interrupt stage, the processor checks to see if any interrupts have occurred, indicated by the presence of an interrupt signal. If no interrupts are pending, the processor proceeds to the fetch stage and fetches the next instruction of the current program. If an interrupt is pending, the processor suspends execution of the current program and executes an interrupthandler routine Simple Interrupt Processing 1. The device issues an interrupt signal to the processor. 2. The processor finishes execution of the current instruction before responding to the interrupt. 3. The processor tests for a pending interrupt request, determines that there is one, and sends an acknowledgment signal to the device that issued the interrupt. The acknowledgment allows the device to remove its interrupt signal. 4. The processor next needs to prepare to transfer control to the interrupt routine. To begin, it saves information needed to resume the current program at the point of interrupt. 5. The processor then loads the program counter with the entry location of the interrupt-handling routine that will respond to this interrupt Once the program counter has been loaded, the processor proceeds to the next instruction cycle, which begins with an instruction fetch. Because the instruction fetch is determined by the contents of the program counter, control is transferred to the interrupt-handler program. The execution of this program results in the following operations: 6. At this point, the program counter and PSW relating to the interrupted program have been saved on the control stack. However, there is other information that is considered part of the state of the executing program. In particular, the contents of the processor registers need to be saved, because these registers may be used by the interrupt handler. 7. The interrupt handler may now proceed to process the interrupt. This includes an examination of status information relating to the I/O operation or other event that caused an interrupt. It may also involve sending additional commands or acknowledgments to the I/O device.

CS6401- Operating Systems

7

8. When interrupt processing is complete, the saved register values are retrieved from the stack and restored to the registers. 9. The final act is to restore the PSW and program counter values from the stack. As a result, the next instruction to be executed will be from the previously interrupted program.

Multiple Interrupts

• An interrupt occurs while another interrupt is being processed e.g. receiving data from a communications line and printing results at the same time

Two approaches: • disable interrupts while an interrupt is being processed • use a priority scheme.

CS6401- Operating Systems

8

The Memory Hierarchy

Major constraints in memory amount speed expense

Memory must be able to keep up with the processor

Cost of memory must be reasonable in relationship to the other components A variety of technologies are used to implement memory systems, and across this spectrum of technologies, the following relationships hold:

• Faster access time, greater cost per bit • Greater capacity, smaller cost per bit • Greater capacity, slower access speed

Computer System Components

1. Hardware – provides basic computing resources (CPU, memory, I/O devices). 2. Operating system – controls and coordinates the use of the hardware among the

various application programs for the various users. 3. Applications programs – define the ways in which the system resources are used

to solve the computing problems of the users (compilers, database systems, video games, business programs).

4. Users (people, machines, other computers).

Going down the hierarchy:

decreasing cost per bit

increasing capacity

increasing access time

decreasing frequency of

access to the memory by

the processor

CS6401- Operating Systems

9

Abstract View of System Components Evolution of Operating System

There are two basic types of operating system – single-user and multi-user. A multi-user operating system handles multiple users as well as multiple peripheral devices simultaneously. Such an operating system is more than single-user OS. Single user systems: A personal computer is a popular single user system. The PC is a small general-purpose system that can execute programs to perform a wide verity of tasks. Multi-user system: When a number of programs have to be run simultaneously or common resources like printers and disks are to be shared by a number of users. Serial Processing: In 1950’s programmer directly interact with hardware. If a programmer wish to execute a program the following steps are maintained.

1. Type the program on the punch cards. 2. Convert the punch card to card reader 3. Then submitting to computing machine If it founds any error, the error condition

was indicated by light 4. The programmer examines the register and main memory to identify the cause of

the error. 5. Take the output on the printer 6. The system is ready to execute next program.

This type of operation termed as processing. It is difficult for users, it takes much time and next program should wait for the completion of previous task. The programs are executed one after other is known as serial processing. Drawbacks:

1. It is difficult to execute a program using computer 2. It takes much time to execute a single program 3. CPU is idle, when the currently running process is waiting for some i/o

Mainframe System This type of computer system is use for commercial and scientific application. An operating system may process its workload serially or concurrently. The resources of a computer system may be dedicated to a single program until its completion or they may be dynamically reassigned among a collection of active programs in different stages of executions. Batch systems: Batch operating systems is one where programs and data are collected together in a batch before processing starts. A job is predefined sequence of commands, programs and data that are combined into a single unit called JOB. Memory management in batch system is

CS6401- Operating Systems

10

very simple. Memory is usually divided into two areas: Operating system and user program area. Scheduling is also simple in batch systems. When a job completes execution,its memory is released and the output for the job gets copied into an output spool for later printing.

Memory Layouts for a Simple Batch System Advantages of batch system

1. Move much of the work of the operator to the computer. 2. Increased performance since it was possible for job to start as soon as the previous

job finished. Disadvantages of batch system

1. Turn around time can be large from user standpoint. 2. Difficult to debug program. 3. A job could enter an infinite loop. 4. A job could corrupt the monitor, thus affecting pending jobs. 5. Due to lack of protection scheme, one batch job can affect pending jobs.

Spooling: A spooling stands for simultaneous pheripheral operation on line.

Disk

Card Reader CPU Printer Spooling Computer can perform I/o in parellel with computation,its becomes possible to have the computer read a deck of cards to a tape,drum or disk and to write a out to a tape printer while it was computing ,hence this process is called spooling.The most common spooling application is print spooling.

CS6401- Operating Systems

11

Multi Programmed systems When two or more programs are in memory at a same time that shares the processor is referred to the multiprogramming operating system. Multiprogramming assumes a single processor that is being shared. It increases CPU utilization by organizing jobs so that the CPU always has one to execute. Job entering into the system is kept into the memory. Operating system picks the job and begins to execute one of the jobs in the memory. If the running process is waits for some I/O, then the CPU switches from the job to another job in the job pool. Multiprogramming operating system monitors the states of all active programs and system resources. This ensures that the CPU is never idle unless there are no jobs.

Shows the Memory layout of multiprogramming system. Advantages of Multiprogramming:

1. Can get efficient memory utilization. 2. CPU is never idle, so the performance of CPU will increase. 3. Throughput of the CPU may also increase. 4. Waiting time is limited in multiprogramming compare to non multiprogramming.

Time Sharing Time sharing systems supports interactive users. Time sharing is also called as multitasking. It uses CPU scheduling and multiprogramming to provide an economical interactive system of two or more users. In time sharing, each user is given a time slice for executing his job. Job continues until the time slice ends. Memory management in timesharing system provides isolation and protection of Co-resistant programs. Time sharing system can run several programs at the same time, so it is called multiprogramming system. But multiprogramming operating system is not a time sharing system.

CS6401- Operating Systems

12

Desktop System A desktop system is nothing that it is a normal pc's. Pc operating systems were neither multi-user nor multitasking. However the goals of this operating system have changed with time, instead of maximizing CPU and peripheral utilization, the systems opt for maximizing user convenience and responsiveness these systems include PCs running Microsoft Windows and the Apple Macintosh. These computers are now tied into other computers over local area networks or other Internet connections. Multi Processor Multiprocessor system has more than one processor in close communication. They share the computer bus, system clock and sometimes memory and peripheral devices. It is possible for two processes to run in parallel. It is also known as parallel systems or tightly coupled systems. It is two types. Symmetric Multiprocessing (SMP)

1. Each processor runs an identical copy of the operating system. 2. Many processes can run at once without performance deterioration. 3. Most modern operating systems support SMP

Symmetric Multiprocessing Architecture

Asymmetric Multiprocessing Each processor is assigned a specific task; master processor schedules and allocated work to slave processors. It is more common in extremely large systems. Advantages Increased throughput

Economical

Increased reliability

Graceful Degradation In multiprocessor systems, failure of one processor will not halt the system, but only slow

it down. If there are ten processors & if one fails the remaining nine processors pick up the

work of the failed processor. This ability to continue providing service is proportional to

the surviving hardware is called graceful degradation.

CS6401- Operating Systems

13

Systems designed for graceful degradation are called fault tolerant.

Distributed System A network is the simplest terms; it is the communication path between two or more systems. Distributed systems depend on networking for their functionality. By being able to communicate, distributed systems are able to share computational tasks, and provide a rich set of features to users. Networks vary by the protocols used, the distances the between nodes, and the transport media. A local -area network (LAN), exists within a room, a floor, or a building. A wide-area network (WAN) usually exists between buildings, cities, or countries. Loosely coupled system – each processor has its own local memory; processors communicate with one another through various communications lines, such as high-speed buses or telephone lines. Definition: A distributed system is one that looks to its users like an ordinary operating system but runs on multiple, independent CPU. It can be either client-server or peer-to-peer systems.

General Structure of Client-Server

Advantages

1. Resource sharing 2. Higher reliability 3. Better Price performance ratio 4. Shorter responses times and higher throughput

Clustered System Clustered systems gather together multiple CPUs to accomplish computational work. Clustered systems differ from parallel systems; however in that they are composed of two or more individual systems coupled together. They generally accepted definition is that clustered computers share storage and are closely linked via LAN networking. Clustering is usually performed to provide high availability. In asymmetric clustering, one machine is in hot standby mode while the other is running the applications. In symmetric mode, two or more hosts are running applications, and they are monitoring each other.

CS6401- Operating Systems

14

Other forms of clusters include parallel clusters and clustering over a WAN. Parallel clusters allow multiple hosts to access the same data on the shared storage. Real Time System Another form of a special-purpose operating system is a real-time system. A real time system is used when rigid time requirements have been placed on the operation of a processor or the flow of data; thus, it is often used as a control device in a dedicated application. Systems that control scientific experiments, medical imaging systems, and certain display systems are real time systems. Some automobile-engine fuel injection systems, home appliance controllers, and weapon systems are also real time systems. A real time system has well-defined, fixed time constraints. Processing must be done within the defined constraints, or the system wills fail. Real-time systems come in two flavors: hard and soft. A hard real time system guarantees that critical tasks be completed on time. This goal requires that all Delays in the system be bounded, from the retrieval of stored data to the time that it takes the operating system to finish any request made of it. Such time constraints dictate the facilities that are available in the hard real time systems. A less restrictive type of real-time system is a soft real time system, where a critical. Real-time task gets priority over other tasks, and retains that priority until it completes. Handheld Systems

Handheld systems include Personal Digital Assistants (PDAs) such as palm pilots and

Cellular telephones with connectivity to a network such as internet.

Issues: 1. Limited memory 2. Slow processors 3. Small display screens. Computer System Organization Operating System Structure and Operations System Calls System calls provide the interface between a running program and the operating system.

o Generally available as assembly-language instructions. o Languages defined to replace assembly language for systems programming allow

system calls to be made directly (e.g., C, C++) Three general methods are used to pass parameters between a running program and the operating system.

o Pass parameters in registers.

CS6401- Operating Systems

15

o Store the parameters in a table in memory, and the table address is passed as a parameter in a register.

o Push (store) the parameters onto the stack by the program, and pop off the stack by operating system

Passing of Parameters As A Table

System calls can be classified into five types: 1. Process control

a. end, abort b. load, execute c. create process, terminate process d. get process attributes, set process attributes e. wait for time f. wait event, signal event g. allocate and free memory

2. File Management a. create file, delete file b. open, close file c. read, write, reposition d. get and set file attributes

3. Device Management a. request device, release device b. read, write, reposition c. get device attributes, set device attributes d. logically attach or detach devices

4. Information Maintenance a. get time or date, set time or date b. get system data, set system data c. get and set process, file, or device attributes

5. Communication a. create, delete communication connection b. send, receive messages c. transfer status information d. attach and detach remote devices

CS6401- Operating Systems

16

System Programs System programs provide a convenient environment for program development and execution. They can be divided into:

o File manipulation Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories

o Status information Some ask the system for info - date, time, amount of available memory, disk

space, number of users Others provide detailed performance, logging, and debugging information Typically, these programs format and print the output to the terminal or

other output devices Some systems implement a registry - used to store and retrieve

configuration information o File modification Text editors to create and modify files Special commands to search contents of files or perform transformations of

the text o Programming language support

Compilers, assemblers, debuggers and interpreters sometimes provided o Program loading and execution

Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language

o Communications Provide the mechanism for creating virtual connections among processes,

users, and computer systems Allow users to send messages to one another’s screens, browse web

pages, send electronic-mail messages, log in remotely, transfer files from one machine to another

OS Generation and System Boot It is possible to design, code, and implement an operating system specifically for one machine at one site. But operating systems are designed to run on any of a class of machines at a variety of sites with a variety of peripheral configurations. The system must then be configured or generated for each specific computer site, a process known as system generation SYSGEN. The operating system is normally distributed on disk, on CD-ROM or DVD-ROM, or as an ―ISO‖ image, which is a file in the format of a CD-ROM or DVD-ROM. The following kinds of information must be determined.

What CPU is to be used? What options are installed? For multiple CPU systems, each CPU may be described.

CS6401- Operating Systems

17

How will the boot disk be formatted?

How much memory is available?

What devices are available?

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.

Once this information is determined, it can be used in several ways. 1. A system administrator can use it to modify a copy of the source code of the

operating system. The operating system then is completely compiled. 2. The system description can lead to the creation of tables and the selection of

modules from a precompiled library. These modules are linked together to form the generated operating system. To construct a system that is completely table driven. All the code is always part of the system, and selection occurs at execution time, rather than at compile or link time. The major differences among these approaches are the size and generality of the generated system and the ease of modifying it as the hardware configuration changes.

System Boot After an operating system is generated, it must be made available for use by the hardware. The procedure of starting a computer by loading the kernel is known as booting the system.

1. Small piece of code known as the bootstrap program or bootstrap loader locates the kernel, loads it into main memory, and starts its execution.

2. Two-step process a. simple bootstrap loader fetches a more complex boot program from disk b. Boot program then loads the kernel.

When a CPU receives a reset event—for instance, when it is powered up or rebooted—the instruction register is loaded with a predefined memory location, and execution starts there. At that location is the initial bootstrap program. This program is in the form of read-only memory (ROM), because the RAM is in an unknown state at system startup. ROM is convenient because it needs no initialization and cannot easily be infected by a computer virus. The bootstrap program can perform a variety of tasks.

CS6401- Operating Systems

18

1. To run diagnostics to determine the state of the machine. If the diagnostics pass, the program can continue with the booting steps. It can also initialize all aspects of the system, from CPU registers to device controllers and the contents of main memory.

2. It starts the operating system. Systems—such as cellular phones, tablets, and game consoles Store the entire operating system in ROM. 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. Resolve this problem by using erasable programmable read-only memory (EPROM), which is read only except when explicitly given a command to become writable. All forms of ROM are also known as firmware, since their characteristics fall somewhere between those of hardware and those of software. A problem with firmware in general is that executing code there is slower than executing code in RAM. Some systems store the operating system in firmware and copy it to RAM for fast execution. A final issue with firmware is that it is relatively expensive, so usually only small amounts are available. For large operating systems or for systems that change frequently, the bootstrap loader is stored in firmware, and the operating system 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 execute the code from that boot block. GRUB is an example of an open-source bootstrap program for Linux systems. All of the disk-bound bootstrap, and the operating system itself, can be easily changed by writing new versions to disk. A disk that has a boot partition is called a boot disk or system disk. Now that the full bootstrap program has been loaded, it can traverse the file system to find the operating system kernel, load it into memory, and start its execution. It is only at this point that the system is said to be running.