{"id":68640,"date":"2024-05-31T23:05:11","date_gmt":"2024-05-31T15:05:11","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=68640"},"modified":"2024-05-31T23:05:11","modified_gmt":"2024-05-31T15:05:11","slug":"cpu-utilization","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/cpu-utilization.html","title":{"rendered":"CPU\u4f7f\u7528\u7387\u5ea6\u91cf\u6307\u6807\u7684\u5206\u6790\uff01"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u6211\u4eec\u7528\u6765\u8861\u91cfCPU\u4f7f\u7528\u7387\uff08CPU utilization\uff09\u7684\u6307\u6807\u5177\u6709\u6781\u5927\u7684\u8bef\u5bfc\u6027\uff0c\u800c\u4e14\u4e00\u5e74\u6bd4\u4e00\u5e74\u6765\u5f97\u8bef\u4eba\u5b50\u5f1f\u3002CPU\u4f7f\u7528\u7387\u5230\u5e95\u662f\u4ec0\u4e48\uff1f\u4f60\u7684\u5904\u7406\u5668\u6709\u591a\u5fd9\u788c\uff1f\u4e0d\uff0c\u90a3\u4e0d\u662fCPU\u4f7f\u7528\u7387\u8861\u91cf\u7684\u65b9\u9762\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u6ca1\u9519\uff0c\u6211\u5728\u8fd9\u91cc\u6240\u8bf4\u7684\u662f\u6bcf\u4e2a\u4eba\u5728\u5230\u5904\u4f7f\u7528\u7684\u201c%CPU\u201d\u8fd9\u4e2a\u5ea6\u91cf\u6307\u6807\uff0c\u7528\u4e8e\u6bcf\u4e00\u6b3e\u6027\u80fd\u76d1\u63a7\u4ea7\u54c1\u4e2d\u3002\u7528top(1)\u547d\u4ee4\u6765\u67e5\u770b\u3002 \u8fd9\u5bf9\u4f60\u6765\u8bf4\u610f\u5473\u7740\u4ec0\u4e48\u5462\uff1f\u4e86\u89e3\u4f60\u7684\u591a\u5c11CPU\u5904\u4e8e\u505c\u6ede\u72b6\u6001\u53ef\u4ee5\u6307\u5bfc\u51cf\u5c11\u4ee3\u7801\u6216\u51cf\u5c11\u5185\u5b58\u8f93\u5165\/\u8f93\u51fa\u4e4b\u95f4\u7684\u6027\u80fd\u8c03\u4f18\u5de5\u4f5c\u3002\u8c01\u8981\u662f\u5728\u5173\u6ce8CPU\u6027\u80fd\uff0c\u5c24\u5176\u662f\u5728\u6839\u636eCPU\u81ea\u52a8\u6269\u5c55\u8d44\u6e90\u7684\u4e91\uff0c\u5982\u679c\u77e5\u9053%CPU\u4e2d\u505c\u6ede\u7684\u90e8\u5206\uff0c\u90a3\u5c06\u5927\u6709\u76ca\u5904\u3002<\/p>\n CPU\u4f7f\u7528\u7387\u5176\u5b9e\u662f\u4ec0\u4e48\u4e1c\u4e1c\uff1f<\/strong><\/div>\n \u6211\u4eec\u79f0\u4e3aCPU\u4f7f\u7528\u7387\u7684\u8861\u91cf\u6307\u6807\u5176\u5b9e\u662f\u201c\u975e\u95f2\u7f6e\u65f6\u95f4\u201d\uff08non-idle time\uff09\uff1a\u4e5f\u5c31\u662fCPU\u672a\u8fd0\u884c\u95f2\u7f6e\u7ebf\u7a0b\u7684\u65f6\u95f4\u3002\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\uff08\u65e0\u8bba\u5b83\u662f\u4ec0\u4e48\u5185\u6838\uff09\u901a\u5e38\u5728\u4e0a\u4e0b\u6587\u5207\u6362\u8fc7\u7a0b\u4e2d\u8ddf\u8e2a\u8fd9\u4e2a\u6307\u6807\u3002\u5982\u679c\u975e\u95f2\u7f6e\u8fdb\u7a0b\u5f00\u59cb\u8fd0\u884c\uff0c\u7136\u540e\u505c\u6b62100\u6beb\u79d2\uff0c\u5185\u6838\u8fd8\u662f\u8ba4\u4e3a\u8be5CPU\u5728\u90a3\u6574\u6bb5\u65f6\u95f4\u90fd\u88ab\u4f7f\u7528\u3002<\/p>\n \u8fd9\u4e2a\u5ea6\u91cf\u6307\u6807\u7684\u5386\u53f2\u4e0e\u5206\u65f6\u7cfb\u7edf\u4e00\u6837\u4e45\u8fdc\u3002Apollo Lunar Module\u5236\u5bfc\u8ba1\u7b97\u673a\uff08\u4e00\u79cd\u5f00\u521b\u6027\u7684\u5206\u65f6\u7cfb\u7edf\uff09\u79f0\u5176\u95f2\u7f6e\u7ebf\u7a0b\u4e3a\u201cDUMMY JOB\u201d\uff0c\u5de5\u7a0b\u5e08\u4eec\u8ddf\u8e2a\u4e86\u8fd0\u884c\u8be5\u95f2\u7f6e\u7ebf\u7a0b\u7684\u5468\u671f\u548c\u8fd0\u884c\u5b9e\u9645\u4efb\u52a1\u7684\u5468\u671f\uff0c\u5c06\u8fd9\u89c6\u4f5c\u662f\u4e00\u4e2a\u8861\u91cf\u8ba1\u7b97\u673a\u4f7f\u7528\u7387\u7684\u91cd\u8981\u6307\u6807\u3002<\/p>\n \u90a3\u4e48\u8fd9\u4e2a\u6307\u6807\u54ea\u91cc\u4e0d\u5bf9\u52b2\u5462\uff1f<\/strong><\/div>\n \u73b0\u5982\u4eca\uff0cCPU\u7684\u901f\u5ea6\u5df2\u53d8\u5f97\u6bd4\u4e3b\u5185\u5b58\u5feb\u5f97\u591a\uff0c\u7b49\u5f85\u5185\u5b58\u5728\u4ecd\u7136\u6240\u8c13\u7684\u201cCPU\u4f7f\u7528\u7387\u201d\u4e2d\u5360\u4e86\u5927\u5934\u3002\u5982\u679c\u4f60\u770b\u5230\u6570\u503c\u5f88\u9ad8\u7684%CPU\uff0c\u53ef\u80fd\u8ba4\u4e3a\u5904\u7406\u5668\u662f\u74f6\u9888\uff08\u5373\u6563\u70ed\u7247\u548c\u98ce\u6247\u4e0b\u9762\u7684CPU\u5c01\u88c5\u4ef6\uff09\uff0c\u800c\u5b9e\u9645\u4e0a\u90a3\u4e9bDRAM\u6a21\u7ec4\u624d\u662f\u74f6\u9888\u3002<\/p>\n \u8fd9\u65b9\u9762\u7684\u60c5\u5f62\u4e00\u76f4\u53d8\u5f97\u8d8a\u6765\u8d8a\u4e25\u5cfb\u3002\u957f\u671f\u4ee5\u6765\uff0c\u5904\u7406\u5668\u5382\u5546\u63d0\u9ad8\u65f6\u949f\u901f\u5ea6\u7684\u5e45\u5ea6\u8d85\u8fc7DRAM\u63d0\u9ad8\u8bbf\u95ee\u5ef6\u8fdf\u7684\u5e45\u5ea6\uff0c\u8fd9\u5c31\u662f\u6240\u8c13\u7684\u201cCPU DRAM\u7f3a\u53e3\u201d\uff08\u00a0CPU DRAM gap\uff09\u3002\u8fd9\u79cd\u60c5\u5f62\u57283 GHz\u5904\u7406\u5668\u9762\u4e16\u76842005\u5e74\u524d\u540e\u8d8b\u7a33\uff1b\u81ea\u90a3\u4ee5\u540e\uff0c\u5904\u7406\u5668\u4f7f\u7528\u66f4\u591a\u7684\u6838\u5fc3\u548c\u8d85\u7ebf\u7a0b\u6765\u63d0\u5347\u6027\u80fd\uff0c\u53e6\u5916\u4f7f\u7528\u591a\u63d2\u5ea7\u914d\u7f6e\uff0c\u8fd9\u4e00\u5207\u7ed9\u5185\u5b58\u5b50\u7cfb\u7edf\u63d0\u51fa\u4e86\u66f4\u9ad8\u7684\u8981\u6c42\u3002\u5904\u7406\u5668\u5382\u5546\u8bd5\u56fe\u91c7\u7528\u66f4\u5e9e\u5927\u3001\u66f4\u667a\u80fd\u7684CPU\u7f13\u5b58\u4ee5\u53ca\u66f4\u5feb\u901f\u7684\u5185\u5b58\u603b\u7ebf\u548c\u4e92\u8fde\u6280\u672f\u6765\u7f13\u89e3\u8fd9\u4e2a\u5185\u5b58\u74f6\u9888\u3002\u4f46\u662f\u6211\u4eec\u4ecd\u7136\u901a\u5e38\u5904\u4e8e\u505c\u6ede\u72b6\u6001\u3002<\/p>\n \u5982\u4f55\u8868\u660eCPU\u5230\u5e95\u5728\u5904\u7406\u4ec0\u4e48\uff1f<\/strong><\/div>\n \u4e0d\u59a8\u4f7f\u7528\u6027\u80fd\u76d1\u63a7\u8ba1\u6570\u5668\uff08PMC\uff09\uff1a\u8fd9\u662f\u4f7f\u7528Linux perf\u53ca\u5176\u4ed6\u5de5\u5177\u53ef\u4ee5\u8bfb\u53d6\u7684\u786c\u4ef6\u8ba1\u6570\u5668\u3002\u6bd4\u5982\u8bf4\uff0c\u5c06\u6574\u4e2a\u7cfb\u7edf\u6d4b\u91cf10\u79d2\u949f\uff1a<\/p>\n # perf stat -a \u2014 sleep 10\r\nPerformance counter\u00a0stats for \u2018system wide\u2019:\r\n641398.723351\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0task-clock\u00a0(msec)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a064.116 CPUs utilized\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(100.00%)\r\n379,651\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0context-switches\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a00.592 K\/sec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(100.00%)\r\n51,546\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cpu-migrations\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a00.080\u00a0K\/sec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(100.00%)\r\n13,423,039\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0page-faults\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a00.021 M\/sec\r\n1,433,972,173,374\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cycles\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a02.236 GHz\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(75.02%)\r\n<not\u00a0supported>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0stalled-cycles-frontend\r\n<not\u00a0supported>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0stalled-cycles-backend\r\n1,118,336,816,068\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0instructions\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0\u00a00.78\u00a0\u00a0insns per cycle\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(75.01%)\r\n249,644,142,804\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0branches\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a0\u00a0389.218 M\/sec\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(75.01%)\r\n7,791,449,769\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0branch-misses\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#\u00a0\u00a03.12% of all branches\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(75.01%)\r\n10.003794539\u00a0seconds time elapsed<\/pre>\n |