{"id":62106,"date":"2025-04-29T13:02:39","date_gmt":"2025-04-29T05:02:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/62106\/"},"modified":"2025-04-29T13:02:39","modified_gmt":"2025-04-29T05:02:39","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8linux%e8%bf%9b%e8%a1%8ccpu%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/62106\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Linux\u8fdb\u884cCPU\u6027\u80fd\u8c03\u4f18"},"content":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528\u8fdb\u884ccpu\u6027\u80fd\u8c03\u4f18<\/p>\n<p>\u5bfc\u8a00\uff1a<br \/>\u968f\u7740\u8ba1\u7b97\u673a\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\uff0cCPU\u6027\u80fd\u8c03\u4f18\u6210\u4e3a\u8bb8\u591a\u7cfb\u7edf\u7ba1\u7406\u5458\u548c\u5f00\u53d1\u4eba\u5458\u5173\u6ce8\u7684\u7126\u70b9\u3002Linux\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u548c\u547d\u4ee4\u6765\u5e2e\u52a9\u6211\u4eec\u8fdb\u884cCPU\u6027\u80fd\u8c03\u4f18\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u548c\u6280\u5de7\uff0c\u5e76\u63d0\u4f9b\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u4e00\u3001\u67e5\u770bCPU\u4fe1\u606f<\/p>\n<p>\u5728\u5f00\u59cbCPU\u6027\u80fd\u8c03\u4f18\u4e4b\u524d\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u4e86\u89e3\u5f53\u524d\u7cfb\u7edf\u4e2d\u7684CPU\u4fe1\u606f\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u67e5\u770bCPU\u7684\u578b\u53f7\u3001\u6838\u5fc3\u6570\u3001\u9891\u7387\u7b49\u4fe1\u606f\uff1a<\/p>\n<pre>cat \/proc\/cpuinfo<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u547d\u4ee4\u5c06\u8f93\u51faCPU\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<pre>processor   : 0\nvendor_id   : GenuineIntel\ncpu family  : 6\nmodel       : 158\nmodel name  : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz\nstepping    : 9\nmicrocode   : 0x8e\ncpu MHz     : 1440.000\ncache size  : 6144 KB\nphysical id : 0\nsiblings    : 8\ncore id     : 0\ncpu cores   : 4\napicid      : 0\ninitial apicid  : 0\nfpu     : yes\nfpu_exception   : yes\ncpuid level : 22\nwp      : yes<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u5206\u6790\u8fd9\u4e9b\u4fe1\u606f\uff0c\u6211\u4eec\u53ef\u4ee5\u4e86\u89e3\u5230\u8fd9\u4e2a\u7cfb\u7edf\u4e2d\u7684CPU\u5177\u6709\u56db\u4e2a\u6838\u5fc3\u3001\u516b\u4e2a\u7ebf\u7a0b\uff0c\u5e76\u4e14\u62e5\u67092.80GHz\u7684\u9891\u7387\u3002<\/p>\n<p>\u4e8c\u3001\u8c03\u6574CPU\u8c03\u5ea6\u7b56\u7565<\/p>\n<p>Linux\u9ed8\u8ba4\u91c7\u7528\u7684\u662fCFS(C Completely Fair Scheduler)\u8c03\u5ea6\u7b97\u6cd5\uff0c\u8be5\u7b97\u6cd5\u4f1a\u516c\u5e73\u5730\u5206\u914dCPU\u65f6\u95f4\u7ed9\u6bcf\u4e2a\u8fdb\u7a0b\u3002\u4f46\u5728\u4e00\u4e9b\u7279\u5b9a\u573a\u666f\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u8c03\u6574CPU\u8c03\u5ea6\u7b56\u7565\u4ee5\u4f18\u5316\u6027\u80fd\u3002<\/p>\n<ol>\n<li>\u67e5\u770b\u5f53\u524dCPU\u8c03\u5ea6\u7b56\u7565\uff1a<\/li>\n<\/ol>\n<pre>cat \/sys\/devices\/system\/cpu\/cpu*\/cpufreq\/scaling_governor<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u547d\u4ee4\u5c06\u8f93\u51fa\u5f53\u524d\u6bcf\u4e2aCPU\u6838\u5fc3\u7684\u8c03\u5ea6\u7b56\u7565\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u5e94\u8be5\u662f&#8217;ondemand&#8217;\u6216&#8217;powersave&#8217;\u3002<\/p>\n<ol>\n<li>\u4fee\u6539CPU\u8c03\u5ea6\u7b56\u7565\u4e3a&#8217;performance&#8217;\uff1a<\/li>\n<\/ol>\n<pre>echo performance | sudo tee \/sys\/devices\/system\/cpu\/cpu*\/cpufreq\/scaling_governor<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u547d\u4ee4\u5c06\u5c06CPU\u8c03\u5ea6\u7b56\u7565\u4fee\u6539\u4e3a&#8217;performance&#8217;\u6a21\u5f0f\uff0c\u8be5\u6a21\u5f0f\u4f1a\u8ba9CPU\u59cb\u7ec8\u5de5\u4f5c\u5728\u6700\u9ad8\u9891\u7387\uff0c\u4ee5\u83b7\u53d6\u6700\u5927\u7684\u6027\u80fd\u3002<\/p>\n<p>\u4e09\u3001\u9650\u5236CPU\u8d44\u6e90<\/p>\n<p>\u5728\u4e00\u4e9b\u60c5\u5883\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u7cfb\u7edf\u4e2d\u7684\u67d0\u4e2a\u8fdb\u7a0b\u6216\u8fdb\u7a0b\u7ec4\u8fdb\u884cCPU\u8d44\u6e90\u7684\u9650\u5236\uff0c\u4ee5\u907f\u514d\u67d0\u4e2a\u8fdb\u7a0b\u5360\u7528\u8fc7\u591a\u7684CPU\u8d44\u6e90\u800c\u5f71\u54cd\u5176\u4ed6\u8fdb\u7a0b\u3002<\/p>\n<ol>\n<li>\u4f7f\u7528cpulimit\u547d\u4ee4\u9650\u5236\u8fdb\u7a0b\u7684CPU\u4f7f\u7528\u7387\uff1a<\/li>\n<\/ol>\n<pre>sudo apt-get install cpulimit\ncpulimit -l 50 -p &lt;pid&gt;&lt;\/pid&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u547d\u4ee4\u5c06\u9650\u5236\u8fdb\u7a0b\u7684CPU\u4f7f\u7528\u7387\u4e3a50%\u3002PID\u9700\u8981\u66ff\u6362\u4e3a\u4f60\u8981\u9650\u5236\u7684\u8fdb\u7a0b\u7684\u8fdb\u7a0bID\u3002<\/p>\n<p>\u56db\u3001\u4f7f\u7528\u6027\u80fd\u5206\u6790\u5de5\u5177<\/p>\n<p>\u9488\u5bf9\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9\u6027\u80fd\u5206\u6790\u5de5\u5177\u6765\u6df1\u5165\u5206\u6790CPU\u7684\u6027\u80fd\u74f6\u9888\u3002<\/p>\n<ol>\n<li>\u4f7f\u7528perf\u5de5\u5177\uff1a<\/li>\n<\/ol>\n<p>perf\u662fLinux\u5185\u6838\u63d0\u4f9b\u7684\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u5bf9CPU\u6027\u80fd\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002<\/p>\n<pre>sudo apt-get install linux-tools-common # \u5b89\u88c5perf\u5de5\u5177\nsudo perf top # \u6267\u884c\u6027\u80fd\u5206\u6790<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528perf top\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u7cfb\u7edf\u4e2d\u5f53\u524d\u5360\u7528CPU\u8d44\u6e90\u8f83\u9ad8\u7684\u8fdb\u7a0b\u548c\u51fd\u6570\u8c03\u7528\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u5982gprof\u3001oprofile\u7b49\uff0c\u8bfb\u8005\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u8fdb\u884c\u4f7f\u7528\u3002<\/p>\n<p>\u7ed3\u8bed\uff1a<br \/>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528linux\u8fdb\u884ccpu\u6027\u80fd\u8c03\u4f18\uff0c\u5e0c\u671b\u8bfb\u8005\u80fd\u591f\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\u548c\u6280\u5de7\u6539\u5584\u7cfb\u7edf\u7684\u6027\u80fd\u3002\u5728\u5b9e\u9645\u7684\u8c03\u4f18\u8fc7\u7a0b\u4e2d\uff0c\u8fd8\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u60c5\u51b5\u548c\u9700\u6c42\u8fdb\u884c\u5177\u4f53\u7684\u8c03\u4f18\u7b56\u7565\u5236\u5b9a\uff0c\u5e76\u5229\u7528\u7cfb\u7edf\u63d0\u4f9b\u7684\u5de5\u5177\u548c\u547d\u4ee4\u8fdb\u884c\u76d1\u63a7\u548c\u4f18\u5316\u3002\u53ea\u6709\u4e0d\u65ad\u7684\u5b9e\u8df5\u548c\u8c03\u8bd5\uff0c\u624d\u80fd\u8fbe\u5230\u6700\u4f73\u7684\u6027\u80fd\u8c03\u4f18\u6548\u679c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528Linux\u8fdb\u884cCPU\u6027\u80fd\u8c03\u4f18\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>\u5982\u4f55\u4f7f\u7528\u8fdb\u884ccpu\u6027\u80fd\u8c03\u4f18 \u5bfc\u8a00\uff1a\u968f\u7740\u8ba1\u7b97\u673a\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\uff0cCPU\u6027\u80fd\u8c03\u4f18\u6210\u4e3a\u8bb8\u591a\u7cfb\u7edf\u7ba1\u7406\u5458\u548c\u5f00\u53d1\u4eba\u5458\u5173\u6ce8\u7684\u7126\u70b9\u3002Linux\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u548c\u547d\u4ee4\u6765\u5e2e\u52a9\u6211\u4eec\u8fdb\u884cCPU\u6027\u80fd\u8c03\u4f18\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u548c\u6280\u5de7\uff0c\u5e76\u63d0\u4f9b\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u4e00\u3001\u67e5\u770bCPU\u4fe1\u606f \u5728\u5f00\u59cbCPU\u6027\u80fd\u8c03\u4f18\u4e4b\u524d\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u4e86\u89e3\u5f53\u524d\u7cfb\u7edf\u4e2d\u7684CPU\u4fe1\u606f\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u67e5\u770bCPU\u7684\u578b\u53f7\u3001\u6838\u5fc3\u6570\u3001\u9891\u7387\u7b49\u4fe1\u606f\uff1a cat \/proc\/cpuinfo \u767b\u5f55\u540e\u590d\u5236 \u8be5\u547d\u4ee4\u5c06\u8f93\u51faCPU\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5982\u56fe\u6240\u793a\uff1a processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 158 model name : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz stepping : 9 microcode : 0x8e cpu MHz : 1440.000 cache size : 6144 KB physical id : 0 siblings : 8 core id : [&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-62106","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62106","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=62106"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62106\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=62106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=62106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=62106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}