CMPT 300 Day: Operating System Instructor: Senqiang Zhou TA: Rong Ge {szhoua, rge}@cs.sfu.ca.

Post on 18-Dec-2015

219 views 0 download

Transcript of CMPT 300 Day: Operating System Instructor: Senqiang Zhou TA: Rong Ge {szhoua, rge}@cs.sfu.ca.

CMPT 300 Day: Operating System

Instructor: Senqiang Zhou TA: Rong Ge {szhoua, rge}@cs.sfu.ca

2

What Is This Course About?

3

Office Hours & Places Instructor:

Time: Mon. 14:30-15:30    Wed  11:00-12:00 Place: ASB 9911

TA: Time: Tue. 10:00-12:00     Fri. 14:00-15:00 Place: MTF109 North - CSIL Linux Study Area

E-MAIL List: cmpt-300-d1@sfu.ca ACS SFU account desk at Strand Hall

Course web-page: http://www.cs.sfu.ca/CC/300/szhoua/

4

Grading

Four  assignments count for 20%. One term project counts for 15%. One  1-hour mid-term exam counts for

20%. Covers Ch 1 to Ch 3 .

One  3-hour final exam counts for 45%. Covers Ch1 to Ch 6.

5

Pre-requisites

C/C++: Necessary for term project Necessary to understand the codes in

textbook Basic hardware knowledge:

CPU, memory, bus, hard disk, I/O devices

Basic data structures: Queue, stack, etc.

6

Chapter 1 Introduction

7

Outline

Definitions of operating system History of operating systems Categories of operating systems Computer hardware review Operating system concepts System calls

8

Why Do We Need OS?

Many resources Hardware: processors, memory, disks,

printers, keyboard, monitors, network interfaces, …

Software: compilers, office tools, browsers, games, …

Many tasks Programming, surfing web, handling emails,

solving equations, playing music, … Many users

Share the resources: fairness Vs. Efficiency

9

A Computer Without OS

Consider a daily task: read data from diskette Basic commands: 13 parameters

Disk address, #blocks to read, #blocks per track….

Controller chips 23 status and error field

Do you want to program the hardware directly?

A simpler interface is needed!

10

The Benefits of OS

Hide the tedious details They are out of the user’s interest E.g., to access data, only need to specify the

file name. Provide a variety of services: system

calls A set of procedures an be called by programs using special

instructions. A simple interface

Present key features to programmer Meet requirements from many programs

11

OS As A Virtual Machine

Virtual machine/extended machine Hide the underlying hardware Access hardware through a set of

system calls Trade-off

Higher efficiency in program development and system management

More important with complex software Less efficiency in program execution

Less important with faster machine

12

OS As A Resource Manager Multiplexing (sharing) resources

In time Users/programs take turns using resources CPU, printers, etc.

In space Users/programs get parts of resources Main memory, disk, etc.

Protecting resources E.g., user’s memory space

Issues about a good manager Fairness, efficiency, safety, …

13

What Is An Operating System?

Provide user programs with a simpler interface

Manage resources

Banking system

Airline reservation

Web browserUser programs

Compilers EditorsCommand interpreter System

programsOperating system

Machine language

Hardware

Micro-architecture

Physical devices

14

Outline

What is an operating system? History of operating systems Categories of operating systems Computer hardware review Operating system concepts System calls

15

History of Operating Systems

OS and architecture of computers Computer evolves so does OS To provide better service OS has

impact on computer design Keep evolving through years (1944-)

Four generations so far during 60 years Speed, volume, storage, interface… Most important: price keeps dropping How many generations for car industry?

16

The First Generation Computer Vacuum tubes and plug-boards

1944-1955 Huge volumes, slow speed, low stability, expensive!

Applications: Straightforward numerical calculations Absolutely no game!

Scenario Single group of people designed, built, programmed,

operated and maintained a machine All in absolute machine language: no assembly

language No operating system

People did all the tasks.

17

The Second Generation OS

Transistors and batch systems 1955-1965

Applications Scientific and engineering calculation Programming Language: FORTRAN

IBM 1401 IBM 7094 IBM 1401

Cards from programmers

Read batch of jobs onto tape

Input tape

Do computing

Output tape

Print out

18

Ancestor of Today’s OS

Batch system Read a job from tape run the job

write output onto a output tape Load next job

A typical input job: series of commands $JOB$FORTRAN$LOAD$RUN

Examples: FMS, IBSYS

19

The Third Generation OS

Features: ICs and multiprogramming 1965-1980

Applications Numerical calculations in science &

engineering Word-oriented, large-scale scientific

computers Massive commercial data processing

Character-oriented, commercial computers

20

Key Advances in 3rd Gen OS

Multiprogramming Run job 2 while job 1 waiting for I/O Keep CPU busy

Spooling Read jobs from cards to disk asap Load new jobs from disk whenever old job

done Time sharing

CPU is allocated in turn Different from multiprogramming

Job 3

Job 2

Job 1

OS

Memory partitions

21

Milestones

IBM OS/360 M.I.T. CTSS M.I.T. MULTICS Ken Thompson UNIX

AT&T UNIX System V UC Berkeley UNIX BSD IEEE POSIX Andrew S. Tanenbaum MINIX Linus Torvalds Linux

22

The Fourth Generation OS Personal computers

1980-now VLSI circuits Cheap: an individual has her own computer

Milestones Kildall CP/M for Intel 8080, Z80 MS-DOS/BASIC for IBM PC Engelbart GUI MS Windows, Windows NT UNIX X Windows Network & distributed operating systems

23

Outline

What is an operating system? History of operating systems Categories of operating systems Computer hardware review Operating system concepts System calls

24

Categories of OS

Mainframe operating systems Server operating systems Multiprocessor operating systems Personal computer operating

systems Real-time operating systems Embedded operating systems Smart card operating systems

25

Mainframe Operating Systems

Characters of mainframe computers Strong I/O capability, e.g., 1000 disks,

TB space High-end servers: web server, B2B

server Features of OS

Batch (background) Transaction processing (interactive) Timesharing

Example: IBM OS/390

26

Server Operating Systems

Hardware platforms Very large personal computers or

workstations Services

Printing File accessing Web

Examples UNIX, Windows 2000, Linux

27

Multiprocessor Operating Systems

Multiple CPUs within a single system Parallel computers:

Local memory, connected via WAN, loosely coupled

Multi-computers: Local memory, connected via LAN, tightly coupled

Multiprocessors: share memory, connected via BUS

Features of OS Variations of the server operating systems

Special features for communication and connectivity between CPUs

28

Personal Computer OS

User friendly interface Easy to manipulate Abundant application software: word

processing, spreadsheets, internet access, game…

Examples Windows 98, Windows 2000 Macintosh operating system Linux

29

Outline

What is an operating system? History of operating systems Categories of operating systems Computer hardware review Operating system concepts System calls

30

Components of A Computer

System bus: connect all components

Bus

CPU MemoryVideo

controllerKeyboard controller

Floppy disk

controller

Hard disk controller

Monitor Keyboard

Floppy disk

driver

Hard disk

driver

I/O Devices

31

CPU (Processor)

Basic model Fetching instruction decoding executing Different CPUs have different instruction sets.

Registers Program counter: pointer to next instruction PSW: program status word

Condition code bit, the mode (kernel or user), etc. Stack pointer: point to the top of current stack General registers: hold temporary results

32

Working Modes

Two modes in CPU Kernel mode: full capability User mode: I/O, memory protection

instructions are disallowed. System calls: get OS service for user

program, switch to kernel mode by TRAP instruction.

User Program

OS User ProgramSystem

CallService Done

User mode

Kernel mode

User mode

33

Memory Hierarchy

Typical access time

Typical capacity

1 nsecRegiste

r<1 KB

2 nsec Cache 1 MB

10 nsec Main memory 64MB-1G

10 msec Magnetic disk 5-100 GB

100 sec Magnetic tape 20-100 GB

Reason: Trade off between speed and Cost

RAM

34

Memory Management

Hold multiple programs in main memory Improve CPU utilization. Why?

Problems Protection

Program A is not allowed to fetch data within program B

Protect kernel from users’ programs Relocation

Each program starts from logical address 0 How to load and allocate them into main

memory?

35

Base/Limit Registers

Base register Point to the start of a program Its content is added to every

program address Limit register

Record the size of program + data Limit of addresses

Virtual address physical address Base = 4096, limit = 6114 Virtual addr = 2000 physical addr

= 2000+4096=6096 < limit, legal! MMU: memory management unit

User program and data

User program and data

Operating system

0

Base

Limit

0xFFFFFFF

36

Split Program and Data Why: multiple users

may run a same program

How: base/limit registers for program and data, respectively

Overhead of switching: context switch

User-2 data

User-1 data

User program

Operating system

Base-1

Limit-1

Registers when

running program 1

Base-2

Limit-2

Base-2

Limit-2

Registers when

running program 2

Base-1

Limit-1