operating systems

17
Operating Systems Parallel Systems (Now basic OS knowledge)

Upload: baruch

Post on 09-Jan-2016

20 views

Category:

Documents


1 download

DESCRIPTION

Operating Systems. Parallel Systems (Now basic OS knowledge). Parallelism. Multiple processes concurrently. CPU1. CPU1. CPU1. Process 1. Pseudo- Parallelism. CPU1. CPU1. CPU1. Process 2. CPU1. Process 1. True Parallelism. CPU2. Process 2. Parallel Hardware. Registers. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Operating Systems

Operating Systems

Parallel Systems

(Now basic OS knowledge)

Page 2: Operating Systems

Parallelism

• Multiple processes concurrently

Process 1

Process 2

CPU1

CPU1

CPU1 CPU1

CPU1 CPU1

Process 1

Process 2

CPU1

CPU2

Pse

udo-

Par

alle

lism

Tru

eP

aral

leli

sm

Page 3: Operating Systems

Parallel Hardware

CPU1Registers Registers

CPU2

MemoryDisk

Controller Disk

• Symmetric Multi-Processors• Increasingly common.• How to modify OS to handle new hardware?

Page 4: Operating Systems

Two Operating Systems

• Divide memory in two

• Run an independent OS in each

• Each has it’s own processes

• Drawbacks– Twice as much memory used for OS– IPC tough– Who controls memory and disk? (convenient)– Inefficient scheduling (efficient)

Page 5: Operating Systems

Sharing the Operating System

Processor 1

Program Counter

Stack Pointer

Processor 2

Program Counter

Stack Pointer

Main Memory

OS Code

OS Common Data

P1’s OS Data

P2’s OS Data

P1’s OS Stack

P2’s OS Stack

Shared? stack process tablecurrent process device queues

RaceConditions!

Page 6: Operating Systems

SOS: Multi-Processor Support

• In StartUsingProcessTable()– What is the exchangeword mechanism similar

too?– We busy wait. Is this ok? Why or why not?

• In FinishUsingProcessTable()– We don’t protect setting the Flag. Is this ok? Why

or why not?

• In SelectProcessTable()– Why do we have the variable return_value?

• What other parts of the OS would need protection?

Page 7: Operating Systems

Example Multiprocessor OSes

• Almost all new OSes!

• Designed from start– Windows NT/2000

– Mach

• Unix– AT&T System V

– Sun Solaris

– HP Unix

– OSF Unix

– IBM AIX

– SGI Irix

– Linux

Page 8: Operating Systems

Threads

Software Multi-Processors

(Ch 5)

Page 9: Operating Systems

Threads (Lightweight Processes)

• Basic unit of CPU utilization – (“What?!” you say)

• Own– program counter– register set– stack space

• Shares– code section– data section– OS resources

text segment

data segment

ProgramCounter

(Threads)

C s

tack

B s

tack

A s

tack

A B C

A B C

“Multithreaded Program”

Process

Page 10: Operating Systems

StackA(int tmp) { B(); printf(tmp);

}B() { C();}C() { A(2);}

A: tmp = 2

C

B

A: tmp = 1

Page 11: Operating Systems

Example: A Threaded Spreadsheet

CommandThread

SpreadsheetData

OtherData

DisplayThread

RecalculateThread

Page 12: Operating Systems

What Kinds of Programs to Thread?

• Independent tasks– ex: debugger needs GUI, program, perf monitor…– especially when blocking for I/O!

• Single program, concurrent operation– Servers

+ ex: file server, Web server

– OS kernels+ concurrent system requests by multiple users

Page 13: Operating Systems

Thread Benefits• “What about just using multiple processes

with shared memory?”– fine– debugging tougher (more thread tools)– processes slower

+ 30 times slower to create on Solaris+ slower to destroy+ slower to context switch among

– processes eat up memory+ few thousand processes not ok+ few thousand threads ok

Page 14: Operating Systems

Threads Standards• POSIX (Pthreads)

– Common API– Almost all Unix’s have thread library

• Win32 and OS/2– very different from POSIX, tough to port– commercial POSIX libraries for Win32– OS/2 has POSIX option

• Solaris– started before POSIX standard– likely to be same as POSIX

Page 15: Operating Systems

SOS: Thread Implementation

• Why doesn’t the Process have a state anymore?– Does a process have to have threads?

• What new system calls might be useful for support of threads?

• What new sheduling criteria might the Dispatcher use when scheduling threads?

Page 16: Operating Systems

Levels of Threads

User Level Thread

Thread

Kernel Thread

Process A Process B

Page 17: Operating Systems

Do they Work?• Operating systems

– Mach, Windows NT, Windows 95, Solaris, IRIX, AIX, OS/2, OSF/1

– Millions of (unforgiving) users

• NFS, SPEC

1 4 8 12 16 20 24 CPUs

Spe

edup