Constructive Computer Architecture Tutorial 6 Cache & Exception

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Final Presentation Part-A
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
Chapter 7 Interupts DMA Channels Context Switching.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
MIPS I/O and Interrupt. SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3 rd Edition) and B7-B8 (4 th Edition).
System Calls 1.
Constructive Computer Architecture Tutorial 5: Programming SMIPS: Single-Core Assembly Andy Wright TA October 10, 2014http://csg.csail.mit.edu/6.175T04-1.
In-Line Interrupt Handling for Software Managed TLBs Aamer Jaleel and Bruce Jacob Electrical and Computer Engineering University of Maryland at College.
Constructive Computer Architecture Realistic Memories and Caches Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Realistic Memories and Caches Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology March 21, 2012L13-1
Virtual Memory Expanding Memory Multiple Concurrent Processes.
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
© 2004, D. J. Foreman 1 Computer Organization. © 2004, D. J. Foreman 2 Basic Architecture Review  Von Neumann ■ Distinct single-ALU & single-Control.
© 2004, D. J. Foreman 1 Computer Organization. © 2004, D. J. Foreman 2 Basic Architecture Review  Von Neumann ■ Distinct single-ALU & single-Control.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
MIPS I/O and Interrupt.
Realistic Memories and Caches – Part II Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology April 2, 2012L14-1.
Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Constructive Computer Architecture Tutorial 8 Final Project Part 2: Coherence Sizhuo Zhang TA Nov 25, 2015T08-1http://csg.csail.mit.edu/6.175.
Computer Architecture: A Constructive Approach Next Address Prediction – Six Stage Pipeline Joel Emer Computer Science & Artificial Intelligence Lab. Massachusetts.
Constructive Computer Architecture Tutorial 4: Running and Debugging SMIPS Andy Wright TA October 10, 2014http://csg.csail.mit.edu/6.175T04-1.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Non-blocking Caches Arvind (with Asif Khan) Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology May 14, 2012L25-1
Realistic Memories and Caches – Part III Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology April 4, 2012L15-1.
Constructive Computer Architecture Store Buffers and Non-blocking Caches Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute.
6.375 Tutorial 4 RISC-V and Final Projects Ming Liu March 4, 2016http://csg.csail.mit.edu/6.375T04-1.
October 20, 2009L14-1http://csg.csail.mit.edu/korea Concurrency and Modularity Issues in Processor pipelines Arvind Computer Science & Artificial Intelligence.
Caches-2 Constructive Computer Architecture Arvind
Realistic Memories and Caches
Prof. Hsien-Hsin Sean Lee
Realistic Memories and Caches
Day 08 Processes.
Day 09 Processes.
Chapter 10 And, Finally... The Stack
Intro to Processes CSSE 332 Operating Systems
Morgan Kaufmann Publishers Large and Fast: Exploiting Memory Hierarchy
Interrupts/Exceptions/Faults
Caches-2 Constructive Computer Architecture Arvind
Chapter 10 The Stack.
Arithmetic using a stack
Cache Coherence Constructive Computer Architecture Arvind
CSCE 212 Chapter 5 The Processor: Datapath and Control
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
RISC-V Instruction Set Architecture (ISA)
From Address Translation to Demand Paging
Constructive Computer Architecture Tutorial 7 Final Project Overview
Realistic Memories and Caches
Cache Coherence Constructive Computer Architecture Arvind
Constructive Computer Architecture Tutorial 5 Epoch & Branch Predictor
Non-Pipelined and Pipelined Processors
Constructive Computer Architecture Tutorial 3 RISC-V Processor
Interrupts/Exceptions
The University of Adelaide, School of Computer Science
Cache Coherence Constructive Computer Architecture Arvind
6.375 Tutorial 5 RISC-V 6-Stage with Caches Ming Liu
CDA 5155 Caches.
CC protocol for blocking caches
Caches-2 Constructive Computer Architecture Arvind
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Caches and store buffers
Morgan Kaufmann Publishers Memory Hierarchy: Cache Basics
Computer Organization
Chapter 10 And, Finally... The Stack
MIPS I/O and Interrupt.
ECE/CS 552: Pipelining and Exceptions
Realistic Memories and Caches
Cache Coherence Constructive Computer Architecture Arvind
Caches-2 Constructive Computer Architecture Arvind
Presentation transcript:

Constructive Computer Architecture Tutorial 6 Cache & Exception Sizhuo Zhang 6.175 TA Nov 6, 2015 http://csg.csail.mit.edu/6.175

Blocking Cache Code Nov 6, 2015 http://csg.csail.mit.edu/6.175

Blocking Cache Interface req status memReq mReqQ mshr DRAM or next level cache Processor Miss Status Handling Register cache memResp resp hitQ mRespQ interface Cache; method Action req(MemReq r); method ActionValue#(Data) resp; method ActionValue#(LineReq) memReq; method Action memResp(Line r); endinterface Miss Status Handling Registers (MSHRs) October 28, 2015 http://csg.csail.mit.edu/6.175

Blocking cache state elements module mkCache(Cache); RegFile#(CacheIndex, Line) dataArray <- mkRegFileFull; RegFile#(CacheIndex, Maybe#(CacheTag)) tagArray <- mkRegFileFull; RegFile#(CacheIndex, Bool) dirtyArray <- mkRegFileFull; Fifo#(1, Data) hitQ <- mkBypassFifo; Reg#(MemReq) missReq <- mkRegU; Reg#(CacheStatus) msrh <- mkReg(Ready); Fifo#(2, LineReq) memReqQ <- mkCFFifo; Fifo#(2, Line) memRespQ <- mkCFFifo; function CacheIndex getIdx(Addr addr) = truncate(addr>>4); function CacheTag getTag(Addr addr) = truncateLSB(addr); October 28, 2015 http://csg.csail.mit.edu/6.175

Req method hit processing method Action req(MemReq r) if(mshr == Ready); let idx = getIdx(r.addr); let tag = getTag(r.addr); Bit#(2) wOffset = truncate(r.addr >> 2); let currTag = tagArray.sub(idx); let hit = isValid(currTag)? fromMaybe(?,currTag)==tag : False; if(hit) begin let x = dataArray.sub(idx); if(r.op == Ld) hitQ.enq(x[wOffset]); else begin x[wOffset]=r.data; dataArray.upd(idx, x); dirtyArray.upd(idx, True); end end else begin missReq <= r; mshr <= StartMiss; end endmethod October 28, 2015 http://csg.csail.mit.edu/6.175

Start-miss rule Ready -> StartMiss -> SendFillReq -> WaitFillResp -> Ready rule startMiss(mshr == StartMiss); let idx = getIdx(missReq.addr); let tag=tagArray.sub(idx); let dirty=dirtyArray.sub(idx); if(isValid(tag) && dirty) begin // write-back let addr = {fromMaybe(?,tag), idx, 4'b0}; let data = dataArray.sub(idx); memReqQ.enq(LineReq{op: St, addr: addr, data: data}); end mshr <= SendFillReq; endrule October 28, 2015 http://csg.csail.mit.edu/6.175

Send-fill rule Ready -> StartMiss -> SendFillReq -> WaitFillResp -> Ready rule sendFillReq (mshr == SendFillReq); memReqQ.enq(LineReq{op:Ld, addr:missReq.addr, data:?}); mshr <= WaitFillResp; endrule Nov 6, 2015 http://csg.csail.mit.edu/6.175

Wait-fill rule Ready -> StartMiss -> SendFillReq -> WaitFillResp -> Ready rule waitFillResp(mshr == WaitFillResp); let idx = getIdx(missReq.addr); let tag = getTag(missReq.addr); let data = memRespQ.first; tagArray.upd(idx, Valid (tag)); if(missReq.op == Ld) begin dirtyArray.upd(idx,False);dataArray.upd(idx, data); hitQ.enq(data[wOffset]); end else begin data[wOffset] = missReq.data; dirtyArray.upd(idx,True); dataArray.upd(idx, data); end memRespQ.deq; mshr <= Ready; endrule Is there a problem with waitFill? What if the hitQ is blocked? Should we not at least write it in the cache? October 28, 2015 http://csg.csail.mit.edu/6.175

Rest of the methods Memory side methods method ActionValue#(Data) resp; hitQ.deq; return hitQ.first; endmethod method ActionValue#(MemReq) memReq; memReqQ.deq; return memReqQ.first; method Action memResp(Line r); memRespQ.enq(r); Memory side methods October 28, 2015 http://csg.csail.mit.edu/6.175

Store Buffer Code Nov 6, 2015 http://csg.csail.mit.edu/6.175

Store Buff: Req method hit processing method Action req(MemReq r) if(mshr == Ready); ... get idx, tag and wOffset if(r.op == Ld) begin // search stb let x = stb.search(r.addr); lockL1[0] <= True; if (isValid(x)) hitQ.enq(fromMaybe(?, x)); else begin // search L1 let currTag = tagArray.sub(idx); let hit = isValid(currTag) ? fromMaybe(?,currTag)==tag : False; if(hit) begin let x = dataArray.sub(idx); hitQ.enq(x[wOffset]); end else begin missReq <= r; mshr <= StartMiss; end end end else stb.enq(r.addr,r.data) // r.op == St endmethod November 2, 2015 http://csg.csail.mit.edu/6.175

Store Buff to mReqQ rule mvStbToL1 (mshr == Ready && !lockL1[1]); stb.deq; match {.addr, .data} = stb.first; ... get idx, tag and wOffset let currTag = tagArray.sub(idx); let hit = isValid(currTag) ? fromMaybe(?,currTag)==tag : False; if(hit) begin let x = dataArray.sub(idx); x[wOffset] = data; dataArray.upd(idx,x) end else begin missReq <= r; mshr <= StartMiss; end endrule rule clearL1Lock; lockL1[1] <= False; endrule November 2, 2015 http://csg.csail.mit.edu/6.175

Lab 7 FPGA Infrastructure Nov 6, 2015 http://csg.csail.mit.edu/6.175

FPGA Infrastructure Avoid re-programming FPGA SW-mkProc Interface Start PC SW testbench mkProc SW-mkProc Interface Start PC mtohost Init DRAM Avoid re-programming FPGA Reset FPGA after each test mtohost Init DRAM 1GB DRAM Nov 6, 2015 http://csg.csail.mit.edu/6.175

Simulation DRAM We also simulate DRAM initialization RegFile + pipelined delay of resp We also simulate DRAM initialization Longer simulation time Reg file ... Nov 6, 2015 http://csg.csail.mit.edu/6.175

Cross Clock Domain Issues mkProc runs at 50MHz DRAM controller runs at 200MHz Cross clock domain Non-atomic behavior at reset Deq DRAM resp FIFO to empty before start new test Guard all rules with processor started Lab 7: src/DDR3Example.bsv Nov 6, 2015 http://csg.csail.mit.edu/6.175

Exception Code Nov 6, 2015 http://csg.csail.mit.edu/6.175

CSR mepc holds pc of the instruction that causes the interrupt mcause indicates the cause of the interrupt mscratch holds the pointer to HW-thread local storage for saving context before handling the interrupt mstatus Mode: 0 – user, 3 – machine … 12 2 1 0 prv0 ie0 prv1 ie1 prv2 ie2 prv3 ie3 Other status bits Privilege mode interrupt enabled? Nov 6, 2015 http://csg.csail.mit.edu/6.175

Interrupt handler- SW handler_entry: # fixed entry point for each mode # for user mode the address is 0x100 j interrupt_handler # One level of indirection interrupt_handler: # Common wrapper for all IH # get the pointer to HW-thread local stack csrrw sp, mscratch, sp # swap sp and mscratch # save x1, x3 ~ x31 to stack (x2 is sp, save later) addi sp, sp, -128 sw x1, 4(sp) sw x3, 12(sp) ... sw x31, 124(sp) # save original sp (now in mscratch) to stack csrr s0, mscratch # store mscratch to s0 sw s0, 8(sp) November 4, 2015 http://csg.csail.mit.edu/6.175

Interrupt handler- SW cont. ... # we have saved all GPRs to stack # call C function to handle interrupt csrr a0, mcause # arg 0: cause csrr a1, mepc # arg 1: epc mv a2, sp # arg 2: sp – pointer to all saved GPRs jal c_handler # call C function # return value is the PC to resume csrw mepc, a0 # restore mscratch and all GPRs addi s0, sp, 128; csrw mscratch, s0 lw x1, 4(sp); lw x3, 12(sp); ...; lw x31, 124(sp) lw x2, 8(sp) # restore sp at last eret # finish handling interrupt November 4, 2015 http://csg.csail.mit.edu/6.175

C function to handle interrupt System call long c_handler(long cause, long epc, long *regs) { // regs[i] refers to GPR xi stored in stack if(cause == 0x08) { // cause code for SCALL is 8 // figure out the type of SCALL (stored in a7/x17) // args are in a0/x10, a1/x11, a2/x12 long type = regs[17]; long arg0 = regs[10]; long arg1 = regs[11]; long arg2 = regs[12]; if(type == SysPrintChar) { ... } else if(type == SysPrintInt) { ... } else if(type == SysExit) { ... } else ... // SCALL finshes, we need to resume to epc + 4 return epc + 4; } else if ... Reg 26 and 27 are temporary registers available to the kernel (specified by Application Binary Interface (ABI)) November 4, 2015 http://csg.csail.mit.edu/6.175

C function to handle interrupt Emulated instruction – MUL long c_handler(long cause, long epc, long *regs) { if(cause == 0x08) { ... /* handle SCALL */ } else if(cause == 0x02) { // cause code for Illegal Instruction is 2 uint32_t inst = *((uint32_t*)epc); // fetch inst // check opcode & function codes if((inst & MASK_MUL) == MATCH_MUL) { // is MUL, extract rd, rs1, rs2 fields int rd = (inst >> 7) & 0x01F; int rs1 = ...; int rs2 = ...; // emulate regs[rd] = regs[rs1] * regs[rs2] emulate_multiply(rd, rs1, rs2, regs); return epc + 4; // done, resume at epc+4 } else ... // try to match other inst } else ... // other causes } Nov 6, 2015 http://csg.csail.mit.edu/6.175