Page 1, 5/4/99 8:22 PM

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

CS61C Review of Cache/VM/TLB. Lecture 26. April 30, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)

Systems Architecture II

CS61C : Machine Structures

COEN-4730 Computer Architecture Lecture 3 Review of Caches and Virtual Memory

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

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Hardware OS & OS- Application interface

What are Exceptions? EE 457 Unit 8. Exception Processing. Exception Examples 1. Exceptions What Happens When Things Go Wrong

POLITECNICO DI MILANO. Exception handling. Donatella Sciuto:

EE 457 Unit 8. Exceptions What Happens When Things Go Wrong

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

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

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier

CS152 Computer Architecture and Engineering Lecture 20: Busses and OS s Responsibilities. Recap: IO Benchmarks and I/O Devices

CISC 662 Graduate Computer Architecture Lecture 7 - Multi-cycles. Interrupts and Exceptions. Device Interrupt (Say, arrival of network message)

CISC 662 Graduate Computer Architecture Lecture 7 - Multi-cycles

The Operating System (OS) MicroComputer Engineering OperatingSystem slide 1!

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

CSCI-375 Operating Systems

An Operating System in Action

CSE 153 Design of Operating Systems

CSE 120 Principles of Operating Systems

Traps, Exceptions, System Calls, & Privileged Mode

CSE 120 Principles of Operating Systems

CSE 153 Design of Operating Systems Fall 18

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

John Wawrzynek & Nick Weaver

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

ECE468 Computer Organization and Architecture. OS s Responsibilities

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Chapter 1 Computer System Overview

Traps, Exceptions, System Calls, & Privileged Mode

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

Computer System Overview

Virtual Machines & the OS Kernel

Introduction to Operating Systems. Chapter Chapter

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

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

Anne Bracy CS 3410 Computer Science Cornell University

Anne Bracy CS 3410 Computer Science Cornell University

CS510 Operating System Foundations. Jonathan Walpole

Levels in memory hierarchy

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

Syscalls, exceptions, and interrupts, oh my!

16 Sharing Main Memory Segmentation and Paging

15 Sharing Main Memory Segmentation and Paging

Introduction to Operating Systems. Chapter Chapter

Memory Hierarchy Review

COMP I/O, interrupts, exceptions April 3, 2016

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

Review: Hardware user/kernel boundary

Process Scheduling Queues

Hakim Weatherspoon CS 3410 Computer Science Cornell University

CS 333 Introduction to Operating Systems Class 2 OS-Related Hardware & Software The Process Concept

Handout 4 Memory Hierarchy

Modern Computer Architecture

CS 341l Fall 2008 Test #4 NAME: Key

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CS399 New Beginnings. Jonathan Walpole

COSC 6385 Computer Architecture. - Memory Hierarchies (I)

Introduction to Operating. Chapter Chapter

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

Unit 2 : Computer and Operating System Structure

14:332:331. Week 13 Basics of Cache

CS152 Computer Architecture and Engineering Lecture 18: Virtual Memory

COS 318: Operating Systems

Protection and System Calls. Otto J. Anshus

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

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

CS 333 Introduction to Operating Systems. Class 2 OS-Related Hardware & Software The Process Concept

CSE 120 Principles of Operating Systems

CS5460: Operating Systems

Chapter 8. Virtual Memory

Operating Systems ECE344

Lecture 23. I/O, Interrupts, exceptions

The Kernel Abstraction

COS 318: Operating Systems

Virtual Machines & the OS Kernel

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2017

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

CS 318 Principles of Operating Systems

CS 61C: Great Ideas in Computer Architecture. Direct Mapped Caches

CSE 120 Principles of Operating Systems Spring 2017

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

Lecture 2: Architectural Support for OSes

Recall: Paging. Recall: Paging. Recall: Paging. CS162 Operating Systems and Systems Programming Lecture 13. Address Translation, Caching

Architectural Support for Operating Systems

Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University. P&H Chapter 4.9, pages , appendix A.

CS 5460/6460 Operating Systems

CIS Operating Systems Memory Management Cache and Demand Paging. Professor Qiang Zeng Spring 2018

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Today: Computer System Overview (Stallings, chapter ) Next: Operating System Overview (Stallings, chapter ,

ECE468 Computer Organization and Architecture. Virtual Memory

CSF Cache Introduction. [Adapted from Computer Organization and Design, Patterson & Hennessy, 2005]

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

Computer Architecture Memory hierarchies and caches

LECTURE 4: LARGE AND FAST: EXPLOITING MEMORY HIERARCHY

Transcription:

Outline Review Pipelining CS61C Review of Cache/VM/TLB Lecture 27 May 5, 1999 (Cinco de Mayo) Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html Review Interrupt/Polling Review slides Administrivia, What s this Stuff Good for? Conclusion cs 61C L27 interrupteview.1 cs 61C L27 interrupteview.2 Review 1/3: Cache/VM/TLB The Principle of Locality: Program access a relatively small portion of the address space at any instant of time. - Temporal Locality: Locality in Time - Spatial Locality: Locality in Space 3 Major Categories of Cache Misses: Compulsory Misses: sad facts of life. Example: cold start misses. Capacity Misses: increase cache size Conflict Misses: increase cache size and/or associativity. Review 2/3: Cache/VM/TLB Caches, TLBs, Virtual Memory all understood by examining how they deal with 4 questions: 1) Where can block be placed? 2) How is block found? 3) What block is replaced on miss? 4) How are writes handled? Page tables map virtual address to physical address TLBs are important for fast translation TLB misses are significant in processor performance cs 61C L27 interrupteview.3 cs 61C L27 interrupteview.4 Review 3/3: Cache/VM/TLB Virtual memory was controversial at the time: can SW automatically manage 64KB across many programs? 1000X DRAM growth removed controversy Today VM allows many processes to share single memory without having to swap all processes to disk; VM protection today is more important than memory hierarchy Today CPU time is a function of (ops, cache misses) vs. just f(ops): What does this mean to Compilers, Data structures, Algorithms? cs 61C L27 interrupteview.5 I/O Review Slide I/O gives computers their 5 senses I/O speed range is million to one Mouse, keyboard, network, disk, display Processor speed means must synchronize with I/O devices before use cs 61C L27 interrupteview.6 Page 1, 5/4/99 8:22 PM

Problem: How CPU Synch. with I/O device? Memory Polling also called Programmed I/O Advantage: Simple - the processor is totally in control and does all the work cs 61C L27 interrupteview.7 CPU IOC device Is the data ready? yes read data store data done? yes no no Problems with Polling Polling overhead can consume a lot of CPU time when waiting for I/O device busy wait loop not an efficient way to use the CPU unless the device is very fast! If not sure when need to do I/O, then lots of processor time spent when could be doing something else useful Solution: I/O Interrupt cs 61C L27 interrupteview.8 Why I/O Interrupt? Advantage: User program progress is only halted during actual transfer An I/O interrupt is like exception except: An I/O interrupt is asynchronous Further information needs to be conveyed An I/O interrupt is asynchronous with respect to instruction execution: I/O interrupt is not associated with any instruction I/O interrupt does not prevent any instruction from completion - CPU picks convenient point to take interrupt cs 61C L27 interrupteview.9 External Interrupt Example: Device Interrupt add $r1,$r2,$r3 subi $r4,$r1,#4 slli $r4,$r4,#2 Hiccup(!) lw lw add sw cs 61C L27 interrupteview.10 $r2,0($r4) $r3,4($r4) $r2,$r2,$r3 8($r4),$r2 PC saved Restore PC Save registers lw $r1,20($r0) lw $r2,0($r1) addi $r3,$r0,#5 sw $r3,0($r1) Restore registers Clear current Int Interrupt Handler Review: Steps in Executing MIPS (Lec. 20) 1) Ifetch: Fetch Instruction, Increment PC Page fault/access fault on Instruction fetch? 2) Decode Instruction, Read Registers Undefined Opcode? 3) Execute: Perform operation Overflow? 4) Memory: read or write memory Page fault/access fault on Data access? 5) Write Back: Write Data to Register I/O interrupts? cs 61C L27 interrupteview.11 Administrivia Everything but last 2 projects, last 2 homeworks on grade record is correct? (We hope) graded last 2 homeworks, last 2 projects handed out in discussion this week; See Kelvin ASAP about disagreements Should have already filled out final survey to help future 61c; how many? haven t? Friday 61C Summary / Your Cal heritage / Cal v. Stanford CS education / HKN Evaluation Wed 5/12 Final 5-8PM in 1 Pimintel Bring 2 sheets, both sides, #2 pencils Sun 5/9 Final Review starting 2PM (1 Pimintel) cs 61C L27 interrupteview.12 Page 2, 5/4/99 8:22 PM

What s it Good For: Sony Playstation 2000 Emotion Engine: 6.2 GFLOPS, 75 million polygons per second (Microprocessor Report, 13:5) Superscalar MIPS core + vector coprocessor Problems with I/O Interrupts I/O interrupt is more complicated than exception: Needs to convey the identity of the device generating the interrupt Special hardware is needed to: Cause an interrupt (I/O device) Detect an interrupt (processor) Save the proper states to resume after the interrupt (processor) Where add special interrupt instructions, registers to instruction set? What prevents interrupt from occurring during interrupt handler? cs 61C L27 Claim: interrupteview.13 Toy Story realism brought to games! cs 61C L27 interrupteview.14 Review Coprocessor Registers Coprocessor 0 Registers: name number usage BadVAddr $8 Bad Virtual memory Address Status $12 Interrupt enable Cause $13 Exception type EPC $14 Instruction address Different registers from integer registers, just as Floating Point is another set of registers independent from integer registers Turn off interrupts? Interrupt Enable Bit Bit in Status Register determines whether or not interrupts enabled: Interrupt Enable bit (IE) (0 off, 1 on) Also Kernel/User bit to support Virtual Memory modes (described later) KU IE Status Register cs 61C L27 interrupteview.15 cs 61C L27 interrupteview.16 Problems with Interrupt Enable Interrupt requests can have different urgencies Conventionally, from highest level to lowest level exception/interrupt levels: 1) Bus error 2) Illegal Instruction/Address trap 3) High priority I/O Interrupt (fast response) 4) Low priority I/O Interrupt (slow response) Alternative to blocking all interrupts? Interrupt request needs to be prioritized Prioritizing Interrupts: Interrupt Mask Categorize interrupts and exceptions into levels, and allow selective interruption via Interrupt Mask(IM) in Status Register: 5 for HW interrupts Interrupt only if IE==1 AND Mask bit == 1 IM KUIE Status Register How support interruption of lower priority interrupts? cs 61C L27 interrupteview.17 cs 61C L27 interrupteview.18 Page 3, 5/4/99 8:22 PM

Interrupt levels Suppose there was an interrupt while the interrupt enable or mask bit is off: what should you do? (cannot ignore) Cause register has field--pending Interrupts (PI)-- 5 bits wide (bits15:10) for each of the 5 HW interrupt levels Bit becomes 1 when an interrupt at its level has occurred but not yet serviced Interrupt routine checks pending interrupts ANDed with interrupt mask to decide what to service PI ExcCode Cause Register Prioritizing Interrupts: Interrupt Mask To support interrupts of interrupts, have 3 deep stack in Status for IE,K/U bits: Current (1:0), Previous (3:2), Old (5:4) IM KUIE KUIE KUIE 0 0 O P C Status Register How is MIPS software organized to take advantage of hardware priority scheme? cs 61C L27 interrupteview.19 cs 61C L27 interrupteview.20 Interrupt Levels in MIPS Software Handling Prioritized Interrupts Conventionally, UNIX software system designed to have 4 to 6 Interrupt Priority Levels (IPL) that match the HW interrupt levels Processor always executing at one IPL, stored in a memory location and Status Register set accordingly Processor at lowest IPL level, any interrupt accepted Processor at highest IPL level, all interrupt ignored Interrupt handlers and device drivers pick IPL to run at, faster response for some cs 61C L27 interrupteview.21 OS convention to simplify software: Process cannot be preempted by interrupt at same or lower level Return to interrupted code as soon as no more interrupts at a higher level Any piece of code is always run at same priority level How write interrupt routine so that it can be interrupted? cs 61C L27 interrupteview.22 Re-entrant Interrupt Routine? How allow interrupt of interrupts and safely save registers? Stack? Resources consumed by each exception, so cannot tolerate arbitrary deep nesting of exceptions/interrupts With priority level system only interrupted by higher priority interrupt, so cannot be recursive Only need one interrupt save area ( exception frame ) per priority level Problems with CPU transferring data Typical I/O devices must transfer large amounts of data to memory of processor: Disk must transfer complete block (4 KB? 16 KB?) Large packets from network Regions of frame buffer Can tie up processor depending on amount of I/O requests cs 61C L27 interrupteview.23 cs 61C L27 interrupteview.24 Page 4, 5/4/99 8:22 PM

Delegating I/O Responsibility from CPU: DMA Direct Memory Access (DMA): External to the CPU Transfer blocks of data to or from memory without CPU intervention CPU sends a starting address, direction, and length count to DMAC. Then issues "start". Memory CPU DMAC IOC device DMA Controller (DMAC) provides signals for Peripheral Controller, and Memory Addresses and signals for Memory. Why DMA? DMA gives external device ability to write memory directly: much lower overhead than having processor request one word at a time cs 61C L27 interrupteview.25 cs 61C L27 interrupteview.26 Problems with DMA Problems with DMA What if I/O devices write data that is currently in processor Cache? The processor may never see new data! Called Cache coherence problem Solutions: Flush cache on every I/O operation (expensive) Have hardware invalidate cache lines of potential address conflicts Virtual Address or Physical Address? 1) If virtual address, how do address translation, since memory uses physical addresses? 2) If physical address, what happens if when cross a page boundary, as virtual memory may not be contiguous in physical memory? Solutions: 1) Give DMA a small number of address translations, done by OS when start DMA 2) Have a list of blocks, each no larger than a page, chained together cs 61C L27 interrupteview.27 cs 61C L27 interrupteview.28 Why use OS for I/O? The operating system acts as the interface between: The I/O hardware and the program that requests I/O The Operating System must be able to prevent: The user program from communicating with the I/O device directly If user programs could perform I/O directly: Protection to the shared I/O resources could not be provided cs 61C L27 interrupteview.29 Responsibilities of the Operating System Three characteristics of the I/O systems: The I/O system is shared by multiple program using the processor I/O systems often use interrupts to communicate information about I/O operations. - Interrupts must be handled by the OS because they cause a transfer to supervisor mode The low-level control of an I/O device is complex: - Managing a set of concurrent events - The requirements for correct device control are very detailed cs 61C L27 interrupteview.30 Page 5, 5/4/99 8:22 PM

Operating System Requirements 1/2 Provide protection to shared I/O resources Guarantees that a user s program can only access the portions of an I/O device to which the user has rights Provides abstraction for accessing devices: Supply routines that handle low-level device operation Handles the interrupts generated by I/O devices Operating System Requirements 2/2 Provide equitable access to the shared I/O resources All user programs must have equal access to the I/O resources Schedule accesses in order to enhance system throughput cs 61C L27 interrupteview.31 cs 61C L27 interrupteview.32 How Protect I/O? MIPS memory maps I/O devices to allow load-store access to send commands, receive status and data To prevent user program from accessing data despite having a 32-bit virtual address, need protection (See above) MIPS CPU runs in 2 privilege levels: user mode and kernel mode User mode: limited to bottom half of 32-bit virtual address Kernel mode: can access full 32-bit virtual address; special areas to enable booting machine before TLB valid cs 61C L27 interrupteview.33 Drawing of MIPS Process Memory Allocation Address (2 32-1) I/O Regs I/O device registers /2 (2 31 ) /2 (2 31-1) $sp $gp 0 cs 61C L27 interrupteview.34 Except. Exception Handlers Stack Heap Static Code OS code/data space User code/data space OS restricts I/O Registers, Exception Handlers to OS In More Depth: Actual MIPS address names Virtual address divided into 4 areas: 1) kuseg (low 2 GB) - for user mode, always translated via TLB and through cache 2) kseg0 (next 0.5 GB) - translated by striping off top 1 bit (kernel mode); maps to low 0.5GB of physical memory via caches 3) kseg1 (next 0.5 GB) - translated by striping off top 3 bits (kernel mode); maps to low 0.5GB of physical memory, not via caches 4) kseg2 (top 1 GB) - kernel mode, always translated via TLB and through cache cs 61C L27 interrupteview.35 How User safely invoke Operating System? 2 instructions break: intended to implement break point debugging feature syscall: intended to ask OS for specific services by passing argument in register cs 61C L27 interrupteview.36 Page 6, 5/4/99 8:22 PM

Summary 1/2 Wide range of devices multimedia and high speed networking poise important challenges Delegating data transfer responsibility from the CPU: DMA I/O performance limited by weakest link in chain between OS and device Operating System started as shared I/O library cs 61C L27 interrupteview.37 Summary 2/2 I/O device notifying the operating system: Polling: it can waste a lot of processor time I/O interrupt: similar to exception except it is asynchronous MIPS OS support / Interrupt control: Interrupt Enable bit, stacked IE bits, Interrupt Priority Levels, Interrupt Mask Support for OS abstraction: Kernel/User bit, stacked KU bits, syscall, rfe MIPS follows coprocessor abstraction to add resources, instructions for OS OS Re-entrant via restricting interrupt to higher priority cs 61C L27 interrupteview.38 Page 7, 5/4/99 8:22 PM