comp.lang.ada
 help / color / mirror / Atom feed
* Task execution time test
@ 2010-12-26 10:25 Dmitry A. Kazakov
  2010-12-29 23:00 ` h_poincare
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry A. Kazakov @ 2010-12-26 10:25 UTC (permalink / raw)


Here is a small test for task execution time.

Five worker tasks are used to generate background CPU load. When the
measured task enters delay 0.1ms (on a system where delay is non-busy) it
should lose the CPU prematurely.

Under at least some Windows systems the test might fail because Windows
performance counters are CPU quants 1ms or 10ms, depending on settings.

Under VxWorks the test may fail because real-time clock there is driven by
the timer interrupts, so it is impossible to have non-busy wait for 0.1ms.

(I cannot say anything about Linux, because I never used it for RT
applications, maybe other people could comment)

----------------------------------------------------
with Ada.Execution_Time;  use Ada.Execution_Time;
with Ada.Real_Time;       use Ada.Real_Time;
with Ada.Text_IO;         use Ada.Text_IO;

with Ada.Numerics.Elementary_Functions;

procedure Executuion_Time is
   task type Measured;
   task body Measured is
      Count    : Seconds_Count;
      Fraction : Time_Span;
   begin
      for I in 1..1_000 loop
         delay 0.000_1;
      end loop;
      Split (Ada.Execution_Time.Clock, Count, Fraction);
      Put_Line
      (  "Seconds" & Seconds_Count'Image (Count) &
         " Fraction" & Duration'Image (To_Duration (Fraction))
      );
   end Measured;

   task type Worker; -- Used to generate CPU load
   task body Worker is
      use Ada.Numerics.Elementary_Functions;
      X : Float;
   begin
      for I in Positive'Range loop
         X := sin (Float (I));
      end loop;
   end Worker;
   
begin
   delay 0.1; -- This might be needed for some buggy versions of GNAT
   declare
      Workers : array (1..5) of Worker;
      Test    : Measured;
   begin
      null;
   end;
end Executuion_Time;
-----------------------------------------------------
On my Windows XP SP3 the test yields 0-0.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Task execution time test
  2010-12-26 10:25 Task execution time test Dmitry A. Kazakov
@ 2010-12-29 23:00 ` h_poincare
  2010-12-30  8:54   ` Dmitry A. Kazakov
  0 siblings, 1 reply; 3+ messages in thread
From: h_poincare @ 2010-12-29 23:00 UTC (permalink / raw)


Le 26/12/2010 11:25, Dmitry A. Kazakov a �crit :
> Here is a small test for task execution time.
>
> Five worker tasks are used to generate background CPU load. When the
> measured task enters delay 0.1ms (on a system where delay is non-busy) it
> should lose the CPU prematurely.
>
> Under at least some Windows systems the test might fail because Windows
> performance counters are CPU quants 1ms or 10ms, depending on settings.
>

> On my Windows XP SP3 the test yields 0-0.
>

Here are the measures of the code on my Windows machines
which tend to prove that the scheduling is correct.

On Windows Vista SP2 :
For 1_000 loops
Seconds 0 Fraction 0.093600600
For 10_000 loops
Seconds 1 Fraction 0.029606600

On Windows XP2002 SP3 :
For 1_000 loops
Seconds 0 Fraction 0.125000000
Seconds 0 Fraction 0.109375000
For 10_000 loops
Seconds 1 Fraction 0.140625000

GPS 4.4.1 (20091215) hosted on i686-pc-mingw32
GNAT GPL 2010 (20100603)

I am just curious to know how to get/set Windows performance counters
-----------------------------------------------
Regards
Fran�ois FABIEN



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Task execution time test
  2010-12-29 23:00 ` h_poincare
@ 2010-12-30  8:54   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2010-12-30  8:54 UTC (permalink / raw)


On Thu, 30 Dec 2010 00:00:10 +0100, h_poincare wrote:

> Here are the measures of the code on my Windows machines
> which tend to prove that the scheduling is correct.
> 
> On Windows Vista SP2 :
> For 1_000 loops
> Seconds 0 Fraction 0.093600600
> For 10_000 loops
> Seconds 1 Fraction 0.029606600
> 
> On Windows XP2002 SP3 :
> For 1_000 loops
> Seconds 0 Fraction 0.125000000
> Seconds 0 Fraction 0.109375000
> For 10_000 loops
> Seconds 1 Fraction 0.140625000
> 
> GPS 4.4.1 (20091215) hosted on i686-pc-mingw32
> GNAT GPL 2010 (20100603)

I think you have a multi-core processor. In effect the measured task does
not lose the processor as the test intends. Make sure that the number of
worker task is sufficiently high to make busy all cores.

(I have posted a better test in a new thread.)

> I am just curious to know how to get/set Windows performance counters

QueryPerformanceCounter returns a 64-bit integer. QueryPerformanceFrequency
gives the frequency of the counter.

Relation of both may serve a replacement for Ada.Real_Time.Clock. Beware
multi-cores. Each core has its own counter. That means, you cannot mix
counts from different cores. SetThreadAffinityMask can be used to glue the
task to a core.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-12-30  8:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-26 10:25 Task execution time test Dmitry A. Kazakov
2010-12-29 23:00 ` h_poincare
2010-12-30  8:54   ` Dmitry A. Kazakov

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