cs 325 principles of operating systems

23
1 Slide 02a-1 CS 325, New Mexico Tech CS 325 Principles of Operating Systems Dr. Xiao Qin New Mexico Tech http://www.cs.nmt.edu/~xqin [email protected] Spring, 2007 These slides are adapted from notes by Dr. Gary Nutt (University of Colorado at Boulder) Slide 02a-2 CS 325, New Mexico Tech Review: The OS as a Conductor The OS coordinates the sharing and use of all the components in the computer

Upload: others

Post on 30-May-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 325 Principles of Operating Systems

1

Slide 02a-1CS 325, New Mexico Tech

CS 325 Principles of Operating Systems

Dr. Xiao QinNew Mexico Tech

http://www.cs.nmt.edu/[email protected]

Spring, 2007

These slides are adapted from notes by Dr. Gary Nutt (University of Colorado at Boulder)

Slide 02a-2CS 325, New Mexico Tech

Review: The OS as a Conductor

The OS coordinates the sharing and use of all the components in the computer

Page 2: CS 325 Principles of Operating Systems

2

Slide 02a-3CS 325, New Mexico Tech

Today’s Goal:

1. Multiprogramming

2. Operating Systems Strategies

Slide 02a-4CS 325, New Mexico Tech

Multiprogramming

AbstractMachine Pi

OS Resource Sharing

Pi MemoryPi Memory

Pk MemoryPk Memory

Pj MemoryPj Memory

…Time-multiplexed Physical Processor

AbstractMachine Pj

AbstractMachine Pk

Space-multiplexed Physical Memory

Page 3: CS 325 Principles of Operating Systems

3

Slide 02a-5CS 325, New Mexico Tech

Multiprogramming(2)• Technique for sharing the CPU among

runnable processes– Process may be blocked on I/O– Process may be blocked waiting for other

resource, including the CPU• While one process is blocked, another might

be able to run• Multiprogramming OS accomplishes CPU

sharing “automatically” – scheduling• Reduces time to run all processes

Slide 02a-6CS 325, New Mexico Tech

How Multiprogramming Works

Process 1

Process 2

Process 3

Process 4

Space-multiplexed Memory

Time-multiplexed CPU

Page 4: CS 325 Principles of Operating Systems

4

Slide 02a-7CS 325, New Mexico Tech

Speeding Up the Car Wash

VacuumInside Wash Dry

VacuumInside

Wash Dry

(a) The Sequential Car Wash

(b) The Parallel Car Wash

Think about pipelining, if you have taken CS331.

Slide 02a-8CS 325, New Mexico Tech

Forms of ParallelismProcess-level

–How do we exploit it? What are the challenges?–Examples? CS325 OS

• Thread-level–How do we exploit it? What are the challenges?–Examples?

• Loop-level –What is really loop level parallelism? What percentage of a program’s time is spent inside loops?–CS423 Compilers

• Instruction-level–CS331 Computer Architectures

Coarse grain

Fine Grain

Hum

an in

terv

enti

on?

Page 5: CS 325 Principles of Operating Systems

5

Slide 02a-9CS 325, New Mexico Tech

Multiprogramming PerformanceTime

Using the processorI/O operation

0 ti

Pi’s Total Execution Time, ti

(a) Pi’s Use of Machine Resources

Time

P1

P2

Pi

PN

(a) All Processes’ Use of Machine Resources

Slide 02a-10CS 325, New Mexico Tech

OS Strategies

• Batch processing• Timesharing• Personal computer & workstations• Process control & real-time• Network• Distributed• Small computers

Page 6: CS 325 Principles of Operating Systems

6

Slide 02a-11CS 325, New Mexico Tech

Batch Processing

Job 19

Input Spooler Output Spooler

Job 3

Input Spool Output Spool

Slide 02a-12CS 325, New Mexico Tech

IBM System/360

Source: http://en.wikipedia.org

Page 7: CS 325 Principles of Operating Systems

7

Slide 02a-13CS 325, New Mexico Tech

Batch Processing(2)

• Job (file of OS commands) prepared offline• Batch of jobs given to OS at one time• OS processes jobs one-after-the-other• No human-computer interaction• OS optimizes resource utilization (how?)• Batch processing (as an option) still used

today

Slide 02a-14CS 325, New Mexico Tech

A Shell Script Batch File

cc -g -c menu.ccc -g -o driver driver.c menu.odriver < test_data > test_outlpr -PthePrinter test_outtar cvf driver_test.tar menu.c driver.c test_data test_outuuencode driver_test.tar driver_test.tar >driver_test.encode

Page 8: CS 325 Principles of Operating Systems

8

Slide 02a-15CS 325, New Mexico Tech

Timesharing Systems

PhysicalMachine

AbstractMachines

…Command

Command

Command

Result

Result

Result

1982 A Televideo ASCII character mode terminal made around

A HP T5700 thin client, with flash memory

Slide 02a-16CS 325, New Mexico Tech

Timesharing Systems(2)

• Uses multiprogramming• Support interactive computing model

(Illusion of multiple consoles)• Different scheduling & memory allocation

strategies than batch• Considerable attention to resource isolation

(security & protection)• Tend to optimize response time• Tends to propagate processes

Page 9: CS 325 Principles of Operating Systems

9

Slide 02a-17CS 325, New Mexico Tech

Personal Computers

• CPU sharing among one person’s processes• Power of computing for personal tasks

– Graphics– Multimedia

• Trend toward very small OS• OS focus on resource abstraction• Rapidly evolved to “personal multitasking”

systems

Slide 02a-18CS 325, New Mexico Tech

Process Control & Real-Time

• Computer is dedicated to a single purpose• Classic embedded systems• Must respond to external stimuli in fixed

time• Continuous media popularizing real-time

techniques• An area of growing interest

Page 10: CS 325 Principles of Operating Systems

10

Slide 02a-19CS 325, New Mexico Tech

Networks

• LAN (Local Area Network) evolution• 3Mbps (1975) → 10 Mbps (1980) → 100 Mbps

(1990) → 1 Gbps (2000)• High speed communication means new way to do

computing– Shared files– Shared memory– Shared procedures/objects– ???

Slide 02a-20CS 325, New Mexico Tech

Distributed OS

• Wave of the future

Distributed OS

App App

App

App

AppApp

Multiple Computers connected by a Network

Page 11: CS 325 Principles of Operating Systems

11

Slide 02a-21CS 325, New Mexico Tech

Small Computers

• PDAs, STBs, embedded systems became commercially significant

• Have an OS, but– Not general purpose– Limited hardware resources– Different kinds of devices

• Touch screen, no keyboard• Graffiti

– Evolving & leading to new class of Oses

• PalmOS, Pocket PC (WinCE), VxWorks, …

Slide 02a-22CS 325, New Mexico Tech

Evolution of Modern OS

Modern OS

Batch

Timesharing

PC & WkstationNetwork OS

Real-TimeMemory Mgmt

ProtectionScheduling

FilesDevices

Memory Mgmt

ProtectionScheduling

System software

Human-ComputerInterface

Client-Server Model

Protocols

Scheduling

Small ComputerNetwork storage,Resource management

Page 12: CS 325 Principles of Operating Systems

12

Slide 02a-23CS 325, New Mexico Tech

Examples of Modern OS

• UNIX variants (e.g. Linux) -- have evolved since 1970

• Windows NT/2K -- has evolved since 1989 (much more modern than UNIX– Win2K = WinNT, V5

• Research OSes – still evolving …• Small computer OSes – still evolving …• Book provides Linux examples• This course will use Windows NT as the

main example

Slide 02a-24CS 325, New Mexico Tech

The Microsoft OS FamilyWin32 APIWin32 API

Windows CE(Pocket PC)

Windows CE(Pocket PC)

Windows 95/98/MeWindows 95/98/Me

Windows NT/2000/XPWindows NT/2000/XP

Win32 API SubsetWin32 API Subset

Win32 API SubSetWin32 API SubSet

Page 13: CS 325 Principles of Operating Systems

13

Slide 02a-25CS 325, New Mexico Tech

Microsoft Windows NT

• Heavily window-oriented• Foundation behavior is windows-

independent– We will focus on the foundation– Use only the “MS-DOS prompt” -- cmd.exe

OS API

NT Kernel

NT User Interfaceand Graphics

NT Executive

Slide 02a-26CS 325, New Mexico Tech

Windows NT (cont)

• OS API has text orientation (like UNIX)• Object-oriented implementation• Heavy use of threads• Broad spectrum of synchronization tools• Modern I/O system

Page 14: CS 325 Principles of Operating Systems

14

Slide 02a-27CS 325, New Mexico Tech

Windows CE Organization

Kernel

OEM Abstraction Layer

Win32 API (& Network Extensions)

Graphics,Window Mgr,

andEvent Mgr

Device Drivers

ObjectStore

Networkand

CommServices

Shells and Applications

Slide 02a-28CS 325, New Mexico Tech

Using the Operating System

2

Page 15: CS 325 Principles of Operating Systems

15

Slide 02a-29CS 325, New Mexico Tech

The Airplane Pilot’s Abstract Machine

Slide 02a-30CS 325, New Mexico Tech

Basic Abstractions

ProgramProgram ResultResult

AbstractMachine

AbstractMachine

ProgramProgram ResultResult

ProgramProgram ResultResult

AbstractMachine

PhysicalMachine

… …Idea

Idea

Idea

Page 16: CS 325 Principles of Operating Systems

16

Slide 02a-31CS 325, New Mexico Tech

Abstract Machine Entities

• Process: A sequential program in execution• Resource: Any abstract resource that a

process can request, and which may can cause the process to be blocked if the resource is unavailable.

• File: A special case of a resource. A linearly-addressed sequence of bytes. “A byte stream.”

Slide 02a-32CS 325, New Mexico Tech

Algorithms, Programs, and Processes

Data

FilesFilesFiles

OtherResources

AlgorithmAlgorithm

Idea

SourceProgramSource

ProgramBinary

Program

Execution Engine

Process

StackStatus

Page 17: CS 325 Principles of Operating Systems

17

Slide 02a-33CS 325, New Mexico Tech

Classic Process

• OS implements {abstract machine} – one per task

• Multiprogramming enables N programs to be space-muxed in executable memory, and time-muxed across the physical machine processor.

• Result: Have an environment in which there can be multiple programs in execution concurrently*, each as a processes

* Concurrently: Programs appear to execute simultaneously

Slide 02a-34CS 325, New Mexico Tech

Process Abstraction

Hardware

DataDataProcessProcess

Stac

k

Processor

ExecutableMemory

ProgramProgram

Operating SystemOperating System

Page 18: CS 325 Principles of Operating Systems

18

Slide 02a-35CS 325, New Mexico Tech

Processes Sharing a Program

Shared Program Text

P1

P2

P3

P1 P2 P3

FilesFiles

FilesFiles

FilesFiles

Slide 02a-36CS 325, New Mexico Tech

Multithreaded Accountant

Purchase Orders

Invoice

Invoice

(a) Separate Processes

Purchase Orders

InvoiceFirst Accountant

Second Accountant

Accountant & Clone

(b) Double Threaded Process

Page 19: CS 325 Principles of Operating Systems

19

Slide 02a-37CS 325, New Mexico Tech

Modern Process & Thread• Divide classic process:

– Process is an infrastructure in which execution takes place – address space + resources

– Thread is a program in execution within a process context – each thread has its own stack

DataDataProcessProcess

Stac

k

ProgramProgram

Operating SystemOperating System

ThreadThread

Thread

Stac

k

Stac

k

Slide 02a-38CS 325, New Mexico Tech

A Process with Multiple Threads

Data

FilesFilesFiles

OtherResources

BinaryProgram

Process

StackStatus

StackStatus

StackStatus

Thread (Execution Engine)

Page 20: CS 325 Principles of Operating Systems

20

Slide 02a-39CS 325, New Mexico Tech

More on Processes• Abstraction of processor resource

– Programmer sees an abstract machine environment with spectrum of resources and a set of resource addresses (most of the addresses are memory addresses)

– User perspective is that its program is the only one in execution– OS perspective is that it runs one program with its resources for a

while, then switches to a different process (context switching)

• OS maintains– A process descriptor data structure to implement the process

abstraction• Identity, owner, things it owns/accesses, etc.• Tangible element of a process

– Resource descriptors for each resource

Slide 02a-40CS 325, New Mexico Tech

Address Space• Process must be able to reference every

resource in its abstract machine• Assign each unit of resource an address

– Most addresses are for memory locations– Abstract device registers– Mechanisms to manipulate resources

• Addresses used by one process are inaccessible to other processes

• Say that each process has its own address space

Page 21: CS 325 Principles of Operating Systems

21

Slide 02a-41CS 325, New Mexico Tech

Shared Address Space

• Classic processes sharing program ⇒ shared address space support

• Thread model simplifies the problem– All threads in a process implicitly use that process’s

address space , but no “unrelated threads” have access to the address space

– Now trivial for threads to share a program and data• If you want sharing, encode your work as threads in a process• If you do not want sharing, place threads in separate processes

Slide 02a-42CS 325, New Mexico Tech

Process & Address Space

Address Space

Code ResourcesResources

Abstract Machine Environment

Stack

DataResources

Page 22: CS 325 Principles of Operating Systems

22

Slide 02a-43CS 325, New Mexico Tech

Creating a Process

• Here is the classic model for creating processes:

FORK(label): Create another process in the same addressspace beginning execution at instruction labelQUIT(): Terminate the process.JOIN(count):

disableInterrupts();count--;if(count > 0) QUIT();enableInterrupts();

Slide 02a-44CS 325, New Mexico Tech

Example

procA() {while(TRUE) {<compute section A1>;update(x);<compute section A2>;retrieve(y);

}}

procB() {while(TRUE) {retrieve(x);<compute section B1>;update(y);<compute section B2>;

}}

Process AProcess A Process BProcess Bx

y

Page 23: CS 325 Principles of Operating Systems

23

Slide 02a-45CS 325, New Mexico Tech

Example (cont)

L0: count = 2;<compute section A1>;update(x);FORK(L2);<compute section A2>;

L1: JOIN(count);retrieve(y);goto L0;

L2: retrieve(x);<compute section B1>;update(y);FORK(L3);goto L1;

L3: <compute section B2>QUIT();