CS 104 Computer Organization and Design

Similar documents
Hardware OS & OS- Application interface

John Wawrzynek & Nick Weaver

CS 326: Operating Systems. Process Execution. Lecture 5

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Intro to Virtual Memory

ecture 33 Virtual Memory Friedland and Weaver Computer Science 61C Spring 2017 April 12th, 2017

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

CSE 153 Design of Operating Systems Fall 18

CS5460: Operating Systems

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Anne Bracy CS 3410 Computer Science Cornell University

Anne Bracy CS 3410 Computer Science Cornell University

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

CS 550 Operating Systems Spring Interrupt

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

CSE 153 Design of Operating Systems

Processes and Exceptions

Syscalls, exceptions, and interrupts, oh my!

Another View of the Memory Hierarchy. Lecture #25 Virtual Memory I Memory Hierarchy Requirements. Memory Hierarchy Requirements

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

CSE 560 Computer Systems Architecture

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

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

THE CPU SPENDS ALMOST ALL of its time fetching instructions from memory

CSC369 Lecture 2. Larry Zhang

EE458 - Embedded Systems Exceptions and Interrupts

OS Structure. Kevin Webb Swarthmore College January 25, Relevant xkcd:

Exceptions and Processes

CS 111. Operating Systems Peter Reiher

CS510 Operating System Foundations. Jonathan Walpole

Input / Output. Kevin Webb Swarthmore College April 12, 2018

Interrupts & System Calls

CS 61C: Great Ideas in Computer Architecture Virtual Memory. Instructors: John Wawrzynek & Vladimir Stojanovic

Address spaces and memory management

Interrupts Peter Rounce

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

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

Interrupts and System Calls

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Computer System Overview

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

5.b Principles of I/O Hardware CPU-I/O communication

Virtual Memory Design and Implementation

Kernel Services CIS 657

Hakim Weatherspoon CS 3410 Computer Science Cornell University

CS 550 Operating Systems Spring System Call

Topic 18: Virtual Memory

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

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

Virtual Memory Outline

Process Scheduling Queues

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

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

Lecture 3: O/S Organization. plan: O/S organization processes isolation

CS399 New Beginnings. Jonathan Walpole

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

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

Kernel Services. System Processes in Traditional Unix. Kernel Processes in FreeBSD 5.x CIS 657. swapper. Three processes created at startup time init

Lecture 4: Memory Management & The Programming Interface

CS 61C: Great Ideas in Computer Architecture. Virtual Memory

Chapter 9: Virtual-Memory

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Fast access ===> use map to find object. HW == SW ===> map is in HW or SW or combo. Extend range ===> longer, hierarchical names

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

CS 111. Operating Systems Peter Reiher

CSC 2405: Computer Systems II

The OS and Multitasking: An Example

Princeton University Computer Science 217: Introduction to Programming Systems Exceptions and Processes

Processes, Execution and State. Process Operations: fork. Variations on Process Creation. Windows Process Creation.

Traps and Faults. Review: Mode and Space

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

I/O Management Software. Chapter 5

Protection and System Calls. Otto J. Anshus

Interrupts Peter Rounce - room 6.18

Reversed Buffer Overflow Cross Stack Attacks. Kris Kaspersky Endeavor Security, Inc.

CSE502: Computer Architecture CSE 502: Computer Architecture

CSE 120 Principles of Operating Systems

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

Last time: introduction. Networks and Operating Systems ( ) Chapter 2: Processes. This time. General OS structure. The kernel is a program!

Design Overview of the FreeBSD Kernel CIS 657

Fast access ===> use map to find object. HW == SW ===> map is in HW or SW or combo. Extend range ===> longer, hierarchical names

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

CS333 Intro to Operating Systems. Jonathan Walpole

Memory Management: Virtual Memory and Paging CS 111. Operating Systems Peter Reiher

CSE 120 Principles of Operating Systems

CSE502: Computer Architecture CSE 502: Computer Architecture

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

CSE 120 Principles of Operating Systems

Notes Interrupts and Exceptions. The book uses exception as a general term for all interrupts...

Last class: Today: Paging. Virtual Memory

Virtual Memory: From Address Translation to Demand Paging

Review: Hardware user/kernel boundary

Misc. Third Generation Batch Multiprogramming. Fourth Generation Time Sharing. Last Time Evolution of OSs

Killing Zombies, Working, Sleeping, and Spawning Children

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

These three counters can be programmed for either binary or BCD count.

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

ECE 571 Advanced Microprocessor-Based Design Lecture 3

OPERATING SYSTEMS CS136

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

Transcription:

CS 104 Computer Organization and Design Exceptions and Interrupts CS104: Exceptions and Interrupts 1

Exceptions and Interrupts App App App System software Mem CPU I/O Interrupts: Notification of external events Exceptions: Situations caused by program, requiring OS Also: A bit about the OS CS104: Exceptions and Interrupts 2

External Events Focus so far: running an application Low level coding to write one ( C ) Assembly level coding How to execute the instructions And store the data And give the illusion of a uniform address space CS104: Exceptions and Interrupts 3

External Events Focus so far: running an application Low level coding to write one ( C ) Assembly level coding How to execute the instructions And store the data And give the illusion of a uniform address space System software (OS) has to deal with external events Which may come at un-expected times Data arrives on network Disk complete read request Fixed interval timer CS104: Exceptions and Interrupts 4

First question: Finding out? Suppose we expect an outside event E.g., requested disk drive read something It will get back to us later with data (think 10M cycles) How do we know when its done? Option 1: Polling Ask it periodically Are we there yet? No Are we there yet? No Downside: can be inefficient (processor busy asking) CS104: Exceptions and Interrupts 5

First question: Finding out? Suppose we expect an outside event E.g., requested disk drive read something It will get back to us later with data (think 10M cycles) How do we know when its done? Option 1: Polling Ask it periodically Are we there yet? No Are we there yet? No Downside: can be inefficient (processor busy asking) Option 2: Interrupts Read a book, I ll tell you when we are there External device signals to processor when it needs attention CS104: Exceptions and Interrupts 6

Interrupts Step 1: External device raises an interrupt Hey, processor! I need your attention! Different interrupt numbers, specifies which one it is Multiple interrupts at once? Interrupt controller prioritizes which one goes to processor CS104: Exceptions and Interrupts 7

Interrupts Step 1: External device raises an interrupt Hey, processor! I need your attention! Different interrupt numbers, specifies which one it is Multiple interrupts at once? Interrupt controller prioritizes which one goes to processor Step 2: CPU transfers control to OS interrupt handler Stops what its doing (drain pipeline: stall front end until empty) Jumps into interrupt handler (and saves current PC) Switches into privileged mode CS104: Exceptions and Interrupts 8

Interrupts Step 1: External device raises an interrupt Hey, processor! I need your attention! Different interrupt numbers, specifies which one it is Multiple interrupts at once? Interrupt controller prioritizes which one goes to processor Step 2: CPU transfers control to OS interrupt handler Stops what its doing (drain pipeline: stall front end until empty) Jumps into interrupt handler (and saves current PC) Switches into privileged mode Step 3: OS runs interrupt handler Software routine to do whatever needs to be done CS104: Exceptions and Interrupts 9

Interrupts Step 1: External device raises an interrupt Hey, processor! I need your attention! Different interrupt numbers, specifies which one it is Multiple interrupts at once? Interrupt controller prioritizes which one goes to processor Step 2: CPU transfers control to OS interrupt handler Stops what its doing (drain pipeline: stall front end until empty) Jumps into interrupt handler (and saves current PC) Switches into privileged mode Step 3: OS runs interrupt handler Software routine to do whatever needs to be done Step 4: OS returns from interrupt Jumps back to application code, leaving privileged mode CS104: Exceptions and Interrupts 10

Interrupt handlers How does processor know where to jump? OS sets up interrupt vector in system startup Array of PCs to jump to for interrupt routines Indexed by interrupt number CS104: Exceptions and Interrupts 11

Interrupt handlers How does processor know where to jump? OS sets up interrupt vector in system startup Array of PCs to jump to for interrupt routines Indexed by interrupt number What if. Another interrupt happens while handling the first one? Or an interrupt happens during interrupt vector is setup? Or CS104: Exceptions and Interrupts 12

Interrupt handlers How does processor know where to jump? OS sets up interrupt vector in system startup Array of PCs to jump to for interrupt routines Indexed by interrupt number What if. Another interrupt happens while handling the first one? Or an interrupt happens during interrupt vector is setup? Or OS can enable/disable interrupts (privileged instruction) Allows it to prevent problematic situations Look, this is important, don t bother me right now! CS104: Exceptions and Interrupts 13

Speaking of OS code where is it? Where does OS code reside? In memory. But doesn t application think it has all of memory to itself? CS104: Exceptions and Interrupts 14

Speaking of OS code where is it? Where does OS code reside? In memory. But doesn t application think it has all of memory to itself? Well sort of It doesn t think anything exists past the top of the stack So the OS lives there Same physical pages mapped into all processes address spaces Privileged bit in page table prevents access by normal code Mapping only valid when in privileged mode 2 n-1 0 OS Stack Heap Data Text Reserved CS104: Exceptions and Interrupts 15

Timer Interrupt: Heart of multitasking Common interrupt: timer interrupt Ticks at fixed interval Gives OS a chance to change currently running program and keep track of the current time and anything else it needs to do This is what lets your computer run multiple programs The OS switches between them quickly Enabled by timer interrupt giving control to OS CS104: Exceptions and Interrupts 16

Exceptions: Like interrupts, but not Interrupts: external events Asynchronous don t really belong to any current instruction Exceptions: unusual circumstances for an instruction Belong to one particular instruction Examples: Page fault: load or store missing translation Divide by 0 Illegal instruction Bits do not encode any valid instruction Or, privileged instruction from user code CS104: Exceptions and Interrupts 17

Interrupts vs Exceptions Exceptions: Processor must (typically) tell OS which instruction caused it OS may want to restart from same instruction Example: page fault for valid address (on disk) Or OS may kill program: Segmentation fault: (or other fatal signal) Aside: OS sends signals to program to kill them Segfault = SIGSEGV Programs can catch signals and not die But not in this class Interrupts: no particular instruction But OS will always restart program after last complete insn Both require precise state: insns either done, or not Division between done and not done in program order CS104: Exceptions and Interrupts 18

Precise state Instructions either done or not: sounds obvious right? Problem: half done instructions: pipeline splits into stages Need to ensure no state change (reg or mem) if not done Also: need clean division. Instructions before exception, all done Instructions after (and including) exception, no effect For interrupts: Must be precise, but division can be anywhere. CS104: Exceptions and Interrupts 19

Handling Exceptions Exceptions handled just like interrupts Some ISAs just give them interrupt numbers Others have separate numbering for exceptions CS104: Exceptions and Interrupts 20

System calls: Exceptions on purpose Programs need OS to do things for them Read/write IO devices (including printing, disks, network) Tell real time of day Spawn new processes/execute other programs Any interaction with the outside world CS104: Exceptions and Interrupts 21

System calls: Exceptions on purpose Programs need OS to do things for them Read/write IO devices (including printing, disks, network) Tell real time of day Spawn new processes/execute other programs Any interaction with the outside world Make a system call (syscall) to do this Special instruction which traps into OS Basically just causes exception specifically for this purpose OS gets control (in privileged mode), and does what program asked Knows what program wants by arguments in registers May deny request and not do it then returns an error CS104: Exceptions and Interrupts 22

System calls: Kind of slow Bothering OS for stuff: kind of slow Empty pipeline Transfer control/change privilege Have OS figure out what you want Then do it Then drain pipeline again Then jump back into program For long tasks, overhead to enter/leave is amortized Reading disk (very slow) For short tasks, overhead is very high Get current time of day CS104: Exceptions and Interrupts 23

Avoiding slowness Userspace (not OS) libraries help avoid by buffering Example: malloc Malloc does not ask OS for more memory on every call Instead, malloc asks OS for large chunks of memory Then manages those chunks itself (in user space) Pedantic annoyance: malloc is not a system call! CS104: Exceptions and Interrupts 24

Vsyscalls: a slick trick Linux has a slick trick: vsyscalls Don t actually make a system call! Example: get current time of day Just needs to read an int (time in seconds) OS maps vsyscall page into all processses Read/execute only All processes map to same physical page OS writes current time to fixed location on this page On each timer interrupt gettimeofday system call actually not a system call Just library function which jumps onto vsyscall page Code there reads time and returns it CS104: Exceptions and Interrupts 25

Wrap-up Summary: Interrupts: Notification of external events Exceptions: Unusual things for an instruction Both: handled by OS, very similar behavior System calls: Ask OS to do something (also, like exception) Ending a bit early today: Course Evaluations I ll pass them out, then leave the room I need a volunteer to take them to Camelia Pierson Eaves CS104: Exceptions and Interrupts 26