{"id":47344,"date":"2025-07-30T07:27:26","date_gmt":"2025-07-29T23:27:26","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/47344.html"},"modified":"2025-07-30T07:27:26","modified_gmt":"2025-07-29T23:27:26","slug":"%e7%ac%ac2%e7%ab%a0-%e4%bb%8e%e5%9f%ba%e7%a1%80%e5%88%b0%e8%bf%9b%e9%98%b6%ef%bc%9a%e7%8e%b0%e4%bb%a3%e8%ae%a1%e7%ae%97%e6%9c%ba%e7%b3%bb%e7%bb%9f%e6%9e%b6%e6%9e%84%e4%b8%8e%e5%b7%a5%e4%bd%9c%e5%8e%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/47344.html","title":{"rendered":"\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790"},"content":{"rendered":"<h2>\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636&#xff1a;\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790<\/h2>\n<p>\u8ba1\u7b97\u673a\u7cfb\u7edf\u662f\u73b0\u4ee3\u79d1\u6280\u7684\u6838\u5fc3\u57fa\u7840&#xff0c;\u7406\u89e3\u5176\u5de5\u4f5c\u539f\u7406\u5bf9\u4e8e\u8f6f\u4ef6\u5f00\u53d1\u548c\u7cfb\u7edf\u8bbe\u8ba1\u81f3\u5173\u91cd\u8981\u3002\u672c\u7ae0\u5c06\u6df1\u5165\u63a2\u8ba8\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u57fa\u672c\u7ed3\u6784\u548c\u5de5\u4f5c\u673a\u5236&#xff0c;\u5e2e\u52a9\u8bfb\u8005\u5efa\u7acb\u5168\u9762\u7684\u7cfb\u7edf\u89c2\u5ff5\u3002<\/p>\n<h4>2.1 \u7cfb\u7edf\u57fa\u672c\u7ec4\u6210\u7ed3\u6784<\/h4>\n<p>\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u4e3b\u8981\u7531\u4ee5\u4e0b\u51e0\u4e2a\u57fa\u672c\u90e8\u5206\u7ec4\u6210&#xff1a;\u5904\u7406\u5668&#xff08;CPU&#xff09;\u3001\u5b58\u50a8\u5668&#xff08;\u5185\u5b58&#xff09;\u3001\u8f93\u5165\/\u8f93\u51fa\u8bbe\u5907\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u7684\u8fde\u63a5\u603b\u7ebf\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u534f\u540c\u5de5\u4f5c&#xff0c;\u5171\u540c\u5b8c\u6210\u6570\u636e\u5904\u7406\u4efb\u52a1\u3002<\/p>\n<p>\u5904\u7406\u5668\u4f5c\u4e3a\u7cfb\u7edf\u7684&#034;\u5927\u8111&#034;&#xff0c;\u8d1f\u8d23\u6267\u884c\u6307\u4ee4\u548c\u6570\u636e\u5904\u7406&#xff1b;\u5b58\u50a8\u5668\u7528\u4e8e\u4fdd\u5b58\u7a0b\u5e8f\u548c\u6570\u636e&#xff1b;\u8f93\u5165\/\u8f93\u51fa\u8bbe\u5907\u5b9e\u73b0\u8ba1\u7b97\u673a\u4e0e\u5916\u90e8\u4e16\u754c\u7684\u4ea4\u4e92&#xff1b;\u603b\u7ebf\u5219\u662f\u8fde\u63a5\u5404\u7ec4\u4ef6\u7684&#034;\u9ad8\u901f\u516c\u8def&#034;&#xff0c;\u4fdd\u969c\u6570\u636e\u4f20\u8f93\u3002<\/p>\n<p>c<\/p>\n<p>\/\/ \u7b80\u5355\u793a\u4f8b&#xff1a;\u7cfb\u7edf\u5404\u7ec4\u4ef6\u4e4b\u95f4\u7684\u4ea4\u4e92<br \/>\nvoid system_interaction_example() {<br \/>\n    \/\/ CPU\u6267\u884c\u6307\u4ee4<br \/>\n    int calculation_result &#061; perform_calculation();<\/p>\n<p>    \/\/ \u5b58\u50a8\u7ed3\u679c\u5230\u5185\u5b58<br \/>\n    store_to_memory(calculation_result);<\/p>\n<p>    \/\/ \u901a\u8fc7I\/O\u8bbe\u5907\u8f93\u51fa\u7ed3\u679c<br \/>\n    output_to_device(calculation_result);<br \/>\n}<\/p>\n<h4>2.2 \u5904\u7406\u5668\u4e0e\u7f13\u5b58\u7ed3\u6784<\/h4>\n<h5>2.2.1 \u9762\u5411\u7528\u6237\u7684\u7f13\u5b58\u7cfb\u7edf<\/h5>\n<p>\u5904\u7406\u5668\u4e2d\u7684\u7f13\u5b58(Cache)\u662f\u4e00\u79cd\u9ad8\u901f\u5c0f\u5bb9\u91cf\u7684\u5b58\u50a8\u5668&#xff0c;\u4f4d\u4e8eCPU\u548c\u4e3b\u5b58\u4e4b\u95f4&#xff0c;\u7528\u4e8e\u52a0\u901f\u6570\u636e\u8bbf\u95ee\u3002\u7531\u4e8e\u5904\u7406\u5668\u901f\u5ea6\u8fdc\u5feb\u4e8e\u5185\u5b58\u8bbf\u95ee\u901f\u5ea6&#xff0c;\u7f13\u5b58\u7684\u5f15\u5165\u6709\u6548\u7f13\u89e3\u4e86\u8fd9\u4e00&#034;\u901f\u5ea6\u9e3f\u6c9f&#034;\u3002<\/p>\n<p>\u7528\u6237\u53ef\u89c1\u7f13\u5b58\u4e3b\u8981\u4f53\u73b0\u5728\u7a0b\u5e8f\u6267\u884c\u6027\u80fd\u4e0a&#xff0c;\u867d\u7136\u7a0b\u5e8f\u5458\u901a\u5e38\u4e0d\u76f4\u63a5\u64cd\u4f5c\u7f13\u5b58&#xff0c;\u4f46\u4e86\u89e3\u5176\u5de5\u4f5c\u539f\u7406\u6709\u52a9\u4e8e\u7f16\u5199\u9ad8\u6548\u4ee3\u7801\u3002<\/p>\n<p>c<\/p>\n<p>\/\/ \u5229\u7528\u7f13\u5b58\u5c40\u90e8\u6027\u539f\u7406\u7684\u4ee3\u7801\u793a\u4f8b<br \/>\nvoid cache_friendly_code() {<br \/>\n    int matrix[1000][1000];<\/p>\n<p>    \/\/ \u6309\u884c\u8bbf\u95ee(\u7f13\u5b58\u53cb\u597d)<br \/>\n    for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n        for (int j &#061; 0; j &lt; 1000; j&#043;&#043;) {<br \/>\n            matrix[i][j] &#061; i &#043; j;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u800c\u975e\u6309\u5217\u8bbf\u95ee(\u7f13\u5b58\u4e0d\u53cb\u597d)<br \/>\n    \/\/ for (int j &#061; 0; j &lt; 1000; j&#043;&#043;) {<br \/>\n    \/\/     for (int i &#061; 0; i &lt; 1000; i&#043;&#043;) {<br \/>\n    \/\/         matrix[i][j] &#061; i &#043; j;<br \/>\n    \/\/     }<br \/>\n    \/\/ }<br \/>\n}<\/p>\n<h5>2.2.2 \u63a7\u5236\u4e0e\u72b6\u6001\u7f13\u5b58\u673a\u5236<\/h5>\n<p>\u5904\u7406\u5668\u5185\u90e8\u8fd8\u5305\u542b\u591a\u79cd\u63a7\u5236\u548c\u72b6\u6001\u5bc4\u5b58\u5668&#xff0c;\u7528\u4e8e\u5b58\u50a8CPU\u5f53\u524d\u5de5\u4f5c\u72b6\u6001\u3001\u63a7\u5236\u4fe1\u606f\u548c\u7279\u6b8a\u529f\u80fd\u6807\u5fd7\u3002\u8fd9\u4e9b\u5bc4\u5b58\u5668\u5bf9\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u548c\u5e95\u5c42\u7a0b\u5e8f\u8bbe\u8ba1\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u63a7\u5236\u548c\u72b6\u6001\u5bc4\u5b58\u5668\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\u7a0b\u5e8f\u8ba1\u6570\u5668(PC)&#xff1a;\u6307\u5411\u4e0b\u4e00\u6761\u5c06\u8981\u6267\u884c\u7684\u6307\u4ee4<\/li>\n<li>\u6307\u4ee4\u5bc4\u5b58\u5668(IR)&#xff1a;\u4fdd\u5b58\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u6307\u4ee4<\/li>\n<li>\u72b6\u6001\u5bc4\u5b58\u5668&#xff1a;\u5305\u542b\u6807\u5fd7\u4f4d\u5982\u96f6\u6807\u5fd7\u3001\u8fdb\u4f4d\u6807\u5fd7\u3001\u6ea2\u51fa\u6807\u5fd7\u7b49<\/li>\n<li>\u63a7\u5236\u5bc4\u5b58\u5668&#xff1a;\u63a7\u5236CPU\u64cd\u4f5c\u6a21\u5f0f\u3001\u4e2d\u65ad\u4f7f\u80fd\u7b49<\/li>\n<\/ul>\n<p>c<\/p>\n<p>\/\/ \u6a21\u62df\u5904\u7406\u5668\u72b6\u6001\u5bc4\u5b58\u5668\u7684\u64cd\u4f5c<br \/>\ntypedef struct {<br \/>\n    unsigned int zero_flag : 1;     \/\/ \u96f6\u6807\u5fd7\u4f4d<br \/>\n    unsigned int carry_flag : 1;    \/\/ \u8fdb\u4f4d\u6807\u5fd7\u4f4d<br \/>\n    unsigned int overflow_flag : 1; \/\/ \u6ea2\u51fa\u6807\u5fd7\u4f4d<br \/>\n    unsigned int sign_flag : 1;     \/\/ \u7b26\u53f7\u6807\u5fd7\u4f4d<br \/>\n    \/\/ \u5176\u4ed6\u6807\u5fd7\u4f4d&#8230;<br \/>\n} StatusRegister;<\/p>\n<p>void update_status_register(StatusRegister* sr, int result) {<br \/>\n    sr-&gt;zero_flag &#061; (result &#061;&#061; 0) ? 1 : 0;<br \/>\n    sr-&gt;sign_flag &#061; (result &lt; 0) ? 1 : 0;<br \/>\n    \/\/ \u66f4\u65b0\u5176\u4ed6\u6807\u5fd7\u4f4d&#8230;<br \/>\n}<\/p>\n<h4>2.3 \u6307\u4ee4\u6267\u884c\u8fc7\u7a0b\u5206\u6790<\/h4>\n<h5>2.3.1 \u6307\u4ee4\u83b7\u53d6\u4e0e\u6267\u884c\u6d41\u7a0b<\/h5>\n<p>\u6307\u4ee4\u6267\u884c\u662f\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u6838\u5fc3\u5de5\u4f5c\u3002\u4e00\u6761\u6307\u4ee4\u7684\u6267\u884c\u901a\u5e38\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u9636\u6bb5&#xff1a;<\/p>\n<li>\u53d6\u6307\u4ee4(Fetch)&#xff1a;\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u6307\u4ee4<\/li>\n<li>\u89e3\u7801(Decode)&#xff1a;\u89e3\u6790\u6307\u4ee4\u5185\u5bb9&#xff0c;\u786e\u5b9a\u64cd\u4f5c\u7c7b\u578b\u548c\u64cd\u4f5c\u6570<\/li>\n<li>\u6267\u884c(Execute)&#xff1a;\u6267\u884c\u6307\u4ee4\u6307\u5b9a\u7684\u64cd\u4f5c<\/li>\n<li>\u8bbf\u5b58(Memory Access)&#xff1a;\u82e5\u9700\u8981&#xff0c;\u8bbf\u95ee\u5185\u5b58<\/li>\n<li>\u5199\u56de(Write Back)&#xff1a;\u5c06\u7ed3\u679c\u5199\u56de\u5bc4\u5b58\u5668<\/li>\n<p>\u8fd9\u4e2a\u8fc7\u7a0b\u88ab\u79f0\u4e3a\u6307\u4ee4\u5468\u671f&#xff0c;\u73b0\u4ee3\u5904\u7406\u5668\u901a\u8fc7\u6d41\u6c34\u7ebf\u6280\u672f\u5e76\u884c\u5904\u7406\u591a\u6761\u6307\u4ee4\u7684\u4e0d\u540c\u9636\u6bb5&#xff0c;\u5927\u5927\u63d0\u9ad8\u4e86\u6267\u884c\u6548\u7387\u3002<\/p>\n<p>c<\/p>\n<p>\/\/ \u6a21\u62df\u7b80\u5355\u7684\u6307\u4ee4\u6267\u884c\u8fc7\u7a0b<br \/>\ntypedef enum {FETCH, DECODE, EXECUTE, MEMORY, WRITEBACK} InstructionStage;<\/p>\n<p>void instruction_cycle_simulation() {<br \/>\n    InstructionStage current_stage &#061; FETCH;<br \/>\n    while (1) {  \/\/ \u6301\u7eed\u6267\u884c\u6307\u4ee4<br \/>\n        switch (current_stage) {<br \/>\n            case FETCH:<br \/>\n                \/\/ \u4ece\u5185\u5b58\u83b7\u53d6\u6307\u4ee4<br \/>\n                fetch_instruction_from_memory();<br \/>\n                current_stage &#061; DECODE;<br \/>\n                break;<br \/>\n            case DECODE:<br \/>\n                \/\/ \u89e3\u6790\u6307\u4ee4<br \/>\n                decode_instruction();<br \/>\n                current_stage &#061; EXECUTE;<br \/>\n                break;<br \/>\n            case EXECUTE:<br \/>\n                \/\/ \u6267\u884c\u64cd\u4f5c<br \/>\n                execute_operation();<br \/>\n                current_stage &#061; MEMORY;<br \/>\n                break;<br \/>\n            case MEMORY:<br \/>\n                \/\/ \u5185\u5b58\u8bbf\u95ee(\u5982\u679c\u9700\u8981)<br \/>\n                if (instruction_needs_memory_access()) {<br \/>\n                    perform_memory_access();<br \/>\n                }<br \/>\n                current_stage &#061; WRITEBACK;<br \/>\n                break;<br \/>\n            case WRITEBACK:<br \/>\n                \/\/ \u5199\u56de\u7ed3\u679c<br \/>\n                write_back_result();<br \/>\n                current_stage &#061; FETCH;  \/\/ \u51c6\u5907\u6267\u884c\u4e0b\u4e00\u6761\u6307\u4ee4<br \/>\n                break;<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h5>2.3.2 \u8f93\u5165\/\u8f93\u51fa\u51fd\u6570\u673a\u5236<\/h5>\n<p>\u8f93\u5165\/\u8f93\u51fa(I\/O)\u64cd\u4f5c\u662f\u8ba1\u7b97\u673a\u4e0e\u5916\u90e8\u8bbe\u5907\u4ea4\u4e92\u7684\u5173\u952e\u3002I\/O\u51fd\u6570\u63d0\u4f9b\u4e86\u7a0b\u5e8f\u4e0e\u5916\u90e8\u8bbe\u5907\u901a\u4fe1\u7684\u63a5\u53e3&#xff0c;\u5b9e\u73b0\u6570\u636e\u7684\u8f93\u5165\u548c\u8f93\u51fa\u3002<\/p>\n<p>I\/O\u64cd\u4f5c\u6709\u4e09\u79cd\u4e3b\u8981\u5b9e\u73b0\u65b9\u5f0f&#xff1a;<\/p>\n<ul>\n<li>\u7a0b\u5e8f\u63a7\u5236I\/O&#xff1a;CPU\u76f4\u63a5\u63a7\u5236I\/O\u64cd\u4f5c&#xff0c;\u8f6e\u8be2\u8bbe\u5907\u72b6\u6001<\/li>\n<li>\u4e2d\u65ad\u9a71\u52a8I\/O&#xff1a;\u8bbe\u5907\u51c6\u5907\u597d\u540e\u901a\u8fc7\u4e2d\u65ad\u901a\u77e5CPU<\/li>\n<li>\u76f4\u63a5\u5185\u5b58\u8bbf\u95ee(DMA)&#xff1a;\u5141\u8bb8\u8bbe\u5907\u76f4\u63a5\u4e0e\u5185\u5b58\u4ea4\u6362\u6570\u636e&#xff0c;\u51cf\u8f7bCPU\u8d1f\u62c5<\/li>\n<\/ul>\n<p>c<\/p>\n<p>\/\/ \u7b80\u5355\u7684\u7a0b\u5e8f\u63a7\u5236I\/O\u793a\u4f8b<br \/>\n#define DEVICE_STATUS_REG 0x1000  \/\/ \u8bbe\u5907\u72b6\u6001\u5bc4\u5b58\u5668\u5730\u5740<br \/>\n#define DEVICE_DATA_REG 0x1004    \/\/ \u8bbe\u5907\u6570\u636e\u5bc4\u5b58\u5668\u5730\u5740<br \/>\n#define STATUS_READY 0x01         \/\/ \u8bbe\u5907\u5c31\u7eea\u72b6\u6001\u4f4d<\/p>\n<p>int programmed_io_read() {<br \/>\n    volatile int* status_reg &#061; (volatile int*)DEVICE_STATUS_REG;<br \/>\n    volatile int* data_reg &#061; (volatile int*)DEVICE_DATA_REG;<\/p>\n<p>    \/\/ \u8f6e\u8be2\u7b49\u5f85\u8bbe\u5907\u5c31\u7eea<br \/>\n    while ((*status_reg &amp; STATUS_READY) &#061;&#061; 0) {<br \/>\n        \/\/ \u7b49\u5f85&#8230;<br \/>\n    }<\/p>\n<p>    \/\/ \u8bbe\u5907\u5c31\u7eea&#xff0c;\u8bfb\u53d6\u6570\u636e<br \/>\n    return *data_reg;<br \/>\n}<\/p>\n<h4>2.4 \u4e2d\u65ad\u7cfb\u7edf\u8bbe\u8ba1<\/h4>\n<p>\u4e2d\u65ad\u662f\u8ba1\u7b97\u673a\u7cfb\u7edf\u5b9e\u73b0\u591a\u4efb\u52a1\u5904\u7406\u7684\u5173\u952e\u673a\u5236&#xff0c;\u5141\u8bb8CPU\u6682\u505c\u5f53\u524d\u4efb\u52a1&#xff0c;\u5904\u7406\u66f4\u7d27\u6025\u7684\u4e8b\u4ef6&#xff0c;\u7136\u540e\u8fd4\u56de\u7ee7\u7eed\u539f\u4efb\u52a1\u3002<\/p>\n<h5>2.4.1 \u4e2d\u65ad\u4e0e\u6307\u4ee4\u5468\u671f\u5173\u7cfb<\/h5>\n<p>\u4e2d\u65ad\u68c0\u6d4b\u901a\u5e38\u53d1\u751f\u5728\u6307\u4ee4\u6267\u884c\u5468\u671f\u7684\u7ed3\u675f\u9636\u6bb5\u3002\u5f53\u4e00\u6761\u6307\u4ee4\u6267\u884c\u5b8c\u6210\u540e&#xff0c;\u5904\u7406\u5668\u4f1a\u68c0\u67e5\u662f\u5426\u6709\u6302\u8d77\u7684\u4e2d\u65ad\u8bf7\u6c42\u3002\u5982\u679c\u6709&#xff0c;\u5219\u4f1a&#xff1a;<\/p>\n<li>\u4fdd\u5b58\u5f53\u524d\u7a0b\u5e8f\u72b6\u6001(\u7a0b\u5e8f\u8ba1\u6570\u5668\u3001\u6807\u5fd7\u5bc4\u5b58\u5668\u7b49)<\/li>\n<li>\u8df3\u8f6c\u5230\u76f8\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f<\/li>\n<li>\u5904\u7406\u5b8c\u6210\u540e\u6062\u590d\u4e4b\u524d\u7684\u7a0b\u5e8f\u72b6\u6001&#xff0c;\u7ee7\u7eed\u6267\u884c<\/li>\n<p>\u4e2d\u65ad\u4e0e\u6307\u4ee4\u5468\u671f\u7d27\u5bc6\u7ed3\u5408&#xff0c;\u786e\u4fdd\u4e86\u7cfb\u7edf\u65e2\u80fd\u54cd\u5e94\u5916\u90e8\u4e8b\u4ef6&#xff0c;\u53c8\u80fd\u4fdd\u6301\u7a0b\u5e8f\u6267\u884c\u7684\u8fde\u7eed\u6027\u3002<\/p>\n<p>c<\/p>\n<p>\/\/ \u6a21\u62df\u5e26\u4e2d\u65ad\u68c0\u6d4b\u7684\u6307\u4ee4\u5468\u671f<br \/>\nvoid instruction_cycle_with_interrupts() {<br \/>\n    while (1) {<br \/>\n        \/\/ 1. \u53d6\u6307\u4ee4<br \/>\n        fetch_instruction();<\/p>\n<p>        \/\/ 2. \u6267\u884c\u6307\u4ee4<br \/>\n        execute_instruction();<\/p>\n<p>        \/\/ 3. \u4e2d\u65ad\u68c0\u6d4b<br \/>\n        if (interrupt_pending()) {<br \/>\n            save_current_state();       \/\/ \u4fdd\u5b58\u5f53\u524d\u72b6\u6001<br \/>\n            handle_interrupt();         \/\/ \u5904\u7406\u4e2d\u65ad<br \/>\n            restore_previous_state();   \/\/ \u6062\u590d\u4e4b\u524d\u72b6\u6001<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h5>2.4.2 \u4e2d\u65ad\u5904\u7406\u673a\u5236\u5b9e\u73b0<\/h5>\n<p>\u4e2d\u65ad\u5904\u7406\u6d89\u53ca\u786c\u4ef6\u548c\u8f6f\u4ef6\u7684\u534f\u540c\u5de5\u4f5c\u3002\u786c\u4ef6\u8d1f\u8d23\u68c0\u6d4b\u4e2d\u65ad\u4fe1\u53f7\u3001\u4fdd\u5b58\u90e8\u5206\u5904\u7406\u5668\u72b6\u6001&#xff0c;\u800c\u8f6f\u4ef6(\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f)\u5219\u8d1f\u8d23\u5904\u7406\u5177\u4f53\u7684\u4e2d\u65ad\u4e8b\u4ef6\u3002<\/p>\n<p>\u4e2d\u65ad\u5904\u7406\u7684\u5178\u578b\u6b65\u9aa4\u5305\u62ec&#xff1a;<\/p>\n<li>\u4fdd\u5b58\u4e0a\u4e0b\u6587&#xff1a;\u4fdd\u5b58\u5bc4\u5b58\u5668\u503c\u7b49\u7a0b\u5e8f\u72b6\u6001<\/li>\n<li>\u786e\u5b9a\u4e2d\u65ad\u6e90&#xff1a;\u8bc6\u522b\u5f15\u53d1\u4e2d\u65ad\u7684\u8bbe\u5907\u6216\u4e8b\u4ef6<\/li>\n<li>\u5904\u7406\u4e2d\u65ad&#xff1a;\u6267\u884c\u76f8\u5e94\u7684\u5904\u7406\u64cd\u4f5c<\/li>\n<li>\u6062\u590d\u4e0a\u4e0b\u6587&#xff1a;\u6062\u590d\u4e4b\u524d\u4fdd\u5b58\u7684\u7a0b\u5e8f\u72b6\u6001<\/li>\n<li>\u4e2d\u65ad\u8fd4\u56de&#xff1a;\u8fd4\u56de\u5230\u88ab\u4e2d\u65ad\u7684\u7a0b\u5e8f\u7ee7\u7eed\u6267\u884c<\/li>\n<p>c<\/p>\n<p>\/\/ \u7b80\u5316\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u7ed3\u6784<br \/>\nvoid interrupt_handler() {<br \/>\n    \/\/ 1. \u4fdd\u5b58\u4e0a\u4e0b\u6587(\u5728\u5b9e\u9645\u7cfb\u7edf\u4e2d&#xff0c;\u90e8\u5206\u7531\u786c\u4ef6\u81ea\u52a8\u5b8c\u6210)<br \/>\n    save_context();<\/p>\n<p>    \/\/ 2. \u786e\u5b9a\u4e2d\u65ad\u6e90<br \/>\n    int interrupt_source &#061; identify_interrupt_source();<\/p>\n<p>    \/\/ 3. \u6839\u636e\u4e2d\u65ad\u6e90\u8c03\u7528\u76f8\u5e94\u7684\u5904\u7406\u51fd\u6570<br \/>\n    switch (interrupt_source) {<br \/>\n        case TIMER_INTERRUPT:<br \/>\n            handle_timer_interrupt();<br \/>\n            break;<br \/>\n        case KEYBOARD_INTERRUPT:<br \/>\n            handle_keyboard_interrupt();<br \/>\n            break;<br \/>\n        case DISK_INTERRUPT:<br \/>\n            handle_disk_interrupt();<br \/>\n            break;<br \/>\n        \/\/ \u5904\u7406\u5176\u4ed6\u4e2d\u65ad&#8230;<br \/>\n    }<\/p>\n<p>    \/\/ 4. \u6062\u590d\u4e0a\u4e0b\u6587<br \/>\n    restore_context();<\/p>\n<p>    \/\/ 5. \u4e2d\u65ad\u8fd4\u56de(\u901a\u5e38\u901a\u8fc7\u7279\u6b8a\u6307\u4ee4\u5b9e\u73b0)<br \/>\n    return_from_interrupt();<br \/>\n}<\/p>\n<h5>2.4.3 \u591a\u91cd\u4e2d\u65ad\u5904\u7406\u6280\u672f<\/h5>\n<p>\u5728\u590d\u6742\u7684\u7cfb\u7edf\u4e2d&#xff0c;\u4e2d\u65ad\u53ef\u80fd\u968f\u65f6\u53d1\u751f&#xff0c;\u751a\u81f3\u5728\u5904\u7406\u4e00\u4e2a\u4e2d\u65ad\u7684\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u53c8\u4ea7\u751f\u65b0\u7684\u4e2d\u65ad\u3002\u591a\u91cd\u4e2d\u65ad\u5904\u7406\u6280\u672f\u901a\u8fc7\u4e2d\u65ad\u5d4c\u5957\u548c\u4f18\u5148\u7ea7\u673a\u5236\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002<\/p>\n<p>\u4e2d\u65ad\u4f18\u5148\u7ea7\u7cfb\u7edf\u5141\u8bb8\u9ad8\u4f18\u5148\u7ea7\u4e2d\u65ad\u6253\u65ad\u4f4e\u4f18\u5148\u7ea7\u4e2d\u65ad\u7684\u5904\u7406&#xff0c;\u786e\u4fdd\u7d27\u6025\u4e8b\u4ef6\u5f97\u5230\u53ca\u65f6\u54cd\u5e94\u3002\u540c\u65f6&#xff0c;\u5bf9\u4e8e\u76f8\u540c\u4f18\u5148\u7ea7\u7684\u4e2d\u65ad&#xff0c;\u7cfb\u7edf\u901a\u5e38\u4f1a\u6682\u65f6\u5c4f\u853d&#xff0c;\u76f4\u5230\u5f53\u524d\u4e2d\u65ad\u5904\u7406\u5b8c\u6210\u3002<\/p>\n<p>c<\/p>\n<p>\/\/ \u591a\u91cd\u4e2d\u65ad\u5904\u7406\u793a\u4f8b<br \/>\nvoid nested_interrupt_handler() {<br \/>\n    \/\/ \u4fdd\u5b58\u5f53\u524d\u4e2d\u65ad\u7ea7\u522b<br \/>\n    int previous_level &#061; current_interrupt_level;<\/p>\n<p>    \/\/ \u83b7\u53d6\u65b0\u4e2d\u65ad\u7684\u7ea7\u522b<br \/>\n    int new_interrupt_level &#061; get_interrupt_level();<\/p>\n<p>    \/\/ \u5982\u679c\u65b0\u4e2d\u65ad\u4f18\u5148\u7ea7\u66f4\u9ad8&#xff0c;\u5219\u5141\u8bb8\u5904\u7406<br \/>\n    if (new_interrupt_level &gt; previous_level) {<br \/>\n        \/\/ \u66f4\u65b0\u5f53\u524d\u4e2d\u65ad\u7ea7\u522b<br \/>\n        current_interrupt_level &#061; new_interrupt_level;<\/p>\n<p>        \/\/ \u5141\u8bb8\u66f4\u9ad8\u4f18\u5148\u7ea7\u4e2d\u65ad(\u9009\u62e9\u6027\u5f00\u4e2d\u65ad)<br \/>\n        enable_higher_priority_interrupts(new_interrupt_level);<\/p>\n<p>        \/\/ \u5904\u7406\u5f53\u524d\u4e2d\u65ad<br \/>\n        process_interrupt();<\/p>\n<p>        \/\/ \u6062\u590d\u4e4b\u524d\u7684\u4e2d\u65ad\u7ea7\u522b<br \/>\n        current_interrupt_level &#061; previous_level;<br \/>\n    }<br \/>\n    else {<br \/>\n        \/\/ \u4f4e\u4f18\u5148\u7ea7\u4e2d\u65ad&#xff0c;\u6682\u65f6\u4fdd\u7559&#xff0c;\u7a0d\u540e\u5904\u7406<br \/>\n        queue_interrupt_for_later();<br \/>\n    }<br \/>\n}<\/p>\n<h5>2.4.4 \u591a\u4efb\u52a1\u7a0b\u5e8f\u8bbe\u8ba1\u57fa\u7840<\/h5>\n<p>\u4e2d\u65ad\u673a\u5236\u4e3a\u591a\u4efb\u52a1\u7a0b\u5e8f\u8bbe\u8ba1\u63d0\u4f9b\u4e86\u57fa\u7840\u3002\u64cd\u4f5c\u7cfb\u7edf\u5229\u7528\u65f6\u949f\u4e2d\u65ad\u5b9e\u73b0\u8fdb\u7a0b\u8c03\u5ea6&#xff0c;\u5141\u8bb8\u591a\u4e2a\u7a0b\u5e8f\u770b\u4f3c\u540c\u65f6\u8fd0\u884c&#xff0c;\u5b9e\u9645\u4e0a\u662f\u5feb\u901f\u5207\u6362\u6267\u884c\u3002<\/p>\n<p>\u591a\u4efb\u52a1\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u6838\u5fc3\u6982\u5ff5\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\u4efb\u52a1\u5207\u6362&#xff1a;\u5728\u4e0d\u540c\u4efb\u52a1\u4e4b\u95f4\u5207\u6362\u6267\u884c<\/li>\n<li>\u4e0a\u4e0b\u6587\u4fdd\u5b58\u548c\u6062\u590d&#xff1a;\u4fdd\u5b58\u548c\u6062\u590d\u4efb\u52a1\u72b6\u6001<\/li>\n<li>\u8c03\u5ea6\u7b97\u6cd5&#xff1a;\u51b3\u5b9a\u4e0b\u4e00\u4e2a\u6267\u884c\u7684\u4efb\u52a1<\/li>\n<li>\u540c\u6b65\u548c\u4e92\u65a5&#xff1a;\u534f\u8c03\u4efb\u52a1\u4e4b\u95f4\u7684\u5173\u7cfb<\/li>\n<\/ul>\n<p>c<\/p>\n<p>\/\/ \u7b80\u5316\u7684\u4efb\u52a1\u5207\u6362\u793a\u4f8b<br \/>\ntypedef struct {<br \/>\n    void* stack_pointer;    \/\/ \u4efb\u52a1\u5806\u6808\u6307\u9488<br \/>\n    int task_id;            \/\/ \u4efb\u52a1ID<br \/>\n    int priority;           \/\/ \u4efb\u52a1\u4f18\u5148\u7ea7<br \/>\n    TaskState state;        \/\/ \u4efb\u52a1\u72b6\u6001(\u5c31\u7eea\u3001\u8fd0\u884c\u3001\u963b\u585e\u7b49)<br \/>\n    \/\/ \u5176\u4ed6\u4efb\u52a1\u4fe1\u606f&#8230;<br \/>\n} Task;<\/p>\n<p>\/\/ \u5f53\u524d\u8fd0\u884c\u7684\u4efb\u52a1<br \/>\nTask* current_task;<\/p>\n<p>\/\/ \u4efb\u52a1\u5207\u6362\u51fd\u6570<br \/>\nvoid switch_to_task(Task* next_task) {<br \/>\n    \/\/ 1. \u4fdd\u5b58\u5f53\u524d\u4efb\u52a1\u4e0a\u4e0b\u6587<br \/>\n    save_context(current_task);<\/p>\n<p>    \/\/ 2. \u66f4\u65b0\u5f53\u524d\u4efb\u52a1\u6307\u9488<br \/>\n    Task* prev_task &#061; current_task;<br \/>\n    current_task &#061; next_task;<\/p>\n<p>    \/\/ 3. \u6062\u590d\u65b0\u4efb\u52a1\u7684\u4e0a\u4e0b\u6587<br \/>\n    restore_context(current_task);<\/p>\n<p>    \/\/ \u6ce8&#xff1a;\u5b9e\u9645\u7684\u4e0a\u4e0b\u6587\u5207\u6362\u901a\u5e38\u9700\u8981\u6c47\u7f16\u5b9e\u73b0<br \/>\n}<\/p>\n<h4>2.5 \u5b58\u50a8\u5668\u7684\u5c42\u7ea7\u7ec4\u7ec7<\/h4>\n<p>\u8ba1\u7b97\u673a\u7cfb\u7edf\u4e2d\u7684\u5b58\u50a8\u8bbe\u5907\u6309\u901f\u5ea6\u3001\u5bb9\u91cf\u548c\u6210\u672c\u5f62\u6210\u4e86\u5c42\u6b21\u7ed3\u6784&#xff0c;\u4ece\u9ad8\u901f\u7f13\u5b58\u5230\u4e3b\u5b58\u518d\u5230\u8f85\u52a9\u5b58\u50a8\u3002\u8fd9\u79cd\u5206\u5c42\u8bbe\u8ba1\u5e73\u8861\u4e86\u6027\u80fd\u548c\u6210\u672c&#xff0c;\u540c\u65f6\u5229\u7528\u7a0b\u5e8f\u7684\u5c40\u90e8\u6027\u539f\u7406\u63d0\u9ad8\u6574\u4f53\u6548\u7387\u3002<\/p>\n<p>\u5b58\u50a8\u5c42\u6b21\u7ed3\u6784\u5178\u578b\u5b89\u6392&#xff1a;<\/p>\n<li>\u5bc4\u5b58\u5668&#xff1a;\u5904\u7406\u5668\u5185\u90e8&#xff0c;\u8bbf\u95ee\u6700\u5feb&#xff0c;\u5bb9\u91cf\u6700\u5c0f<\/li>\n<li>\u9ad8\u901f\u7f13\u5b58&#xff1a;L1\/L2\/L3\u7f13\u5b58&#xff0c;\u901f\u5ea6\u5feb&#xff0c;\u5bb9\u91cf\u76f8\u5bf9\u8f83\u5c0f<\/li>\n<li>\u4e3b\u5b58(RAM)&#xff1a;\u4e2d\u7b49\u901f\u5ea6\u548c\u5bb9\u91cf<\/li>\n<li>\u56fa\u6001\u786c\u76d8(SSD)&#xff1a;\u8f83\u5feb\u7684\u8f85\u52a9\u5b58\u50a8<\/li>\n<li>\u786c\u76d8\u9a71\u52a8\u5668(HDD)&#xff1a;\u5927\u5bb9\u91cf&#xff0c;\u4f4e\u901f\u8f85\u52a9\u5b58\u50a8<\/li>\n<li>\u7f51\u7edc\u5b58\u50a8\u3001\u78c1\u5e26\u7b49&#xff1a;\u8d85\u5927\u5bb9\u91cf&#xff0c;\u6700\u4f4e\u901f\u5ea6<\/li>\n<p>\u968f\u7740\u8ddd\u79bb\u5904\u7406\u5668\u8d8a\u8fdc&#xff0c;\u5b58\u50a8\u8bbe\u5907\u7684\u8bbf\u95ee\u901f\u5ea6\u964d\u4f4e&#xff0c;\u4f46\u5bb9\u91cf\u589e\u5927&#xff0c;\u5355\u4f4d\u6210\u672c\u964d\u4f4e\u3002<\/p>\n<p>c<\/p>\n<p>\/\/ \u6f14\u793a\u5185\u5b58\u5c42\u6b21\u5bf9\u6027\u80fd\u7684\u5f71\u54cd<br \/>\n#include &lt;time.h&gt;<br \/>\n#include &lt;stdio.h&gt;<\/p>\n<p>void memory_hierarchy_demo() {<br \/>\n    const int SIZE &#061; 100000000;  \/\/ 1\u4ebf\u4e2a\u6574\u6570<br \/>\n    int* large_array &#061; malloc(SIZE * sizeof(int));<br \/>\n    clock_t start, end;<br \/>\n    double cpu_time_used;<\/p>\n<p>    \/\/ \u521d\u59cb\u5316\u6570\u7ec4<br \/>\n    for (int i &#061; 0; i &lt; SIZE; i&#043;&#043;) {<br \/>\n        large_array[i] &#061; i;<br \/>\n    }<\/p>\n<p>    \/\/ \u6d4b\u8bd51: \u987a\u5e8f\u8bbf\u95ee(\u5229\u7528\u7f13\u5b58)<br \/>\n    start &#061; clock();<br \/>\n    long sum1 &#061; 0;<br \/>\n    for (int i &#061; 0; i &lt; SIZE; i&#043;&#043;) {<br \/>\n        sum1 &#043;&#061; large_array[i];<br \/>\n    }<br \/>\n    end &#061; clock();<br \/>\n    cpu_time_used &#061; ((double) (end &#8211; start)) \/ CLOCKS_PER_SEC;<br \/>\n    printf(&#034;\u987a\u5e8f\u8bbf\u95ee\u65f6\u95f4: %f\u79d2\\\\n&#034;, cpu_time_used);<\/p>\n<p>    \/\/ \u6d4b\u8bd52: \u8df3\u8dc3\u8bbf\u95ee(\u7f13\u5b58\u547d\u4e2d\u7387\u4f4e)<br \/>\n    start &#061; clock();<br \/>\n    long sum2 &#061; 0;<br \/>\n    for (int i &#061; 0; i &lt; SIZE; i &#043;&#061; 16) {  \/\/ \u6b65\u957f\u4e3a16<br \/>\n        sum2 &#043;&#061; large_array[i];<br \/>\n    }<br \/>\n    end &#061; clock();<br \/>\n    cpu_time_used &#061; ((double) (end &#8211; start)) \/ CLOCKS_PER_SEC;<br \/>\n    printf(&#034;\u8df3\u8dc3\u8bbf\u95ee\u65f6\u95f4: %f\u79d2\\\\n&#034;, cpu_time_used);<\/p>\n<p>    free(large_array);<br \/>\n}<\/p>\n<h4>2.6 \u9ad8\u6027\u80fd\u7f13\u5b58\u6280\u672f<\/h4>\n<h5>2.6.1 \u7f13\u5b58\u8bbe\u8ba1\u52a8\u673a<\/h5>\n<p>\u9ad8\u901f\u7f13\u5b58\u7684\u4e3b\u8981\u52a8\u673a\u662f\u89e3\u51b3\u5904\u7406\u5668\u4e0e\u4e3b\u5b58\u4e4b\u95f4\u7684&#034;\u901f\u5ea6\u9e3f\u6c9f&#034;\u3002\u968f\u7740\u5904\u7406\u5668\u901f\u5ea6\u7684\u4e0d\u65ad\u63d0\u5347&#xff0c;\u4e3b\u5b58\u8bbf\u95ee\u901f\u5ea6\u6210\u4e3a\u7cfb\u7edf\u6027\u80fd\u7684\u4e3b\u8981\u74f6\u9888\u3002\u7f13\u5b58\u901a\u8fc7\u5b58\u50a8\u6700\u8fd1\u8bbf\u95ee\u6216\u9891\u7e41\u4f7f\u7528\u7684\u6570\u636e&#xff0c;\u51cf\u5c11\u5bf9\u4e3b\u5b58\u7684\u8bbf\u95ee&#xff0c;\u4ece\u800c\u63d0\u9ad8\u7cfb\u7edf\u6574\u4f53\u6027\u80fd\u3002<\/p>\n<p>\u5904\u7406\u5668\u4e0e\u4e3b\u5b58\u901f\u5ea6\u5dee\u8ddd\u6301\u7eed\u6269\u5927&#xff1a;<\/p>\n<ul>\n<li>\u73b0\u4ee3CPU\u6267\u884c\u901f\u5ea6\u53ef\u8fbeGHz\u7ea7\u522b(\u6bcf\u79d2\u6570\u5341\u4ebf\u6b21\u64cd\u4f5c)<\/li>\n<li>\u4e3b\u5b58\u8bbf\u95ee\u5ef6\u8fdf\u4ecd\u5728\u6570\u5341\u5230\u6570\u767e\u4e2aCPU\u5468\u671f<\/li>\n<li>\u65e0\u7f13\u5b58\u7cfb\u7edf\u4e2d&#xff0c;CPU\u5927\u90e8\u5206\u65f6\u95f4\u90fd\u5728\u7b49\u5f85\u6570\u636e<\/li>\n<\/ul>\n<p>c<\/p>\n<p>\/\/ \u7f13\u5b58\u91cd\u8981\u6027\u6f14\u793a<br \/>\nvoid cache_importance() {<br \/>\n    \/\/ \u5047\u8bbe\u4e3b\u5b58\u8bbf\u95ee\u9700\u8981100\u4e2aCPU\u5468\u671f<br \/>\n    \/\/ \u7f13\u5b58\u8bbf\u95ee\u9700\u89811\u4e2aCPU\u5468\u671f<br \/>\n    \/\/ \u7f13\u5b58\u547d\u4e2d\u7387\u4e3a90%<\/p>\n<p>    int memory_access_time &#061; 100;  \/\/ \u5468\u671f<br \/>\n    int cache_access_time &#061; 1;     \/\/ \u5468\u671f<br \/>\n    float hit_rate &#061; 0.9;          \/\/ 90%\u547d\u4e2d\u7387<\/p>\n<p>    \/\/ \u4e0d\u4f7f\u7528\u7f13\u5b58\u7684\u5e73\u5747\u8bbf\u95ee\u65f6\u95f4<br \/>\n    int no_cache_time &#061; memory_access_time;  \/\/ 100\u5468\u671f<\/p>\n<p>    \/\/ \u4f7f\u7528\u7f13\u5b58\u7684\u5e73\u5747\u8bbf\u95ee\u65f6\u95f4<br \/>\n    float with_cache_time &#061; hit_rate * cache_access_time &#043;<br \/>\n                          (1 &#8211; hit_rate) * (cache_access_time &#043; memory_access_time);<br \/>\n    \/\/ &#061; 0.9*1 &#043; 0.1*101 &#061; 0.9 &#043; 10.1 &#061; 11\u5468\u671f<\/p>\n<p>    printf(&#034;\u65e0\u7f13\u5b58\u8bbf\u95ee\u65f6\u95f4: %d\u5468\u671f\\\\n&#034;, no_cache_time);<br \/>\n    printf(&#034;\u6709\u7f13\u5b58\u8bbf\u95ee\u65f6\u95f4: %.1f\u5468\u671f\\\\n&#034;, with_cache_time);<br \/>\n    printf(&#034;\u6027\u80fd\u63d0\u5347: %.1f\u500d\\\\n&#034;, (float)no_cache_time \/ with_cache_time);<br \/>\n}<\/p>\n<h5>2.6.2 \u9ad8\u901f\u7f13\u5b58\u5de5\u4f5c\u539f\u7406\u89e3\u6790<\/h5>\n<p>\u7f13\u5b58\u7684\u5de5\u4f5c\u5efa\u7acb\u5728\u7a0b\u5e8f\u5c40\u90e8\u6027\u539f\u7406\u7684\u57fa\u7840\u4e0a&#xff1a;<\/p>\n<ul>\n<li>\u65f6\u95f4\u5c40\u90e8\u6027&#xff1a;\u6700\u8fd1\u8bbf\u95ee\u8fc7\u7684\u6570\u636e\u5f88\u53ef\u80fd\u518d\u6b21\u88ab\u8bbf\u95ee<\/li>\n<li>\u7a7a\u95f4\u5c40\u90e8\u6027&#xff1a;\u8bbf\u95ee\u67d0\u4e2a\u6570\u636e\u540e&#xff0c;\u5176\u9644\u8fd1\u7684\u6570\u636e\u5f88\u53ef\u80fd\u4e5f\u4f1a\u88ab\u8bbf\u95ee<\/li>\n<\/ul>\n<p>\u57fa\u4e8e\u8fd9\u4e9b\u539f\u7406&#xff0c;\u7f13\u5b58\u7cfb\u7edf\u4e0d\u4ec5\u5b58\u50a8\u5355\u4e2a\u6570\u636e&#xff0c;\u800c\u662f\u4ee5&#034;\u7f13\u5b58\u884c&#034;(Cache Line)\u4e3a\u5355\u4f4d\u4ece\u4e3b\u5b58\u8bfb\u53d6\u6570\u636e&#xff0c;\u901a\u5e38\u4e3a64\u5b57\u8282\u3002\u8fd9\u79cd\u8bbe\u8ba1\u5229\u7528\u4e86\u7a7a\u95f4\u5c40\u90e8\u6027&#xff0c;\u63d0\u9ad8\u4e86\u7f13\u5b58\u6548\u7387\u3002<\/p>\n<p>c<\/p>\n<p>\/\/ \u6a21\u62df\u7f13\u5b58\u7cfb\u7edf\u7684\u57fa\u672c\u5de5\u4f5c\u6d41\u7a0b<br \/>\ntypedef struct {<br \/>\n    bool valid;         \/\/ \u6709\u6548\u4f4d<br \/>\n    unsigned int tag;   \/\/ \u6807\u8bb0\u4f4d<br \/>\n    int data[16];       \/\/ \u7f13\u5b58\u6570\u636e(\u4e00\u4e2a\u7f13\u5b58\u884c)<br \/>\n} CacheLine;<\/p>\n<p>typedef struct {<br \/>\n    CacheLine lines[128];  \/\/ 128\u4e2a\u7f13\u5b58\u884c<br \/>\n} Cache;<\/p>\n<p>\/\/ \u4ece\u7f13\u5b58\/\u5185\u5b58\u8bfb\u53d6\u6570\u636e<br \/>\nint read_memory(Cache* cache, unsigned int address) {<br \/>\n    \/\/ \u8ba1\u7b97\u5730\u5740\u5bf9\u5e94\u7684\u7f13\u5b58\u884c\u7d22\u5f15\u548c\u6807\u8bb0<br \/>\n    unsigned int index &#061; (address \/ sizeof(int)) % 128;<br \/>\n    unsigned int tag &#061; (address \/ sizeof(int)) \/ 128;<br \/>\n    unsigned int offset &#061; (address \/ sizeof(int)) % 16;<\/p>\n<p>    \/\/ \u68c0\u67e5\u7f13\u5b58\u662f\u5426\u547d\u4e2d<br \/>\n    if (cache-&gt;lines[index].valid &amp;&amp; cache-&gt;lines[index].tag &#061;&#061; tag) {<br \/>\n        \/\/ \u7f13\u5b58\u547d\u4e2d<br \/>\n        return cache-&gt;lines[index].data[offset];<br \/>\n    } else {<br \/>\n        \/\/ \u7f13\u5b58\u672a\u547d\u4e2d&#xff0c;\u4ece&#034;\u4e3b\u5b58&#034;\u8bfb\u53d6\u6574\u4e2a\u7f13\u5b58\u884c<br \/>\n        for (int i &#061; 0; i &lt; 16; i&#043;&#043;) {<br \/>\n            \/\/ \u7b80\u5316\u6a21\u62df&#xff0c;\u5b9e\u9645\u5e94\u4ece\u4e3b\u5b58\u8bfb\u53d6<br \/>\n            cache-&gt;lines[index].data[i] &#061; simulate_memory_read(address &#8211; offset*sizeof(int) &#043; i*sizeof(int));<br \/>\n        }<br \/>\n        cache-&gt;lines[index].valid &#061; true;<br \/>\n        cache-&gt;lines[index].tag &#061; tag;<\/p>\n<p>        \/\/ \u8fd4\u56de\u8bf7\u6c42\u7684\u6570\u636e<br \/>\n        return cache-&gt;lines[index].data[offset];<br \/>\n    }<br \/>\n}<\/p>\n<h5>2.6.3 \u73b0\u4ee3\u9ad8\u901f\u7f13\u5b58\u8bbe\u8ba1\u6280\u672f<\/h5>\n<p>\u73b0\u4ee3\u5904\u7406\u5668\u4e2d\u7684\u7f13\u5b58\u8bbe\u8ba1\u6d89\u53ca\u591a\u4e2a\u5173\u952e\u51b3\u7b56&#xff1a;<\/p>\n<li>\n<p>\u7f13\u5b58\u6620\u5c04\u7b56\u7565<\/p>\n<ul>\n<li>\u76f4\u63a5\u6620\u5c04&#xff1a;\u6bcf\u4e2a\u4e3b\u5b58\u5730\u5740\u53ea\u80fd\u6620\u5c04\u5230\u7279\u5b9a\u7f13\u5b58\u884c<\/li>\n<li>\u5168\u76f8\u8054&#xff1a;\u4efb\u4f55\u7f13\u5b58\u884c\u53ef\u4ee5\u5b58\u50a8\u4efb\u4f55\u4e3b\u5b58\u6570\u636e<\/li>\n<li>\u7ec4\u76f8\u8054&#xff1a;\u6298\u4e2d\u65b9\u6848&#xff0c;\u63d0\u4f9b\u6709\u9650\u7684\u7075\u6d3b\u6027<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u66ff\u6362\u7b56\u7565<\/p>\n<ul>\n<li>LRU (\u6700\u8fd1\u6700\u5c11\u4f7f\u7528)&#xff1a;\u66ff\u6362\u6700\u957f\u65f6\u95f4\u672a\u4f7f\u7528\u7684\u6570\u636e<\/li>\n<li>FIFO (\u5148\u8fdb\u5148\u51fa)&#xff1a;\u66ff\u6362\u6700\u65e9\u52a0\u5165\u7684\u6570\u636e<\/li>\n<li>\u968f\u673a\u66ff\u6362&#xff1a;\u968f\u673a\u9009\u62e9\u8981\u66ff\u6362\u7684\u7f13\u5b58\u884c<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5199\u5165\u7b56\u7565<\/p>\n<ul>\n<li>\u5199\u76f4\u8fbe&#xff1a;\u6570\u636e\u540c\u65f6\u5199\u5165\u7f13\u5b58\u548c\u4e3b\u5b58<\/li>\n<li>\u5199\u56de&#xff1a;\u6570\u636e\u53ea\u5199\u5165\u7f13\u5b58&#xff0c;\u6807\u8bb0\u4e3a\u810f&#xff0c;\u4ec5\u5728\u66ff\u6362\u65f6\u5199\u56de\u4e3b\u5b58<\/li>\n<\/ul>\n<\/li>\n<p>c<\/p>\n<p>\/\/ \u7ec4\u76f8\u8054\u7f13\u5b58\u6a21\u62df(\u4e24\u8def\u7ec4\u76f8\u8054)<br \/>\ntypedef struct {<br \/>\n    bool valid;<br \/>\n    bool dirty;          \/\/ \u810f\u4f4d&#xff0c;\u7528\u4e8e\u5199\u56de\u7b56\u7565<br \/>\n    unsigned int tag;<br \/>\n    int data[16];<br \/>\n    unsigned int last_used;  \/\/ \u7528\u4e8eLRU\u7b97\u6cd5<br \/>\n} CacheLine;<\/p>\n<p>typedef struct {<br \/>\n    CacheLine ways[2][64];  \/\/ 2\u8def\u7ec4\u76f8\u8054&#xff0c;64\u7ec4<br \/>\n} SetAssociativeCache;<\/p>\n<p>\/\/ LRU\u66ff\u6362\u7b56\u7565<br \/>\nint find_lru_way(SetAssociativeCache* cache, unsigned int set) {<br \/>\n    if (cache-&gt;ways[0][set].last_used &lt; cache-&gt;ways[1][set].last_used) {<br \/>\n        return 0;<br \/>\n    } else {<br \/>\n        return 1;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u5199\u56de\u7f13\u5b58\u6a21\u62df<br \/>\nvoid write_to_cache(SetAssociativeCache* cache, unsigned int address, int value) {<br \/>\n    unsigned int set &#061; (address \/ sizeof(int) \/ 16) % 64;<br \/>\n    unsigned int tag &#061; (address \/ sizeof(int)) \/ (16 * 64);<br \/>\n    unsigned int offset &#061; (address \/ sizeof(int)) % 16;<br \/>\n    static unsigned int time_counter &#061; 0;<br \/>\n    time_counter&#043;&#043;;<\/p>\n<p>    \/\/ \u68c0\u67e5\u662f\u5426\u547d\u4e2d<br \/>\n    for (int way &#061; 0; way &lt; 2; way&#043;&#043;) {<br \/>\n        if (cache-&gt;ways[way][set].valid &amp;&amp; cache-&gt;ways[way][set].tag &#061;&#061; tag) {<br \/>\n            \/\/ \u7f13\u5b58\u547d\u4e2d&#xff0c;\u5199\u5165\u6570\u636e<br \/>\n            cache-&gt;ways[way][set].data[offset] &#061; value;<br \/>\n            cache-&gt;ways[way][set].dirty &#061; true;  \/\/ \u6807\u8bb0\u4e3a\u810f<br \/>\n            cache-&gt;ways[way][set].last_used &#061; time_counter;<br \/>\n            return;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u7f13\u5b58\u672a\u547d\u4e2d&#xff0c;\u9700\u8981\u627e\u4e00\u4e2a\u4f4d\u7f6e\u653e\u5165\u65b0\u6570\u636e<br \/>\n    \/\/ \u5148\u68c0\u67e5\u662f\u5426\u6709\u7a7a\u95f2\u4f4d\u7f6e<br \/>\n    for (int way &#061; 0; way &lt; 2; way&#043;&#043;) {<br \/>\n        if (!cache-&gt;ways[way][set].valid) {<br \/>\n            \/\/ \u627e\u5230\u7a7a\u95f2\u4f4d\u7f6e<br \/>\n            load_cache_line(cache, way, set, address);  \/\/ \u52a0\u8f7d\u7f13\u5b58\u884c<br \/>\n            cache-&gt;ways[way][set].data[offset] &#061; value;<br \/>\n            cache-&gt;ways[way][set].dirty &#061; true;<br \/>\n            cache-&gt;ways[way][set].last_used &#061; time_counter;<br \/>\n            return;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u6ca1\u6709\u7a7a\u95f2\u4f4d\u7f6e&#xff0c;\u9700\u8981\u66ff\u6362&#xff0c;\u4f7f\u7528LRU\u7b56\u7565<br \/>\n    int way_to_replace &#061; find_lru_way(cache, set);<\/p>\n<p>    \/\/ \u5982\u679c\u88ab\u66ff\u6362\u7684\u884c\u662f\u810f\u7684&#xff0c;\u9700\u8981\u5199\u56de\u4e3b\u5b58<br \/>\n    if (cache-&gt;ways[way_to_replace][set].valid &amp;&amp;<br \/>\n        cache-&gt;ways[way_to_replace][set].dirty) {<br \/>\n        write_back_to_memory(cache, way_to_replace, set);<br \/>\n    }<\/p>\n<p>    \/\/ \u52a0\u8f7d\u65b0\u7684\u7f13\u5b58\u884c<br \/>\n    load_cache_line(cache, way_to_replace, set, address);<br \/>\n    cache-&gt;ways[way_to_replace][set].data[offset] &#061; value;<br \/>\n    cache-&gt;ways[way_to_replace][set].dirty &#061; true;<br \/>\n    cache-&gt;ways[way_to_replace][set].last_used &#061; time_counter;<br \/>\n}<\/p>\n<h4>2.7 \u8f93\u5165\/\u8f93\u51fa\u901a\u4fe1\u7cfb\u7edf<\/h4>\n<h5>2.7.1 \u53ef\u7f16\u7a0b\u8f93\u5165\/\u8f93\u51fa\u6280\u672f<\/h5>\n<p>\u53ef\u7f16\u7a0bI\/O\u662f\u6700\u57fa\u672c\u7684\u8f93\u5165\/\u8f93\u51fa\u63a7\u5236\u65b9\u5f0f&#xff0c;CPU\u901a\u8fc7\u7279\u5b9a\u6307\u4ee4\u76f4\u63a5\u63a7\u5236I\/O\u8bbe\u5907\u7684\u64cd\u4f5c\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0b&#xff0c;CPU\u4e0d\u65ad\u8f6e\u8be2\u8bbe\u5907\u72b6\u6001&#xff0c;\u7b49\u5f85\u8bbe\u5907\u51c6\u5907\u597d\u540e\u518d\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u3002<\/p>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u5b9e\u73b0\u7b80\u5355&#xff0c;\u786c\u4ef6\u8981\u6c42\u4f4e<\/li>\n<li>\u9002\u7528\u4e8e\u4f4e\u901f\u8bbe\u5907<\/li>\n<\/ul>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>CPU\u5229\u7528\u7387\u4f4e&#xff0c;\u5927\u91cf\u65f6\u95f4\u7528\u4e8e\u7b49\u5f85<\/li>\n<li>\u4e0d\u9002\u5408\u9ad8\u901f\u8bbe\u5907\u6216\u591a\u8bbe\u5907\u7cfb\u7edf<\/li>\n<\/ul>\n<p>c<\/p>\n<p>\/\/ \u53ef\u7f16\u7a0bI\/O\u793a\u4f8b&#xff1a;\u5411\u4e32\u53e3\u53d1\u9001\u4e00\u4e2a\u5b57\u7b26<br \/>\n#define SERIAL_STATUS_PORT 0x3F8 &#043; 5  \/\/ \u4e32\u53e3\u72b6\u6001\u5bc4\u5b58\u5668<br \/>\n#define SERIAL_DATA_PORT 0x3F8        \/\/ \u4e32\u53e3\u6570\u636e\u5bc4\u5b58\u5668<br \/>\n#define SERIAL_READY_TO_SEND 0x20     \/\/ \u53d1\u9001\u5c31\u7eea\u4f4d<\/p>\n<p>void programmed_io_send_char(char c) {<br \/>\n    \/\/ \u8f6e\u8be2\u7b49\u5f85\u4e32\u53e3\u51c6\u5907\u597d\u53d1\u9001<br \/>\n    while ((inp(SERIAL_STATUS_PORT) &amp; SERIAL_READY_TO_SEND) &#061;&#061; 0) {<br \/>\n        \/\/ \u7a7a\u5faa\u73af\u7b49\u5f85<br \/>\n    }<\/p>\n<p>    \/\/ \u4e32\u53e3\u51c6\u5907\u597d&#xff0c;\u53d1\u9001\u6570\u636e<br \/>\n    outp(SERIAL_DATA_PORT, c);<br \/>\n}<\/p>\n<p>\/\/ \u53d1\u9001\u5b57\u7b26\u4e32<br \/>\nvoid programmed_io_send_string(const char* str) {<br \/>\n    while (*str) {<br \/>\n        programmed_io_send_char(*str);<br \/>\n        str&#043;&#043;;<br \/>\n    }<br \/>\n}<\/p>\n<h5>2.7.2 \u4e2d\u65ad\u9a71\u52a8\u578b\u8f93\u5165\/\u8f93\u51fa\u5b9e\u73b0<\/h5>\n<p>\u4e2d\u65ad\u9a71\u52a8I\/O\u89e3\u51b3\u4e86\u53ef\u7f16\u7a0bI\/O\u7684\u6548\u7387\u95ee\u9898\u3002CPU\u53d1\u51faI\/O\u8bf7\u6c42\u540e\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4efb\u52a1&#xff0c;\u5f53\u8bbe\u5907\u5b8c\u6210\u64cd\u4f5c\u540e\u901a\u8fc7\u4e2d\u65ad\u673a\u5236\u901a\u77e5CPU&#xff0c;CPU\u518d\u6267\u884c\u76f8\u5e94\u7684\u6570\u636e\u4f20\u8f93\u3002<\/p>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>CPU\u5229\u7528\u7387\u9ad8&#xff0c;\u53ef\u4ee5\u5e76\u884c\u5904\u7406\u5176\u4ed6\u4efb\u52a1<\/li>\n<li>\u9002\u5408\u5904\u7406\u5076\u53d1\u6027I\/O\u64cd\u4f5c<\/li>\n<\/ul>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u6bcf\u6b21\u6570\u636e\u4f20\u8f93\u4ecd\u9700CPU\u53c2\u4e0e<\/li>\n<li>\u9891\u7e41\u4e2d\u65ad\u4f1a\u5bfc\u81f4\u4e0a\u4e0b\u6587\u5207\u6362\u5f00\u9500\u589e\u5927<\/li>\n<\/ul>\n<p>c<\/p>\n<p>\/\/ \u4e2d\u65ad\u9a71\u52a8I\/O\u793a\u4f8b<br \/>\n#include &lt;signal.h&gt;<\/p>\n<p>\/\/ \u5168\u5c40\u53d8\u91cf\u8bb0\u5f55I\/O\u72b6\u6001<br \/>\nvolatile bool io_operation_complete &#061; false;<br \/>\nvolatile char received_data;<\/p>\n<p>\/\/ \u4e2d\u65ad\u5904\u7406\u51fd\u6570<br \/>\nvoid io_interrupt_handler(int signum) {<br \/>\n    \/\/ \u8bfb\u53d6\u8bbe\u5907\u6570\u636e(\u7b80\u5316\u793a\u4f8b)<br \/>\n    received_data &#061; read_device_data();<br \/>\n    io_operation_complete &#061; true;<br \/>\n}<\/p>\n<p>\/\/ \u521d\u59cb\u5316\u4e2d\u65ad\u9a71\u52a8I\/O<br \/>\nvoid init_interrupt_driven_io() {<br \/>\n    \/\/ \u6ce8\u518c\u4e2d\u65ad\u5904\u7406\u51fd\u6570<br \/>\n    signal(SIGUSR1, io_interrupt_handler);<\/p>\n<p>    \/\/ \u914d\u7f6e\u8bbe\u5907\u4f7f\u7528\u4e2d\u65ad<br \/>\n    configure_device_for_interrupts();<br \/>\n}<\/p>\n<p>\/\/ \u4f7f\u7528\u4e2d\u65ad\u9a71\u52a8I\/O\u8bfb\u53d6\u6570\u636e<br \/>\nchar interrupt_driven_read() {<br \/>\n    \/\/ \u91cd\u7f6e\u5b8c\u6210\u6807\u5fd7<br \/>\n    io_operation_complete &#061; false;<\/p>\n<p>    \/\/ \u542f\u52a8I\/O\u64cd\u4f5c<br \/>\n    start_device_read_operation();<\/p>\n<p>    \/\/ \u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4efb\u52a1\u76f4\u5230I\/O\u5b8c\u6210<br \/>\n    while (!io_operation_complete) {<br \/>\n        \/\/ \u6267\u884c\u5176\u4ed6\u6709\u7528\u7684\u5de5\u4f5c<br \/>\n        do_other_processing();<\/p>\n<p>        \/\/ \u6216\u77ed\u6682\u4f11\u7720\u907f\u514d\u5fd9\u7b49\u5f85<br \/>\n        usleep(1000);<br \/>\n    }<\/p>\n<p>    \/\/ I\/O\u5b8c\u6210&#xff0c;\u8fd4\u56de\u6570\u636e<br \/>\n    return received_data;<br \/>\n}<\/p>\n<h5>2.7.3 \u76f4\u63a5\u5185\u5b58\u5b58\u53d6\u6280\u672f\u8be6\u89e3<\/h5>\n<p>\u76f4\u63a5\u5185\u5b58\u8bbf\u95ee(DMA)\u8fdb\u4e00\u6b65\u51cf\u5c11\u4e86CPU\u5728I\/O\u64cd\u4f5c\u4e2d\u7684\u53c2\u4e0e\u3002\u5728DMA\u6a21\u5f0f\u4e0b&#xff0c;CPU\u53ea\u9700\u8bbe\u7f6e\u597dDMA\u63a7\u5236\u5668\u7684\u53c2\u6570(\u6e90\u5730\u5740\u3001\u76ee\u6807\u5730\u5740\u3001\u4f20\u8f93\u957f\u5ea6\u7b49)&#xff0c;\u7136\u540e\u542f\u52a8\u4f20\u8f93&#xff0c;DMA\u63a7\u5236\u5668\u76f4\u63a5\u63a7\u5236\u5185\u5b58\u548c\u8bbe\u5907\u4e4b\u95f4\u7684\u6570\u636e\u4f20\u8f93&#xff0c;\u5b8c\u6210\u540e\u624d\u901a\u77e5CPU\u3002<\/p>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>CPU\u51e0\u4e4e\u4e0d\u53c2\u4e0e\u6570\u636e\u4f20\u8f93\u8fc7\u7a0b&#xff0c;\u6548\u7387\u6700\u9ad8<\/li>\n<li>\u9002\u5408\u5927\u91cf\u6570\u636e\u4f20\u8f93\u548c\u9ad8\u901f\u8bbe\u5907<\/li>\n<\/ul>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u786c\u4ef6\u590d\u6742\u5ea6\u589e\u52a0<\/li>\n<li>\u53ef\u80fd\u4e0eCPU\u4e89\u7528\u5185\u5b58\u603b\u7ebf<\/li>\n<\/ul>\n<p>c<\/p>\n<p>\/\/ DMA\u4f20\u8f93\u6a21\u62df\u793a\u4f8b<br \/>\ntypedef struct {<br \/>\n    void* source;        \/\/ \u6e90\u5730\u5740<br \/>\n    void* destination;   \/\/ \u76ee\u6807\u5730\u5740<br \/>\n    size_t length;       \/\/ \u4f20\u8f93\u957f\u5ea6<br \/>\n    bool direction;      \/\/ \u4f20\u8f93\u65b9\u5411(0:\u5185\u5b58\u5230\u8bbe\u5907, 1:\u8bbe\u5907\u5230\u5185\u5b58)<br \/>\n    volatile bool busy;  \/\/ DMA\u63a7\u5236\u5668\u5fd9\u72b6\u6001<br \/>\n} DMAController;<\/p>\n<p>\/\/ \u5168\u5c40DMA\u63a7\u5236\u5668<br \/>\nDMAController dma_controller;<\/p>\n<p>\/\/ \u521d\u59cb\u5316DMA\u4f20\u8f93<br \/>\nvoid setup_dma_transfer(void* source, void* destination, size_t length, bool direction) {<br \/>\n    \/\/ \u7b49\u5f85DMA\u63a7\u5236\u5668\u7a7a\u95f2<br \/>\n    while (dma_controller.busy) {<br \/>\n        \/\/ \u7b49\u5f85&#8230;<br \/>\n    }<\/p>\n<p>    \/\/ \u8bbe\u7f6eDMA\u53c2\u6570<br \/>\n    dma_controller.source &#061; source;<br \/>\n    dma_controller.destination &#061; destination;<br \/>\n    dma_controller.length &#061; length;<br \/>\n    dma_controller.direction &#061; direction;<br \/>\n}<\/p>\n<p>\/\/ \u542f\u52a8DMA\u4f20\u8f93<br \/>\nvoid start_dma_transfer() {<br \/>\n    \/\/ \u6807\u8bb0DMA\u63a7\u5236\u5668\u4e3a\u5fd9<br \/>\n    dma_controller.busy &#061; true;<\/p>\n<p>    \/\/ \u5728\u5b9e\u9645\u786c\u4ef6\u4e2d&#xff0c;\u8fd9\u91cc\u4f1a\u89e6\u53d1DMA\u63a7\u5236\u5668\u5f00\u59cb\u4f20\u8f93<br \/>\n    \/\/ \u5728\u6a21\u62df\u4e2d&#xff0c;\u6211\u4eec\u542f\u52a8\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c\u4f20\u8f93<br \/>\n    pthread_t dma_thread;<br \/>\n    pthread_create(&amp;dma_thread, NULL, dma_transfer_thread, NULL);<br \/>\n    pthread_detach(dma_thread);<br \/>\n}<\/p>\n<p>\/\/ DMA\u4f20\u8f93\u7ebf\u7a0b(\u6a21\u62dfDMA\u63a7\u5236\u5668\u7684\u5de5\u4f5c)<br \/>\nvoid* dma_transfer_thread(void* arg) {<br \/>\n    \/\/ \u6267\u884c\u6570\u636e\u4f20\u8f93<br \/>\n    if (dma_controller.direction &#061;&#061; 0) {<br \/>\n        \/\/ \u5185\u5b58\u5230\u8bbe\u5907<br \/>\n        memcpy(dma_controller.destination, dma_controller.source, dma_controller.length);<br \/>\n    } else {<br \/>\n        \/\/ \u8bbe\u5907\u5230\u5185\u5b58<br \/>\n        memcpy(dma_controller.destination, dma_controller.source, dma_controller.length);<br \/>\n    }<\/p>\n<p>    \/\/ \u4f20\u8f93\u5b8c\u6210&#xff0c;\u6807\u8bb0DMA\u63a7\u5236\u5668\u4e3a\u7a7a\u95f2<br \/>\n    dma_controller.busy &#061; false;<\/p>\n<p>    \/\/ \u751f\u6210\u4e2d\u65ad\u901a\u77e5CPU\u4f20\u8f93\u5b8c\u6210<br \/>\n    generate_dma_complete_interrupt();<\/p>\n<p>    return NULL;<br \/>\n}<\/p>\n<p>\/\/ \u4f7f\u7528DMA\u8bfb\u53d6\u78c1\u76d8\u6570\u636e\u7684\u793a\u4f8b<br \/>\nvoid read_disk_block_dma(int block_number, void* buffer) {<br \/>\n    \/\/ \u8ba1\u7b97\u78c1\u76d8\u5757\u5730\u5740<br \/>\n    void* disk_address &#061; calculate_disk_address(block_number);<\/p>\n<p>    \/\/ \u8bbe\u7f6eDMA\u4f20\u8f93<br \/>\n    setup_dma_transfer(disk_address, buffer, BLOCK_SIZE, 1);<\/p>\n<p>    \/\/ \u542f\u52a8DMA\u4f20\u8f93<br \/>\n    start_dma_transfer();<\/p>\n<p>    \/\/ CPU\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u4efb\u52a1<br \/>\n    \/\/ &#8230;<\/p>\n<p>    \/\/ \u5982\u679c\u9700\u8981\u7b49\u5f85\u4f20\u8f93\u5b8c\u6210<br \/>\n    wait_for_dma_completion();<br \/>\n}<\/p>\n<h4>2.8 \u63a8\u8350\u8bfb\u7269\u4e0e\u5728\u7ebf\u8d44\u6e90<\/h4>\n<p>\u4e3a\u4e86\u6df1\u5165\u7406\u89e3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784&#xff0c;\u4ee5\u4e0b\u662f\u4e00\u4e9b\u63a8\u8350\u7684\u4e66\u7c4d\u548c\u5728\u7ebf\u8d44\u6e90&#xff1a;<\/p>\n<li>\n<p>\u7ecf\u5178\u4e66\u7c4d&#xff1a;<\/p>\n<ul>\n<li>&#034;\u8ba1\u7b97\u673a\u7ec4\u6210\u4e0e\u8bbe\u8ba1&#xff1a;\u786c\u4ef6\/\u8f6f\u4ef6\u63a5\u53e3&#034;(Patterson &amp; Hennessy)<\/li>\n<li>&#034;\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784&#xff1a;\u91cf\u5316\u7814\u7a76\u65b9\u6cd5&#034;(Hennessy &amp; Patterson)<\/li>\n<li>&#034;\u6df1\u5165\u7406\u89e3\u8ba1\u7b97\u673a\u7cfb\u7edf&#034;(Bryant &amp; O&#039;Hallaron)<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5728\u7ebf\u8bfe\u7a0b&#xff1a;<\/p>\n<ul>\n<li>MIT\u7684&#034;\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784&#034;\u8bfe\u7a0b<\/li>\n<li>Stanford\u7684&#034;\u8ba1\u7b97\u673a\u7ec4\u6210\u4e0e\u7cfb\u7edf&#034;\u8bfe\u7a0b<\/li>\n<li>Coursera\u4e0a\u7684\u76f8\u5173\u4e13\u4e1a\u8bfe\u7a0b<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f51\u7ad9\u548c\u8bba\u575b&#xff1a;<\/p>\n<ul>\n<li>Stack Overflow\u7684\u8ba1\u7b97\u673a\u67b6\u6784\u677f\u5757<\/li>\n<li>Computer Architecture Today\u535a\u5ba2<\/li>\n<li>ACM SIGARCH\u7f51\u7ad9<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b9e\u8df5\u8d44\u6e90&#xff1a;<\/p>\n<ul>\n<li>\u5f00\u6e90CPU\u8bbe\u8ba1\u9879\u76ee(\u5982RISC-V)<\/li>\n<li>\u8ba1\u7b97\u673a\u6a21\u62df\u5668\u548c\u865a\u62df\u673a<\/li>\n<li>\u786c\u4ef6\u63cf\u8ff0\u8bed\u8a00\u6559\u7a0b(\u5982Verilog, VHDL)<\/li>\n<\/ul>\n<\/li>\n<h4>2.9 \u5173\u952e\u672f\u8bed\u3001\u4e60\u9898\u4e0e\u5b9e\u8df5\u7ec3\u4e60<\/h4>\n<h5>\u5173\u952e\u672f\u8bed<\/h5>\n<ul>\n<li>\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784&#xff1a;\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u7ec4\u7ec7\u7ed3\u6784\u548c\u5de5\u4f5c\u65b9\u5f0f<\/li>\n<li>\u51af\u00b7\u8bfa\u4f9d\u66fc\u67b6\u6784&#xff1a;\u5b58\u50a8\u7a0b\u5e8f\u5f0f\u8ba1\u7b97\u673a\u7684\u57fa\u672c\u67b6\u6784<\/li>\n<li>\u7f13\u5b58(Cache)&#xff1a;\u9ad8\u901f\u5c0f\u5bb9\u91cf\u5b58\u50a8\u5668&#xff0c;\u7528\u4e8e\u52a0\u901f\u6570\u636e\u8bbf\u95ee<\/li>\n<li>\u6307\u4ee4\u5468\u671f&#xff1a;\u53d6\u6307\u3001\u8bd1\u7801\u3001\u6267\u884c\u3001\u8bbf\u5b58\u3001\u5199\u56de\u7684\u5faa\u73af\u8fc7\u7a0b<\/li>\n<li>\u4e2d\u65ad&#xff1a;\u6682\u505c\u5f53\u524d\u7a0b\u5e8f\u6267\u884c&#xff0c;\u5904\u7406\u7d27\u6025\u4e8b\u4ef6\u7684\u673a\u5236<\/li>\n<li>DMA&#xff1a;\u76f4\u63a5\u5185\u5b58\u8bbf\u95ee&#xff0c;\u65e0\u9700CPU\u53c2\u4e0e\u7684\u6570\u636e\u4f20\u8f93\u65b9\u5f0f<\/li>\n<li>\u6d41\u6c34\u7ebf&#xff1a;\u5c06\u6307\u4ee4\u6267\u884c\u8fc7\u7a0b\u5206\u89e3\u4e3a\u591a\u4e2a\u9636\u6bb5\u5e76\u884c\u6267\u884c<\/li>\n<li>\u5b58\u50a8\u5c42\u6b21\u7ed3\u6784&#xff1a;\u4ece\u9ad8\u901f\u7f13\u5b58\u5230\u4e3b\u5b58\u5230\u8f85\u5b58\u7684\u5b58\u50a8\u8bbe\u5907\u7ec4\u7ec7<\/li>\n<\/ul>\n<h5>\u590d\u4e60\u9898<\/h5>\n<li>\u63cf\u8ff0\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u57fa\u672c\u7ec4\u6210\u90e8\u5206\u53ca\u5176\u529f\u80fd\u3002<\/li>\n<li>\u89e3\u91ca\u7f13\u5b58\u5728\u8ba1\u7b97\u673a\u7cfb\u7edf\u4e2d\u7684\u4f5c\u7528&#xff0c;\u4ee5\u53ca\u7f13\u5b58\u547d\u4e2d\u548c\u7f13\u5b58\u672a\u547d\u4e2d\u7684\u6982\u5ff5\u3002<\/li>\n<li>\u63cf\u8ff0\u6307\u4ee4\u6267\u884c\u7684\u57fa\u672c\u5468\u671f&#xff0c;\u5e76\u89e3\u91ca\u73b0\u4ee3\u5904\u7406\u5668\u5982\u4f55\u901a\u8fc7\u6d41\u6c34\u7ebf\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<li>\u6bd4\u8f83\u7a0b\u5e8f\u63a7\u5236I\/O\u3001\u4e2d\u65ad\u9a71\u52a8I\/O\u548cDMA\u4e09\u79cdI\/O\u65b9\u5f0f\u7684\u4f18\u7f3a\u70b9\u3002<\/li>\n<li>\u89e3\u91ca\u4e2d\u65ad\u5982\u4f55\u5f71\u54cd\u6307\u4ee4\u6267\u884c\u8fc7\u7a0b&#xff0c;\u4ee5\u53ca\u5904\u7406\u5668\u5982\u4f55\u5904\u7406\u4e2d\u65ad\u3002<\/li>\n<h5>\u5b9e\u8df5\u7ec3\u4e60<\/h5>\n<p>\u7ec3\u4e601&#xff1a;\u6d4b\u91cf\u7f13\u5b58\u6027\u80fd<br \/>\n\u7f16\u5199\u7a0b\u5e8f&#xff0c;\u901a\u8fc7\u6bd4\u8f83\u987a\u5e8f\u8bbf\u95ee\u548c\u968f\u673a\u8bbf\u95ee\u5927\u6570\u7ec4\u7684\u6027\u80fd\u5dee\u5f02&#xff0c;\u89c2\u5bdf\u7f13\u5b58\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u3002<\/p>\n<p>c<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;time.h&gt;<\/p>\n<p>#define ARRAY_SIZE 100000000  \/\/ 1\u4ebf\u4e2a\u6574\u6570<\/p>\n<p>int main() {<br \/>\n    int* array &#061; (int*)malloc(ARRAY_SIZE * sizeof(int));<br \/>\n    if (!array) {<br \/>\n        printf(&#034;\u5185\u5b58\u5206\u914d\u5931\u8d25\\\\n&#034;);<br \/>\n        return 1;<br \/>\n    }<\/p>\n<p>    \/\/ \u521d\u59cb\u5316\u6570\u7ec4<br \/>\n    for (int i &#061; 0; i &lt; ARRAY_SIZE; i&#043;&#043;) {<br \/>\n        array[i] &#061; i;<br \/>\n    }<\/p>\n<p>    \/\/ \u6d4b\u8bd51: \u987a\u5e8f\u8bbf\u95ee<br \/>\n    clock_t start &#061; clock();<br \/>\n    long sum1 &#061; 0;<br \/>\n    for (int i &#061; 0; i &lt; ARRAY_SIZE; i&#043;&#043;) {<br \/>\n        sum1 &#043;&#061; array[i];<br \/>\n    }<br \/>\n    clock_t end &#061; clock();<br \/>\n    double time1 &#061; ((double)(end &#8211; start)) \/ CLOCKS_PER_SEC;<\/p>\n<p>    \/\/ \u6d4b\u8bd52: \u968f\u673a\u8bbf\u95ee<br \/>\n    int* indices &#061; (int*)malloc(ARRAY_SIZE \/ 100 * sizeof(int));<br \/>\n    for (int i &#061; 0; i &lt; ARRAY_SIZE \/ 100; i&#043;&#043;) {<br \/>\n        indices[i] &#061; rand() % ARRAY_SIZE;<br \/>\n    }<\/p>\n<p>    start &#061; clock();<br \/>\n    long sum2 &#061; 0;<br \/>\n    for (int i &#061; 0; i &lt; ARRAY_SIZE \/ 100; i&#043;&#043;) {<br \/>\n        sum2 &#043;&#061; array[indices[i]];<br \/>\n    }<br \/>\n    end &#061; clock();<br \/>\n    double time2 &#061; ((double)(end &#8211; start)) \/ CLOCKS_PER_SEC;<\/p>\n<p>    printf(&#034;\u987a\u5e8f\u8bbf\u95ee\u65f6\u95f4: %.6f\u79d2\\\\n&#034;, time1);<br \/>\n    printf(&#034;\u968f\u673a\u8bbf\u95ee\u65f6\u95f4(\u603b\u65701\/100): %.6f\u79d2\\\\n&#034;, time2);<br \/>\n    printf(&#034;\u968f\u673a\u8bbf\u95ee\u65f6\u95f4(\u5f52\u4e00\u5316): %.6f\u79d2\\\\n&#034;, time2 * 100);<br \/>\n    printf(&#034;\u968f\u673a\/\u987a\u5e8f\u65f6\u95f4\u6bd4: %.2f\\\\n&#034;, (time2 * 100) \/ time1);<\/p>\n<p>    free(array);<br \/>\n    free(indices);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u7ec3\u4e602&#xff1a;\u6a21\u62df\u6307\u4ee4\u5468\u671f<br \/>\n\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u5904\u7406\u5668\u6a21\u62df\u5668&#xff0c;\u6267\u884c\u57fa\u672c\u6307\u4ee4\u5e76\u5904\u7406\u4e2d\u65ad\u3002<\/p>\n<p>c<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdbool.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>\/\/ \u6307\u4ee4\u7c7b\u578b<br \/>\ntypedef enum {<br \/>\n    INST_ADD,    \/\/ \u52a0\u6cd5<br \/>\n    INST_SUB,    \/\/ \u51cf\u6cd5<br \/>\n    INST_LOAD,   \/\/ \u52a0\u8f7d\u6570\u636e<br \/>\n    INST_STORE,  \/\/ \u5b58\u50a8\u6570\u636e<br \/>\n    INST_JUMP,   \/\/ \u8df3\u8f6c<br \/>\n    INST_HALT    \/\/ \u505c\u6b62<br \/>\n} InstructionType;<\/p>\n<p>\/\/ \u6307\u4ee4\u7ed3\u6784<br \/>\ntypedef struct {<br \/>\n    InstructionType type;<br \/>\n    int operand1;<br \/>\n    int operand2;<br \/>\n    int operand3;<br \/>\n} Instruction;<\/p>\n<p>\/\/ CPU\u72b6\u6001<br \/>\ntypedef struct {<br \/>\n    int registers[16];        \/\/ 16\u4e2a\u901a\u7528\u5bc4\u5b58\u5668<br \/>\n    int program_counter;      \/\/ \u7a0b\u5e8f\u8ba1\u6570\u5668<br \/>\n    bool halt;                \/\/ \u505c\u6b62\u6807\u5fd7<br \/>\n    bool interrupt_pending;   \/\/ \u4e2d\u65ad\u6302\u8d77\u6807\u5fd7<br \/>\n    int interrupt_vector;     \/\/ \u4e2d\u65ad\u5411\u91cf<br \/>\n} CPUState;<\/p>\n<p>\/\/ \u5185\u5b58\u6a21\u62df<br \/>\n#define MEMORY_SIZE 1024<br \/>\nint memory[MEMORY_SIZE];<\/p>\n<p>\/\/ \u6307\u4ee4\u5185\u5b58<br \/>\nInstruction program[] &#061; {<br \/>\n    {INST_LOAD, 0, 100, 0},   \/\/ \u5c06\u5185\u5b58\u5730\u5740100\u7684\u503c\u52a0\u8f7d\u5230\u5bc4\u5b58\u56680<br \/>\n    {INST_LOAD, 1, 101, 0},   \/\/ \u5c06\u5185\u5b58\u5730\u5740101\u7684\u503c\u52a0\u8f7d\u5230\u5bc4\u5b58\u56681<br \/>\n    {INST_ADD, 2, 0, 1},      \/\/ \u5bc4\u5b58\u56680\u548c\u5bc4\u5b58\u56681\u76f8\u52a0&#xff0c;\u7ed3\u679c\u5b58\u5165\u5bc4\u5b58\u56682<br \/>\n    {INST_STORE, 2, 102, 0},  \/\/ \u5c06\u5bc4\u5b58\u56682\u7684\u503c\u5b58\u5165\u5185\u5b58\u5730\u5740102<br \/>\n    {INST_HALT, 0, 0, 0}      \/\/ \u505c\u6b62\u6267\u884c<br \/>\n};<\/p>\n<p>\/\/ \u521d\u59cb\u5316CPU\u548c\u5185\u5b58<br \/>\nvoid initialize_system(CPUState* cpu) {<br \/>\n    \/\/ \u521d\u59cb\u5316CPU\u72b6\u6001<br \/>\n    for (int i &#061; 0; i &lt; 16; i&#043;&#043;) {<br \/>\n        cpu-&gt;registers[i] &#061; 0;<br \/>\n    }<br \/>\n    cpu-&gt;program_counter &#061; 0;<br \/>\n    cpu-&gt;halt &#061; false;<br \/>\n    cpu-&gt;interrupt_pending &#061; false;<\/p>\n<p>    \/\/ \u521d\u59cb\u5316\u5185\u5b58<br \/>\n    for (int i &#061; 0; i &lt; MEMORY_SIZE; i&#043;&#043;) {<br \/>\n        memory[i] &#061; 0;<br \/>\n    }<\/p>\n<p>    \/\/ \u8bbe\u7f6e\u6d4b\u8bd5\u6570\u636e<br \/>\n    memory[100] &#061; 25;  \/\/ \u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570<br \/>\n    memory[101] &#061; 17;  \/\/ \u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570<br \/>\n}<\/p>\n<p>\/\/ \u6267\u884c\u5355\u6761\u6307\u4ee4<br \/>\nvoid execute_instruction(CPUState* cpu, Instruction inst) {<br \/>\n    switch (inst.type) {<br \/>\n        case INST_ADD:<br \/>\n            cpu-&gt;registers[inst.operand1] &#061; cpu-&gt;registers[inst.operand2] &#043;<br \/>\n                                           cpu-&gt;registers[inst.operand3];<br \/>\n            break;<br \/>\n        case INST_SUB:<br \/>\n            cpu-&gt;registers[inst.operand1] &#061; cpu-&gt;registers[inst.operand2] &#8211;<br \/>\n                                           cpu-&gt;registers[inst.operand3];<br \/>\n            break;<br \/>\n        case INST_LOAD:<br \/>\n            cpu-&gt;registers[inst.operand1] &#061; memory[inst.operand2];<br \/>\n            break;<br \/>\n        case INST_STORE:<br \/>\n            memory[inst.operand2] &#061; cpu-&gt;registers[inst.operand1];<br \/>\n            break;<br \/>\n        case INST_JUMP:<br \/>\n            cpu-&gt;program_counter &#061; inst.operand1 &#8211; 1;  \/\/ -1\u56e0\u4e3a\u540e\u9762\u4f1a&#043;1<br \/>\n            break;<br \/>\n        case INST_HALT:<br \/>\n            cpu-&gt;halt &#061; true;<br \/>\n            break;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u4e2d\u65ad\u5904\u7406<br \/>\nvoid handle_interrupt(CPUState* cpu) {<br \/>\n    printf(&#034;\u5904\u7406\u4e2d\u65ad: \u5411\u91cf %d\\\\n&#034;, cpu-&gt;interrupt_vector);<\/p>\n<p>    \/\/ \u7b80\u5355\u7684\u4e2d\u65ad\u5904\u7406&#xff1a;\u5c06\u4e2d\u65ad\u5411\u91cf\u5b58\u5165\u5185\u5b58\u7279\u5b9a\u4f4d\u7f6e<br \/>\n    memory[500] &#061; cpu-&gt;interrupt_vector;<\/p>\n<p>    cpu-&gt;interrupt_pending &#061; false;<br \/>\n}<\/p>\n<p>\/\/ \u6a21\u62df\u6307\u4ee4\u5468\u671f<br \/>\nvoid instruction_cycle(CPUState* cpu) {<br \/>\n    while (!cpu-&gt;halt) {<br \/>\n        \/\/ 1. \u68c0\u67e5\u4e2d\u65ad<br \/>\n        if (cpu-&gt;interrupt_pending) {<br \/>\n            handle_interrupt(cpu);<br \/>\n        }<\/p>\n<p>        \/\/ 2. \u53d6\u6307\u4ee4<br \/>\n        Instruction current_instruction &#061; program[cpu-&gt;program_counter];<\/p>\n<p>        \/\/ 3. \u6267\u884c\u6307\u4ee4<br \/>\n        execute_instruction(cpu, current_instruction);<\/p>\n<p>        \/\/ 4. \u66f4\u65b0\u7a0b\u5e8f\u8ba1\u6570\u5668<br \/>\n        cpu-&gt;program_counter&#043;&#043;;<\/p>\n<p>        \/\/ \u6253\u5370CPU\u72b6\u6001<br \/>\n        printf(&#034;PC: %d, R0: %d, R1: %d, R2: %d\\\\n&#034;,<br \/>\n               cpu-&gt;program_counter, cpu-&gt;registers[0],<br \/>\n               cpu-&gt;registers[1], cpu-&gt;registers[2]);<br \/>\n    }<\/p>\n<p>    printf(&#034;\u7a0b\u5e8f\u6267\u884c\u5b8c\u6bd5\\\\n&#034;);<br \/>\n}<\/p>\n<p>\/\/ \u751f\u6210\u6a21\u62df\u4e2d\u65ad<br \/>\nvoid generate_interrupt(CPUState* cpu, int vector) {<br \/>\n    cpu-&gt;interrupt_pending &#061; true;<br \/>\n    cpu-&gt;interrupt_vector &#061; vector;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    CPUState cpu;<br \/>\n    initialize_system(&amp;cpu);<\/p>\n<p>    \/\/ \u5728\u7b2c2\u6761\u6307\u4ee4\u6267\u884c\u540e\u751f\u6210\u4e2d\u65ad<br \/>\n    int interrupt_after &#061; 2;<\/p>\n<p>    \/\/ \u4fee\u6539\u4e3b\u5faa\u73af\u4ee5\u5728\u7279\u5b9a\u6307\u4ee4\u540e\u751f\u6210\u4e2d\u65ad<br \/>\n    while (!cpu.halt) {<br \/>\n        \/\/ \u68c0\u67e5\u4e2d\u65ad<br \/>\n        if (cpu.interrupt_pending) {<br \/>\n            handle_interrupt(&amp;cpu);<br \/>\n        }<\/p>\n<p>        \/\/ \u53d6\u6307\u4ee4<br \/>\n        Instruction current_instruction &#061; program[cpu.program_counter];<\/p>\n<p>        \/\/ \u6267\u884c\u6307\u4ee4<br \/>\n        execute_instruction(&amp;cpu, current_instruction);<\/p>\n<p>        \/\/ \u66f4\u65b0\u7a0b\u5e8f\u8ba1\u6570\u5668<br \/>\n        cpu.program_counter&#043;&#043;;<\/p>\n<p>        \/\/ \u6253\u5370CPU\u72b6\u6001<br \/>\n        printf(&#034;PC: %d, R0: %d, R1: %d, R2: %d\\\\n&#034;,<br \/>\n               cpu.program_counter, cpu.registers[0],<br \/>\n               cpu.registers[1], cpu.registers[2]);<\/p>\n<p>        \/\/ \u5728\u6307\u5b9a\u6307\u4ee4\u540e\u751f\u6210\u4e2d\u65ad<br \/>\n        if (cpu.program_counter &#061;&#061; interrupt_after) {<br \/>\n            printf(&#034;\u751f\u6210\u4e2d\u65ad&#xff01;\\\\n&#034;);<br \/>\n            generate_interrupt(&amp;cpu, 42);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    printf(&#034;\u7a0b\u5e8f\u6267\u884c\u5b8c\u6bd5\\\\n&#034;);<br \/>\n    printf(&#034;\u8ba1\u7b97\u7ed3\u679c(\u5185\u5b58\u5730\u5740102): %d\\\\n&#034;, memory[102]);<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>\u901a\u8fc7\u672c\u7ae0\u7684\u5b66\u4e60&#xff0c;\u8bfb\u8005\u5e94\u8be5\u80fd\u591f\u7406\u89e3\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u57fa\u672c\u7ec4\u6210\u548c\u5de5\u4f5c\u539f\u7406&#xff0c;\u4e3a\u540e\u7eed\u6df1\u5165\u5b66\u4e60\u64cd\u4f5c\u7cfb\u7edf\u3001\u7f16\u8bd1\u539f\u7406\u548c\u8ba1\u7b97\u673a\u7f51\u7edc\u7b49\u5185\u5bb9\u5960\u5b9a\u57fa\u7840\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb904\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790\u4e86\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u7684\u6838\u5fc3\u7ec4\u6210\u548c\u5de5\u4f5c\u539f\u7406\u3002\u9996\u5148\u4ecb\u7ecd\u4e86\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u57fa\u672c\u7ed3\u6784\uff0c\u5305\u62ec\u5904\u7406\u5668\u3001\u5b58\u50a8\u5668\u3001I\/O\u8bbe\u5907\u548c\u603b\u7ebf\u7b49\u7ec4\u4ef6\u3002\u91cd\u70b9\u5206\u6790\u4e86\u5904\u7406\u5668\u4e0e\u7f13\u5b58\u7ed3\u6784\uff0c\u9610\u91ca\u4e86\u7f13\u5b58\u7cfb\u7edf\u5982\u4f55\u901a\u8fc7\u5c40\u90e8\u6027\u539f\u7406\u63d0\u5347\u6027\u80fd\u3002\u8be6\u7ec6\u8bb2\u89e3\u4e86\u6307\u4ee4\u6267\u884c\u6d41\u7a0b\uff08\u53d6\u6307\u3001\u89e3\u7801\u3001\u6267\u884c\u3001\u8bbf\u5b58\u3001\u5199\u56de\uff09\u548c\u4e2d\u65ad\u5904\u7406\u673a\u5236\uff0c\u5305\u62ec\u4e2d\u65ad\u4f18\u5148\u7ea7\u548c\u591a\u91cd\u4e2d\u65ad\u5904\u7406\u6280\u672f\u3002\u6b64\u5916\uff0c\u63a2\u8ba8\u4e86\u5b58\u50a8\u5c42\u6b21\u7ed3\u6784\uff08\u5bc4\u5b58\u5668-\u7f13\u5b58-\u5185\u5b58-\u5916\u5b58\uff09\u548c\u4e09\u79cdI\/O\u901a\u4fe1\u65b9\u5f0f\uff08\u53ef\u7f16\u7a0bI\/O\u3001\u4e2d\u65ad\u9a71\u52a8I\/O\u548cDMA\uff09\u7684\u7279\u70b9\u4e0e\u5b9e\u73b0\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u7f13\u5b58\u53cb\u597d\u7f16\u7a0b\u3001\u6307\u4ee4\u5468\u671f\u6a21\u62df\u7b49\u5173\u952e\u6280\u672f\uff0c\u5e2e\u52a9\u8bfb\u8005\u7406\u89e3\u8ba1\u7b97\u673a\u5e95\u5c42\u5de5\u4f5c<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4533,442],"topic":[],"class_list":["post-47344","post","type-post","status-publish","format-standard","hentry","category-server","tag-linuxwindows","tag-442"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/47344.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb904\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790\u4e86\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u7684\u6838\u5fc3\u7ec4\u6210\u548c\u5de5\u4f5c\u539f\u7406\u3002\u9996\u5148\u4ecb\u7ecd\u4e86\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u57fa\u672c\u7ed3\u6784\uff0c\u5305\u62ec\u5904\u7406\u5668\u3001\u5b58\u50a8\u5668\u3001I\/O\u8bbe\u5907\u548c\u603b\u7ebf\u7b49\u7ec4\u4ef6\u3002\u91cd\u70b9\u5206\u6790\u4e86\u5904\u7406\u5668\u4e0e\u7f13\u5b58\u7ed3\u6784\uff0c\u9610\u91ca\u4e86\u7f13\u5b58\u7cfb\u7edf\u5982\u4f55\u901a\u8fc7\u5c40\u90e8\u6027\u539f\u7406\u63d0\u5347\u6027\u80fd\u3002\u8be6\u7ec6\u8bb2\u89e3\u4e86\u6307\u4ee4\u6267\u884c\u6d41\u7a0b\uff08\u53d6\u6307\u3001\u89e3\u7801\u3001\u6267\u884c\u3001\u8bbf\u5b58\u3001\u5199\u56de\uff09\u548c\u4e2d\u65ad\u5904\u7406\u673a\u5236\uff0c\u5305\u62ec\u4e2d\u65ad\u4f18\u5148\u7ea7\u548c\u591a\u91cd\u4e2d\u65ad\u5904\u7406\u6280\u672f\u3002\u6b64\u5916\uff0c\u63a2\u8ba8\u4e86\u5b58\u50a8\u5c42\u6b21\u7ed3\u6784\uff08\u5bc4\u5b58\u5668-\u7f13\u5b58-\u5185\u5b58-\u5916\u5b58\uff09\u548c\u4e09\u79cdI\/O\u901a\u4fe1\u65b9\u5f0f\uff08\u53ef\u7f16\u7a0bI\/O\u3001\u4e2d\u65ad\u9a71\u52a8I\/O\u548cDMA\uff09\u7684\u7279\u70b9\u4e0e\u5b9e\u73b0\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u7f13\u5b58\u53cb\u597d\u7f16\u7a0b\u3001\u6307\u4ee4\u5468\u671f\u6a21\u62df\u7b49\u5173\u952e\u6280\u672f\uff0c\u5e2e\u52a9\u8bfb\u8005\u7406\u89e3\u8ba1\u7b97\u673a\u5e95\u5c42\u5de5\u4f5c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/47344.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T23:27:26+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47344.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/47344.html\",\"name\":\"\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T23:27:26+00:00\",\"dateModified\":\"2025-07-29T23:27:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/47344.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/47344.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47344.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/47344.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb904\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790\u4e86\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u7684\u6838\u5fc3\u7ec4\u6210\u548c\u5de5\u4f5c\u539f\u7406\u3002\u9996\u5148\u4ecb\u7ecd\u4e86\u8ba1\u7b97\u673a\u7cfb\u7edf\u7684\u57fa\u672c\u7ed3\u6784\uff0c\u5305\u62ec\u5904\u7406\u5668\u3001\u5b58\u50a8\u5668\u3001I\/O\u8bbe\u5907\u548c\u603b\u7ebf\u7b49\u7ec4\u4ef6\u3002\u91cd\u70b9\u5206\u6790\u4e86\u5904\u7406\u5668\u4e0e\u7f13\u5b58\u7ed3\u6784\uff0c\u9610\u91ca\u4e86\u7f13\u5b58\u7cfb\u7edf\u5982\u4f55\u901a\u8fc7\u5c40\u90e8\u6027\u539f\u7406\u63d0\u5347\u6027\u80fd\u3002\u8be6\u7ec6\u8bb2\u89e3\u4e86\u6307\u4ee4\u6267\u884c\u6d41\u7a0b\uff08\u53d6\u6307\u3001\u89e3\u7801\u3001\u6267\u884c\u3001\u8bbf\u5b58\u3001\u5199\u56de\uff09\u548c\u4e2d\u65ad\u5904\u7406\u673a\u5236\uff0c\u5305\u62ec\u4e2d\u65ad\u4f18\u5148\u7ea7\u548c\u591a\u91cd\u4e2d\u65ad\u5904\u7406\u6280\u672f\u3002\u6b64\u5916\uff0c\u63a2\u8ba8\u4e86\u5b58\u50a8\u5c42\u6b21\u7ed3\u6784\uff08\u5bc4\u5b58\u5668-\u7f13\u5b58-\u5185\u5b58-\u5916\u5b58\uff09\u548c\u4e09\u79cdI\/O\u901a\u4fe1\u65b9\u5f0f\uff08\u53ef\u7f16\u7a0bI\/O\u3001\u4e2d\u65ad\u9a71\u52a8I\/O\u548cDMA\uff09\u7684\u7279\u70b9\u4e0e\u5b9e\u73b0\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u7f13\u5b58\u53cb\u597d\u7f16\u7a0b\u3001\u6307\u4ee4\u5468\u671f\u6a21\u62df\u7b49\u5173\u952e\u6280\u672f\uff0c\u5e2e\u52a9\u8bfb\u8005\u7406\u89e3\u8ba1\u7b97\u673a\u5e95\u5c42\u5de5\u4f5c","og_url":"https:\/\/www.wsisp.com\/helps\/47344.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T23:27:26+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"11 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/47344.html","url":"https:\/\/www.wsisp.com\/helps\/47344.html","name":"\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T23:27:26+00:00","dateModified":"2025-07-29T23:27:26+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/47344.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/47344.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/47344.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7b2c2\u7ae0 \u4ece\u57fa\u7840\u5230\u8fdb\u9636\uff1a\u73b0\u4ee3\u8ba1\u7b97\u673a\u7cfb\u7edf\u67b6\u6784\u4e0e\u5de5\u4f5c\u539f\u7406\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=47344"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47344\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=47344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=47344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=47344"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=47344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}