Скачать презентацию CPS 110 Intro to Operating Systems Author Landon Скачать презентацию CPS 110 Intro to Operating Systems Author Landon

48aa8d387bd256520d44d9cb60a5ff69.ppt

  • Количество слайдов: 53

CPS 110: Intro to (Operating) Systems Author: Landon Cox Instructor: Jeff Chase August 24, CPS 110: Intro to (Operating) Systems Author: Landon Cox Instructor: Jeff Chase August 24, 2009

Syllabus: prerequisites ê CPS 100 ê Basic data structures and memory layout ê Allocating Syllabus: prerequisites ê CPS 100 ê Basic data structures and memory layout ê Allocating memory on the stack versus from the heap ê CPS 104 ê ê ê Basic computer architecture, ISAs Registers: stack pointer, PC, general-purpose Virtual memory translation Page tables TLB, caching ê Other: C/C++

Syllabus: lectures and textbook ê Lecture notes on the web (125 pages) ê Exams Syllabus: lectures and textbook ê Lecture notes on the web (125 pages) ê Exams based on content of lectures ê Textbooks ê ê Only suggested “Modern Operating Systems” Easy to find on-line New book: Saltzer and Kaashoek

Syllabus: discussion sections ê One section, starting this week ê F 2: 50 – Syllabus: discussion sections ê One section, starting this week ê F 2: 50 – 4: 05 ê Teaching Assistant ê Jie Xiao (“Jennifer”) ê ([email protected] duke. edu) ê Undergraduate Teaching Assistants ê Matt Jacobson

Syllabus: homework problems ê Posted on web on Monday of each week ê Should Syllabus: homework problems ê Posted on web on Monday of each week ê Should be done before discussion section ê Not graded, but count toward participation

Syllabus: projects ê Where you will learn the most ê 4 projects ê ê Syllabus: projects ê Where you will learn the most ê 4 projects ê ê 0: very simple intro to C++ 1: build a user-level concurrency package (thread library) 2: build a virtual memory manager 3: hack into a vulnerable system ê Projects aren’t long, but are difficult (and “exacting”) ê Only 100 -1, 000 lines/code, but could be many hours ê Everything is in C++ ê Project 0 will be posted in a few days

Syllabus: project environment ê Linux/GNU environment ê You need a CS account ê Don’t Syllabus: project environment ê Linux/GNU environment ê You need a CS account ê Don’t have one? Send me e-mail. ê [email protected] duke. edu by August 28 ê Login to linux. cs. duke. edu to submit

Syllabus: project groups ê All projects done in groups of 2 or 3 ê Syllabus: project groups ê All projects done in groups of 2 or 3 ê Email groups to [email protected] duke. edu ê By Friday (August 28) ê {name, Net. ID, CS login} for each member ê Group members may be asked to rate each other ê Procedure for firing, quitting in syllabus

Syllabus: project auto-grading ê All projects are auto-graded ê Immediate feedback ê Use submit Syllabus: project auto-grading ê All projects are auto-graded ê Immediate feedback ê Use submit 110 script on cs machines ê One submission/group/day gets feedback ê Can’t use to debug your project ê + three bonus submissions/group/project ê Any group member’s submission counts

More on the auto-grader ê Very narrow feedback: correct or incorrect ê Doesn’t say More on the auto-grader ê Very narrow feedback: correct or incorrect ê Doesn’t say what is wrong ê Follow specifications carefully ê Still have to write a test suite (except P 0) ê Don’t rely on auto-grader feedback alone ê To get more useful feedback ê Come talk to us! ê We will provide many office hours every week ê (double office hours week before a deadline)

Syllabus: project timelines ê Due at 6 pm, accepted until 11: 59 pm ê Syllabus: project timelines ê Due at 6 pm, accepted until 11: 59 pm ê Auto-grader clock is the one that counts ê Last submission to auto-grader is final ê 3 late days/group/semester ê Intended for unexpected problems ê No extensions ê Start early!

Syllabus: project collaboration ê Ok, among groups ê C++ syntax, course concepts ê “What Syllabus: project collaboration ê Ok, among groups ê C++ syntax, course concepts ê “What does this part of the handout mean? ” ê Not ok, among groups ê Design/writing of another’s program ê Includes prior class solutions ê “How do I do this part of the handout? ” ê We use automated similarity-detection software ê Just changing the variable names won’t save you ê http: //theory. stanford. edu/~aiken/moss/ ê If in doubt, ask me

Syllabus: grades, exams ê Projects: 35% ê Midterm: 30% ê Monday, February 23 ê Syllabus: grades, exams ê Projects: 35% ê Midterm: 30% ê Monday, February 23 ê Final: 30% ê Wednesday, April 29, 7 -10 pm ê Participation: 5%

Projects and exams ê The two are not independent ê Familiarity with projects is Projects and exams ê The two are not independent ê Familiarity with projects is critical to doing well on exams ê I like to ask questions about projects on exams ê “Extend Project X to include this functionality” ê Know your project! ê You can assign roles to different people ê But each member must understand all aspects

Syllabus: getting help ê Newsgroup ê http: //courses. duke. edu ê Office hours ê Syllabus: getting help ê Newsgroup ê http: //courses. duke. edu ê Office hours ê With me: Tu, 1: 00 – 3: 00, etc… ê With Jie: Tu, 1: 30 – 2: 30, Th 4: 00 -5: 00 ê UTAs… ê Post to the newsgroup ê And you may also cc: us

Questions about the course? Questions about the course?

Goals for CPS 110 ê First part: demystify the operating system ê How does Goals for CPS 110 ê First part: demystify the operating system ê How does my computer start running? ê How does a program load into memory? ê Second part: demystify the Internet ê How does my email know where to go? ê Why is Google so fast?

Duke curriculum: one view CPS 1, 6, 100, 108 What’s missing? CPS 110 CPS Duke curriculum: one view CPS 1, 6, 100, 108 What’s missing? CPS 110 CPS 104 Applications Ideas high-level programming languages compiling, reading programs off disk, getting program into memory, reading keyboard, starting the computer, saving files, filenames, networking Hardware Assembly language program gates

“Systems”: A Bigger Picture ê Programmable platforms to enable sharing of data and resources “Systems”: A Bigger Picture ê Programmable platforms to enable sharing of data and resources ê “Textbook” example: operating systems ê “Cloud” clusters ê Etc…?

Systems as Art http: //www. sammlung. daimler. com/sculpt/potsdamerplatz/potsd_tinguely 500. jpg Systems as Art http: //www. sammlung. daimler. com/sculpt/potsdamerplatz/potsd_tinguely 500. jpg

Thinking about interfaces ê Consider the Java language and its key word “interface” ê Thinking about interfaces ê Consider the Java language and its key word “interface” ê What is a Java object? ê List of methods and collection of internal state ê What is a Java interface? ê Set of methods associated with an object that a programmer can call ê What do those methods do? ê Invoke code (let the object do work on the caller’s behalf) ê Modify the object’s public/private state ê Why are interfaces useful? ê They provide an “abstraction” or simplification ê Callers don’t have to know an object exact type or implementation

OS terminology ê Key terms: interface, resource (cpu, mem, etc), abstraction, virtual ê What OS terminology ê Key terms: interface, resource (cpu, mem, etc), abstraction, virtual ê What is an interface? ê An interface is a set of primitives or operations ê Interfaces provide access to resources and/or data ê What do we mean by abstraction? ê How resources are presented to a client ê Can think of as an illusion that makes resources easier to program ê What does it mean to virtualize something? ê Provides an abstraction (simple way to manipulate resources) ê (mostly) disallow direct access to reality/resources

Interface and abstraction Interface and abstraction

Virtualization? Virtualization?

Standards, wrappers, adapters Standards, wrappers, adapters

What is an operating system? ê Program that runs on CPU, (mostly) like any What is an operating system? ê Program that runs on CPU, (mostly) like any other Applications OS Hardware “Virtual machine” Interface “Physical machine” Interface ê Virtual interface should be “easier” than physical

What is an operating system? Applications OS Hardware What interface does the OS present? What is an operating system? Applications OS Hardware What interface does the OS present? “Virtual machine” Interface “Physical machine” Interface What interface does the hardware present? Instruction set: Load/store, mem, regs

Hardware-software stack Applications OS Hardware Hardware-software stack Applications OS Hardware

OS vs user-level programs Familiar view Alternate view User program OS OS User program OS vs user-level programs Familiar view Alternate view User program OS OS User program How do programs start? Tasks outside program? (net recv) How do prevent CPU hogging? User program OS runs first, calls program Programs run until they return control to OS (by themselves or forced by hardware) Then OS calls another program Who calls whom?

Functions of the OS 1. Illusionist ê Makes hardware seem “nicer” than it really Functions of the OS 1. Illusionist ê Makes hardware seem “nicer” than it really is ê Examples? ê ê ê Programs seem to have their own CPU AFS: single, unified file system Name data with human-readable names Directories Packets get lost; OS makes net look reliable Disk is slow; OS makes it look fast via caching

Functions of the OS 1. Illusionist ê Makes hardware seem nicer than it really Functions of the OS 1. Illusionist ê Makes hardware seem nicer than it really is 2. Government ê Divides hardware resources among competing programs ê What hardware resources does the OS manage? ê ê Processor Memory Network Disk

Functions of the OS 1. Illusionist ê Makes hardware seem nicer than it really Functions of the OS 1. Illusionist ê Makes hardware seem nicer than it really is 2. Government ê Divides hardware resources among competing programs ê Taxes programs (OS needs CPU, memory to run) ê Taken for granted when it works, cursed when it breaks

Why study operating systems? ê Very few of you will ever write one … Why study operating systems? ê Very few of you will ever write one … 1. Illusionist, govn functions appear in many domains ê Google provides the illusion of a single web server ê How should basketball seats be allocated? 2. Design principles ê Proper abstractions, caching, indirection ê Concurrency, naming, atomicity, authentication ê Protection, resource multiplexing (fairness) ê How does OS create the illusions we know/love?

Hints for designing systems ê What is a system? ê Components, interconnections ê Interfaces, Hints for designing systems ê What is a system? ê Components, interconnections ê Interfaces, environment ê Systems do something for their environs ê Export this behavior via an interface ê Cleanly divides the world in two ê Parts of the system + the environment

Systems from 10, 000 feet Component System Environment aka “the client” Systems from 10, 000 feet Component System Environment aka “the client”

Why is designing systems hard? 1. Emergent properties ê Can’t predict all component interactions Why is designing systems hard? 1. Emergent properties ê Can’t predict all component interactions ê Millennium bridge ê Synchronized stepping leads to swaying ê Swaying leads to more forceful synchronized stepping ê Leads to more swaying … 2. Propagation of effects 3. Incommensurate scaling 4. Trade-offs

Why is designing systems hard? 1. Emergent properties 2. Propagation of effects ê ê Why is designing systems hard? 1. Emergent properties 2. Propagation of effects ê ê ê Want a better ride so increase the tire size Need a larger trunk for the larger spare Need to move the back seat forward Need to make front seats thinner Leads to worse driver comfort than before 3. Incommensurate scaling 4. Trade-offs

Why is designing systems hard? 1. Emergent properties 2. Propagation of effects 3. Incommensurate Why is designing systems hard? 1. Emergent properties 2. Propagation of effects 3. Incommensurate scaling ê ê Consider the giant mouse Weight ~ size 3 (volume) Bone strength ~ size 2 (cross section area) An elephant sized mouse is not sustainable 4. Trade-offs

Why is designing systems hard? 1. 2. 3. 4. Emergent properties Propagation of effects Why is designing systems hard? 1. 2. 3. 4. Emergent properties Propagation of effects Incommensurate scaling Trade-offs ê ê “Waterbed effect” Push on one end, and the other goes up Spam filters and smoke detectors False positives vs false negatives

Why is designing systems hard? 1. 2. 3. 4. ê Emergent properties Propagation of Why is designing systems hard? 1. 2. 3. 4. ê Emergent properties Propagation of effects Incommensurate scaling Trade-offs In the immortal words of HT Kung ê “Systems hard. Must work harder. ”

History of operating systems ê History dominated by two trends ê Hardware: better, cheaper, History of operating systems ê History dominated by two trends ê Hardware: better, cheaper, faster ê Software: sprawl ê Microsoft embodies tension between these trends ê MS gained 90% market share by running on cheap hw ê Supporting all that hardware complicates the OS ê (3 rd-party drivers responsible for vast majority of crashes) ê How is Apple’s strategy different? ê Jobs chooses the hardware you will run ê HW-to-app control reduces complexity, choice, discount

First phase: single operator ê One goal: make it work ê Interactive (user has First phase: single operator ê One goal: make it work ê Interactive (user has entire machine to herself) ê Users sign up, get room for two hours at a time ê “OS” is really just a library linked into your program What is wrong with this timeline? CPU utilization is awful Since CPUs were expensive, this mattered

Second phase: batch processing ê Goal: improve CPU, I/O utilization ê Machine is no Second phase: batch processing ê Goal: improve CPU, I/O utilization ê Machine is no longer interactive ê Users submit program (stack of cards) to queue ê One job at a time, CPU idle during I/O, I/O idle during CPU ê OS is a batch monitor + library of services ê Loads program, runs program, prints results ê Loads next program …

Second phase: batch processing ê Goal: improve CPU, I/O utilization ê Machine is no Second phase: batch processing ê Goal: improve CPU, I/O utilization ê Machine is no longer interactive ê Users submit program (stack of cards) to queue ê One job at a time, CPU idle during I/O, I/O idle during CPU ê What key OS function starts to matter now? ê Protection: programs must not corrupt monitor ê Programs must relinquish CPU to monitor

Second phase: batch processing ê Goal: improve CPU, I/O utilization ê Machine is no Second phase: batch processing ê Goal: improve CPU, I/O utilization ê Machine is no longer interactive ê Users submit program (stack of cards) to queue ê One job at a time, CPU idle during I/O, I/O idle during CPU ê Why wasn’t protection an issue before? ê No batch monitor to corrupt ê Person in lab coat took CPU back from program

Third phase: multi-program batch ê Goal: overlap CPU, I/O ê ê When one job Third phase: multi-program batch ê Goal: overlap CPU, I/O ê ê When one job is reading from disk, run another job on CPU Use DMA + interrupts to allow background I/O DMA: devices write to program memory Interrupts: devices can tell CPU the I/O is done Job 1 Job 2

Third phase: multi-program batch ê Goal: overlap CPU, I/O ê What are the OS’s Third phase: multi-program batch ê Goal: overlap CPU, I/O ê What are the OS’s new responsibilities? ê Switch between processes ê Manage multiple I/Os across devices ê Protect processes from each other Job 1 Job 2

Fourth phase: time-sharing ê Goal: keep efficiency, restore interactivity ê Key insight: humans are Fourth phase: time-sharing ê Goal: keep efficiency, restore interactivity ê Key insight: humans are really just slow I/O devices ê Switch between programs during think-time Job 1 Job 2 Job 3 Increased complexity: • Many jobs • Outstanding reqs • Many job sources

4 a: computing as a social medium JCR Licklider, “The Computer as a Communication 4 a: computing as a social medium JCR Licklider, “The Computer as a Communication Device” Science and Technology, April 1968.

Fifth phase: personal computing ê What are PC operating systems most like? ê As Fifth phase: personal computing ê What are PC operating systems most like? ê As PC prices dropped, single-operator became feasible ê OS was again just a library of services (MS-DOS) ê With one user, do jobs need to time-share? ê Early PC OSes could only do one thing at a time ê Everything waited while printing/loading a program (Mac < X) ê Need protection if I’m the only one using the PC? ê Protect me from myself (or my buggy software) ê Early PCs provided no protection ê (why Windows before XP, Mac before X were awful) ê PC operating systems are basically time-sharing OSes now

Operating system complexity ê Windows XP ê > 40 million lines of code ê Operating system complexity ê Windows XP ê > 40 million lines of code ê Most of this code is device drivers (not written by MS) ê Windows NT took 7 years to develop ê Only worked well years after it shipped ê Windows 2000 ê Shipped with 63, 000 “potential known defects” ê Hot research area ê Simplify, automatically find OS bugs

OS Complexity ê Lines of code ê Vista: 50 million ê Linux 2. 6: OS Complexity ê Lines of code ê Vista: 50 million ê Linux 2. 6: 6 million ê (mostly driver code) ê Sources of complexity ê Multiple instruction streams (processes) ê Multiple interrupt sources (I/O, timers, faults) ê How can we keep everything straight?

Dealing with complexity ê Program decomposition ê Functions ê OO: Classes, types int main Dealing with complexity ê Program decomposition ê Functions ê OO: Classes, types int main () { cout << “input: ”; cin >> input; output = sqrt (input); output = pow (output, 3); cout << output << endl; } int main () { get. Input (); compute. Result (); print. Output (); } void get. Input () { cout << “input: ”; cin >> input; } void computer. Result () { output = sqrt (input); output = pow (output, 3); } void print. Output () { cout << output << endl; }