cs4023 – operating systems (week 2) dr. atif azad [email protected] 1

45
CS4023 – Operating Systems (week 2) Dr. Atif Azad [email protected] 1

Upload: randolph-day

Post on 11-Jan-2016

233 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

1

CS4023 – Operating Systems(week 2)

Dr. Atif [email protected]

Page 2: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

2

Acknowledgement

• Significant material in this set of lectures has been borrowed from:– http://www.cs.berkeley.edu/~kubitron/courses/cs

162/. Copyright © 2010 UCB

– http://www.os-book.com . © 2014 Silberschatz et al.

– Dr Patrick Healy at CSIS Department, University of Limerick.

Page 3: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

3

Secondary Storage - Review

• RAM is fast but limited and volatile. • Need secondary storage.

– Different types. – Solid State Devices (SSD) are faster than typical

magnetic hard drive (can mix RAM and non-volatile storage).

• Different criteria for judging the storage type.

Page 4: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Storage Hierarchy

• Storage systems organized in hierarchy– Speed– Cost– Volatility

• Caching – copying information into faster storage system; main memory can be viewed as a cache for secondary storage– Faster storage checked first. if info there use it, else copy data

into cache, because– Information in use is likely to be used again– Cache smaller than storage being cached. Thus cache

management is an important design problem.• Cache size?• When to swap data in and out of cache?

Section 1.8/1.8.2

Page 5: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Storage-Device HierarchySp

eed

and

Cost

Volatile

Page 6: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

6

Performance of Various Levels of Storage

Page 7: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

7

I/O Structure and Interrupts• Device controllers (DC) (hardware) handle devices.

– Contains memory: registers and local buffer.• OS talks to DC through Device Drivers (DD)

(software)• I/O (summary):

– DD indicates what is required (e.g. read/write).– DC transfers data: device to/from local buffer.– End of transfer:

• DC indicates to DD via an interrupt.• And also interrupts the CPU.

Book section 1.2.3

Page 8: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

8

Interrupt Timeline

• Interrupt CPU when data copied from buffer to main memory.• Repeated, small data I/O can slow things down• Direct Memory Access (such as disk copying).

Interrupts to CPU

Page 9: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

9

Direct Memory Access (DMA)

• Instead of generating one interrupt per byte of data:– Copy the whole block of data from the buffer to main memory

and then interrupt the CPU.– Point: I/O without disturbing CPU.

• High speed I/O– Less overhead for the CPU with DMA

• Note: for programmers:– Avoid repetitive I/O in your programs. – Can slow things down– Java provides (bulk) Buffered readers and writer classes.

Page 10: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

10

DMA: Implications for Cache?

• Cache Incoherence1. CPU updates X in the cache Y is stale.2. Device (through DMA) updates Y X is stale.

• Solution– External (DMA) ‘write’ forces a cache read.– External (DMA) ‘read’ forces a cache flush (write back)– Either hardware or OS looks after cache coherence.

X is a cached copy of Y.

Details: http://en.wikipedia.org/wiki/Direct_memory_access#Cache_coherency

Page 11: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

11

Putting it together: How Computer System Works

• Fetch and Execute• First the OS loads a program into RAM : program process.

(section 1.4)

Section 1.3

Page 12: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

12

Lab and Tutorial Survey

• 49 responses. • Discarded Lab: Wed 1700hrs• Discarded Tut: Wed 1600hrs• Go to other labs of choice

– Hopefully, no oversubscription:– In which case re-assignments happen next week– Stick to 1 lab and 1 tutorial, as you will be marked

present.

Page 13: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

13

Life without an OS• Source CodeCompilerObject CodeHardware• How do you get object code onto the hardware?• How do you print out the answer?• Once upon a time, had to Toggle in program in

binary and read out answer from LED’s!

Altair 8080

Page 14: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

14

What if only one Application Runs: Simple OS

• Happened in early PCs• Still happens in special purpose processors

such as those in elevators, cars etc. • The OS was simple library of services:

– standard device drivers– Interrupt handlers– Math libraries – No protection from processes interfering with

each other or with OS e.g. MS DOS

Page 15: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

15

• Multi-programming: many processes executing (not necessarily in parallel):– Many loaded in RAM together– While one has to wait, another starts.– CPU remains busy.– But response time may become a problem.

• Time sharing: extends multi-programming– CPU switches from one process to another fast– It appears all processes are running in parallel. – But they are not: called concurrent programming.

Modern OS: Multiple AppsSection 1.4

Page 16: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

16

Memory Structure with Multi-programming

• Which job runs first: scheduling• More jobs than RAM size?

– Use disk space to swap in and out of RAM

– This disk space is Virtual Memory.– Thus logical memory > physical

memory• Jobs writing/reading into space of

other jobs or OS? Need protection.

Page 17: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

17

Protecting OS and other Processes from each other

• Problem: run multiple applications such that– User programs do not crash OS– User programs do not crash each other– Different parts of OS do not crash other parts.

• Mechanisms: – Address Translation– Dual Mode Operation

• Mechanisms implement a simple policy:– Programs are not allowed to read/write memory of

other programs.

Page 18: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

18

Address Translation• Address Space

– A group of memory addresses usable by something – Each program (process) and kernel has potentially

different address spaces.• Address Translation:

– Translate from Virtual Addresses (emitted by CPU) into Physical Addresses (of memory)

– Mapping often performed in Hardware by Memory Management Unit (MMU)

CPU MMU

VirtualAddresses

PhysicalAddresses

Page 19: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Example of Address Translation

Prog 1Virtual

AddressSpace 1

Prog 2Virtual

AddressSpace 2

CodeDataHeapStack

CodeDataHeapStack

Data 2

Stack 1

Heap 1

OS heap & Stacks

Code 1

Stack 2

Data 1

Heap 2

Code 2

OS code

OS dataTranslation Map 1 Translation Map 2

Physical Address Space

Q: Still vulnerable?

Page 20: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Dual Mode Operation• Hardware provides at least two modes:

– “Kernel” mode (or “supervisor” or “protected” or “previliged”)– “User” mode: Normal programs executed

• Some instructions/ops prohibited in user mode:– Example: cannot modify MMU functionality in user mode

• Attempt to modify Exception generated

• System boots into kernel mode; then, goes into user mode.• Transitions from user mode to kernel mode:

– System Calls, software Interrupts (traps or exceptions)

Section 1.5

Page 21: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

21

Dual Mode Operation (Contd.)• Protection issues if no dual mode in hardware

– E.g. Intel 8088 processor and MS DOS. – Buggy/malicious program can wipe out the OS

• Modern OS: Windows 7, Unix, Linux etc use dual mode in modern intel CPUs.

• System call: conducts previliged operations on behalf of user processes.– System call generates a software interrupt (trap).– Trap is serviced by an interrupt service routine in the interrupt vector.– Service routine executes in kernel mode.

• Q: What mode for the instruction that switches to kernel mode?– A: Kernel mode. – Kernel examines the interrupt generating instruction, whether it is legal and

contains correct parameters.

Page 22: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

22

Computer System architecture• All these facilities in a single processor system.

– Remember the difference between concurrency and parallel?

– Concurrent is not necessarily parallel– May contain special purpose processors: e.g.

device controllers. – 1 general purpose processor single processor

system.

Section 1.3

Page 23: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Multi-Processor Systems

• Multiprocessors systems growing in use and importance– Also known as parallel systems, tightly-coupled systems– Advantages include:

• Increased throughput• Economy of scale• Increased reliability – graceful degradation or fault tolerance

– Two types:• Asymmetric Multiprocessing – each processor is assigned a

specific task.• Symmetric Multiprocessing (SMP) – each processor performs

all tasks

Page 24: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Symmetric Multiprocessing Architecture

• Independent cache and registers.• Shared Memory. (minimise variance of mem.)• Concern: utilization of all processors equally.

– Ineffciencies if some work while others are idle.

Page 25: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

A Dual-Core Design

• Multicore machines have multiple cores on the same chip.

• The design below: each core having its own cache. – Not always: possible to have a shared cache or shared/local

mix.

– Cache coherence[1] in local caches?

• Parallel software required to utilise multiple cores. [1]http://en.wikipedia.org/wiki/Cache_coherence

Aside: Blade Servers

Page 26: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

26

Clustered Systems.

• Independent computer systems (nodes) connected through a network.– Local area network (LAN)– Internet/Wide Area Networks– Through a switch

• Layer of cluster software.

http://en.citizendium.org/wiki/Beowulf_cluster

Page 27: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

27

Clustered Systems

• High availability of services. – Redundant nodes taking over if another node fails

• Can be more powerful than SMP systems.– Application can run on independent systems– Provide High Performance Computing.

• What should the software do?– Be parallelizable to take advantage– And then combine the results back

• Case study: MapReduce on Hadoop.

Page 28: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

28

History of Operating Systems

• A history of resource driven choices. • Reference in Book: section 1.12

Page 29: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

29

Moore’s Law Effects

• Nothing like this in any other area of business• Transportation in over 200 years:

– 2 orders of magnitude from horseback @10mph to Concorde @1000mph

– Computers do this every decade (at least until 2002)!

• What does this mean for us?– Techniques have to vary over time to adapt to

changing tradeoffs

Page 30: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Dawn of timeENIAC: (1945—1955)

• “The machine designed by Drs. Eckert and Mauchly was a monstrosity. When it was finished, the ENIAC filled an entire room, weighed thirty tons, and consumed two hundred kilowatts of power.”

• http://ei.cs.vt.edu/~history/ENIAC.Richey.HTML

Page 31: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

History Phase 1 (1948—1970)Hardware Expensive, Humans Cheap

• When computers cost millions of $’s, optimize for more efficient use of the hardware!– Lack of interaction between user and computer

• User at console: one user at a time• Batch monitor: load program, run, print

• Optimize to better use hardware– When user thinking at console, computer idleBAD!– Feed computer batches and make users wait

• No protection: what if batch program has bug?

Page 32: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Core Memories (1950s & 60s)

• Core Memory stored data as magnetization in iron rings– Iron “cores” woven into a 2-dimensional mesh of wires– Origin of the term “Dump Core”

• See: http://www.columbia.edu/acis/history/core.html

The first magnetic core memory, from the IBM 405 Alphabetical Accounting Machine.

Page 33: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

History Phase 1½ (late 60s/early 70s)• Important to keep machines busy: overlap I/O and compute

– DMA – Direct Memory Access for I/O devices– I/O can be completed asynchronously

• Multiprogramming: several programs run simultaneously– Small jobs not delayed by large jobs– More overlap between I/O and CPU– Need memory protection between programs and/or OS

• Complexity gets out of hand: – Multics: announced in 1963, ran in 1969

• 1777 people “contributed to Multics” (30-40 core dev)• Turing award lecture from Fernando Corbató (key researcher): “On building systems

that will fail”

– OS 360: released with 1000 known bugs (APARs)• “Anomalous Program Activity Report”

• OS finally becomes an important science:– How to deal with complexity???– UNIX based on Multics, but vastly simplified

Page 34: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

1973:1. 7 Mbit/sq. in140 MBytes

1979:7. 7 Mbit/sq. in2,300 MBytes

Early Disk History

Contrast: Seagate 2TB,400 Gbit/SQ in, 3½ in disk, 4 platters

Page 35: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

History Phase 2 (1970 – 1985)Hardware Cheaper, Humans Expensive

• Computers available for tens of thousands of dollars instead of millions

• OS Technology maturing/stabilizing• Interactive timesharing:

– Use cheap terminals (~$1000) to let multiple users interact with the system at the same time

– Sacrifice CPU time to get better response time– Users do debugging, editing, and email online

• Problem: Thrashing– Performance very non-linear

response with load– Thrashing caused by many

factors including• Swapping, queueing Users

Resp

on

se

time

Page 36: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

The ARPANet (1968-1970’s)

• Paul Baran– RAND Corp, early 1960s– Communications networks that

would survive a major enemy attack

• ARPANet: Research vehicle for “Resource Sharing Computer Networks”– 2 September 1969: UCLA first

node on the ARPANet– December 1969: 4 nodes

connected by 56 kbps phone lines– 1971: First Email– 1970’s: <100 computers

SRI940

UCLASigma 7

UCSBIBM 360

UtahPDP 10

IMPs

BBN team that implementedthe interface message processor (IMP)

Page 37: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

History Phase 3 (1981— )Hardware Very Cheap, Humans Very Expensive

• Computer costs $1K, Programmer costs $100K/year– If you can make someone 1% more efficient by giving them

a computer, it’s worth it!– Use computers to make people more efficient

• Personal computing: – Computers cheap, so give everyone a PC

• Limited Hardware Resources Initially:– OS becomes a subroutine library– One application at a time (MSDOS, CP/M, …)

• Eventually PCs become powerful:– OS regains all the complexity of a “big” OS– multiprogramming, memory protection, etc (NT,OS/2)

Page 38: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

History Phase 3 (con’t)Graphical User Interfaces

• Human Computer Interaction• Xerox Star: 1981

– Originally a researchproject (Alto)

– First “mice”, “windows”• Apple Lisa/Machintosh: 1984

– “Look and Feel” suit 1988• Microsoft Windows:

– Win 1.0 (1985)– Win 3.1 (1990)– Win 95 (1995)– Win NT (1993)– Win 2000 (2000)– Win XP (2001)– Win Vista (2007)– Windows 7

Xero

x S

tar

Win

dow

s 3

.1

HAL/Protection

No HAL/Full Prot

Page 39: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

History Phase 4 (1988—): Distributed Systems

• Networking (Local Area Networking)– Different machines share resources– Printers, File Servers, Web Servers– Client – Server Model

• Services– Computing– File Storage

Page 40: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

• Developed by the research community– Based on open standard: Internet Protocol– Internet Engineering Task Force (IETF)

• Technical basis for many other types of networks– Intranet: enterprise IP network

• Services Provided by the Internet– Shared access to computing resources: telnet (1970’s)– Shared access to data/files: FTP, NFS, AFS (1980’s)– Communication medium over which people interact

• email (1980’s), on-line chat rooms, instant messaging (1990’s)• audio, video (1990’s, early 00’s)

– Medium for information dissemination• USENET (1980’s)• WWW (1990’s)• Audio, video (late 90’s, early 00’s) – replacing radio, TV?• File sharing (late 90’s, early 00’s)

History Phase 4 (1988—): Internet

Page 41: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

The Morris Internet Worm (1988)• Internet worm (Self-reproducing)

– Author Robert Morris, a first-year Cornell grad student– Launched close of Workday on November 2, 1988– Within a few hours of release, it consumed resources to the point of

bringing down infected machines

• Techniques– Exploited UNIX networking features (remote access)– Bugs in finger (buffer overflow) and sendmail programs (debug mode

allowed remote login)– Dictionary lookup-based password cracking– Grappling hook program uploaded main worm program

Page 42: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Network “Cloud”Section 1.11.7

Page 43: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

History Phase 5 (1995—): Mobile Systems• Ubiquitous Mobile Devices

– Laptops, PDAs, phones– Small, portable, and inexpensive

• Recently twice as many smart phones as PDAs• Many computers/person!

– Limited capabilities (memory, CPU, power, etc…)• Wireless/Wide Area Networking

– Leveraging the infrastructure– Huge distributed pool of resources extend devices– Traditional computers split into pieces. Wireless

keyboards/mice, CPU distributed, storage remote• Peer-to-peer systems

– Many devices with equal responsibilities work together– Components of “Operating System” spread across globe

Page 44: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

Open-Source Operating Systems

• Operating systems made available in source-code format rather than just binary closed-source

• Counter to the copy protection and Digital Rights Management (DRM) movement

• Started by Free Software Foundation (FSF), which has “copyleft” GNU Public License (GPL)

• Examples include GNU/Linux and BSD UNIX (including core of Mac OS X), and many more

• Can use VMM like VMware Player (Free on Windows), Virtualbox (open source and free on many platforms - http://www.virtualbox.com) – Use to run guest operating systems for exploration

Page 45: CS4023 – Operating Systems (week 2) Dr. Atif Azad Atif.azad@ul.ie 1

History of OS: Summary

• Change is continuous and OSs should adapt– Not: look how stupid batch processing was– But: Made sense at the time

• Diverse OSs– Small OS: 100K lines– Large OS: 10M lines (5M for the browser!)

• 100-1000 people-years

• Complexity still reigns• Understand OSs to simplify them