cs357 Lecture Notes Spring 2000 Week 2, Tuesday The reading for today was Chapter 1, and you should have prepared answers to questions 1.1, 1.5, 1.8, 1.11, 1.12 Reading for Thursday, 2.1 through 2.4 Prepare an answer for Question 2.4 Warning: Chapter 2 is not a great read -- the level of detail is all over the map. Good chance to practice hierarchical reading. Review ------ Last time, I gave an overview of the academic and administrative structure of the class, and I answered the question... What is an operating system? An operating system is a software layer between application programmers and hardware. It is largely defined by: 1) the API, or virtual machine interface 2) the hardware interface 3) the performance consequences of its implementation Outline ------- 1) questions for today 2) the story hidden in Sections 1.2 - 1.5 3) intro to Chapter 2 Questions --------- 1.1 What are the three main purposes of an OS? 1.5 What is the main advantage of multiprogramming? 1.8 The books stresses the need for an OS to make efficient use of the computing hardware. When is it appropriate for the OS to forsake this principle and to "waste" resources. Why is such a system not really wasteful? 1.11 Why are distributed systems desireable? 1.12 What the main difficulty that a programmer must overcome in writing an OS for a real-time environment? History of OS ------------- 1.2 Batch systems OS shares physical memory with one process. Pro: simple Con: lots of idle time because loading is much slower than CPU 1.3 Multiprogramming OS shares physical memory with multiple processes. Pro: overlap I/O with CPU on coarse scale -- better CPU utilization Con: complications like interprocess protection 1.4 Time-sharing systems As computers get cheaper and people get more expensive, human utilization becomes more important than CPU utilization. Support interaction by multitasking -- switching between processes on a smaller time scale. Use virtual memory so the total demand can exceed the limits of physical memory. Pro: nifty Con: complicated 1.5 Single user systems Now computers are very cheap, humans very expensive. If each computer has a single user, We don't need multitasking, right? We don't need inter-process protection, right? We don't need virtual memory, right? (Also, these machines were usually not connected to networks, so their OS often lacked network capability) WRONG! Need multitasking for responsiveness (not CPU utilization). Need protection for reliability and security. (for n components, interactions grow as n^2. How many inits does a typical Mac boot?) Need virtual memory to implement protection (not for performance). Problem: Hard to add these features as an afterthought. They need to be central to the design of the OS, and they need a little help from the hardware. The history of MacOS and Windows shows how hard it is to back into these features. But if you know how to do it, it's not that hard. The kernel of Linux was written by one person in six months. Chapter 2 --------- 2.1 System model 2.2 I/O 2.3 Storage (memory and disk) 2.4 Memory hierarchy 2.5 Implementation of protection dual-mode instructions I/O interface memory cpu System model: for now, just a CPU connected to memory and a disk drive by a bus. In real systems, there is usually one bus for memory and one bus for everything else, bit lets keep things simple for now. Section 2.2 ----------- How does data get from the CPU to somewhere else. 1) CPU puts signal onto bus to identify the target device, then puts a block of data on bus. Block size varies depending on the device. Data winds up in the controller for the device, which is hardware that includes at least a little memory. Controller does its thing. 2) CPU might wait for the controller to finish before proceeding (synchronous I/O) or go off and do something else (asynchronous). What kind of something else can it do? 3) If the operation produces a result, the CPU might have to poll (ask repeatedly) to see if it is done, or the device might generate an interrupt when it is done. 4) If the destination of the result is memory, we have another choice. The CPU can explicitly move the data from the device into memory, or the device might move it into memory without interrupting the CPU. The latter is called DMA -- direct memory access.