CSE 120 Principles of Operating Systems Spring 2009AdministriviaWhy Start With Architecture?Architectural Features for OSTypes of Arch SupportProtected InstructionsOS ProtectionMemory ProtectionEventsCategorizing EventsCategorizing Events (2)FaultsHandling FaultsHandling Faults (2)System CallsSystem CallSystem Call QuestionsInterruptsTimerI/O ControlI/O CompletionI/O ExampleInterrupt QuestionsSynchronizationSummaryNext Time…BlankTodoCSE 120Principles of Operating SystemsSpring 2009Lecture 2: Architectural Support for Operating SystemsGeoffrey M. VoelkerApril 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 2Administrivia Mailing list You should be getting mail on the list. If not, let me know. Homework #1 Due 4/9 Project 0 Due 4/9, done individually Project groups When you have chosen groups, send your group info to Will ([email protected])April 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 3Why Start With Architecture? Operating system functionality fundamentally depends upon the architectural features of the computer Key goals of an OS are to enforce protection and resource sharing If done well, applications can be oblivious to HW details Unfortunately for us, the OS is left holding the bag Architectural support can greatly simplify – or complicate – OS tasks Early PC operating systems (DOS, MacOS) lacked virtual memory in part because the architecture did not support it Early Sun 1 computers used two M68000 CPUs to implement virtual memory (M68000 did not have VM hardware support)April 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 4Architectural Features for OS Features that directly support the OS include Protection (kernel/user mode) Protected instructions Memory protection System calls Interrupts and exceptions Timer (clock) I/O control and operation SynchronizationApril 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 5Types of Arch Support Manipulating privileged machine state Protected instructions Manipulate device registers, TLB entries, etc. Generating and handling “events” Interrupts, exceptions, system calls, etc. Respond to external events CPU requires software intervention to handle fault or trap Mechanisms to handle concurrency Interrupts, atomic instructionsApril 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 6Protected Instructions A subset of instructions of every CPU is restricted to use only by the OS Known as protected (privileged) instructions Only the operating system can Directly access I/O devices (disks, printers, etc.)» Security, fairness (why?) Manipulate memory management state» Page table pointers, page protection, TLB management, etc. Manipulate protected control registers » Kernel mode, interrupt level Halt instruction (why?)April 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 7OS Protection How do we know if we can execute a protected instruction? Architecture must support (at least) two modes of operation: kernel mode and user mode» VAX, x86 support four modes; earlier archs (Multics) even more» Why? Protect the OS from itself (software engineering) Mode is indicated by a status bit in a protected control register User programs execute in user mode OS executes in kernel mode (OS == “kernel”) Protected instructions only execute in kernel mode CPU checks mode bit when protected instruction executes Setting mode bit must be a protected instruction Attempts to execute in user mode are detected and preventedApril 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 8Memory Protection OS must be able to protect programs from each other OS must protect itself from user programs May or may not protect user programs from OS Memory management hardware provides memory protection mechanisms Base and limit registers Page table pointers, page protection, TLB Virtual memory Segmentation Manipulating memory management hardware uses protected (privileged) operationsApril 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 9Events An event is an “unnatural” change in control flow Events immediately stop current execution Changes mode, context (machine state), or both The kernel defines a handler for each event type Event handlers always execute in kernel mode The specific types of events are defined by the machine Once the system is booted, all entry to the kernel occurs as the result of an event In effect, the operating system is one big event handlerApril 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 10Categorizing Events Two kinds of events, interrupts and exceptions Exceptions are caused by executing instructions CPU requires software intervention to handle a fault or trap Interrupts are caused by an external event Device finishes I/O, timer expires, etc. Two reasons for events, unexpected and deliberate Unexpected events are, well, unexpected What is an example? Deliberate events are scheduled by OS or application Why would this be useful?April 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 11Categorizing Events (2) This gives us a convenient table: Terms may be used slightly differently by various OSes, CPU architectures… Software interrupt – a.k.a. async system trap (AST), async or deferred procedure call (APC or DPC) Will cover faults, system calls, and interrupts next Does anyone remember from CSE 141 what a software interrupt is?Unexpected DeliberateExceptions (sync) fault syscall trapInterrupts (async) interrupt software interruptApril 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 12Faults Hardware detects and reports “exceptional” conditions Page fault, unaligned access, divide by zero Upon exception, hardware “faults” (verb) Must save state (PC, regs, mode, etc.) so that the faulting process can be restarted Modern OSes use VM faults for many functions Debugging, distributed VM, garbage collection, copy-on-write Fault exceptions are a performance optimization Could detect faults by inserting extra instructions into code (at a significant performance penalty)April 2, 2009 CSE 120 – Lecture 2 – Architectural Support for OSes 13Handling Faults Some faults
View Full Document