comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Gnat 3.15p & Windows & Hyperthreading Q
Date: Fri, 01 Apr 2005 01:09:28 -0600
Date: 2005-04-01T01:09:28-06:00	[thread overview]
Message-ID: <SpudndJHxoo1btHfRVn-2A@comcast.com> (raw)
In-Reply-To: 424a67f2$0$28071$ba620e4c@news.skynet.be

> 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;



      reply	other threads:[~2005-04-01  7:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-26  0:28 Gnat 3.15p & Windows & Hyperthreading Q tmoran
2005-03-26  4:45 ` Steve
2005-03-26  9:41 ` Pascal Obry
2005-03-26 13:53 ` Marin David Condic
2005-03-26 18:36   ` tmoran
2005-03-28 13:16     ` Marin David Condic
2005-03-27 11:27   ` Simon Wright
2005-03-29 18:33 ` Wiljan Derks
2005-03-30  8:48   ` Adrien Plisson
2005-04-01  7:09     ` tmoran [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox