An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
Alpha微处理器 • Time of a full cache miss in instructions executed: 1st Alpha : 340 ns/5.0 ns = 68 clks x 2 or 136 2nd Alpha : 266 ns/3.3 ns = 80 clks x 4 or 320 3rd Alpha : 180 ns/1.7 ns =108 clks x 6 or 648 • 1/2X latency x 3X clock rate x 3X Instr/clock ?X
Cache性能 CPU time = (CPU execution clock cycles + Memory stall clock cycles) clock cycle time Memory stall clock cycles = (Reads Read miss rate Read miss penalty + Writes Write miss rate Write miss penalty) Memory stall clock cycles = Memory accesses Miss rate Miss penalty
Cache 性能(续) CPUtime = Instruction Count (CPIexecution + Mem accesses per instruction Miss rate Miss penalty) Clock cycle time Misses per instruction = Memory accesses per instruction Miss rate CPUtime = IC (CPIexecution + Misses per instruction Miss penalty) Clock cycle time Memory stall cycles per instruction = Misses per instruction (Total miss latency – Overlapped miss latency) Average Memory access time = Hit time + Miss rate Miss penalty
改进Cache性能 Average Memory access time = Hit time + Miss rate Miss penalty 1. 降低失效率 2. 降低失效损失,或者 3. 减少在cache中命中的时间
DATA TAGS One Cache line of Data Tag and Comparator One Cache line of Data Tag and Comparator One Cache line of Data Tag and Comparator One Cache line of Data Tag and Comparator To Next Lower Level In Hierarchy Victim Cache
合并数据的示例 /* Before: 2 sequential arrays */ int val[SIZE]; int key[SIZE]; /* After: 1 array of stuctures */ struct merge { int val; int key; }; struct merge merged_array[SIZE]; 减少 val和 key之间的冲突 改进空间局部性
循环交换示例 /* Before */ for (k = 0; k < 100; k = k+1) for (j = 0; j < 100; j = j+1) for (i = 0; i < 5000; i = i+1) x[i][j] = 2 * x[i][j]; /* After */ for (k = 0; k < 100; k = k+1) for (i = 0; i < 5000; i = i+1) for (j = 0; j < 100; j = j+1) x[i][j] = 2 * x[i][j]; 用顺序访问代替跳步(100个存储字)访问存储器 改进空间局部性
循环合并示例 /* Before */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) a[i][j]= 1/b[i][j] * c[i][j]; for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) d[i][j] = a[i][j]+ c[i][j]; /* After */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) { a[i][j] = 1/b[i][j] * c[i][j]; d[i][j] = a[i][j] + c[i][j];} 每次对a & c访问两次失效 与 每次访问一次失效; 改进空间局部性
分块示例 /* Before */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) {r = 0; for (k = 0; k < N; k = k+1){ r = r + y[i][k]*z[k][j];}; x[i][j] = r; }; • 两个内层循环: • 读取z[]的所有 NN个元素 • 分别读取y[]一行的N个元素 • 写x[]一行的N个元素 • 容量失效是 N和Cache容量的函数: • 3 N N 4 => 无容量失效;否则 ... • 思路:计算满足条件的 B B子阵
分块示例(续) /* After */ for (jj = 0; jj < N; jj = jj+B) for (kk = 0; kk < N; kk = kk+B) for (i = 0; i < N; i = i+1) for (j = jj; j < min(jj+B-1,N); j = j+1) {r = 0; for (k = kk; k < min(kk+B-1,N); k = k+1) { r = r + y[i][k]*z[k][j];}; x[i][j] = x[i][j] + r; }; • B 称为 块化因子(Blocking Factor) • 容量失效从2N3 + N2减至 2N3/B +N2 • 是否也会降低冲突失效?
通过分块减少冲突失效 • 没有全相联的cache的冲突失效 与 块化大小 • Lam et al [1991] a blocking factor of 24 had a fifth the misses vs. 48 despite both fit in cache MISS RATIO
改进cache性能(续) Average Memory access time = Hit time + Miss rate Miss penalty 1. 降低失效率 2. 降低失效损失,或者 3. 减少在cache中命中的时间
1. 减少失效损失: 在失效时读比写优先 • Write through with write buffers offer RAW conflicts with main memory reads on cache misses • If simply wait for write buffer to empty, might increase read miss penalty (old MIPS 1000 by 50% ) • Check write buffer contents before read; if no conflicts, let the memory access continue • Write Back? • Read miss replacing dirty block • Normal: Write dirty block to memory, and then do the read • Instead copy the dirty block to a write buffer, then do the read, and then do the write • CPU stall less since restarts as soon as do read
CPU in out write buffer DRAM (or lower mem) 1.1 在失效时读比写优先 1.2 Merging Write Buffer Write Buffer
2. 减少失效损失: 子块放置 • Don’t have to load full block on a miss • Have valid bitsper subblock to indicate valid • (Originally invented to reduce tag storage) Subblocks Valid Bits
3. 减少失效损失: 提前重启和关键字先送 • Don’t wait for full block to be loaded before restarting CPU • Early restartAs soon as the requested word of the block arrives, send it to the CPU and let the CPU continue execution • Critical Word FirstRequest the missed word first from memory and send it to the CPU as soon as it arrives; let the CPU continue execution while filling the rest of the words in the block. Also called wrapped fetch and requested word first • Generally useful only in large blocks, • Spatial locality a problem; tend to want next sequential word, so not clear if benefit by early restart block
4. 减少失效损失: 用Non-blocking Caches来减少失效时暂停 • Non-blocking cacheor lockup-free cacheallow data cache to continue to supply cache hits during a miss • requires out-of-order executuion CPU • hit under miss reduces the effective miss penalty by working during miss vs. ignoring CPU requests • hit under multiple miss or miss under miss? may further lower the effective miss penalty by overlapping multiple misses • Significantly increases the complexity of the cache controller as there can be multiple outstanding memory accesses • Requires muliple memory banks (otherwise cannot support) • Penium Pro allows 4 outstanding memory misses
5.二级cache • 二级cache的计算公式 AMAT = Hit TimeL1 + Miss RateL1 x Miss PenaltyL1 Miss PenaltyL1 = Hit TimeL2 + Miss RateL2 x Miss PenaltyL2 AMAT = Hit TimeL1 +Miss RateL1x (Hit TimeL2 +Miss RateL2+ Miss PenaltyL2) 定义: • 局部失效率 该cache的失效次数除以对 该级cache进行的总的存储访问次数 (Miss rateL2) • 总失效率 该cache的失效次数除以 CPU产生的 总的存储器访问次数 (Miss RateL1 x Miss RateL2) • 总失效率是我们真正关心的
虚拟地址Caches CPU CPU CPU VA VA VA VA Tags PA Tags $ TB $ TB VA PA PA L2 $ TB $ MEM PA PA MEM MEM Cache访问与虚拟地址变换重叠:需要cahe索引来保持变换间的不变性 常规组织 虚拟地址cache 只在失效时才变换 别名问题