{"id":61335,"date":"2025-04-29T11:28:25","date_gmt":"2025-04-29T03:28:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/61335\/"},"modified":"2025-04-29T11:28:25","modified_gmt":"2025-04-29T03:28:25","slug":"%e9%85%8d%e7%bd%aelinux%e7%b3%bb%e7%bb%9f%e4%bb%a5%e6%94%af%e6%8c%81%e5%ae%9e%e6%97%b6%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e5%bc%80%e5%8f%91-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/61335\/","title":{"rendered":"\u914d\u7f6eLinux\u7cfb\u7edf\u4ee5\u652f\u6301\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1"},"content":{"rendered":"<p>\u914d\u7f6elinux\u7cfb\u7edf\u4ee5\u652f\u6301\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1<\/p>\n<p>\u968f\u7740\u5d4c\u5165\u5f0f\u7cfb\u7edf\u7684\u53d1\u5c55\uff0c\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\uff08RTOS\uff09\u5728\u5404\u79cd\u5e94\u7528\u9886\u57df\u4e2d\u5f97\u5230\u4e86\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4e3a\u4e86\u652f\u6301RTOS\u7684\u5f00\u53d1\uff0c\u6211\u4eec\u9700\u8981\u5bf9Linux\u7cfb\u7edf\u8fdb\u884c\u914d\u7f6e\uff0c\u4ee5\u6ee1\u8db3\u5b9e\u65f6\u6027\u548c\u53ef\u9884\u6d4b\u6027\u7684\u8981\u6c42\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e2d\u914d\u7f6e\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1\u73af\u5883\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u4e00\u3001\u5185\u6838\u914d\u7f6e<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bf9Linux\u5185\u6838\u8fdb\u884c\u914d\u7f6e\uff0c\u4ee5\u542f\u7528\u5b9e\u65f6\u6027\u7684\u529f\u80fd\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u914d\u7f6e\uff1a<\/p>\n<ol>\n<li>\n<p>\u4e0b\u8f7dLinux\u5185\u6838\u6e90\u7801\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e0b\u8f7dLinux\u5185\u6838\u7684\u6e90\u7801\u3002\u53ef\u4ee5\u4eceLinux\u5b98\u65b9\u7f51\u7ad9\uff08www.kernel.org\uff09\u4e0a\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u5185\u6838\u6e90\u7801\u3002<\/p>\n<\/li>\n<li>\n<p>\u7f16\u8bd1\u5185\u6838\u3002<\/p>\n<p>\u89e3\u538b\u4e0b\u8f7d\u7684\u5185\u6838\u6e90\u7801\uff0c\u5e76\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\u5185\u6838\uff1a<\/p>\n<pre>make menuconfig<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u5c06\u542f\u52a8\u5185\u6838\u914d\u7f6e\u83dc\u5355\u3002\u5728\u83dc\u5355\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u4ee5\u4e0b\u9009\u9879\u8fdb\u884c\u914d\u7f6e\uff1a<\/p>\n<ul>\n<li>\n<p>General setup -&gt; Preemption model<\/p>\n<p>\u9009\u62e9&#8221;Fully preemptible kernel (RT)&#8221;\u3002\u8fd9\u5c06\u542f\u7528\u5185\u6838\u7684\u5b9e\u65f6\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>Processor type and features -&gt; Preemption Model<\/p>\n<p>\u9009\u62e9&#8221;Voluntary Kernel Preemption (Desktop)&#8221;\u3002\u8fd9\u5c06\u542f\u7528\u5185\u6838\u7684\u53ef\u62a2\u5360\u6027\uff0c\u63d0\u9ad8\u5b9e\u65f6\u6027\u80fd\u3002<\/p>\n<\/li>\n<li>\n<p>Processor type and features -&gt; Timer frequency<\/p>\n<p>\u5c06\u5b9a\u65f6\u5668\u9891\u7387\u8bbe\u7f6e\u4e3a1000 HZ\u3002<\/p>\n<\/li>\n<li>\n<p>Processor type and features -&gt; Timer tick handling<\/p>\n<p>\u9009\u62e9&#8221;Standard clock tick&#8221;\u3002\u8fd9\u5c06\u542f\u7528\u6807\u51c6\u7684\u65f6\u949f\u4e2d\u65ad\u5904\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>Processor type and features -&gt; Timer slack<\/p>\n<p>\u5c06\u5b9a\u65f6\u5668\u677e\u5f1b\u5ea6\u8bbe\u7f6e\u4e3a1\u3002<\/p>\n<\/li>\n<li>\n<p>Power management options -&gt; CPU Frequency scaling<\/p>\n<p>\u7981\u7528CPU\u9891\u7387\u8c03\u8282\u529f\u80fd\uff0c\u4ee5\u907f\u514d\u9891\u7387\u5207\u6362\u5bf9\u5b9e\u65f6\u6027\u7684\u5f71\u54cd\u3002<\/p>\n<\/li>\n<li>\n<p>Power management options -&gt; CPU idle -&gt; CPU idle governor<\/p>\n<p>\u9009\u62e9&#8221;Menu&#8221;\u3002\u8fd9\u5c06\u7981\u7528CPU\u7a7a\u95f2\u72b6\u6001\u7684\u81ea\u52a8\u7ba1\u7406\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5b8c\u6210\u914d\u7f6e\u540e\uff0c\u4fdd\u5b58\u5e76\u9000\u51fa\u83dc\u5355\u3002\u7136\u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\u5185\u6838\uff1a<\/p>\n<pre>make -j4<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u5c06\u4f7f\u75284\u4e2a\u7ebf\u7a0b\u8fdb\u884c\u7f16\u8bd1\u3002\u6839\u636e\u7cfb\u7edf\u7684\u6027\u80fd\uff0c\u53ef\u4ee5\u81ea\u884c\u8c03\u6574\u7ebf\u7a0b\u6570\u3002<\/p>\n<p>\u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u65b0\u7684\u5185\u6838\uff1a<\/p>\n<pre>make modules_install\nmake install<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u91cd\u542f\u7cfb\u7edf\uff0c\u5e76\u9009\u62e9\u65b0\u7f16\u8bd1\u7684\u5185\u6838\u542f\u52a8\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u4e8c\u3001\u5b9e\u65f6\u6027\u529f\u80fd\u5e93<\/p>\n<p>\u5728\u914d\u7f6e\u597d\u5185\u6838\u540e\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5b89\u88c5\u4e00\u4e9b\u5b9e\u65f6\u6027\u529f\u80fd\u5e93\uff0c\u4ee5\u652f\u6301\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u7684\u5f00\u53d1\u3002<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5\u5b9e\u65f6\u6027\u5bf9\u6027\u80fd\u5f71\u54cd\u8f83\u5c0f\u7684\u8c03\u5ea6\u5668<\/p>\n<p>Linux\u5185\u6838\u9ed8\u8ba4\u7684\u8c03\u5ea6\u5668\uff08CFS\uff09\u5bf9\u5b9e\u65f6\u6027\u80fd\u5f71\u54cd\u8f83\u5927\uff0c\u53ef\u4ee5\u8003\u8651\u5b89\u88c5\u4e00\u4e9b\u66ff\u4ee3\u7684\u8c03\u5ea6\u5668\uff0c\u5982&#8221;Real-Time Preemption Patch&#8221;\uff08PREEMPT-RT\uff09\u548c&#8221;Staircase Deadline Scheduler&#8221;\uff08SDS\uff09\u3002<\/p>\n<p>\u5b89\u88c5\u8fd9\u4e9b\u8c03\u5ea6\u5668\u7684\u5177\u4f53\u6b65\u9aa4\u53ef\u4ee5\u53c2\u8003\u5176\u5b98\u65b9\u6587\u6863\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b89\u88c5\u5b9e\u65f6\u6027\u529f\u80fd\u5e93<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u5b9e\u65f6\u6027\u529f\u80fd\u5e93\uff1a<\/p>\n<pre>sudo apt-get install libc6-dev-i386\nsudo apt-get install libncurses5-dev\nsudo apt-get install build-essential<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<\/ol>\n<p>\u4e09\u3001\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1\u793a\u4f8b<\/p>\n<p>\u914d\u7f6e\u5b8c\u5b9e\u65f6\u6027\u529f\u80fd\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u8fdb\u884c\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u7684\u5f00\u53d1\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e2d\u4f7f\u7528\u5b9e\u65f6\u6027\u529f\u80fd\u3002<\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684C\u6587\u4ef6\uff0c\u5982&#8221;realtime.c&#8221;\uff0c\u5e76\u5199\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>#include &lt;stdio.h&gt;\n#include &lt;pthread.h&gt;\n#include &lt;sched.h&gt;\n#include &lt;stdlib.h&gt;\n\nvoid *realtime_thread(void *arg) {\n    struct sched_param param;\n    param.sched_priority = 99;\n    if (sched_setscheduler(0, SCHED_FIFO, &amp;amp;param) == -1) {\n        perror(\"sched_setscheduler() failed\");\n        exit(EXIT_FAILURE);\n    }\n\n    \/\/ \u5b9e\u65f6\u7ebf\u7a0b\u7684\u4ee3\u7801\n    \/\/ ...\n\n    return NULL;\n}\n\nint main() {\n    pthread_t thread_id;\n    pthread_create(&amp;amp;thread_id, NULL, realtime_thread, NULL);\n    pthread_join(thread_id, NULL);\n\n    return 0;\n}&lt;\/stdlib.h&gt;&lt;\/sched.h&gt;&lt;\/pthread.h&gt;&lt;\/stdio.h&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7pthread\u5e93\u521b\u5efa\u4e86\u4e00\u4e2a\u5b9e\u65f6\u7ebf\u7a0b\uff0c\u5e76\u5c06\u5176\u8bbe\u7f6e\u4e3a\u6700\u9ad8\u4f18\u5148\u7ea7\uff0899\uff09\u3002\u5728\u5b9e\u65f6\u7ebf\u7a0b\u7684\u4ee3\u7801\u4e2d\uff0c\u53ef\u4ee5\u7f16\u5199\u9700\u8981\u5b9e\u65f6\u6027\u4fdd\u969c\u7684\u4efb\u52a1\u3002<\/p>\n<p>\u7f16\u8bd1\u8be5\u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>gcc -o realtime realtime.c -lpthread<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd0\u884c\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5373\u53ef\u5728Linux\u7cfb\u7edf\u4e2d\u8fd0\u884c\u5b9e\u65f6\u6027\u4efb\u52a1\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u6210\u529f\u914d\u7f6eLinux\u7cfb\u7edf\u4ee5\u652f\u6301\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u7684\u5f00\u53d1\u3002\u914d\u7f6e\u5185\u6838\u548c\u5b89\u88c5\u5b9e\u65f6\u6027\u529f\u80fd\u5e93\u540e\uff0c\u53ef\u4ee5\u7f16\u5199\u5e76\u8fd0\u884c\u5177\u6709\u5b9e\u65f6\u6027\u8981\u6c42\u7684\u4efb\u52a1\u3002\u8fd9\u5c06\u4e3a\u5d4c\u5165\u5f0f\u7cfb\u7edf\u7684\u5f00\u53d1\u63d0\u4f9b\u66f4\u5927\u7684\u7075\u6d3b\u6027\u548c\u53ef\u9884\u6d4b\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u914d\u7f6eLinux\u7cfb\u7edf\u4ee5\u652f\u6301\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u914d\u7f6elinux\u7cfb\u7edf\u4ee5\u652f\u6301\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1 \u968f\u7740\u5d4c\u5165\u5f0f\u7cfb\u7edf\u7684\u53d1\u5c55\uff0c\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\uff08RTOS\uff09\u5728\u5404\u79cd\u5e94\u7528\u9886\u57df\u4e2d\u5f97\u5230\u4e86\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4e3a\u4e86\u652f\u6301RTOS\u7684\u5f00\u53d1\uff0c\u6211\u4eec\u9700\u8981\u5bf9Linux\u7cfb\u7edf\u8fdb\u884c\u914d\u7f6e\uff0c\u4ee5\u6ee1\u8db3\u5b9e\u65f6\u6027\u548c\u53ef\u9884\u6d4b\u6027\u7684\u8981\u6c42\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e2d\u914d\u7f6e\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1\u73af\u5883\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u4ee3\u7801\u793a\u4f8b\u3002 \u4e00\u3001\u5185\u6838\u914d\u7f6e \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bf9Linux\u5185\u6838\u8fdb\u884c\u914d\u7f6e\uff0c\u4ee5\u542f\u7528\u5b9e\u65f6\u6027\u7684\u529f\u80fd\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u914d\u7f6e\uff1a \u4e0b\u8f7dLinux\u5185\u6838\u6e90\u7801\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e0b\u8f7dLinux\u5185\u6838\u7684\u6e90\u7801\u3002\u53ef\u4ee5\u4eceLinux\u5b98\u65b9\u7f51\u7ad9\uff08www.kernel.org\uff09\u4e0a\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u5185\u6838\u6e90\u7801\u3002 \u7f16\u8bd1\u5185\u6838\u3002 \u89e3\u538b\u4e0b\u8f7d\u7684\u5185\u6838\u6e90\u7801\uff0c\u5e76\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\u5185\u6838\uff1a make menuconfig \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u542f\u52a8\u5185\u6838\u914d\u7f6e\u83dc\u5355\u3002\u5728\u83dc\u5355\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u4ee5\u4e0b\u9009\u9879\u8fdb\u884c\u914d\u7f6e\uff1a General setup -&gt; Preemption model \u9009\u62e9&#8221;Fully preemptible kernel (RT)&#8221;\u3002\u8fd9\u5c06\u542f\u7528\u5185\u6838\u7684\u5b9e\u65f6\u6027\u3002 Processor type and features -&gt; Preemption Model \u9009\u62e9&#8221;Voluntary Kernel Preemption (Desktop)&#8221;\u3002\u8fd9\u5c06\u542f\u7528\u5185\u6838\u7684\u53ef\u62a2\u5360\u6027\uff0c\u63d0\u9ad8\u5b9e\u65f6\u6027\u80fd\u3002 Processor type and features -&gt; Timer frequency \u5c06\u5b9a\u65f6\u5668\u9891\u7387\u8bbe\u7f6e\u4e3a1000 HZ\u3002 Processor type and features -&gt; Timer tick handling \u9009\u62e9&#8221;Standard clock tick&#8221;\u3002\u8fd9\u5c06\u542f\u7528\u6807\u51c6\u7684\u65f6\u949f\u4e2d\u65ad\u5904\u7406\u3002 Processor type and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-61335","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/61335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=61335"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/61335\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=61335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=61335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=61335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}