{"id":1013,"date":"2019-11-20T14:50:38","date_gmt":"2019-11-20T06:50:38","guid":{"rendered":"http:\/\/149.129.74.185\/?p=1013"},"modified":"2019-11-21T17:49:12","modified_gmt":"2019-11-21T09:49:12","slug":"%e8%ae%a1%e7%ae%97%e6%9c%ba%e4%bd%93%e7%b3%bb%e7%bb%93%e6%9e%84week-10-note","status":"publish","type":"post","link":"http:\/\/www.magicmipamipa.com\/?p=1013","title":{"rendered":"[\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784]Week 10 Note"},"content":{"rendered":"<h4 style=\"text-align: center;\">Memory &#8211; Hierarchy Design \u5b58\u50a8\u5c42\u6b21\u8bbe\u8ba1<\/h4>\n<p>1.\u00a0 Intro<\/p>\n<p>\u5b58\u50a8\u5668\u4ef6\u7684 <code>\u5b58\u50a8\u901f\u5ea6&amp;\u79bbcpu\u7684\u8ddd\u79bb&amp;\u4ef7\u683c\/\u5927\u5c0f<\/code> \u9006\u76f8\u5173\uff0c\u79bbCPU\u8d8a\u8fd1\uff0c\u901f\u5ea6\u8d8a\u5feb\uff0c\u7a7a\u95f4\u8d8a\u5c0f\uff0c\u4ef7\u683c\u8d8a\u9ad8\u3002<\/p>\n<p>\u65f6\u95f4\u5c40\u90e8\u6027\uff08Temporal Locality\uff09\uff1aIf an item is referenced, the same item will tend to be referenced again soon.<\/p>\n<p>\u7a7a\u95f4\u5c40\u90e8\u6027\uff08Spatial Locality\uff09\uff1aIf an item is referenced, nearby itemswill tend to be referenced soon.<\/p>\n<p>&nbsp;<\/p>\n<p>2. ABCs 36\u4e2a\u540d\u8bcd<\/p>\n<div>Cache \u7f13\u5b58\uff0c\u5728CPU\u4e0e\u589e\u52a0\u6570\u636e\u8bfb\u53d6\u901f\u5ea6<\/div>\n<div>full associative\u00a0<span>\u5168\u76f8\u5173\u6620\u5c04\u53ef\u4ee5\u5c06\u4e00\u4e2a\u4e3b\u5b58\u5757\u5b58\u50a8\u5230\u4efb\u610f\u4e00\u4e2aCache\u884c\uff0c\u4f7f\u7528\u7075\u6d3b\uff0c\u5229\u7528\u7387\uff08\u547d\u4e2d\u7387\uff09\u9ad8\u3002<\/span><\/div>\n<div>write allocate miss\u65f6\uff1a\u5148\u8bfb\u5230\u901f\u5ea6\u66f4\u5feb\u7684\u7f13\u5b58\u4e2d\u8fdb\u884c\u66f4\u6539<\/div>\n<div>Virtual memory \u628a\u5206\u6563\u7684\u7269\u7406\u5730\u5740\u6620\u5c04\u5230\u8fde\u7eed\u7684\u903b\u8f91\u5730\u5740\u4e2d\uff0c\u901a\u8fc7\u9875\u8868\u8fdb\u884c\u8f6c\u6362<\/div>\n<div>dirty bit cache\u4e2d\u5df2\u7ecf\u6539\u8fc7\u4f46\u8fd8\u6ca1\u6709\u5199\u56de\u4e3b\u5b58<\/div>\n<div>unified cache \u5408\u5e76\u7684cache\uff0c\u65e2\u6709data\u4e5f\u6709inst<\/div>\n<div>Memory stall cycles \u6307\u4ee4\u8bbf\u95ee\u5b58\u50a8\u65f6\u7531\u4e8emiss\u5e26\u6765\u7684\u505c\u987f\u5468\u671f\u6570<\/div>\n<div>block \u5757<\/div>\n<div>block offset \u6620\u5c04\u5230\u67d0block\u540e\u7684\u5177\u4f53\u4f4d\u7f6e<\/div>\n<div>misses per instruction \u6307\u4ee4\u7684\u4e22\u5931<\/div>\n<div>direct mapped \u76f4\u63a5\u6620\u5c04 \u6709\u591a\u5c11\u4f4d\u7f6e\u5c31\u6709\u591a\u5c11\u7ec4<\/div>\n<div>write back \u5728cache\u4e2d\u8fdb\u884c\u4fee\u6539\u540e\u8981\u5199\u56de\u5230\u4e3b\u5b58<\/div>\n<div>Valid bit \u662f\u5426\u53ef\u7528<\/div>\n<div>data cache \u5b58\u50a8\u6570\u636e\u7684\u90e8\u5206<\/div>\n<div>locality \u5c40\u90e8\u6027<\/div>\n<div>Block address \uff08index+tag\uff09block\u7684\u5730\u5740<\/div>\n<div>hit time \u547d\u4e2d\u65f6\u95f4<\/div>\n<div>address trace \u5b58\u653e\u6307\u4ee4\u7684cache \u5b58\u653e\u5b8f\u6307\u4ee4\u65f6\u4f1a\u628a\u76f8\u5173\u6307\u4ee4\u5b58\u5165 \u5bf9\u5206\u652f\u7ed3\u6784\u7684\u89e3\u51b3\u65b9\u6848\u7684cache<\/div>\n<div>Write through \u5728\u5199cache\u7684\u540c\u65f6\u5199\u5230\u5185\u5b58\u91cc<\/div>\n<div>cache miss \u5728cache\u672a\u627e\u5230\u5185\u5bb9<\/div>\n<div>set \u6709\u591a\u5c11\u4e2a\u7ec4<\/div>\n<div>Instruction cache \u5b58\u50a8\u6307\u4ee4\u7684\u90e8\u5206<\/div>\n<div>page fault \u7f3a\u9875\uff0cMemory\u4e2d\u4e0d\u542b\u8be5\u5730\u5740\uff0c\u9700\u8981\u8bfb\u53d6disk<\/div>\n<div>miss rate cache\u7684\u5931\u914d\u7387<\/div>\n<div>random replacememt \u968f\u673a\u5339\u914d\u4e00\u4e2ablock\u6765\u66ff\u6362<\/div>\n<div>index field cache block\u7684index\u5339\u914d\u5931\u8d25<\/div>\n<div>cache hit cache\u547d\u4e2d<\/div>\n<div>Average memory access time \u5e73\u5747\u5b58\u50a8\u8bbf\u95ee\u65f6\u95f4 hit time + miss rate * miss penalty<\/div>\n<div>page \u903b\u8f91\u5730\u5740\u548c\u7269\u7406\u5730\u5740\u4e4b\u95f4\u7684\u5173\u7cfb<\/div>\n<div>tag field cache blcok\u7684tag\u5339\u914d\u5931\u8d25<\/div>\n<div>n-way set associative \u6620\u5c04\u5230\u67d0\u7ec4\u4e2d\u4efb\u610f\u4e00\u4e2a\u7a7a\u95f4<\/div>\n<div>no-write allocate miss\u65f6\u4e0d\u5148\u8bfb\u5230\u901f\u5ea6\u66f4\u5feb\u7684\u7f13\u5b58\u4e2d\u8fdb\u884c\u66f4\u6539\uff0c\u5728\u5e95\u5c42\u66f4\u6539<\/div>\n<div>miss penalty miss\u540e\u8981\u5230\u5185\u5b58\u53bb\u8bfb\u6570\u636e\u6240\u4ea7\u751f\u7684\u4ee3\u4ef7<\/div>\n<div>Least-recently used \uff08LRU\uff09\u6700\u8fd1\u6700\u5c11\u8bbf\u95ee<\/div>\n<div>write buffer \u9632\u6b62\u5199\u56de\u901f\u5ea6\u8fc7\u5feb\u5bfc\u81f4\u6709\u6570\u636e\u6ca1\u6709\u5199\u56de\u53bb<\/div>\n<div>write stall write\u5f88\u5feb\u65f6\u9700\u8981\u8fdb\u884c\u505c\u987f<\/div>\n<p>&nbsp;<\/p>\n<p>3. Cache\u8bbe\u8ba1\u7684\u56db\u7c7b\u95ee\u9898<\/p>\n<ul>\n<li>Block placement\uff08\u6620\u5c04\u5173\u7cfb\uff09\n<ul>\n<li>Fully Associative, Set Associative, Direct Mapped<\/li>\n<\/ul>\n<\/li>\n<li>Block identification\uff08\u8bc6\u522b\u673a\u5236\uff09\n<ul>\n<li>Tag\/Block<\/li>\n<\/ul>\n<\/li>\n<li>Block replacement\uff08\u66ff\u6362\u7b56\u7565\uff09\n<ul>\n<li>Random, LRU,FIFO<\/li>\n<\/ul>\n<\/li>\n<li>Write strategy\uff08\u5199\u7b56\u7565\uff09\n<ul>\n<li>Write Back or Write Through (with Write Buffer)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>4. Block Placement<\/p>\n<p><code>Direct Mapped<\/code>\u00a0\u4e3b\u5b58\u4e2d\u7684\u4e00\u4e2a Block \u53ea\u80fd\u6620\u5c04\u5230 Cache \u4e0a\u7684\u552f\u4e00\u4f4d\u7f6e\u3002<\/p>\n<p>*\u53ef\u4ee5\u770b\u4f5c\u5c06 Cache \u5206\u6210\u4e86\u516b\u4e2a\u7ec4\uff0c\u6bcf\u4e2a\u7ec4\u53ea\u6709\u4e00\u4e2a Block\u3002\u7b97\u6cd5\uff1aMod \u53d6\u6a21\u3002<\/p>\n<p><code>Full-associative<\/code>\u00a0\u4e3b\u5b58\u4e2d\u7684\u4e00\u4e2a Block \u53ef\u4ee5\u6620\u5c04\u5230 Cache \u4e0a\u7684\u4efb\u4f55\u4f4d\u7f6e\u3002<\/p>\n<p>* \u53ef\u4ee5\u770b\u4f5c\u5c06Cache \u5206\u6210\u4e86\u4e00\u4e2a\u7ec4\u3002<\/p>\n<p><code>n-way associative<\/code>\u00a0 \u4e3b\u5b58\u4e2d\u7684\u4e00\u4e2a Block \u53ef\u4ee5\u6620\u5c04\u5230 Cache \u552f\u4e00\u4e2a\u7ec4\u7684\u4efb\u4f55\u4f4d\u7f6e\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>5.\u00a0The Format of the Physical Address<\/p>\n<p>Tag\/Index\/Byte Offset<\/p>\n<p><code>Index<\/code>\u00a0 \u300c\u91c7\u7528n-way\uff1a\u9009\u62e9\u7ec4\uff1b\u91c7\u7528\u76f4\u63a5\u6620\u5c04\uff1a\u9009\u62e9block\u300d<\/p>\n<p><code>Tag<\/code>\u00a0\u300c\u91c7\u7528n-way\uff1a\u6709log2(#sets)\u4f4d \uff1b\u91c7\u7528\u76f4\u63a5\u6620\u5c04\uff1a\u6709log2(#blocks)\u4f4d\u300d<\/p>\n<p><code>Byte Offset<\/code>\u00a0\u300c\u6709log2(block size)\u4f4d\u300d<\/p>\n<p>&nbsp;<\/p>\n<p>6. Block Replacement<\/p>\n<ul>\n<li>\u5728\u76f4\u63a5\u6620\u5c04\u7684 Cache \u91cc\uff0c\u53ea\u6709\u4e00\u4e2a Block \u80fd\u591f\u88ab\u66ff\u6362\u3002\uff08\u4e0d\u9700\u8981\u5757\u66ff\u6362\u7b56\u7565\uff09<\/li>\n<li>\u5728\u5168\u5173\u8054\u548c\u7ec4\u5173\u8054\u7684 Cache \u91cc\uff0c\u6709\u591a\u4e2a Block \u80fd\u591f\u88ab\u66ff\u6362\u3002<\/li>\n<\/ul>\n<p><code>Random replacement<\/code>\u00a0\u968f\u673a\u66ff\u6362<\/p>\n<p><code>Least-recently used (LRU)<\/code>\u00a0\u6700\u8fd1\u6700\u5c11\u4f7f\u7528<\/p>\n<p><code>First in,first out(FIFO)<\/code>\u00a0\u5148\u8fdb\u5148\u51fa<\/p>\n<p>&nbsp;<\/p>\n<p>7. Write Strategy<\/p>\n<p><code>Write-through cache<\/code>\u00a0written to memory \u76f4\u63a5\u5199\u56de\u5185\u5b58<\/p>\n<p><code>Write-back cache<\/code>\u00a0NOT written to memory \u4e0d\u76f4\u63a5\u5199\u56de\uff0c\u5728\u5757\u66ff\u6362\u65f6\u7edf\u4e00\u5199\u56de<\/p>\n<p>&nbsp;<\/p>\n<p>8. Write stall<\/p>\n<p><code>Write stall<\/code>\u00a0CPU\u7b49\u5f85\u5199\u6267\u884c\u7684\u505c\u987f<\/p>\n<p><code>Write buffers<\/code>\u00a0\u9632\u6b62\u5927\u91cf\u5199\u64cd\u4f5c\u5835\u585e\uff0c\u5148\u5199\u5165write buffer\uff0c\u5728\u5176\u4ed6\u65f6\u5019\u518d\u5199\u56de\u5185\u5b58\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>9. Write misses \u5199\u64cd\u4f5c\u5728 write \u65f6\u672a\u547d\u4e2d<\/p>\n<p><code>Write allocate<\/code>\u00a0\u5148\u8f7d\u5165\u5230cache\u4e2d\uff0c\u518d\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<p><code>Write around<\/code>\u00a0\u53ea\u5199\u5165\u4e3b\u5b58\u4e2d\uff0c\u4e0d\u5b58\u50a8\u5728cache\u4e2d\u3002<\/p>\n<div class=\"tlid-input input\">\n<div class=\"source-wrap\">\n<div class=\"input-full-height-wrapper tlid-input-full-height-wrapper\">\n<div class=\"source-input\">\n<div class=\"source-footer-wrap source-or-target-footer\">\n<div class=\"character-count tlid-character-count\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"tlid-results-container results-container\">\n<div class=\"tlid-result result-dict-wrapper\">\n<div class=\"result tlid-copy-target\">\n<ul>\n<li class=\"result-header\">\u4e00\u822c\u7684\uff0cwrite-back\u4f7f\u7528write-allocate\uff0cwrite-through\u4f7f\u7528write-around\u3002<\/li>\n<\/ul>\n<div class=\"result-header\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>10. Cache performance<\/p>\n<p><code>CPU Execution Time<\/code><\/p>\n<p><code>Average Memory Access Time<\/code><\/p>\n<p>= Hit time + Miss Rate * Miss Penalty<\/p>\n<p>= (Accesses time on hitting + Accesses time on miss) \/ All memory accesses in program<\/p>\n<p>= HitTime<sub>inst<\/sub> + MissRataInst * Miss<\/p>\n<ul>\n<li>\u5982\u679c100\u6761\u6307\u4ee4\u91cc\u670926\u6761LS\u6307\u4ee4\uff0c\u5219INST%\u4e3a100\/126\uff0cDATA%\u4e3a26\/100\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Memory &#8211; Hierarchy Design \u5b58\u50a8\u5c42\u6b21\u8bbe\u8ba1 1.\u00a0 Intro \u5b58 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,16],"tags":[],"_links":{"self":[{"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=\/wp\/v2\/posts\/1013"}],"collection":[{"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1013"}],"version-history":[{"count":4,"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1019,"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions\/1019"}],"wp:attachment":[{"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicmipamipa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}