Lecture 2: Architectural Support for OSes

Similar documents
CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems

CSE 153 Design of Operating Systems Fall 18

CSE 153 Design of Operating Systems

Operating Systems ECE344

Traps and Faults. Review: Mode and Space

Architectural Support for Operating Systems

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Hardware OS & OS- Application interface

Lecture 2: September 9

Machines and Virtualization. Systems and Networks Jeff Chase Spring 2006

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Memory Protection. Machines and Virtualization. Architectural Foundations of OS Kernels. Memory and the CPU. Introduction to Virtual Addressing

Even coarse architectural trends impact tremendously the design of systems

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Process Scheduling Queues

OS: An Overview. ICS332 Operating Systems

CS 537 Lecture 2 Computer Architecture and Operating Systems. OS Tasks

Lec 22: Interrupts. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

CS 153 Design of Operating Systems

CS 5460/6460 Operating Systems

Chap.6 Limited Direct Execution. Dongkun Shin, SKKU

OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

CSE 451: Operating Systems Winter Module 2 Architectural Support for Operating Systems

Even coarse architectural trends impact tremendously the design of systems

Even coarse architectural trends impact tremendously the design of systems. Even coarse architectural trends impact tremendously the design of systems

Protection and System Calls. Otto J. Anshus

Part I Introduction Hardware and OS Review

Architecture and OS. To do. q Architecture impact on OS q OS impact on architecture q Next time: OS components and structure

Traps, Exceptions, System Calls, & Privileged Mode

Interrupts and System Calls

The Kernel Abstraction

CSE380 - Operating Systems. Communicating with Devices

Architectural Support for Operating Systems. Jinkyu Jeong ( Computer Systems Laboratory Sungkyunkwan University

Syscalls, exceptions, and interrupts, oh my!

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Anne Bracy CS 3410 Computer Science Cornell University

Review: Hardware user/kernel boundary

CSC 2405: Computer Systems II

Architectural Support for Operating Systems. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

for Operating Systems Computer Systems Laboratory Sungkyunkwan University

Introduction to Concurrency (Processes, Threads, Interrupts, etc.)

CS 201. Exceptions and Processes. Gerson Robboy Portland State University

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Common Computer-System and OS Structures

Windows Interrupts

EE458 - Embedded Systems Exceptions and Interrupts

Architectural Support for OS

Architectural Support for Operating Systems

Design of Operating System

CS510 Operating System Foundations. Jonathan Walpole

Computer System Architecture. CMPT 300 Operating Systems I. Summer Segment 3: Computer System Architecture. Melissa O Neill

John Wawrzynek & Nick Weaver

CS370 Operating Systems

CS370 Operating Systems

Operating System Review

Lecture 11: Interrupt and Exception. James C. Hoe Department of ECE Carnegie Mellon University

Virtual Memory Review. Page faults. Paging system summary (so far)

Chapter 5 B. Large and Fast: Exploiting Memory Hierarchy

Processes. CS439: Principles of Computer Systems January 30, 2019

Project #1 Exceptions and Simple System Calls

ECE 650 Systems Programming & Engineering. Spring 2018

A process. the stack

Traps, Exceptions, System Calls, & Privileged Mode

CPS104 Computer Organization and Programming Lecture 17: Interrupts and Exceptions. Interrupts Exceptions and Traps. Visualizing an Interrupt

CS5460: Operating Systems

Computer Systems II. First Two Major Computer System Evolution Steps

Process Description and Control. Chapter 3

OS and Computer Architecture. Chapter 3: Operating-System Structures. Common System Components. Process Management

KERNEL THREAD IMPLEMENTATION DETAILS. CS124 Operating Systems Winter , Lecture 9

3.1 Introduction. Computers perform operations concurrently

An Overview of the BLITZ System

CS 153 Design of Operating Systems Winter 2016

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

Announcement. Exercise #2 will be out today. Due date is next Monday

COS 318: Operating Systems

CSCE Introduction to Computer Systems Spring 2019

CSC369 Lecture 2. Larry Zhang, September 21, 2015

COS 318: Operating Systems

Processes. Johan Montelius KTH

CSE 120 Principles of Operating Systems Spring 2017

The Kernel Abstraction. Chapter 2 OSPP Part I

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Topic 18: Virtual Memory

CPS221 Lecture: Operating System Protection

Lecture 4: Threads; weaving control flow

19: I/O. Mark Handley. Direct Memory Access (DMA)

15 Sharing Main Memory Segmentation and Paging

16 Sharing Main Memory Segmentation and Paging

CS333 Intro to Operating Systems. Jonathan Walpole

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Processes and Non-Preemptive Scheduling. Otto J. Anshus

COS 318: Operating Systems

CSC227: Operating Systems Fall Chapter 1 INTERRUPTS. Dr. Soha S. Zaghloul

Computer-System Structures

Architectural Support for Operating Systems

Anne Bracy CS 3410 Computer Science Cornell University

Transcription:

Lecture 2: Architectural Support for OSes CSE 120: Principles of Operating Systems Alex C. Snoeren HW 1 Due Tuesday 10/03

Why Architecture? Operating systems mediate between applications and the physical hardware 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 The details of the HW architecture matter Small differences in hardware may have large repercussions Early PC operating systems did not support virtual memory, due in large part to the fact that the H/W provided no support Sun 1 machines used an entirely separate processor just to manage virtual memory! (M68000 chips did not have hardware support for virtual memory.) CSE 120 Lecture 2: Architectural Support for OSes 2

Types of Arch Support Providing protected machine state Device registers, memory management state, etc. Manipulated with privileged instructions Allows OS to enforce protection Generating and handing asynchronous signals Method to respond to external events Interrupts, exceptions, system calls, etc. Allows OS to enforce sharing Mechanisms to handle concurrency More on this in a few lectures CSE 120 Lecture 2: Architectural Support for OSes 3

Architectural Features Privileged instructions Protection modes (user/kernel) Memory protection mechanisms Interrupts and exceptions Timer (clock) I/O control and operation System calls Synchronization primitives (e.g., atomic instructions) CSE 120 Lecture 2: Architectural Support for OSes 4

Privileged Instructions A select few CPU instructions available only to OS Allows access to protected state Perform global operations For example, only the OS should be able to: Directly access I/O devices (disks, printers, etc.)» Allows OS to enforce security and fairness Manipulate memory management state» E.g., page tables, protection bits, TLB entries, etc. Adjusted protected control registers» Change between user/kernel mode or raise/lower interrupt level Execute the halt instruction CSE 120 Lecture 2: Architectural Support for OSes 5

OS Protection How does CPU know when an instruction is OK? Architecture must support (at least) two modes of operation: kernel and user mode» VAX, x86 support four modes (rings); early archs 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 a 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 prevented CSE 120 Lecture 2: Architectural Support for OSes 6

Memory 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 protection Base and limit registers Segmentation Page table pointers, page protection, TLB Virtual memory Manipulating memory management hardware uses protected (privileged) instructions CSE 120 Lecture 2: Architectural Support for OSes 7

Events An event is an unnatural change in control flow Events immediately stop current execution Change mode, context (machine state), or both The kernel defines a hander for each event type Event handlers always execute in kernel mode The specific types of events are defined by the machine Events are the only entry into the kernel System boot is the first event, loads OS Once in user mode, only way back to kernel is an event The OS is really just one big event handler CSE 120 Lecture 2: Architectural Support for OSes 8

Types of Events Two kinds of events: exceptions and interrupts Exceptions are caused by executing instructions Exceptions indicate software intervention is needed Interrupts are caused by external event Usually hardware devices, timers, etc. Events can be both expected and unexpected Unexpected, a.k.a. asynchronous events Sometimes events are caused deliberately CSE 120 Lecture 2: Architectural Support for OSes 9

Types of Events Exceptions Interrupts Unexpected Fault (H/W) Interrupt Deliberate Syscall trap Software interrupt Each type has its own special term Terms vary slightly across architectures, OSes Software interrupt is also known as async system trap (AST), async or deferred procedure call (A/DPC) CSE 120 Lecture 2: Architectural Support for OSes 10

Faults Hardware detects and reports exceptional conditions Page fault, unaligned memory access, divide by zero Upon detecting an exception, CPU faults Needs to save context (PC, registers, mode bit, etc.) so that faulting instruction can be resumed OSes use page faults to implement many things Debugging, garbage collection, copy-on-write, etc. Faults are strictly a performance optimization Not needed for correctness Extra code could be used to test for fault conditions, but at significant performance expense CSE 120 Lecture 2: Architectural Support for OSes 11

Handling Faults Some faults are silently fixed by the OS Once exceptional condition is dealt with, process resumes» E.g., page faults cause the OS to load the missing page Fault handler reloads the context of the faulting process and reissues the instruction that caused the fault Others are passed on to the application itself OS fault handler modifies the saved context to transfer control to a user-mode handler on return from fault Applications must pre-register handlers with the OS Unix signals or NT user-mode Async Procedure Calls (APCs)» SIGALRM, SIGHUP, SIGTERM, etc. CSE 120 Lecture 2: Architectural Support for OSes 12

Fatal Faults Some faults cannot be properly handled OS has no default handler for the particular fault Application also failed to register a handler App is halted, state dumped to a (core) file, process destroyed Hopefully such faults do not occur inside the kernel Unhandled faults in the kernel itself are fatal; OS crashes» Divide by zero, dereference NULL pointer, invalid instruction, etc. Unix kernel panic, Windows Blue screen of death» Kernel is halted, state dumped to a core file, machine locked up CSE 120 Lecture 2: Architectural Support for OSes 13

System Calls What if an application needs something privileged? Must ask the OS to perform instruction on its behalf Needs to make a protected procedure call or cross the protection boundary Application issues a special system call instruction Raises an exception, which is trapped by a kernel handler Application passes a parameter which handler reads to determine which system call routine to invoke Kernel saves caller context and restores on completion of call Requires architectural support Validate input parameters (e.g., buffer addresses) Restore saved state, reset mode bit, resume execution CSE 120 Lecture 2: Architectural Support for OSes 14

Anatomy of a System call App: read() User Mode Kernel Mode Specify read system call; trap to kernel mode; save context System call handler Lookup call parameter; Invoke read() routine Restore context; return to user mode; Resume execution read() procedure CSE 120 Lecture 2: Architectural Support for OSes 15

System Call Complications What if the kernel invokes a system call? What if user mode tries to return from a system call? How does the kernel return parameters to user mode? Why not simply pass the address of kernel memory? The first of many naming issues we ll face OS uses integer object handles or descriptors» Only meaningful as parameters to other system calls» E.g., Unix file descriptors Kernel s job to ensure descriptors are valid» Will allow us to enforce resource protection» In this context, descriptors are called capabilities» More later in the term CSE 120 Lecture 2: Architectural Support for OSes 16

Interrupts Used to signal asynchronous events I/O hardware interrupts Software and hardware timers Two different implementation models Precise: CPU transfers control on instruction boundaries Imprecise: Control potentially transferred in the middle of instruction execution» What does that mean? OS designers like precise interrupts, hardware folks like to build imprecise interrupts» Why? CSE 120 Lecture 2: Architectural Support for OSes 17

Timers Operating system timer is a critical building block Many resources are time-shared; e.g., CPU Allows OS to prevent infinite loops Fallback mechanism by which OS regains control Timer is set to generate an interrupt at periodic intervals When timer expires, generates an interrupt Handled by kernel, which controls resumption context» Basis for OS scheduler; more later Setting (and clearing) a timer is a privileged instruction Also used to provide time services for applications E.g., sleep() system call CSE 120 Lecture 2: Architectural Support for OSes 18

For Next Class Homework 1 due in one week Read Chapter 3 and Appendix C (online) Email John with your project groups Log into your account and check out Lab 0 Discussion section tomorrow 12-12:50pm in HSS 1330 CSE 120 Lecture 2: Architectural Support for OSes 19