From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,27eba2f78fbdcc60 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 01 Apr 2005 01:09:27 -0600 From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Gnat 3.15p & Windows & Hyperthreading Q References: <424a67f2$0$28071$ba620e4c@news.skynet.be> X-Newsreader: Tom's custom newsreader Message-ID: Date: Fri, 01 Apr 2005 01:09:28 -0600 NNTP-Posting-Host: 67.161.24.234 X-Trace: sv3-ju6qin7jrvcE96uPIWL9HdUyed0cFD7Bl/A7QrdRCH/ft42XoSC0M+5c9+okoNv5ePIllD/XuMN/ucQ!ohiZ3QFV+e55W/Y5+XmSuI51VFbk2h/5Au+bZrC/yAdyAdD35Y0t4w0d/EecNg== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:10202 Date: 2005-04-01T01:09:28-06:00 List-Id: > a single processor. what's different is that it has 2 sets of > "states", allowing for more efficient context switches. as noted by > Wiljan, this makes the system more responsive. > > but this paper does explain it in more details: > http://www.intel.com/business/bss/products/hyperthreading/server/ht_server.pdf That paper doesn't tell much, since it says resources unused by one virtual cpu are available to the other. If there are lots of such resources, then two threads ought to run with almost no interference, ie, nearly twice as fast as sequentially. If there are bottleneck resources then clearly things are single-file and no different than a software implemented time-slicing multitasking. And the paper doesn't tell which. Here's a little program which should create two definite and different patterns on Windows/Task Manager/Performance/CPU History(s). Compile with "gnatmake -gnato cpu2" - no optimization desired. Run Task Manager/Performance so it displays two CPU History windows (for multi or hyperthreaded CPUs). Start a separate Command Prompt window and run cpu2.exe. It will run almost 100 seconds making pattern(s) on the CPU History window(s), and some text output. On a single CPU machine, the pattern should be like a short spike 5 seconds zero use 38 seconds of 100% CPU use, ie, the graph pinned at the top. 21 seconds containing two spikes of CPU use. 33 seconds of 100% use. total 97 seconds On a multi or hyperthreaded CPU, I would expect CPU 1 window CPU 2 window a short spike 5 seconds zero use 5 seconds zero use 24 seconds at 100% 24 seconds with 3 spikes 40 seconds containing 5 spikes 40 seconds of zero use 24 seconds at 100% 24 more seconds of zero use total 93 seconds For a single CPU run, here's the text output I got: 2.85042E+07 loops/sec start both tasks task 1 now quiet 43.830936614 task 1 busy again 64.005100369 task 2 done 90.933717554 task 1 done 97.452995004 with Ada.Calendar, Ada.Exceptions, Ada.Text_IO; procedure Cpu2 is use type Ada.Calendar.Time; Loops_Per_Second: Float := 0.0; -- set by Find_Speed procedure High(T : in Duration) is N : constant Positive := Integer(Float(T) * Loops_Per_Second); X : Integer := 0; begin for I in 1 .. N loop X := X + 1; end loop; end High; procedure Low(T : in Duration) is begin delay T; end Low; task Two is entry Start(Wavelength: in Duration; Cycle_Count: in Natural); end Two; procedure Find_Speed is T0 : constant Ada.Calendar.Time := Ada.Calendar.Clock; begin Loops_Per_Second := 10_000_000.0; High(1.0); Loops_Per_Second := Loops_Per_Second / Float(Ada.Calendar.Clock - T0); end Find_Speed; T0 : Ada.Calendar.Time; task body Two is W : Duration; N : Natural; begin accept Start(Wavelength: in Duration; Cycle_Count: in Natural) do W := Wavelength; N := Cycle_Count; end Start; delay 0.01; -- let caller run for Cycle in 1 .. N loop High(W / 2); Low(W / 2); end loop; Ada.Text_IO.Put_Line("task 2 done" & Duration'Image(Ada.Calendar.Clock - T0)); exception when Oops : others => Ada.Text_IO.Put_Line("task two:" & Ada.Exceptions.Exception_Information(Oops)); end Two; begin Find_Speed; Ada.Text_IO.Put_Line(Float'Image(Loops_Per_Second) & " loops/sec"); T0 := Ada.Calendar.Clock; delay 5.0; Ada.Text_IO.Put_Line("start both tasks"); Two.Start(Wavelength => 8.0, Cycle_Count => 8); High(25.0); Ada.Text_IO.Put_Line("task 1 now quiet" & Duration'Image(Ada.Calendar.Clock - T0)); delay until T0 + 64.0; Ada.Text_IO.Put_Line("task 1 busy again" & Duration'Image(Ada.Calendar.Clock - T0)); High(25.0); Ada.Text_IO.Put_Line("task 1 done" & Duration'Image(Ada.Calendar.Clock - T0)); exception when Oops : others => Ada.Text_IO.Put_Line(Ada.Exceptions.Exception_Information(Oops)); end Cpu2;