1.39k likes | 1.47k Views
Instructor: Liviu Iftode (iftode@cs) TA: Nader Boushehrinejadmoradi (naderb@cs) Fall 2011. CS 519: Operating System Theory. Logistics. Location and schedule: CoRE A, Thursdays from noon to 3 pm Instructor: Liviu Iftode Office: CoRE 311 Office Hours: Thursdays 10-11 am
E N D
Instructor: Liviu Iftode (iftode@cs) TA: Nader Boushehrinejadmoradi (naderb@cs) Fall 2011 CS 519: Operating System Theory
Operating System Theory Logistics Location and schedule: CoRE A, Thursdays from noon to 3 pm Instructor: Liviu Iftode Office: CoRE 311 Office Hours: Thursdays 10-11 am TA: Nader Boushehrinejadmoradi Office: Hill 353 Office Hours: Wednesdays, 2-4 pm More information http://www.cs.rutgers.edu/~iftode/cs519-2011.html http://sakai.rutgers.edu page for the course
Operating System Theory Course Overview Goals: Understand how an operating system works Learn how OS concepts are implemented in a real operating system Introduce to systems programming Learn about performance evaluation Learn about current trends in OS research
Operating System Theory Course Structure • Structure: • Each major area: • Review basic material • Discuss the implementation on xv6 • Read, present, and discuss interesting papers • Programming assignments and project
Suggested Studying Approach • Read the assigned chapter and/or code before the lecture and try to understand it • Start homework and project right away, systems programming is not easy, it takes a lot of time! • Ask questions during the lecture • Use the mailing list for discussion, do not be afraid to answer a question posted by your colleague even if you are not sure. This is a way to validate your understanding of the material.
Course Topics • Processes, threads and synchronization • Memory management and virtual memory • CPU scheduling • File systems and I/O management • Distributed systems • New trends in OS research
Operating System Theory Textbooks - Required • Stallings. Operating Systems: Internals and Design Principles, Prentice-Hall. • Any recent version will do • Papers available on the Web
Operating System Theory Textbooks - Recommended • Andrew Tanenbaum. Distributed Operating Systems, Prentice-Hall.
Operating System Theory MIT xv6 OS • Teaching OS developed by Russ Cox, Frans Kaashoek and Robert Morris from MIT • UNIX V6 ported to Intel x86 machines • Download source code and lecture materials from xv6 home page at MIT
Operating System Theory Course Requirements Prerequisites Undergraduate OS and computer architecture courses Good programming skills in C and UNIX What to expect Several programming assignments with write-ups Challenging project (a distributed shared memory protocol) Midterm and final exams Substantial reading Read, understand, and extend/modify xv6 code Paper presentations
Operating System Theory Homework Goals Learn to design, implement, and evaluate a significant OS-level software system Improve systems programming skills: virtual memory, threads, synchronization, sockets, etc Structure They are all individual assignments Software must execute correctly Performance evaluation Written report for each assignment
Operating System Theory Grading Midterm 25% Final 25% Programming assignments and in-class presentations 25% Project 25%
Operating System Theory Today What is an Operating System? Stallings 2.1-2.4 Architecture refresher …
Operating System Theory What is an operating system? application (user) operating system hardware • A software layer between the hardware and the application programs/users, which provides a virtual machine interface: easy to use (hides complexity) and safe (prevents and handles errors) • Acts as resource manager that allows programs/users to share the hardware resources in a protected way: fair and efficient
Operating System Theory How does an OS work? application (user) system calls upcalls hardware independent OS commands interrupts hardware dependent hardware • Receives requests from the application: system calls • Satisfies the requests: may issue commands to hardware • Handles hardware interrupts: may upcall the application • OS complexity: synchronous calls + asynchronous events
Operating System Theory Mechanism and Policy application (user) operating system: mechanism+policy hardware • Mechanisms: data structures and operations that implement an abstraction (e.g. the buffer cache) • Policies: the procedures that guide the selection of a certain course of action from among alternatives (e.g. the replacement policy for the buffer cache) • Traditional OS is rigid: mechanism together with policy
Operating System Theory Mechanism-Policy Split Single policy often not the best for all cases Separate mechanisms from policies: OS provides the mechanism + some policy Applications may contribute to the policy Flexibility + efficiency require new OS structures and/or new OS interfaces
Operating System Theory OS Mechanisms and Policies
Operating System Theory user: application create, kill processes, inter-process comm. operating system: process multiplex resources hardware: computer System Abstraction: Processes A process is a system abstraction: illusion of being the only job in the system
Operating System Theory Processes: Mechanism and Policy • Mechanism: • Creation, destruction, suspension, context switch, signaling, IPC, etc. • Policy: • Minor policy questions: • Who can create/destroy/suspend processes? • How many active processes can each user have? • Major policy question that we will concentrate on: • How to share system resources between multiple processes? • Typically broken into a number of orthogonal policies for individual resources such as CPU, memory, and disk.
Operating System Theory Processor Abstraction: Threads A thread is a processor abstraction: illusion of having 1 processor per execution context application: execution context create, kill, synch. operating system: thread context switch hardware: processor Process vs. Thread: Process is the unit of resource ownership, while Thread is the unit of instruction execution.
Operating System Theory Threads: Mechanism and Policy • Mechanism: • Creation, destruction, suspension, context switch, signaling, synchronization, etc. • Policy: • How to share the CPU between threads from different processes? • How to share the CPU between threads from the same process?
Operating System Theory Threads • Traditional approach: OS uses a single policy (or at most a fixed set of policies) to schedule all threads in the system. Assume two classes of jobs: interactive and batch. • More sophisticated approaches: application-controlled scheduling, reservation-based scheduling, etc
Operating System Theory Memory Abstraction: Virtual memory Virtual memory is a memory abstraction: illusion of large contiguous memory, often more memory than physically available application: address space virtual addresses operating system: virtual memory physical addresses hardware: physical memory
Operating System Theory Virtual Memory: Mechanism • Mechanism: • Virtual-to-physical memory mapping, page-fault, etc. virtual address spaces p1 p2 processes: v-to-p memory mappings physical memory:
Operating System Theory Virtual Memory: Policy • Policy: • How to multiplex a virtual memory that is larger than the physical memory onto what is available? • How to share physical memory between multiple processes?
Operating System Theory Virtual Memory • Traditional approach: OS provides a sufficiently large virtual address space for each running application, does memory allocation and replacement, and may ensure protection • More sophisticated approaches: external memory management, huge (64-bit) address space, global virtual address space
Operating System Theory Storage Abstraction: File System A file system is a storage abstraction: illusion of structured storage space application/user: copy file1 file2 naming, protection, operations on files operating system: files, directories operations on disk blocks hardware: disk
Operating System Theory File System • Mechanism: • File creation, deletion, read, write, file-block-to-disk-block mapping, file buffer cache, etc. • Policy: • Sharing vs. protection? • Which block to allocate for new data? • File buffer cache management?
Operating System Theory File System • Traditional approach: OS does disk block allocation and caching (buffer cache), disk operation scheduling, and management of the buffer cache • More sophisticated approaches: application-controlled buffer cache replacement, log-based allocation (makes writes fast)
Operating System Theory Communication Abstraction: Messaging Message passing is a communication abstraction: illusion of reliable (sometimes ordered) msg transport application: sockets naming, messages operating system: TCP/IP protocols network packets hardware: network interface
Operating System Theory Message Passing • Mechanism: • Send, receive, buffering, retransmission, etc. • Policy: • Congestion control and routing • Multiplexing multiple connections onto a single NIC
Operating System Theory Message Passing • Traditional approach: OS provides naming schemes, reliable transport of messages, packet routing to destination • More sophisticated approaches: user-level protocols, zero-copy protocols, active messages, memory-mapped communication
Operating System Theory Character & Block Devices The device interface gives the illusion that devices support the same API – character stream and block access application/user: read character from device naming, protection, read, write operating system: character & block API hardware-specific PIO, interrupt handling, or DMA hardware: keyboard, mouse, etc.
Operating System Theory Devices • Mechanisms • Open, close, read, write, ioctl, etc. • Buffering • Policies • Protection • Sharing? • Scheduling?
Operating System Theory UNIX Source: Silberschatz, Galvin, and Gagne 2005
Operating System Theory Major Issues in OS Design • Programming API: what should the VM look like? • Resource management: how should the hardware resources be multiplexed among multiple users? • Sharing: how should resources be shared among multiple users? • Protection: how to protect users from each other? How to protect programs from each other? How to protect the OS from applications and users? • Communication: how can applications exchange information? • Structure: how to organize the OS? • Concurrency: how do we deal with the concurrency that is inherent in OS’es?
Operating System Theory Major Issues in OS Design • Performance: how to make it all run fast? • Reliability: how do we keep the OS from crashing? • Persistence: how can we make data last beyond program execution? • Accounting: how do we keep track of resource usage? • Distribution: how do we make it easier to use multiple computers in conjunction? • Scaling: how do we keep the OS efficient and reliable as the offered load increases (more users, more processes, more processors)?
Operating System Theory von Neumann Machine The first computers (late 40’s) were calculators The advance was the idea of storing the instructions (coded as numbers) along with the data in the same memory
Operating System Theory Conceptual Model Memory contents 0 CPU 1 2 + - * / 3 4 5 6 7 8 9 Addresses of memory cells "big byte array"
Operating System Theory Operating System Perspective A computer is a piece of hardware that runs the fetch-decode-execute loop Next slides: walk through a very simple computer to illustrate Machine organization What the pieces are and how they fit together The basic fetch-decode-execute loop How higher-level constructs are translated into machine instructions At its core, the OS builds what looks like a more sophisticated machine on top of this basic hardware
Operating System Theory Fetch-Decode-Execute Computer as a large, general-purpose calculator Want to program it for multiple functions All von Neumann computers follow the same loop: Fetch the next instruction from memory Decode the instruction to figure out what to do Execute the instruction and store the result Instructions are simple. Examples: Increment the value of a memory cell by 1 Add the contents of memory cells X and Y and store in Z Multiply contents of memory cells A and B and store in B
Operating System Theory Instruction Encoding How to represent instructions as numbers? 8 bits 8 bits 8 bits 8 bits operators +: 1 -: 2 *: 3 /: 4 operands destination
Operating System Theory Example Encoding Add cell 28 to cell 63 and place result in cell 100: 8 bits 8 bits 8 bits 8 bits operator +: 1 -: 2 *: 3 /: 4 source operands destination Cell 28 Cell 63 Cell 100 Instruction as a number in: Decimal: 1:28:63:100 Binary: 00000001:00011100:00111111:01100100 Hexadecimal: 01:1C:3F:64
Operating System Theory The Program Counter Where is the “next instruction”? A special memory cell in the CPU called the “program counter" (the PC) points to it Special-purpose memory in the CPU and devices is called a register Naïve fetch cycle: Increment the PC by the instruction length (4) after each execute Assumes all instructions are the same length
Operating System Theory Conceptual Model Memory 0 operator 1 operand 1 2 operand 2 3 destination 4 5 6 7 8 9 Instruction 0 @ memory address 0 CPU + - * / Arithmetic Units Instruction 1 @ memory address 4 Program Counter 4
Operating System Theory Memory Indirection How do we access array elements efficiently if all we can do is name a cell? Modify the operand to allow for fetching an operand "through" a memory location E.g.: LOAD [5], 2 means fetch the contents of the cell whose address is in cell 5 and put it into cell 2 So, if cell 5 had the number 100, we would place the contents of cell 100 into cell 2 This is called indirection Fetch the contents of the cell “pointed to” by the cell in the opcode Use an operand bit to signify if an indirection is desired
Operating System Theory Conditionals and Looping Primitive “computers” only followed linear instructions Breakthrough in early computing was addition of conditionals and branching Instructions that modify the Program Counter Conditional instructions If the content of this cell is [positive, not zero, etc.] execute the instruction or not Branch Instructions If the content of this cell is [zero, non zero, etc.], set the PC to this location jump is an unconditional branch
Operating System Theory Example: While Loop while (counter > 0) { sum = sum + Y[counter]; counter–-; }; Variables to memory cells: counter is cell 1 sum is cell 2 index is cell 3 Y[0]=cell 4, Y[1]=cell 5… Memory cell address Assembly label Assembly "mnemonic" English 100 LOOP: BZ 1,END // Branch to address of END // if cell 1 is 0. 104 ADD 2,[3],2 // Add cell 2 and the value // of the cell pointed to by // cell 3 then place the // result in cell 2 108 DEC 3 // Decrement cell 3 by 1 112 DEC 1 // Decrement cell 1 by 1 116 JUMP LOOP // Start executing from the // address of LOOP 120 END: <next code block>