advanced operating systems

67
Advanced Operating Systems Mehdi Naghavi [email protected] Winter 1385

Upload: tal

Post on 23-Feb-2016

48 views

Category:

Documents


0 download

DESCRIPTION

Advanced Operating Systems. Mehdi Naghavi [email protected] Winter 1385. Course motivation and goals. Programming computer hardware directly is difficult Operating systems provide a layer between applications and computer hardware (VM) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Advanced Operating  Systems

Advanced Operating Systems

Mehdi [email protected]

Winter 1385

Page 2: Advanced Operating  Systems

66/2

Course motivation and goals

Programming computer hardware directly is difficult

Operating systems provide a layer between applications and computer hardware (VM)

Understanding operating system concepts is essential to many advanced programming tasks

Page 3: Advanced Operating  Systems

66/3

Class outline

Introduction and Overview Processes and threads Operating system structures Memory management Scheduling Input/Output File Systems Security

Page 4: Advanced Operating  Systems

66/4

Textbook

Andrew S. Tanenbaum. “Operating Systems design and implementation”, 3nd ed., Prentice Hall, 2006.

Abraham Silberschatz, Galvin, and Gagne. “Operating Systems Concepts”, 7nd ed., John Wiley and Sons, 2005

William Stallings. “Operating Systems”, 4nd ed., Prentice Hall, 2001.

Andrew S. Tanenbaum. “Modern Operating Systems”, 2nd ed., Prentice Hall, 2001.

Andrew S. Tanenbaum. “Distributed Operating Systems”, Prentice Hall.

Page 5: Advanced Operating  Systems

66/5

Points

Mobile Phones, pagers and other similar devices OFF during class

Collegians must be Presence in classroom

Contact [email protected] [email protected]

Page 6: Advanced Operating  Systems

Operating Systems

Mehdi [email protected]

Winter 1385

Introduction to Operating Systems

Page 7: Advanced Operating  Systems

66/7

Overview:

What is an operating system? Operating systems history The zoo of modern operating systems Review of computer hardware Operating system concepts System calls Operating system structure

User interface to the operating system Anatomy of a system call

Page 8: Advanced Operating  Systems

66/8

Samples of Operating Systems

IBSYS (IBM 7090) OS/360 (IBM 360) TSS/360 (360 mod 67) Michigan Terminal System CP/CMS & VM 370 MULTICS (GE 645) Alto (Xerox PARC) Pilot (Xerox STAR) CP/M IRIX Solaris MVS VxWorks

MACH Apollo DOMAIN Unix (System V & BSD) Apple Mac (v. 1– v. 9) MS-DOS Windows NT, 2000, XP Novell Netware Linux FreeBSD PalmOS PocketPC VxWorks

Page 9: Advanced Operating  Systems

66/9

Samples of Operating Systems (continue…)

Page 10: Advanced Operating  Systems

66/10

What is an Operating System?

An Operating System is a program that acts as an intermediary/interface between a user of a computer and the computer hardware.

It is an extended machine Hides the messy details which must be performed Presents user with a virtual machine, easier to use

It is a resource manager Each program gets time with the resource Each program gets space on the resource

Page 11: Advanced Operating  Systems

66/11

The Operating System controls the machine

User

Application

Operating System

Hardware

OS Kernel

Hardware

Compiler Debugger

Editor

Video

Terminalemulator 

Browser

Game

App.

Page 12: Advanced Operating  Systems

66/12

Static View of System Components

Operating System

Hardware

User 1 User 2 User 3 User 4 User n…

Compiler Editor Database Calculator WP

Page 13: Advanced Operating  Systems

66/13

Dynamic View of System Components

Page 14: Advanced Operating  Systems

66/14

Layers of a Computer System

EndUser

Programmer

Operating-System

Designer

Computer Hardware

Operating-System

Utilities

ApplicationPrograms

Page 15: Advanced Operating  Systems

66/15

History of Operating Systems

First generation: 1945 – 1955 Vacuum tubes, Plug boards

Second generation: 1955 – 1965 Transistors, Batch systems

Third generation: 1965 – 1980 Integrated circuits, Multiprogramming

Fourth generation: 1980 – present Large scale integration, Personal computers

Next generation: ??? Systems connected by high-speed

networks? Wide area resource management?

Page 16: Advanced Operating  Systems

66/16

First generation: direct input

Run one job at a time Enter it into the computer (might require rewiring!) Run it Record the results

Problem: lots of wasted computer time! Computer was idle during first and last steps Computers were very expensive!

Goal: make better use of an expensive commodity: computer time

Page 17: Advanced Operating  Systems

66/17

Second generation: batch systems

Bring cards to 1401 Read cards onto input tape Put input tape on 7094 Perform the computation, writing results to output tape Put output tape on 1401, which prints output

Page 18: Advanced Operating  Systems

66/18

$END

$RUN $LOAD

Structure of a typical 2nd generation job

$FORTRAN $JOB, 10,6610802, JANE DOE

FORTRANprogram

Data forprogram

Page 19: Advanced Operating  Systems

66/19

Operatingsystem

Third generation: multiprogramming

Multiple jobs in memory Protected from one another

Operating system protected from each job as well

Resources (time, hardware) split between jobs

Still not interactive User submits job Computer runs it User gets results minutes

(hours, days) later

Job 1

Job 2

Job 3

Memorypartitions

Page 20: Advanced Operating  Systems

66/20

Multi tasking

Job 1

Job 2

Job 3

Operating System

Main M

emory

CPU

Task 1

Task 2

Resource utilization Multiprogramming, multitasking, and multiple users. Time sharing. Response time.

Page 21: Advanced Operating  Systems

66/21

Timesharing

Multiprogramming allowed several jobs to be active at one time Initially used for batch systems Cheaper hardware terminals → interactive use

Computer use got much cheaper and easier No more “priesthood” Quick turnaround meant quick fixes for problems

Page 22: Advanced Operating  Systems

66/22

Types of modern operating systems

Mainframe operating systems: MVS Server operating systems: FreeBSD, Solaris Multiprocessor operating systems: Cellular IRIX Personal computer operating systems: XP, Linux PDA operating systems: PalmOS, PocketPC Real-time/embedded operating systems: VxWorks, QNX Smart card operating systemsÞ Some operating systems can fit into more than one

category

Page 23: Advanced Operating  Systems

66/23

Computer Hardware Review

Computer block diagram Components of a simple personal computer CPU internals Memory Storage pyramid Disk drive structure Anatomy of a device request Structure of a large Pentium system

Page 24: Advanced Operating  Systems

66/24

Memory

CPU

Registers Bank

MonitorPrinterModem

Main Memory

ALU

Secondary Memory

Tertiary Memory

Control UnitKeyboardMouseScannerModem

Input Unit Output Unit

Cache Memory

Computer

ROMRAM

HD FD CD Flash

Tape

Page 25: Advanced Operating  Systems

66/25

Computer Components: Top-Level View

MAR - Memory Address Register address for next read or write

MBR - Memory Buffer Register data to be written into memory receives data read from memory

I/OAR - I/O Address specifies a particular I/O device

I/OBR - I/O Buffer exchange of data between an I/O

module and the processor

Page 26: Advanced Operating  Systems

66/26

Components of a simple personal computer

Hard drivecontroller

Videocontroller

Memory

USBcontroller

Networkcontroller

Outsideworld

CPU Computer internals(inside the “box”)

Page 27: Advanced Operating  Systems

66/27

Executeunit

Executeunit

Executeunit

Executeunit

Holding buffer

Fetchunit

Decodeunit

Fetchunit

Decodeunit

Fetchunit

Decodeunit

CPU internals

(a) A three-stage Pipelined CPU (b) A Superscalar CPU

Page 28: Advanced Operating  Systems

66/28

Memory

User 2 programand data

User 1 programand data

Operatingsystem

Address

0x0001dfff

0x00023000

0x00027fff

0x0002b000

0x0002ffff

0x00000000

Single base/limit pair: set for each process Two base/limit registers: one for program, one for data

Base

Limit

User 2 data

User program

Operatingsystem

User 1 data

Base1

Limit2

Limit1

Base2

Address

0x0001dfff

0x00023000

0x000290000x0002bfff

0x0002ffff

0x00000000

0x0002d000

0x00024fff

Page 29: Advanced Operating  Systems

66/29

Access latency

1 ns

2–5 ns

50 ns

5 ms

50 sec

< 1 KB

1 MB

1 GB

200 GB

> 1 TB

Capacity

Storage pyramid

Registers

Cache (SRAM)

Main memory (DRAM)

Magnetic disk

Magnetic tape

Goal: really large memory with very low latency Latencies are smaller at the top of the hierarchy Capacities are larger at the bottom of the hierarchy

Solution: move data between levels to create illusion of large memory with low latency

Better

Better

Page 30: Advanced Operating  Systems

66/30

Disk drive structure

sector

cylinder

platter

spindle

track

head

actuator

surfaces

Data stored on surfaces Up to two surfaces per platter One or more platters per disk

Data in concentric tracks Tracks broken into sectors

256B-1KB per sector Cylinder: corresponding

tracks on all surfaces Data read and written by

heads Actuator moves heads Heads move in unison

Page 31: Advanced Operating  Systems

66/31

Anatomy of a device request

InterruptcontrollerCPU

5 Diskcontroller

3 2

61 4

Left: sequence as seen by hardware Request sent to controller, then to disk Disk responds, signals disk controller which tells interrupt controller Interrupt controller notifies CPU

Right: interrupt handling (software point of view)

Instructionn

Operatingsystem

Instructionn+1

Interrupt handler

1: Interrupt

2: Process interrupt

3: Return

Page 32: Advanced Operating  Systems

66/32

Structure of a large Pentium system

Page 33: Advanced Operating  Systems

66/33

Operating system Components

Process Management Memory Management File Management I/O Management Process Scheduler Inter Process Communication Network Unit Command Interpreter Security Management

Page 34: Advanced Operating  Systems

66/34

Modern Operating System Structure

Hardware

Application ApplicationApplication

Shared Runtime Librariesuser-mode

supervisor-mode

System Call Interface

Device Driver Components

memorymanager

taskmanager

filemanager

networkmanager

OS Kernel

Page 35: Advanced Operating  Systems

66/35

Processes

Process: program in execution Address space (memory) the

program can use State (registers, including

program counter & stack pointer)

OS keeps track of all processes in a process table

Processes can create other processes

Process tree tracks these relationships

A is the root of the tree A created three child processes:

B, C, and D C created two child processes: E

and F D created one child process: G

A

B

E F

C D

G

Page 36: Advanced Operating  Systems

66/36

Memory image of a Unix process

Processes have three segments

Text: program code Data: program data

Statically declared variables Areas allocated by

malloc() or new (heap) Stack

Automatic variables Procedure call information

Address space growth Text: doesn’t grow Data: grows “up” Stack: grows “down”

Stack

Data

Text

0x7fffffff

0x00000000

Data

Page 37: Advanced Operating  Systems

66/37

Synchronization and deadlock

(a) A Potential deadlock (b) An Actual deadlock

Page 38: Advanced Operating  Systems

66/38

Hierarchical file systems

File system for a university department

Page 39: Advanced Operating  Systems

66/39

Mounting

Before mounting, files on floppy are inaccessible

After mounting floppy on b, files on floppy are part of file hierarchy

Page 40: Advanced Operating  Systems

66/40

Inter-process communication

Processes may want to exchange information with each other Many ways to do this, including

Network Pipe (special file): A writes into pipe, and B reads from it

A B

Process Process

Pipe

Two processes connected by a pipe

Page 41: Advanced Operating  Systems

66/41

Types of OS structures

Monolithic system Layered system Virtual machine Exokernel Client/Server

Page 42: Advanced Operating  Systems

66/42

Monolithic system

Mainprocedure

ServiceProcedures

UtilityProcedures

Simple structuring model for a monolithic system

Page 43: Advanced Operating  Systems

66/43

Monolithic system…

Applications

System call interface

MM PS IPC FS

I/O Net …

Kernel

User spaceKernel space

MM = Memory ManagerPS = Processor SchedulerIPC = Inter Process CommunicationFS = File SystemI/O = Input/Output managerNet = Network manager

Page 44: Advanced Operating  Systems

66/44

MS-DOS Layer Structure

Page 45: Advanced Operating  Systems

66/45

Layered Operating System

Page 46: Advanced Operating  Systems

66/46

Layered system

Structure of the THE operating system

User

Process Scheduling

Memory Management

Message Interpreter

Hardw

areI/O Management

User ApplicationUser space

Kernel space

Layer 0

Layer 3

Layer 2

Layer 1

Layer 4

Layer 5

Page 47: Advanced Operating  Systems

66/47

UNIX System Structure

Page 48: Advanced Operating  Systems

66/48

Virtual machine

First widely used in VM/370 with CMS (Conversational Monitor System)

Available today in VMware Allows users to run any x86-based OS on top of Linux or NT

“Guest” OS can crash without harming underlying OS Only virtual machine fails—rest of underlying OS is fine

“Guest” OS can even use raw hardware Virtual machine keeps things separated

Bare hardware

VM/370

CMS (VMW)

Linux

App1 App2 App3

CMS (VMW) CMS (VMW)

Windows NT FreeBSDI/O instructions

System calls

Calls to simulate I/O

“Real” I/O instructions

Page 49: Advanced Operating  Systems

66/49

VMware Architecture

Page 50: Advanced Operating  Systems

66/50

The Java Virtual Machine

Page 51: Advanced Operating  Systems

66/51

Exokernel

Same as Virtual machine Assign one virtual computer to any user Allocate sub set of resource to any virtual machine

Page 52: Advanced Operating  Systems

66/52

Microkernel

Clientprocess

Processserver

Terminalserver

Clientprocess

Fileserver

Memoryserver… User mode

Kernel mode

Client/Server

Processes (clients and OS servers) don’t share memory Communication via message-passing Separation reduces risk of “byzantine” failures

Examples include Mach, QNX, early versions of Windows NT

Client obtains service by sending messages to server processes

The client-server model

Page 53: Advanced Operating  Systems

66/53

Client/Server…

Applications

System call interface

Micro Kernel

User space

Kernel space

Process SchedulerFile System Device manager …

IPC

Memory Management Synchronization

Page 54: Advanced Operating  Systems

66/54

Mac OS X Structure

Page 55: Advanced Operating  Systems

66/55

Client/Server…

The client-server model in a distributed system

Page 56: Advanced Operating  Systems

66/56

System calls

Programs want the OS to perform a service Access a file Create a process Others…

Accomplished by system call Program passes relevant information to OS OS performs the service if

The OS is able to do so The service is permitted for this program at this time

OS checks information passed to make sure it’s OK Don’t want programs reading data into other programs’ memory!

Page 57: Advanced Operating  Systems

66/57

System calls…

System call interface

MM PS IPC FS

I/O Net …

User space

Kernel space

OS Component

Applications ApplicationsApplications

Page 58: Advanced Operating  Systems

66/58

Making a system call

System call:read(fd,buffer,length)

Program pushes arguments, calls library

Library sets up trap, calls OS

OS handles system call Control returns to library Library returns to user

program There are 9 steps in making

the system call

Return to callerTrap to kernelTrap code in register

Increment SPCall readPush arguments

Dispatch Sys callhandler

Kernelspace(OS)

Userspace

0

0xffffffff

1

2

3

4

5 6

7

8

9

Library(read call)

Usercode

Page 59: Advanced Operating  Systems

66/59

System calls for files & directories

Call Descriptionfd = open(name,how) Open a file for reading and/or writing

s = close(fd) Close an open file

n = read(fd,buffer,size) Read data from a file into a buffer

n = write(fd,buffer,size) Write data from a buffer into a file

s = lseek(fd,offset,whence)

Move the “current” pointer for a file

s = stat(name,&buffer) Get a file’s status information (in buffer)

MINIX System calls

Page 60: Advanced Operating  Systems

66/60

Call Descriptionpid = fork() Create a child process identical to the parent

pid=waitpid(pid,&statloc,options)

Wait for a child to terminate

s = execve(name,argv,environp)

Replace a process’ core image

exit(status) Terminate process execution and return status

s = chdir(dirname) Change the working directory

s = chmod(name,mode) Change a file’s protection bits

s = kill(pid,signal) Send a signal to a process

seconds = time(&seconds) Get the elapsed time since 1 Jan 1970

More system calls

MINIX System calls

Page 61: Advanced Operating  Systems

66/61

A simple shell

while (TRUE) { /* repeat forever */ type_prompt( ) ; /* display prompt */ read_command (command, parameters); /* input from

terminal */ if (fork() != 0) { /* fork off child

process */ /* Parent code */ waitpid( -1, &status, 0); /* wait for

child to exit */} else { /* Child code */ execve (command, parameters, 0); /* execute

command */ }}

Page 62: Advanced Operating  Systems

66/62

System Calls

Some UNIX and Win32 API calls

Page 63: Advanced Operating  Systems

66/63

Metric units

Exp. Number Prefix Exp. Number Prefix10-3 0.001 milli 103 1,000 Kilo10-6 0.000001 micro 106 1,000,000 Mega10-9 0.000000001 nano 109 1,000,000,000 Giga

10-12 0.000000000001 pico 1012 1,000,000,000,000 Tera10-15 0.000000000000001 femto 1015 1,000,000,000,000,000 Peta10-18 0.000000000000000001 atto 1018 1,000,000,000,000,000,000 Exa

Page 64: Advanced Operating  Systems

66/64

Review

How does a batch operating system differ from a multiprogrammed operating system?

Why is multiprogramming useful? Why are multiprogrammed systems much more

difficult to implement than are batch systems? What is timesharing? How does it differ from

multiprogramming? What is an online system? What is a real-time system? Which systems try to maximize throughput? Which

ones try to minimize response time?

Page 65: Advanced Operating  Systems

66/65

What type of operating system would you use

For editing a letter? For controlling a chemical reaction? For processing payroll? In a cellphone? In a toy? For surfing the web? For air traffic control? For a scientific simulation? To play MP3?

Page 66: Advanced Operating  Systems

66/66

Computer architecture

What connects the processor to memory? What are the components of the storage hierarchy? What is between the processor and I/O devices? What are the components of a disk? What is an interrupt? Why are interrupts useful? What happens to program execution when an

interrupt occurs?

Page 67: Advanced Operating  Systems

66/67

OS interaction

Does it differ if the operating system is monolithic or a microkernel?

What are the steps involved when the operating system is monolithic?

What additional steps happen in case of a microkernel?