47
COSC 4P13 Operating Systems : Design and Implementation

COSC 4P13 Operating Systems : Design and Implementation

Embed Size (px)

Citation preview

COSC 4P13

Operating Systems : Design and Implementation

Course Description(1)

The Goals for this course Understand UNIX Understand Operating Systems

Prerequisites: COSC 2P13 : Introduction to Operating Systems COSC 2P91 : Procedural Programming COSC 1P12 : Computer Organization and

Assembly Language

Course Description(2) An intensive study of computer operating

system design Multiprogramming Time-sharing Real-time processing Job and task control Synchronization of concurrent processes and

processors Resource scheduling Protection Management of hierarchical storage.

How to study this course Read and remember

Read the book, remember the concepts and commands

Think Think operating systems as natural

administrative agents Practice

Coding with UNIX, use and understand of UNIX commands and get the results

The Textbook Used Uresh Vahalia, UNIX Internals: The

New Frontiers, Prentice Hall, 1996 Why we use this book?

UNIX is one of the popular operating systems of the world.

If you understand UNIX, you can understand other operating systems.

References William Stallings, Operating Systems,4th

Ed., Prentice Hall,2000 A. Tanenbaum, Modern Operating

Systems, 2nd ed. Prentice Hall 2001 Kay A. Robbins and Steven Robbins,

Practical UNIX Programming, Prentice Hall,1996

W. R. Stevens, Advanced Programming in the UNIX Environment, Addison Wesley, 1992

Operating System Overview

Computer System Computer Hardware

Components Registers Instruction execution Interrupt Memory Hierarchy and I/O

Operating System Services of OS Major Achievements Characteristics of Modern OS

Computer System

EndUser

Programmer

Operating-System

Designer

Computer Hardware

Operating-System

Utilities

ApplicationPrograms

Computer Hardware Processor Main Memory

referred to as real memory or primary memory volatile

I/O modules secondary memory devices communications equipment terminals

System interconnection communication among processors, memory, and

I/O modules

Computer Components:top-level view

IR

MAR

MBR

I/O AR

I/O BR

PC

CPU

Buffers

I/O Module

Memory

InstructionInstruction

Instruction

Data

Data

DataData

...

..

...

..

MAR - Memory Address Registeraddress for next read or write

MBR - Memory Buffer Registerdata to be written into memory

receives data read from memory

I/OAR - I/O Addressspecifies a particular I/O device

I/OBR - I/O Bufferexchange of data between an I/O module and the processor

I/O Module Structure

Data to/from system bus are buffered in data register(s)

Status/Control register(s) I/O logic interact with CPU via control bus Contains logic specific to the interface of each device

Processor Registers User-visible registers

Data Registers Address Registers

index register segment pointer stack pointer

Condition Codes or Flags Control and Status Registers

Program Counter (PC) Instruction Register (IR) Program Status Word (PSW)

Instruction Execution Processor executes instructions in a

program Instructions are fetched from memory

one at a time

STARTSTART HALTHALTFetch NextInstruction

Fetch NextInstruction

ExecuteInstruction

ExecuteInstruction

Fetch Cycle Execute Cycle

Instruction Fetch and Execute

The processor fetches the instruction from memory

Program counter (PC) holds address of the instruction to be fetched next

Program counter is incremented after each fetch

Instruction Register Fetched instruction is placed here Types of instructions

Processor-memory transfer data between processor and memory

Processor-I/O data transferred to or from a peripheral device

Data processing arithmetic or logic operation on data

Control alter sequence of execution

Interrupts An interruption of the normal processing of

processor Improves processing efficiency Allows the processor to execute other

instructions while an I/O operation is in progress

A suspension of a process caused by an event external to that process and performed in such a way that the process can be resumed

Classes of Interrupts Program

arithmetic overflow division by zero execute illegal instruction reference outside user’s memory space

Timer I/O Hardware failure

Instruction Cycle with Interrupts

STARTSTART

HALT

Fetch NextInstruction

Fetch NextInstruction

ExecuteInstruction

ExecuteInstruction

Check forInterrupt:

Process Interrupt

Check forInterrupt:

Process Interrupt

Fetch Cycle Execute Cycle Interrupt Cycle

InterruptsDisabled

InterruptsEnabled

Interrupt Handler A program that determines nature of

the interrupt and performs whatever actions are needed

Control is transferred to this program Generally part of the operating system

Interrupt Cycle Processor checks for interrupts If no interrupts fetch the next instruction

for the current program If an interrupt is pending, suspend

execution of the current program, and execute the interrupt handler

Simple Interrupt Processing

Device controller orother system hardwareissues an interrupt

Processor finishesexecution of currentinstruction

Processor signalsacknowledgmentof interrupt

Processor pushes PSWand PC onto controlstack

Processor loads newPC value based oninterrupt

Save remainder ofprocess stateinformation

Process interrupt

Restore process stateinformation

Restore old PSWand PC

Interrupts improve CPU usage I/O pgm prepares the I/O module

and issues the I/O command (eg: to printer)

I/O pgm branches to user pgm User code gets executed during

I/O operation (eg: printing): no waiting

User pgm gets interrupted (x) when I/O operation is done and branches to interrupt handler to examine status of I/O module

Execution of user code resumes

Disable interrupts during an interrupt Interrupts remain pending until the processor enables

interrupts After interrupt handler routine completes, the

processor checks for additional interrupts

Multiple interrupts: sequential order

Multiple Interrupts: priorities

Higher priority interrupts cause lower-priority interrupts to wait Causes a lower-priority interrupt handler to be interrupted Example: when input arrives from communication line, it needs to be

absorbed quickly to make room for more input

Cache/Main-Memory Structure

MemoryAddress

1

3

0

2

2n - 1

Block

Block(k words)

WordLength

SlotNumber Tag Block

0

21

C - 1Block Length(k words)

(a) Main Memory

(b) Cache

Cache Design

Cache size Block size Mapping function Replacement algorithm

I/O Techniques Programmed I/O Interrupt-Driven I/O Direct Memory Access

Programmed I/OInsert Readcommand toI/O Module

Read Statusof I/OModule

CheckStatus

Read wordfrom I/OModule

Write wordinto memory

Done?

Yes

No

Next Instruction

CPU Memory

I/O CPU

ErrorCondition

I/O CPU

CPU I/O

Ready

NotReady

I/O module performs the action, not the processor

Sets appropriate bits in the I/O status register

No interrupts occur

Processor is kept busy checking status

Interrupt-Driven I/OInsert Readcommand toI/O Module

Read Statusof I/OModule

CheckStatus

Read wordfrom I/OModule

Write wordinto memory

Done?

Yes

No

Next Instruction

CPU Memory

I/O CPU

ErrorCondition

I/O CPU

CPU I/O

Ready

Do somethingelse

Interrupt

Processor is interrupted when I/O module ready to exchange data

Processor is free to do other work

No needless waiting

Consumes a lot of processor time because every word read or written passes through the processor

Direct Memory Access

Next Instruction

CPU DMA

Interrupt

DMA CPU

Do somethingelse

Issue Readblock commandto I/O module

Read statusof DMAmodule

Transfers a block of data directly to or from memory

An interrupt is sent when the task is complete

The processor is only involved at the beginning and end of the transfer

Operating System Making computing power available to

users by controlling the hardware a program that controls execution of

application programs an interface between the user and

hardware Directs the processor in the use of system

resources Directs the processor when executing

other programs

Services Provided by the OS Facilities for Program creation

editors, compilers, linkers, and debuggers

Program execution loading in memory, I/O and file initialization

Access to I/O and files deals with the specifics of I/O and file formats

System access Protection of access to resources and data Resolves conflicts for resource contention

Services Provided by the OS

Error Detection internal and external

hardware errors memory error device failure

software errors arithmetic overflow access forbidden

memory locations Inability of OS to

grant request of application

Error Response simply report error to

the application Retry the operation Abort the application

Services Provided by the OS

Accounting collect statistics on resource usage monitor performance (eg: response time) used for system parameter tuning to

improve performance useful for anticipating future

enhancements used for billing users (on multiuser

systems)

Operating System as a Resource Manager

Processor . . .

.

.

.

Computer System

I/O Controller

Processor

I/O Controller

I/O Controller

Memory

OperatingSystemSoftware

Programsand Data

OSPrograms

Data

Ability to Evolve

Must be able to adapt to hardware upgrades and new types of hardware. Examples: Character vs graphic terminals Introduction of paging hardware

Must be able to offer new services, eg: internet support

Major Achievements Processes Memory Management Information protection and security Scheduling and resource

management System structure

Memory Management Process isolation Automatic allocation and management Support for modular programming Protection and access control Long-term storage

Virtual Memory Allows programmers to address

memory from a logical point of view While program is running portions of

the program and data are kept in blocks on disk

File System Implements long-term store Information stored in named objects

called files

Categories of Security and Protection

Access control regulate user access to the system

Information flow control regulate flow of data within the system and

its delivery to users Certification

proving that access and flow control perform according to specifications

Scheduling and Resource Management

Fairness give equal and fair access to all processes

Differential responsiveness discriminate between different classes of

jobs Efficiency

maximize throughput, minimize response time, and accommodate as many uses as possible

Characteristics of Modern Operating Systems

Microkernel architecture assigns only a few essential functions to

the kernel address space interprocess communication (IPC) basic scheduling

Characteristics of Modern Operating Systems

Multithreading process

is divided into threads that can run simultaneously

Process is a collection of one or more threads

Thread dispatchable unit of work executes sequentially and is interruptable

Characteristics of Modern Operating Systems

Symmetric multiprocessing there are multiple processors these processors share the same main

memory and I/O facilities All processors can perform the same

functions

Characteristics of Modern Operating Systems

Distributed operating systems provides the illusion of a single main

memory used for distributed file system

Characteristics of Modern Operating Systems

Object-oriented design used for adding modular extensions to a

small kernel enables programmers to customize an

operating system without disrupting system integrity