{"id":3053,"date":"2020-04-04T22:35:36","date_gmt":"2020-04-04T14:35:36","guid":{"rendered":"https:\/\/www.aoisnow.net\/blog\/?p=3053"},"modified":"2020-04-04T22:35:36","modified_gmt":"2020-04-04T14:35:36","slug":"tont-37003-%e8%bf%bd%e5%af%bb%e6%9b%b4%e5%8a%a0%e8%bf%85%e9%80%9f%e7%9a%84syscall%e9%99%b7%e9%98%b1","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/3053","title":{"rendered":"TONT 37003 \u8ffd\u5bfb\u66f4\u52a0\u8fc5\u901f\u7684syscall\u9677\u9631"},"content":{"rendered":"<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20041215-00\/?p=37003\" target=\"_blank\" rel=\"noopener\">https:\/\/devblogs.microsoft.com\/oldnewthing\/20041215-00\/?p=37003<\/a><\/p>\n<p>The performance of the syscall trap gets a lot of attention.<\/p>\n<p>\u6709\u5173 syscall \u9677\u9631\u7684\u6548\u7387\u95ee\u9898\u5438\u5f15\u4e86\u5f88\u591a\u4eba\u7684\u6ce8\u610f\u3002<\/p>\n<p>I was reminded of a meeting that took place between Intel and Microsoft over fifteen years ago. (Sadly, I was not myself at this meeting, so the story is second-hand.)<\/p>\n<p>\u6211\u60f3\u8d77\u4e86\u5341\u4e94\u5e74\u524d Intel \u548c\u5fae\u8f6f\u4e4b\u95f4\u7684\u4e00\u6b21\u4f1a\u8bae\u3002\uff08\u5f88\u9057\u61be\u5f53\u65f6\u6211\u6ca1\u6709\u4eb2\u81ea\u5728\u573a\uff0c\u6240\u4ee5\u63a5\u4e0b\u6765\u7684\u6545\u4e8b\u662f\u8f6c\u8ff0\u7684\u3002\uff09<\/p>\n<p>Since Microsoft is one of Intel\u2019s biggest customers, their representatives often visit Microsoft to show off what their latest processor can do, lobby the kernel development team to support a new processor feature, and solicit feedback on what sort of features would be most useful to add.<\/p>\n<p>\u9274\u4e8e\u5fae\u8f6f\u662f Intel \u6700\u5927\u7684\u5ba2\u6237\u4e4b\u4e00\uff0cIntel \u7684\u4ee3\u8868\u7ecf\u5e38\u5230\u8bbf\u5fae\u8f6f\uff0c\u70ab\u8000\u4ed6\u4eec\u6700\u65b0\u6b3e\u7684\u5904\u7406\u5668\u7684\u80fd\u529b\uff0c\u6e38\u8bf4\u5185\u6838\u5f00\u53d1\u56e2\u961f\u652f\u6301\u4e00\u9879\u65b0\u7684\u5904\u7406\u5668\u529f\u80fd\uff0c\u5e76\u4e14\u5f81\u6c42\u6709\u5173\u6709\u610f\u5411\u6dfb\u52a0\u5230\u5904\u7406\u5668\u4e2d\u7684\u3001\u6700\u6709\u7528\u7684\u529f\u80fd\u7c7b\u522b\u3002<\/p>\n<p>At this meeting, the Intel representatives asked, \u201cSo if you could ask for only one thing to be made faster, what would it be?\u201d<\/p>\n<p>\u5728\u90a3\u6b21\u4f1a\u8bae\u4e0a\uff0cIntel \u7684\u4ee3\u8868\u95ee\u9053\uff0c\u300e\u5982\u679c\u53ea\u6709\u4e00\u4ef6\u4e8b\u53ef\u4ee5\u63d0\u901f\uff0c\u4f60\u4eec\u5e0c\u671b\u662f\u4ec0\u4e48\u5462\uff1f\u300f<\/p>\n<p>Without hesitation, one of the lead kernel developers replied, \u201cSpeed up faulting on an invalid instruction.\u201d<\/p>\n<p>\u5185\u6838\u56e2\u961f\u7684\u4e00\u4f4d\u9886\u5934\u5f00\u53d1\u8005\u4e0d\u5047\u601d\u7d22\u5730\u56de\u7b54\u9053\uff1a\u300e\u6267\u884c\u65e0\u6548\u6307\u4ee4\u65f6\u7684\u51fa\u9519\u518d\u5feb\u4e00\u70b9\u3002\u300f<\/p>\n<p>The Intel half of the room burst out laughing. \u201cOh, you Microsoft engineers are so funny!\u201d And so the meeting ended with a cute little joke.<\/p>\n<p>\u4f1a\u8bae\u5ba4\u91cc Intel \u4e00\u4fa7\u7684\u4eba\u4eec\u5927\u7b11\u8d77\u6765\uff0c\u300e\u54ce\u5440\uff0c\u4f60\u4eec\u5fae\u8f6f\u7684\u5de5\u7a0b\u5e08\u53ef\u771f\u6709\u610f\u601d\uff01\u300f\u4f1a\u8bae\u5728\u8fd9\u4e2a\u5c0f\u800c\u6709\u8da3\u7684\u73a9\u7b11\u4e2d\u6536\u573a\u4e86\u3002<\/p>\n<p>After returning to their labs, the Intel engineers ran profiles against the Windows kernel and lo and behold, they discovered that Windows spent a lot of its time dispatching invalid instruction exceptions. How absurd! Was the Microsoft engineer not kidding around after all?<\/p>\n<p>\u7b49\u56de\u5230\u5b9e\u9a8c\u5ba4\u4e4b\u540e\uff0cIntel \u7684\u5de5\u7a0b\u5e08\u4eec\u5bf9 Windows \u7684\u5185\u6838\u8fdb\u884c\u4e86\u6d4b\u8bc4\uff0c\u51fa\u4e4e\u610f\u6599\u5730\u53d1\u73b0 Windows \u82b1\u4e86\u5927\u91cf\u7684\u65f6\u95f4\u6765\u8c03\u5ea6\u65e0\u6548\u7684\u6307\u4ee4\u5f02\u5e38\u3002\u8fd9\u4e5f\u592a\u8352\u8c2c\u4e86\u5427\uff01\u5fae\u8f6f\u7684\u90a3\u4e9b\u5de5\u7a0b\u5e08\u539f\u6765\u5e76\u4e0d\u662f\u5728\u5f00\u73a9\u7b11\u5417\uff1f<\/p>\n<p>No he wasn\u2019t.<\/p>\n<p>\u8fd8\u771f\u4e0d\u662f\u3002<\/p>\n<p>It so happens that on the 80386 chip of that era, the fastest way to get from V86-mode into kernel mode was to execute an invalid instruction! Consequently, Windows\/386 used an invalid instruction as its syscall trap.<\/p>\n<p>\u539f\u6765\u5728\u90a3\u4e2a\u65f6\u4ee3\u7684 80386 \u5904\u7406\u5668\u4e0a\uff0c\u4ece\u865a\u62df8086\u6a21\u5f0f\u5207\u6362\u5230\u5185\u6838\u6a21\u5f0f\u6700\u5feb\u7684\u65b9\u6cd5\uff0c\u6b63\u662f\u6267\u884c\u4e00\u4e2a\u65e0\u6548\u7684\u6307\u4ee4\uff01\u56e0\u6b64\uff0cWindows\/386 \u5c06\u65e0\u6548\u6307\u4ee4\u4f5c\u4e3a\u4e86 syscall \u7684\u9677\u9631\u3002<\/p>\n<p>What\u2019s the moral of this story? I\u2019m not sure. Perhaps it\u2019s that when you create something, you may find people using it in ways you had never considered.<\/p>\n<p>\u81f3\u4e8e\u8fd9\u4e2a\u6545\u4e8b\u6559\u7ed9\u6211\u4eec\u7684\u9053\u7406\u662f\u4ec0\u4e48\uff0c\u6211\u5e76\u4e0d\u592a\u786e\u5b9a\u3002\u5927\u6982\u662f\u5f53\u4f60\u521b\u9020\u4e86\u4e00\u9879\u4e8b\u7269\u65f6\uff0c\u4f60\u4f1a\u53d1\u73b0\u4eba\u4eec\u4f1a\u7528\u4f60\u4ece\u672a\u8003\u8651\u8fc7\u7684\u65b9\u5f0f\u53bb\u4f7f\u7528\u5b83\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/devblogs.microsoft.com\/oldnewthing\/2004121 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3053","post","type-post","status-publish","format-standard","hentry","category-tont_history"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/3053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=3053"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/3053\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=3053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=3053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=3053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}