Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.

Slides:



Advertisements
Similar presentations
COMP 4211 Seminar Presentation Based On: Computer Architecture A Quantitative Approach by Hennessey and Patterson Presenter : Feri Danes.
Advertisements

February 2, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 5 - Pipelining II Krste Asanovic Electrical Engineering and Computer.
Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
February 2, 2011CS152, Spring 2011 CS 152 Computer Architecture and Engineering Lecture 5 - Pipelining II Krste Asanovic Electrical Engineering and Computer.
Computer Architecture: A Constructive Approach Instruction Representation Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute.
Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Modeling Processors Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February 22, 2011L07-1
Interrupts / Exceptions / Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology April 30, 2012L21-1
Non-Pipelined Processors Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology March 6, 2013
Computer Architecture: A Constructive Approach One-Cycle Implementation Joel Emer Computer Science & Artificial Intelligence Lab. Massachusetts Institute.
Constructive Computer Architecture: Branch Prediction Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology October.
Constructive Computer Architecture Cache Coherence Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Virtual Memory: Part Deux
Constructive Computer Architecture Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Constructive Computer Architecture Virtual Memory and Interrupts Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Constructive Computer Architecture Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology September.
Constructive Computer Architecture: Control Hazards Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology October.
Constructive Computer Architecture Store Buffers and Non-blocking Caches Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute.
CSC 4250 Computer Architectures September 22, 2006 Appendix A. Pipelining.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Modeling Processors Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology March 1, 2010
Exceptions and Interrupts “Unexpected” events requiring change in flow of control – Different ISAs use the terms differently Exception – Arises within.
Computer Architecture: A Constructive Approach Implementing SMIPS Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Interrupts and exceptions
Computer Organization CS224
Basic Processor Structure/design
Control Hazards Constructive Computer Architecture: Arvind
Non-Pipelined Processors
Interrupts/Exceptions/Faults
Pipelining: Advanced ILP
The processor: Exceptions and Interrupts
Non-Pipelined Processors
Virtual Memory and Interrupts
CSCE 212 Chapter 5 The Processor: Datapath and Control
Non-Pipelined Processors - 2
Non-Pipelined Processors
Non-Pipelined Processors
The processor: Pipelining and Branching
Combinational circuits
Non-Pipelined and Pipelined Processors
Multi-cycle SMIPS Implementations
Control Hazards Constructive Computer Architecture: Arvind
Interrupts/Exceptions
Realistic Memories and Caches
Branch Prediction: Direction Predictors
Architectural Support for OS
Multistage Pipelined Processors and modular refinement
Pipelined Processors Arvind
Project Instruction Scheduler Assembler for DLX
Pipelined Processors Constructive Computer Architecture: Arvind
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
ECE 445 – Computer Organization
Control Hazards Branches (conditional, unconditional, call-return)
Datapath and Control Exceptions
Control Hazards Constructive Computer Architecture: Arvind
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Modular Refinement Arvind
ECE/CS 552: Pipelining and Exceptions
Tutorial 7: SMIPS Labs and Epochs Constructive Computer Architecture
Interrupts and exceptions
Non-Pipelined Processors
CMSC 611: Advanced Computer Architecture
Pipelined Processors: Control Hazards
Presentation transcript:

Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November 6, L19-1

Contributors to the course material Arvind, Rishiyur S. Nikhil, Joel Emer, Muralidaran Vijayaraghavan Staff and students in (Spring 2013), 6.S195 (Fall 2012), 6.S078 (Spring 2012) Asif Khan, Richard Ruhler, Sang Woo Jun, Abhinav Agarwal, Myron King, Kermin Fleming, Ming Liu, Li- Shiuan Peh External Prof Amey Karkare & students at IIT Kanpur Prof Jihong Kim & students at Seoul Nation University Prof Derek Chiou, University of Texas at Austin Prof Yoav Etsion & students at Technion November 6,

Interrupts altering the normal flow of control An external or internal event that needs to be processed by another (system) program. The event is usually unexpected or rare from program’s point of view. program HI 1 HI 2 HI n interrupt handler I i-1 IiIi I i+1 November 6,

Causes of Interrupts events that request the attention of the processor Asynchronous: an external event input/output device service-request/response timer expiration power disruptions, hardware failure Synchronous: an internal event (a.k.a exceptions, faults and traps) undefined opcode, privileged instruction arithmetic overflow, FPU exception misaligned memory access virtual memory exceptions: page faults, TLB misses, protection violations traps: system calls, e.g., jumps into kernel November 6,

Asynchronous Interrupts: invoking the interrupt handler An I/O device requests attention by asserting one of the prioritized interrupt request lines After the processor decides to process the interrupt It stops the current program at instruction I i, completing all the instructions up to I i-1 (Precise interrupt) It saves the PC of instruction I i in a special register (EPC) It disables interrupts and transfers control to a designated interrupt handler running in the kernel mode  Privileged/user mode to prevent user programs from causing harm to other users or OS Usually speed is not the paramount concern in handling interrupts November 6,

Interrupt Handler Saves EPC before enabling interrupts to allow nested interrupts  need an instruction to move EPC into GPRs need a way to mask further interrupts at least until EPC can be saved Needs to read a status register that indicates the cause of the interrupt Uses a special indirect jump instruction ERET (return-from-exception) which enables interrupts restores the processor to the user mode restores hardware status and control state November 6,

Synchronous Interrupts A synchronous interrupt is caused by a particular instruction and causes a control hazard requires undoing the effect of one or more partially executed instructions. Comes in two varieties: Exception: The instruction cannot be completed and needs to be restarted after the exception has been handled information about the exception has to be recorded and conveyed to the exception handler Faults (aka Trap): Like a system call and the instruction is considered to have been completed requires a special jump instruction involving a change to privileged kernel mode November 6,

Synchronous Interrupt Handling Overflow Illegal Opcode PC address Exception Data address Exceptions... PC Inst. Mem Decode Data Mem + Illegal Opcode Overflow Data address Exceptions PC address Exception WB When an instruction causes multiple exceptions the first one has to be processed November 6,

Additional Features for Exceptions/Faults register: epc holds pc+4 of instruction that causes exception/fault instruction: eret returns from an exception/fault handler sub-routine using epc As an example consider a complex instruction which may be implemented in SW mult ra, rb causes a fault, sets epc to pc+4 jumps to the exception handler for mult the mult instruction is considered to have been completed November 6,

Software Considerations : 1004: li $t1, 1010 // all exceptions jump to : addiu $t1, causeR // causeR contains 0 for mul, 4 for div, etc 100c: jr $t1 1010: j 1020 // 1014: j 1060 // : 1020: addiu $t1,$a0,0 1024:24aa0000 addiu $t2,$a1, c: eret :... 11a0: mult $a0,$a1 November 6,

We need to change the interfaces to handle exceptions wherever necessary For example, - a memory request will return a 2-tuple ; - decoder will have to recognize new instructions mult, eret,... November 6, L19-11

Decoded Instruction typedef struct { IType iType; AluFunc aluFunc; BrFunc brFunc; Maybe#(FullIndx) dst; Maybe#(FullIndx) src1; Maybe#(FullIndx) src2; Maybe#(Data) imm; } DecodedInst deriving(Bits, Eq); typedef enum {Unsupported, Alu, Ld, St, J, Jr, Br, Mult, ERet} IType deriving(Bits, Eq); typedef enum {Add, Sub, And, Or, Xor, Nor, Slt, Sltu, LShift, RShift, Sra} AluFunc deriving(Bits, Eq); typedef enum {Eq, Neq, Le, Lt, Ge, Gt, AT, NT} BrFunc deriving(Bits, Eq); Bit#(6) fcMULT = 6'b011000; Bit#(5) rsERET = 5'b10000; November 6,

Decode function DecodedInst decode(Data Inst); DecodedInst dInst = ?;... opFUNC: begin case (funct)... fcMULT: dInst.iType = Mult; dInst.brFunc = AT; dInst.rDst = Invalid; dInst.rSrc1 = validReg(rs); dInst.rSrc2 = validReg(rt); end opRS: begin if(rs==rsERET) dInst.iType = ERet; dInst.brFunc = AT; dInst.rDst = Invalid; dInst.rSrc1 = Invalid; dInst.rSrc2 = Invalid; end return dInst; endfunction November 6,

Branch Address Calculation function Addr brAddrCalc(Addr pc, Data val, IType iType, Data imm, Bool taken, Addr epc); Addr pcPlus4 = pc + 4; Addr targetAddr = case (iType) J : {pcPlus4[31:28], imm[27:0]}; Jr : val; Br : (taken? pcPlus4 + imm : pcPlus4); Mult: h’1004; // Interrupt handler ERet: epc; Alu, Ld, St, Unsupported: pcPlus4; endcase; return targetAddr; endfunction November 6,

Execute Function function ExecInst exec(DecodedInst dInst, Data rVal1, Data rVal2, Addr pc, Addr epc);... let brAddr = brAddrCalc(pc, rVal1, dInst.iType, validValue(dInst.imm), brTaken, epc);... eInst.brAddr =... brAddr...;... return eInst; endfunction With these changes the single-cycle machine will handle exceptions November 6,

One-Cycle SMIPS rule doExecute; let inst = iMem.req(pc); let dInst = decode(inst); let rVal1 = rf.rd1(validRegValue(dInst.src1)); let rVal2 = rf.rd2(validRegValue(dInst.src2)); let eInst = exec(dInst, rVal1, rVal2, pc, epc); if(eInst.iType == Ld) eInst.data <- dMem.req(MemReq{op: Ld, addr: eInst.addr, data: ?}); else if(eInst.iType == St) let d <- dMem.req(MemReq{op: St, addr: eInst.addr, data: eInst.data}); if (isValid(eInst.dst)) rf.wr(validRegValue(eInst.dst), eInst.data); pc <= eInst.brTaken ? eInst.addr : pc + 4; if(eInst.iType == Mult) begin epc <= eInst.addr; causeR <= 0; end endrule endmodule November 6,

Exception handling in pipeline machines November 6, L19-17

Exception Handling PC Inst. Mem D Decode EM Data Mem W + Illegal Opcode Overflow Data address Exceptions PC address Exception Asynchronous Interrupts Ex D PC D Ex E PC E Ex M PC M Cause EPC Kill D Stage Kill F Stage Kill E Stage Select Handler PC Kill Writeback Commit Point 1. An instruction may cause multiple exceptions; which one should we process? 2. When multiple instructions are causing exceptions; which one should we process first? from the earliest stage from the oldest instruction November 6,

Exception Handling When instruction x in stage i raises an exception, its cause is recorded and passed down the pipeline For a given instruction, exceptions from the later stages of the pipeline do not override cause of exception from the earlier stages At commit point external interrupts, if present, override other internal interrupts If an exception is present at commit: Cause and EPC registers are set, and pc is redirected to the handler PC Epoch mechanism takes care of redirecting the pc November 6,

Multiple stage pipeline PC Inst Memory Decode Register File Execute Data Memory f2d Epoch m2c d2e Next Addr Pred scoreboard f12f2 e2m November 6, wrong path insts are dropped wrong path insts are poisoned This affects whether an instruction is removed from sb in case of an interrupt external interrupts considered at Commit

Interrupt processing Internal interrupts can happen at any stage but cause a redirection only at Commit External interrupts are considered only at Commit Some instructions, like Store, cannot be undone once launched. So an instruction is considered to have completed before an external interrupt is taken If an instruction causes an interrupt then the external interrupt, if present, is given a priority and the instruction is executed again November 6, 2013 L19-21http://csg.csail.mit.edu/6.S195

Interrupt processing at Execute-1 November 4, 2013 L18-22http://csg.csail.mit.edu/6.S195 Incoming Interrupt cause -if (mem type) issue Ld/St -if (mispred) redirect -pass eInst to M stage -pass eInst to M stage unmodified none! none eInst will contain information about any newly detected interrupts at Execute

Interrupt processing at Execute-2 or Mem stage November 4, 2013 L18-23http://csg.csail.mit.edu/6.S195 Incoming Interrupt cause -pass eInst with modified data to Commit -pass eInst to Commit unmodified none! none Memory Interrupt? noyes -pass new Cause to Commit

Interrupt processing at Commit November 4, 2013 L18-24http://csg.csail.mit.edu/6.S195 External Interrupt? EPC<= if (Exception) pc : pc+4; causeR <= inCause; if (inCause after Reg Fetch) sb.rm; mode <= Privlage; Redirect noyes Incoming cause none ! none none! none -commit -sb.rm Incoming cause commit; sb.rm; EPC<= ppc; causeR <= Ext; mode <= Privlage; Redirect EPC<= pc; causeR <= Ext; if (inCause after Reg Fetch) sb.rm; mode <= Privlage; Redirect