{"id":37883,"date":"2004-09-13T07:00:00","date_gmt":"2004-09-13T14:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/09\/13\/how-does-windows-exploit-hyperthreading\/"},"modified":"2004-09-13T07:00:00","modified_gmt":"2004-09-13T14:00:00","slug":"how-does-windows-exploit-hyperthreading","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040913-00\/?p=37883","title":{"rendered":"How does Windows exploit hyperthreading?"},"content":{"rendered":"<p><P>\nIt depends which version of Windows you&#8217;re asking about.\n<\/P>\n<P>\nFor Windows&nbsp;95, Windows&nbsp;98, and Windows&nbsp;Me,\nthe answer is simple: Not at all.\nThese are not multiprocessor operating systems.\n<\/P>\n<P>\nFor Windows&nbsp;NT and Windows&nbsp;2000, the answer is\n&#8220;It doesn&#8217;t even know.&#8221;\nThese operating systems are not hyperthreading-aware\nbecause they were written before hyperthreading was invented.\nIf you enable hyperthreading, then each of your CPUs looks\nlike two separate CPUs to these operating systems.\n(And will get charged as two separate CPUs for licensing\npurposes.)\nSince the scheduler doesn&#8217;t realize the connection between\nthe virtual CPUs, it can end up doing a worse job than\nif you had never enabled hyperthreading to begin with.\n<\/P>\n<P>\nConsider a dual-hyperthreaded-processor machine.\nThere are two physical processors A and B, each with\ntwo virtual hyperthreaded processors, call them A1, A2,\nB1, and B2.\n<\/P>\n<P>\nSuppose you have two CPU-intensive tasks.\nAs far as the Windows&nbsp;NT\nand Windows&nbsp;2000 schedulers are concerned, all four\nprocessors are equivalent, so it figure it doesn&#8217;t matter which two \nit uses.  And if you&#8217;re unlucky, it&#8217;ll pick\nA1 and A2, forcing one physical processor to shoulder two\nheavy loads (each of which will probably run at something\nbetween half-speed and three-quarter speed),\nleaving physical processor B idle;\ncompletely unaware that it could have done a better job\nby putting one on A1 and the other on B1.\n<\/P>\n<P>\nWindows&nbsp;XP and Windows Server&nbsp;2003 are hyperthreading-aware.\nWhen faced with the above scenario, those schedulers will know\nthat it is better to put one task on one of the A&#8217;s and the other\non one of the B&#8217;s.\n<\/P>\n<P>\nNote that even with a hyperthreading-aware processor, \nyou can concoct pathological scenarios where hyperthreading ends\nup a net loss.  (For example, if you have four tasks, two of which\nrely heavily on L2 cache and two of which don&#8217;t, you&#8217;d be better\noff putting each of the L2-intensive tasks on separate processors,\nsince the L2 cache is shared by the two virtual processors.\nPutting them both on the same processor would result in a lot of L2-cache\nmisses as the two tasks fight over L2 cache slots.)\n<\/P>\n<P>\nWhen you go to the expensive end of the scale (the Datacenter Servers,\nthe Enterprise Servers), things get tricky again.\nI refer still-interested parties to the\n<A HREF=\"http:\/\/www.microsoft.com\/whdc\/hwdev\/platform\/proc\/HT-Windows.mspx\">\nWindows Support for Hyper-Threading Technology<\/A> white paper.\n<\/P>\n<P>\n<B>Update 06\/2007<\/B>: The white paper\n<A HREF=\"http:\/\/www.microsoft.com\/whdc\/system\/CEC\/HT-Windows.mspx\">\nappears to have moved<\/A>.\n<\/P>\n<P>\n<B>Update 10\/2016<\/B>: The white paper\n<A HREF=\"https:\/\/view.officeapps.live.com\/op\/view.aspx?src=http:\/\/download.microsoft.com\/download\/5\/7\/7\/577a5684-8a83-43ae-9272-ff260a9c20e2\/Hyper-thread_Windows.doc\">\nmoved again<\/A>.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Depends which version of Windows.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-37883","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Depends which version of Windows.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=37883"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37883\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=37883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=37883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=37883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}