{"id":4297,"date":"2013-03-03T14:03:09","date_gmt":"2013-03-03T06:03:09","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=4297"},"modified":"2013-03-03T14:16:52","modified_gmt":"2013-03-03T06:16:52","slug":"linux%e4%b8%8bcpu%e7%9a%84%e5%88%a9%e7%94%a8%e7%8e%87","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/4297","title":{"rendered":"Linux\u4e0bCPU\u7684\u5229\u7528\u7387"},"content":{"rendered":"<p>CPU\u5229\u7528\u7387\u662f\u5bf9\u7cfb\u7edf\u8fdb\u884c\u6027\u80fd\u5206\u6790\u7684\u91cd\u8981\u56e0\u7d20\uff0c\u672c\u6587\u5c06\u8bf4\u660eCPU\u65f6\u95f4\u7684\u7ec4\u6210\u4ee5\u53ca\u5229\u7528\u7387\u7684\u8ba1\u7b97\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u5185\u6838\u4e2d\u7684\u65f6\u95f4<\/strong><\/p>\n<p>\u5177\u4f53\u8bf4\u660eCPU\u7684\u5404\u79cd\u65f6\u95f4\u4e4b\u524d\uff0c\u5148\u8bf4\u660e\u5185\u6838\u4e2d\u51e0\u4e2a\u91cd\u8981\u7684\u65f6\u95f4\u6982\u5ff5\u3002<\/p>\n<p>HZ\u662f\u7cfb\u7edf\u65f6\u949f\u5728\u4e00\u79d2\u5185\u56fa\u5b9a\u53d1\u51fa\u65f6\u949f\u4e2d\u65ad\u7684\u6b21\u6570\u3002HZ\u5728\u7f16\u8bd1\u5185\u6838\u524d\u662f\u53ef\u4ee5\u8fdb\u884c\u914d\u7f6e\u7684\uff0c\u56e0\u6b64\u901a\u8fc7\u4e0b\u8ff0\u547d\u4ee4\u5c31\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u7684\u65f6\u949f\u4e2d\u65ad\u9891\u7387\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ncat \/boot\/config-`uname -r` | grep CONFIG_HZ\r\n<\/pre>\n<p>tick\u4e3a\u7cfb\u7edf\u65f6\u949f\u6bcf\u201c\u6ef4\u7b54\u201d\u4e00\u6b21\u7684\u65f6\u95f4\uff0c\u5176\u503c\u4e3a(1\/HZ)\u79d2\u3002\u4e5f\u5c31\u662f\u8fde\u7eed\u4e24\u6b21\u65f6\u949f\u4e2d\u65ad\u4e4b\u95f4\u7684\u65f6\u95f4\u95f4\u9694\u3002<\/p>\n<p><span style=\"font-size: 13px;\">jiffies\u7528\u6765\u8ba1\u7b97\u81ea\u7cfb\u7edf\u542f\u52a8\u4ee5\u6765tick\u7684\u6b21\u6570\uff0c\u4e5f\u5c31\u662f\u8bf4\u7cfb\u7edf\u65f6\u949f\u6bcf\u4ea7\u751f\u4e00\u6b21\u65f6\u949f\u4e2d\u65ad\uff0c\u8be5\u53d8\u91cf\u7684\u503c\u5c31\u589e\u52a0\u4e00\u6b21\u3002<\/span><\/p>\n<p><strong>CPU\u65f6\u95f4<\/strong><\/p>\n<p>CPU\u7684\u5de5\u4f5c\u65f6\u95f4\u7531\u4e09\u90e8\u5206\u7ec4\u6210\uff1a\u7528\u6237\u6001\u65f6\u95f4\u3001\u7cfb\u7edf\u6001\u65f6\u95f4\u548c\u7a7a\u95f2\u6001\u65f6\u95f4\u3002\u5177\u4f53\u7684\u7ec4\u6210\u4e3a\uff1b<\/p>\n<p>CPU\u65f6\u95f4=User time+Nice time+System time+Hardirq time+Softirq time+Waiting time+Idle time+Steal time<\/p>\n<p>\u7a7a\u95f2\u6001\u65f6\u95f4\u53ea\u5305\u542b\u4e86idle time\uff0c\u800c\u7528\u6237\u6001\u65f6\u95f4\u548c\u7cfb\u7edf\u6001\u65f6\u95f4\u5219\u7531\u591a\u4e2a\u90e8\u5206\u7ec4\u6210\uff0c\u8be6\u6790\u4ecb\u7ecd\u5982\u4e0b\u3002<\/p>\n<p><strong>\u7528\u6237\u6001\u65f6\u95f4<\/strong><\/p>\n<p>\u7528\u6237\u6001\u65f6\u95f4\u5305\u62ec\u7528\u6237\u65f6\u95f4\u548cnice\u65f6\u95f4\u3002<\/p>\n<p>\u7528\u6237\u65f6\u95f4\uff08user time\uff09\u6307\u7684\u662fCPU\u5728\u7528\u6237\u6001\u6267\u884c\u8fdb\u7a0b\u7684\u65f6\u95f4\u3002nice\u65f6\u95f4\uff08nice time\uff09\u662f\u6307\u7cfb\u7edf\u82b1\u8d39\u5728\u8c03\u6574\u8fdb\u7a0b\u4f18\u5148\u7ea7\u4e0a\u7684\u65f6\u95f4\u3002<\/p>\n<p><strong>\u5185\u6838\u6001\u65f6\u95f4<\/strong><\/p>\n<p>\u5185\u6838\u6001\u65f6\u95f4\u5305\u62ec\u7cfb\u7edf\u65f6\u95f4\u3001\u8f6f\u4e2d\u65ad\u65f6\u95f4\u548c\u786c\u4e2d\u65ad\u65f6\u95f4\u3002<\/p>\n<p>\u7cfb\u7edf\u65f6\u95f4\uff08system time\uff09\u8868\u793aCPU\u5728\u5185\u6838\u8fd0\u884c\u7684\u65f6\u95f4\uff0c\u5982\u679c\u4e00\u4e2aCPU\u7684\u7cfb\u7edf\u65f6\u95f4\u5360\u6709\u7387\u9ad8\uff0c\u5219\u8bf4\u660e\u8be5\u7cfb\u7edf\u4e2d\u67d0\u4e2a\u5b50\u7cfb\u7edf\u4ea7\u751f\u4e86\u74f6\u9888\u3002<\/p>\n<p>\u8f6f\u4e2d\u65ad\u65f6\u95f4\u548c\u786c\u4e2d\u65ad\u65f6\u95f4\u5206\u522b\u5bf9\u5e94\u7cfb\u7edf\u5728\u5904\u7406\u8f6f\u786c\u4e2d\u65ad\u65f6\u5019\u6240\u82b1\u8d39\u7684CPU\u65f6\u95f4\u3002<\/p>\n<p>\u6b64\u5916\uff0cwaiting time\u662f\u6307CPU\u5728\u7b49\u5f85I\/O\u5b8c\u6210\u65f6\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u3002\u800csteal time\u6307\u7684\u662f\u5f53\u524dCPU\u7b49\u5f85\u53e6\u5916\u865a\u62df\u7684CPU\u5904\u7406\u5b8c\u6bd5\u65f6\u8bdd\u8d39\u7684\u65f6\u95f4\u3002<\/p>\n<p><strong>CPU\u5229\u7528\u7387<\/strong><\/p>\n<p>CPU\u5229\u7528\u7387\u53ef\u4ee5\u901a\u8fc7top\u7b49\u547d\u4ee4\u6765\u67e5\u770b\uff0c\u5b83\u4eec\u7684\u8ba1\u7b97\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>%us =(User time + Nice time)\/CPU\u65f6\u95f4*100%<\/p>\n<p>%sy=(System time + Hardirq time +Softirq time)\/<\/p>\n<p>%id=(Idle time)\/CPU\u65f6\u95f4*100%<\/p>\n<p>%ni=(Nice time)\/CPU\u65f6\u95f4*100%<\/p>\n<p>%wa=(Waiting time)\/CPU\u65f6\u95f4*100%<\/p>\n<p>%hi=(Hardirq time)\/CPU\u65f6\u95f4*100%<\/p>\n<p>%si=(Softirq time)\/CPU\u65f6\u95f4*100%<\/p>\n<p>%st=(Steal time)\/CPU\u65f6\u95f4*100%<\/p>\n<p><strong>\u67e5\u770b\u65b9\u6cd5<\/strong><\/p>\n<p>\u901a\u8fc7top\u3001iostat\u548cvmstat\u7b49\u547d\u4ee4\u5747\u53ef\u4ee5\u67e5\u770b\u4e0a\u8ff0CPU\u7684\u5229\u7528\u7387\u3002\u8fd9\u4e9b\u547d\u4ee4\u7684\u6570\u636e\u6765\u6e90\u5747\u6765\u81ea\u4e0e\/proc\/stat\u6587\u4ef6\uff0c\u4e0d\u8fc7\u8be5\u6587\u4ef6\u4e2d\u7684\u65f6\u95f4\u662f\u4ee5tick\u4e3a\u5355\u4f4d\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CPU\u5229\u7528\u7387\u662f\u5bf9\u7cfb\u7edf\u8fdb\u884c\u6027\u80fd\u5206\u6790\u7684\u91cd\u8981\u56e0\u7d20\uff0c\u672c\u6587\u5c06\u8bf4\u660eCPU\u65f6\u95f4\u7684\u7ec4\u6210\u4ee5\u53ca\u5229\u7528\u7387\u7684\u8ba1\u7b97\u65b9\u6cd5\u3002 \u5185\u6838\u4e2d\u7684\u65f6\u95f4 \u5177 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[368,367],"class_list":["post-4297","post","type-post","status-publish","format-standard","hentry","category-366","tag-cpu","tag-367"],"views":26002,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/4297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=4297"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/4297\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=4297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=4297"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=4297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}