comp.lang.ada
 help / color / mirror / Atom feed
* Task Priorities on Ubuntu Linux
@ 2009-12-09 14:34 singo
  2009-12-09 15:10 ` Dmitry A. Kazakov
  2009-12-09 21:20 ` sjw
  0 siblings, 2 replies; 4+ messages in thread
From: singo @ 2009-12-09 14:34 UTC (permalink / raw)


Hi,

Another question on the real-time annex and its implementation in
gnat-4.3 (Ubuntu Linux).

When I use different task priorities I get an - at least for me -
unexpected behavior... I have defined 10 tasks with different
priority. When I run my program, I expect only one task per processor
(this means four on my quad-core machine) to run. However,
unexpectedly all 10 tasks are run on my machine.

Is this because the tasks are mapped on the underlying OS (here
Linux), which then instead schedules the tasks of different priority
with some kind of time-slicing (round-robin) approach? I would
appreciate some clarification in this matter.

Best regards

Ingo

P.S: Here comes my example program:

pragma Task_Dispatching_Policy(FIFO_Within_Priorities);
pragma Queuing_Policy(Priority_Queuing);

with Ada.Text_IO;
use Ada.Text_IO;

with Ada.Real_Time;
use Ada.Real_Time;

procedure TaskPriorities is

   task type T(Id: Integer) is
      pragma Priority(Id);
   end;

   task body T is
   begin
      loop
	 Put(Integer'Image(Id));
      end loop;
   end T;

   Task10 : T(11);
   Task9  : T(12);
   Task8  : T(13);
   Task7  : T(14);
   Task6  : T(15);
   Task5  : T(16);
   Task4  : T(17);
   Task3  : T(18);
   Task2  : T(19);
   Task1  : T(20);

begin
   null;
end TaskPriorities;



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

* Re: Task Priorities on Ubuntu Linux
  2009-12-09 14:34 Task Priorities on Ubuntu Linux singo
@ 2009-12-09 15:10 ` Dmitry A. Kazakov
  2009-12-09 21:20 ` sjw
  1 sibling, 0 replies; 4+ messages in thread
From: Dmitry A. Kazakov @ 2009-12-09 15:10 UTC (permalink / raw)


On Wed, 9 Dec 2009 06:34:45 -0800 (PST), singo wrote:

> When I use different task priorities I get an - at least for me -
> unexpected behavior... I have defined 10 tasks with different
> priority. When I run my program, I expect only one task per processor
> (this means four on my quad-core machine) to run. However,
> unexpectedly all 10 tasks are run on my machine.
> 
> Is this because the tasks are mapped on the underlying OS (here
> Linux), which then instead schedules the tasks of different priority
> with some kind of time-slicing (round-robin) approach? I would
> appreciate some clarification in this matter.

No, there could be a different reason from that. You perform I/O, which
leads to task switching. Once I/O is initiated the OS completes it anyway
(if the kernel is non-preemptive for your tasks). This is what you
observed. I guess.

Try this instead:

pragma Task_Dispatching_Policy (FIFO_Within_Priorities);
pragma Queuing_Policy (Priority_Queuing);

with Ada.Text_IO;    use Ada.Text_IO;
with Ada.Real_Time;  use Ada.Real_Time;

procedure TaskPriorities is

   task type T (Id: Integer) is
      pragma Priority (Id);
   end;

   task body T is
      I : Integer;
   begin
      Put (Integer'Image (Id));
      for Index in Integer'Range loop
         I := Index;
      end loop;
   end T;
   Task10 : T (11);
   Task9  : T (12);
   Task8  : T (13);
   Task7  : T (14);
   Task6  : T (15);
   Task5  : T (16);
   Task4  : T (17);
   Task3  : T (18);
   Task2  : T (19);
   Task1  : T (20);
begin
   null;
end TaskPriorities;

It should print 20 19 (on two cores), then you would like to reset your
computer, if under Windows, because there non-preemptive priorities are the
real-time ones. They override pretty much everything, unless tasks end you
will have to reboot.

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



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

* Re: Task Priorities on Ubuntu Linux
  2009-12-09 14:34 Task Priorities on Ubuntu Linux singo
  2009-12-09 15:10 ` Dmitry A. Kazakov
@ 2009-12-09 21:20 ` sjw
  2009-12-10  8:27   ` singo
  1 sibling, 1 reply; 4+ messages in thread
From: sjw @ 2009-12-09 21:20 UTC (permalink / raw)


On Dec 9, 2:34 pm, singo <sander.i...@gmail.com> wrote:
> Hi,
>
> Another question on the real-time annex and its implementation in
> gnat-4.3 (Ubuntu Linux).
>
> When I use different task priorities I get an - at least for me -
> unexpected behavior... I have defined 10 tasks with different
> priority. When I run my program, I expect only one task per processor
> (this means four on my quad-core machine) to run. However,
> unexpectedly all 10 tasks are run on my machine.
>
> Is this because the tasks are mapped on the underlying OS (here
> Linux), which then instead schedules the tasks of different priority
> with some kind of time-slicing (round-robin) approach? I would
> appreciate some clarification in this matter.
>
> Best regards
>
> Ingo
>
> P.S: Here comes my example program:
>
> pragma Task_Dispatching_Policy(FIFO_Within_Priorities);
> pragma Queuing_Policy(Priority_Queuing);
>
> with Ada.Text_IO;
> use Ada.Text_IO;
>
> with Ada.Real_Time;
> use Ada.Real_Time;
>
> procedure TaskPriorities is
>
>    task type T(Id: Integer) is
>       pragma Priority(Id);
>    end;
>
>    task body T is
>    begin
>       loop
>          Put(Integer'Image(Id));
>       end loop;
>    end T;
>
>    Task10 : T(11);
>    Task9  : T(12);
>    Task8  : T(13);
>    Task7  : T(14);
>    Task6  : T(15);
>    Task5  : T(16);
>    Task4  : T(17);
>    Task3  : T(18);
>    Task2  : T(19);
>    Task1  : T(20);
>
> begin
>    null;
> end TaskPriorities;

It used to be that on Linux you would have to run as root for
specified priorities to be respected.

FWIW, on Mac OS X Dmitry's program behaves much the same as an
ordinary user and as root: variously,

$ ./taskpriorities
 11 13 12 15 14 18 17 20 19^C
$ ./taskpriorities
 19 20 18 16 14^C
$ ./taskpriorities
 19 20 18 17^C
$ sudo ./taskpriorities
Password:
 19 20 18 16 14^C



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

* Re: Task Priorities on Ubuntu Linux
  2009-12-09 21:20 ` sjw
@ 2009-12-10  8:27   ` singo
  0 siblings, 0 replies; 4+ messages in thread
From: singo @ 2009-12-10  8:27 UTC (permalink / raw)


On Dec 9, 10:20 pm, sjw <simon.j.wri...@mac.com> wrote:
> On Dec 9, 2:34 pm, singo <sander.i...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > Another question on the real-time annex and its implementation in
> > gnat-4.3 (Ubuntu Linux).
>
> > When I use different task priorities I get an - at least for me -
> > unexpected behavior... I have defined 10 tasks with different
> > priority. When I run my program, I expect only one task per processor
> > (this means four on my quad-core machine) to run. However,
> > unexpectedly all 10 tasks are run on my machine.
>
> > Is this because the tasks are mapped on the underlying OS (here
> > Linux), which then instead schedules the tasks of different priority
> > with some kind of time-slicing (round-robin) approach? I would
> > appreciate some clarification in this matter.
>
> > Best regards
>
> > Ingo
>
> > P.S: Here comes my example program:
>
> > pragma Task_Dispatching_Policy(FIFO_Within_Priorities);
> > pragma Queuing_Policy(Priority_Queuing);
>
> > with Ada.Text_IO;
> > use Ada.Text_IO;
>
> > with Ada.Real_Time;
> > use Ada.Real_Time;
>
> > procedure TaskPriorities is
>
> >    task type T(Id: Integer) is
> >       pragma Priority(Id);
> >    end;
>
> >    task body T is
> >    begin
> >       loop
> >          Put(Integer'Image(Id));
> >       end loop;
> >    end T;
>
> >    Task10 : T(11);
> >    Task9  : T(12);
> >    Task8  : T(13);
> >    Task7  : T(14);
> >    Task6  : T(15);
> >    Task5  : T(16);
> >    Task4  : T(17);
> >    Task3  : T(18);
> >    Task2  : T(19);
> >    Task1  : T(20);
>
> > begin
> >    null;
> > end TaskPriorities;
>
> It used to be that on Linux you would have to run as root for
> specified priorities to be respected.
>
> FWIW, on Mac OS X Dmitry's program behaves much the same as an
> ordinary user and as root: variously,
>
> $ ./taskpriorities
>  11 13 12 15 14 18 17 20 19^C
> $ ./taskpriorities
>  19 20 18 16 14^C
> $ ./taskpriorities
>  19 20 18 17^C
> $ sudo ./taskpriorities
> Password:
>  19 20 18 16 14^C

Thanks a lot for the information!

Yes, you are right! In order to get a correct behavior I have to run
the program as root (which I was not aware of). I made a small change
of Dimitri's program (I moved the 'Put' statement after the loop),
i.e.

   task body T is
      I : Integer;
   begin
      for Index in Integer'Range loop
         I := Index;
      end loop;
      Put (Integer'Image (Id));
   end T;

and then I get the following expected output:

On a machine with four cores:

> sudo ./taskpriorities
 17 18 20 19 16 15 14 13 12 11

On a machine with one core:

> sudo ./taskpriorities
 20 19 18 17 16 15 14 13 12 11

Best regards

Ingo



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

end of thread, other threads:[~2009-12-10  8:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-09 14:34 Task Priorities on Ubuntu Linux singo
2009-12-09 15:10 ` Dmitry A. Kazakov
2009-12-09 21:20 ` sjw
2009-12-10  8:27   ` singo

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