Constructive Computer Architecture Virtual Memory and Interrupts Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.

Slides:



Advertisements
Similar presentations
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Advertisements

Virtual to Physical Address Translation Effective Address TLB Lookup Page Table Walk Update TLBPage Fault OS Table Walk Protection Check Physical Address.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Virtual Memory I Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 490/590 Computer Architecture Virtual Memory II
February 25, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 11 - Virtual Memory and Caches Krste Asanovic Electrical Engineering.
CS 152 Computer Architecture and Engineering Lecture 11 - Virtual Memory and Caches Krste Asanovic Electrical Engineering and Computer Sciences University.
CS 152 Computer Architecture and Engineering Lecture 10 - Virtual Memory Krste Asanovic Electrical Engineering and Computer Sciences University of California.
February 23, 2011CS152, Spring 2011 CS 152 Computer Architecture and Engineering Lecture 9 - Virtual Memory Krste Asanovic Electrical Engineering and Computer.
February 23, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 10 - Virtual Memory Krste Asanovic Electrical Engineering and.
Translation Buffers (TLB’s)
Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
© Krste Asanovic, 2014CS252, Spring 2014, Lecture 15 CS252 Graduate Computer Architecture Spring 2014 Lecture 15: Virtual Memory and Caches Krste Asanovic.
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
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Virtual Memory Expanding Memory Multiple Concurrent Processes.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Virtual Memory Muhamed Mudawar CS 282 – KAUST – Spring 2010 Computer Architecture & Organization.
Virtual Memory: Part Deux
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
February 21, 2012CS152, Spring 2012 CS 152 Computer Architecture and Engineering Lecture 9 - Virtual Memory Krste Asanovic Electrical Engineering and Computer.
Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Computer Architecture: A Constructive Approach Next Address Prediction – Six Stage Pipeline Joel Emer Computer Science & Artificial Intelligence Lab. Massachusetts.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Virtual Memory CENG331 - Computer Organization Instructor: Murat Manguoglu(Section 1) Adapted from:
Constructive Computer Architecture: Control Hazards Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology October.
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
Modeling Processors Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology March 1, 2010
Constructive Computer Architecture Interrupts/Exceptions/Faults Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
CMSC 611: Advanced Computer Architecture
Computer Organization CS224
From Address Translation to Demand Paging
From Address Translation to Demand Paging
Control Hazards Constructive Computer Architecture: Arvind
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Interrupts/Exceptions/Faults
Virtual Memory and Interrupts
Non-Pipelined Processors - 2
Non-Pipelined Processors
From Address Translation to Demand Paging
The processor: Pipelining and Branching
Non-Pipelined and Pipelined Processors
Control Hazards Constructive Computer Architecture: Arvind
Interrupts/Exceptions
Multistage Pipelined Processors and modular refinement
Realistic Memories and Caches
Branch Prediction: Direction Predictors
Branch Prediction: Direction Predictors
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Translation Buffers (TLB’s)
Pipelined Processors Arvind
Control Hazards Constructive Computer Architecture: Arvind
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Pipelined Processors Constructive Computer Architecture: Arvind
Branch Prediction: Direction Predictors
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Modeling Processors Arvind
Control Hazards Branches (conditional, unconditional, call-return)
Control Hazards Constructive Computer Architecture: Arvind
Modular Refinement Arvind
Tutorial 7: SMIPS Labs and Epochs Constructive Computer Architecture
Translation Buffers (TLBs)
Virtual Memory.
Review What are the advantages/disadvantages of pages versus segments?
Presentation transcript:

Constructive Computer Architecture Virtual Memory and Interrupts Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November 13, L21-1

Address Translation: putting it all together Virtual Address TLB Lookup Page Table Walk Update TLB Page Fault (OS loads page) Protection Check Physical Address (to cache) miss hit the page is  memory  memory denied permitted Protection Fault hardware hardware or software software SEGFAULT Where? Resume the instruction November 13,

Address Translation in Pipeline Machines Software handlers need a restartable exception on page fault or protection violation Handling a TLB miss needs a hardware or software mechanism to refill TLB Methods to overcome the additional latency of a TLB: slow down the clock pipeline the TLB and cache access virtual address caches parallel TLB/cache access PC Inst TLB Inst. Cache D Decode EM Data TLB Data Cache W + TLB miss? Page Fault? Protection violation? TLB miss? Page Fault? Protection violation?   November 13,

Physical vs Virtual Address Caches? One cycle in case of a hit (+) cache needs to be flushed on a context switch unless address space identifiers (ASIDs) included in tags (-) aliasing problems due to the sharing of pages (-) CPU Physical Cache TLB Primary Memory VA PA Alternative: place the cache before the TLB CPU VA (StrongARM) Virtual Cache PA TLB Primary Memory November 13,

Aliasing in Virtual-Address Caches VA 1 VA 2 Page Table Data Pages PA VA 1 VA 2 1st Copy of Data at PA 2nd Copy of Data at PA TagData Two virtual pages share one physical page Virtual cache can have two copies of same physical data. Writes to one copy not visible to reads of other! General Solution: Disallow aliases to coexist in cache Software (i.e., OS) solution for direct-mapped cache VAs of shared pages must agree in cache index bits; this ensures all VAs accessing same PA will conflict in direct- mapped cache (early SPARCs) November 13,

Concurrent Access to TLB & Cache Index L is available without consulting the TLB cache and TLB accesses can begin simultaneously Tag comparison is made after both accesses are completed Cases: L + b = kL + b < k L + b > k what happens here? VPN L b TLB Direct-map Cache 2 L blocks 2 b -byte block PPN Page Offset = hit? DataPhysical Tag Tag VA PA Virtual Index k Partially VA cache! November 13,

Virtual-Index Physical-Tag Caches: Associative Organization VPN L = k-b b TLB Direct-map 2 L blocks PPN Page Offset = hit? Data Phy. Tag VA PA Virtual Index k Direct-map 2 L blocks = After the PPN is known, W physical tags are compared Allows cache size to be greater than 2 L+b bytes W ways November 13,

Exception handling in a pipeline machine November 13, 2015L21-8

Exception Handling PC Inst. Mem D Decode EM Data Mem W + Illegal Opcode Overflow Data address Exceptions PC address Exception External 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 13,

Interrupt processing Internal interrupts can happen at any stage but cause a redirection only at Commit External interrupts are considered only at Commit If an instruction causes an interrupt then the external interrupt, if present, is given a priority and the instruction is executed again Some instructions, like Store, cannot be undone once launched. So an instruction is considered to have completed before an external interrupt is taken November 13,

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 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 4,

Killing vs Poisoning PC Inst Memory Decode Register File Execute Data Memory f2d Epoch m2c d2e Next Addr Pred scoreboard f12f2 e2m 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 November 4,

Interrupt processing at Execute Incoming Interrupt -if (mem type) issue Ld/St -if (mispred) redirect -pass eInst to M stage -pass eInst to M stage unmodified no yes eInst will contain information about any newly detected interrupts at Execute November 13,

Interrupt processing at Memory stage Incoming Interrupt -pass eInst with modified data to Commit -pass eInst to Commit unmodified no yes Memory Interrupt? noyes -pass new Cause to Commit November 13,

Interrupt processing at Commit External Interrupt? EPC<= pc; causeR <= inCause; if (inCause after Reg Fetch) sb.rm; mode <= privilege; Redirect noyes Incoming interrupt no yes noyes -commit -sb.rm Incoming interrupt commit; sb.rm; EPC<= ppc; causeR <= Ext; mode <= privilege; Redirect EPC<= pc; causeR <= Ext; if (inCause after Reg Fetch) sb.rm; mode <= privilege; Redirect November 13,

Final comment There is generally a lot of machinery associated with a plethora of exceptions in ISAs Precise exceptions are difficult to implement correctly in pipelined machines Performance is usually not the issue and therefore sometimes exceptions are implemented using microcode November 4, The code slides follow

One-Cycle SMIPS rule doExecute; let inst = iMem.req(pc); let dInst = decode(inst, csrf.getStatus); let rVal1 = rf.rd1(fromMaybe(?, dInst.src1)); let rVal2 = rf.rd2(fromMaybe(?, dInst.src2)); let eInst = exec(dInst, rVal1, rVal2, pc, ?); 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(fromMaybe(?, eInst.dst), eInst.data); … setting special registers … … next address calculation … endrule endmodule November 4,

Type: Decoded Instruction typedef struct { IType iType; AluFunc aluFunc; BrFunc brFunc; Maybe#(RIndx) dst; Maybe#(RIndx) src1; Maybe#(RIndx) src2; Maybe#(Data) imm; Maybe#(CsrIndx) csr; } DecodedInst deriving(Bits, Eq); typedef enum {Unsupported, NoPermit, Alu, Ld, St, J, Jr, Br,..., Syscall, ERet} IType deriving(Bits, Eq); November 4,

Decode function DecodedInst decode(Data inst, Status status); DecodedInst dInst = ?;... opSystem: begin case (funct3)... fnPRIV: begin // privilege inst dInst.iType = (case(inst[31:20]) fn12SCALL: Syscall; // sys call // ERET can only be executed under privilege mode fn12ERET: isPrivMode(status) ? Eret : NoPermit; default: Unsupported; endcase); dInst.dst = Invalid; dInst.src1 = Invalid; dInst.src2 = Invalid; dInst.imm = Invalid; dInst.aluFunc = ?; dInst.brFunc = NT; end... endcase end... return dInst; endfunction November 4,

Set special registers if (eInst.iType==Syscall) begin csrf.setStatus(statusPushKU(csrf.getStatus)); csrf.setCause(32’h08); // cause for System call csrf.setEpc(pc); end else if (eInst.iType==ERet) begin cop.setStatus(statusPopKU(cop.getStatus)); end November 4,

Redirecting PC if (eInst.iType==Syscall) pc <= csrf.getTvec; else if (eInst.iType==ERet) pc <= cop.getEpc; else pc <= eInst.brTaken ? eInst.addr : pc + 4; November 4,