comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: Task Scheduling
  @ 2007-01-07 20:47  5% ` Jeffrey Creem
  0 siblings, 0 replies; 6+ results
From: Jeffrey Creem @ 2007-01-07 20:47 UTC (permalink / raw)


  jpluto wrote:
> 
> 
> A questions please:
> 
> I am trying to solve a problem, and I am not sure how to code it.
> 
> For example, if I have three arbitrary tasks, task1 has a priority than 
> task2.
> Therefore, task1 will always preempt task2 and task3.
> 
> However, if task2 ran first and locked a shared data resource that is 
> shared with ONLY task3 and NOT task1.  Then if task1 arrives, I want 
> task1 to yield the processor to task2 until task2 is finished using the 
> resource even though task1 has the highest priority.
> 
> The problem, task1 has a higher priority and does NOT use this shared 
> resource.
> How can I ask this task1 not to run, and to wait whenever this shared 
> resource is locked by task2 or task3?

I can't really think of a way. What you are asking for really seems 
quite odd and seems like a very strange way to abuse the priority system.

It sounds like what you 'really' want to do is to have dynamic 
priorities on tasks 2 and 3 such that whenever they 'have' the shared 
resource, they elevate their priority higher than task 1.

Have you considered just building the code that controls access to the 
resource such that it uses Ada.Dynamic_Priorities to capture initial 
priority, raise it up while the resource is held and then restore it 
when the resource is done....Or something like that?



^ permalink raw reply	[relevance 5%]

* Re: Priority Ceiling
  2003-07-23 21:24  6% Priority Ceiling Stephan Heinemann
@ 2003-07-23 22:19  3% ` Robert I. Eachus
  0 siblings, 0 replies; 6+ results
From: Robert I. Eachus @ 2003-07-23 22:19 UTC (permalink / raw)


Stephan Heinemann wrote:

> Now the questions:
> (1)
> If I understood correctly then the task priority should be raised to the
> ceiling priority of the protected object (immediate ceiling priority
> protocol). However, I cannot obtain this new active priority using
> "Get_Priority(Current_Task)"; the base priority is returned instead. Why?

Because that is the way Get_Priority is defined:  D.5(8):

"The function Get_Priority returns T's current base priority."

If you think about it any other definition would be unfriendly.

> (2)
> The procedure "Priorities" would run with default priority (15) if
> pragma Priority(0) was not given. But this change seems to affect the
> defined tasks as well, eventhough they have their own base priorities
> assigned to them. Do they inherit their priorities from the
> "Priorities"-executing task, if they are assigned lower base priorities
> than the latter?

That is actually about a dozen questions...

First, the procedure "Priorities" will only run with a priority other 
than the default if it is the main program, the main program contains a 
pragma Priority, or Priorities is called by a task with a non-default 
priorty.

To turn that around in a way that makes sense, a pragma Priority in the 
main program can set the priority of the environment task.  At any other 
point, the priority of a subprogram is the (current) priority of the 
task it is executing in.

Next D.1(21): "During activation, a task being activated inherits the 
active priority that its activator (see 9.2) had at the time the 
activation was initiated."

In other words, during task creation the task runs with the priority of 
its creator.  This allows a high-priority task to create a 
lower-priority task without having to wait for that process to complete. 
  After that a task will run with its own priority, except when it 
inherits a higher priority during a rendezvous, or runs at the priority 
ceiling of a protected object, or when its priority is changed (or set) 
by a call to Ada.Dynamic_Priorities.Set_Priority.

Note that with pragma Locking_Policy(Ceiling_Locking) the ceiling 
priority of a protected object is, by default, Priority'Last, but it can 
be set as high as Interrupt_Priority'Last.  (And is not less than 
Interrupt_Priority'First if a pragma Interrupt_Handler or Attach_Handler 
  appears in the protected object.)

A task that attempts to call an entry, procedure, or function of a 
protected object whose ceiling is less than the current priority of the 
task, Program_Error will be raised.

So if you try to play with this stuff without design tool support it 
gets hard fast.  The tools can tell you the base priority of each task, 
the highest priority it will inherit, and any case where it might 
violate a priority ceiling.  Of course, you can use Set_Priority with 
run time computed values to confuse the best of priority inheritance 
design tools.  Of course, tasking design tools is not my area of 
experitise, so maybe some other posters will recommend some.

-- 

                                                        Robert I. Eachus

�In an ally, considerations of house, clan, planet, race are 
insignificant beside two prime questions, which are: 1. Can he shoot? 2. 
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and 
Steve Miller.




^ permalink raw reply	[relevance 3%]

* Priority Ceiling
@ 2003-07-23 21:24  6% Stephan Heinemann
  2003-07-23 22:19  3% ` Robert I. Eachus
  0 siblings, 1 reply; 6+ results
From: Stephan Heinemann @ 2003-07-23 21:24 UTC (permalink / raw)


Please have a look at the following piece of code:

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

with System; use System;
with Ada.Dynamic_Priorities; use Ada.Dynamic_Priorities;
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Priorities is
    pragma Priority(0);
    -- if not specified default priority is inherited by tasks?
    P1: constant Priority := Priority'First;
    P2: constant Priority := Priority'Last;

    protected Ceiling_Object is
        --pragma Priority(System.Priority'Last);
        pragma Priority(2);
        -- less than 15 raises Program_Error?
        -- default priority
        procedure E;
    end Ceiling_Object;

    protected body Ceiling_Object is    
        procedure E is
        begin
            Put_Line("E entered");
            -- delay 5.0; -- should actually not be done
            -- display the active priority
            Put(Image(Current_Task));
            Put(Get_Priority(Current_Task)); New_Line;
            -- dynamic priority not raised?
            Put_Line("E finished");
        end E;
    end Ceiling_Object;
    
    task A is
        pragma Priority(0);
    end A;
    
    task body A is
    begin
        Put_Line("T running");
        Ceiling_Object.E;
        -- should raise Program_Error only if task priority
        --- higher than ceiling priority
        Put_Line("T done");
    exception
        when Ex: others =>
            Put(Image(Current_Task) & " ");
            Put(Exception_Name(Ex)); New_Line;
    end A;
    
    task B is
        pragma Priority(1);
    end B;
    
    task body B is
    begin
        Put_Line("B running");
        Ceiling_Object.E;
        Put_Line("B done");
    exception
        when Ex: others =>
            Put(Image(Current_Task) & " ");
            Put(Exception_Name(Ex)); New_Line;
    end B;

begin
    Put("P1: "); Put(P1); New_Line;
    Put("P2: "); Put(P2); New_Line;
end Priorities;

Now the questions:
(1)
If I understood correctly then the task priority should be raised to the
ceiling priority of the protected object (immediate ceiling priority
protocol). However, I cannot obtain this new active priority using
"Get_Priority(Current_Task)"; the base priority is returned instead. Why?
(2)
The procedure "Priorities" would run with default priority (15) if
pragma Priority(0) was not given. But this change seems to affect the
defined tasks as well, eventhough they have their own base priorities
assigned to them. Do they inherit their priorities from the
"Priorities"-executing task, if they are assigned lower base priorities
than the latter?

Thanks in advance,
Stephan



^ permalink raw reply	[relevance 6%]

* gnat Dynamic Priority Dispatching Anomalies
@ 2003-02-04 12:04  7% Ian Broster
  0 siblings, 0 replies; 6+ results
From: Ian Broster @ 2003-02-04 12:04 UTC (permalink / raw)


Hello

I've noticed some anomalies with dynamic priorites and task dispatching
with gnat 3.15p, using both FSU threads and the native (linux) threads. It
seems that the highest priority runnable task does not always execute.

I have produced a test program which demonstrates the problem.
Can someone explain whether it is my misunderstanding or
whether it is a compiler/runtime problem.

The test programs are below, but I've also bundled them together at 
http://www-users.cs.york.ac.uk/~ianb/pub/gnatdispatching.tgz

The program output (with FSU threads) is below.
The first number in each line is the (dynamic) base priority, 
the second field is the task ID.

So the question is: at lines 4 and 6, why is a low priority (1)
task running when there is a high priority task (15) still
ready to execute?

 15  main_task_080921A8  Main started
 15  t1_08092888  Before set_priority
 15  main_task_080921A8  t1 made
 1  t1_08092888  After set_priority
 15  t2_0809AE60  Before set_priority
 1  t1_08092888  After delay
 15  main_task_080921A8  t2 made
 1  t2_0809AE60  After set_priority
 1  t2_0809AE60  After delay

Thanks for any help

Ian Broster



Program and version information follows.

Compiler version: (binary distribution)
GNAT 3.15p  (20020523) Copyright 1996-2002 Free Software Foundation, Inc.

uname:
Linux x 2.4.18 #14 SMP Fri Aug 30 14:37:42 BST 2002 i686 unknown


with text_io; use text_io;
with tasks; use tasks;

procedure main is
	t1 : athread_p;
	t2 : athread_p;
begin
	info("Main started");
	t1 := new athread;
	info("t1 made");
	t2 := new athread;
	info("t2 made");
end main;

package tasks  is
	procedure info(s: string);

	task type athread;
	type athread_p is access athread;
end tasks;


with Ada.Dynamic_Priorities; 
with system; use system;
with text_io; use text_io;
with Ada.Task_Identification; 

package body tasks  is
	procedure info(s: string) is
	begin
		put(Integer'image(Ada.Dynamic_Priorities.Get_Priority));
		put("  " );
		put(
			Ada.Task_Identification.Image(
				Ada.Task_Identification.Current_Task)
		);
		put("  ");
		put_line(s);
	end info;
	
	task body athread is
	begin
		info("Before set_priority");
		Ada.Dynamic_Priorities.Set_Priority(priority'first+1);
		info("After set_priority");
		delay 0.0;
		info("After delay");
		loop
			delay 0.0;
		end loop;
	end athread;

end tasks;



^ permalink raw reply	[relevance 7%]

* Re: GUI Design for Ada
  @ 1999-10-29  0:00  4% ` Ted Dennison
  1999-10-29  0:00  0%   ` Andrew
  0 siblings, 1 reply; 6+ results
From: Ted Dennison @ 1999-10-29  0:00 UTC (permalink / raw)


In article <7vb03r$1ea$1@news5.fast.net>,
  "Andrew" <mysig@fast.net> wrote:

> However, the project I'm working on is a multi-process  simulation
> that runs on a dual PowerPC system.

Out of curiosity, what OS are you using?

> I'm looking for a good reference/tutorial type book that discusses
> real-time programming in Ada that's new to this field.

I'm not aware of an Ada book specific to real-time. Chapters 17 and 18
in Cohen's Ada as a Second Language cover a lot of the issues.
We also have a couple of copies of A Practitioner's Handbook for
Real-Time Analysis, which covers a lot of issues related to
Rate-Monotonic systems in a language-neutral manner.

In Ada you can make a simple rate-monotonic system by putting each
scheduled item in its own task. Each task should set its priority
relative to the other tasks to be the same as its iteration rate
relative to the other tasks (using Ada.Dynamic_Priorities). A global
package that keeps track of everyone's priority and rate (perhaps as
read from a configuration file) can be useful for this purpose.

Before its first iteration, each task should save the current value of
Ada.Real_Time.Clock. At the end of each iteration, the task will add its
iteration rate to the saved time, and perform a "delay until" that time.
More sophistacted logic can be added to detect and handle overruns.

We discovered on our project that with careful attention given to using
standard Ada constructs rather than their OS equivalents, one can create
an entire real-time simulation in Ada that is souce code portable to
other OS/compiler combinations (excepting specialized hardware
interfaces, of course). For instance, when hardware availability turned
out to be a problem, we were able to compile and test early versions of
our entire system on NT boxes using Gnat, even though the code was
written for the GreenHills Ada cross-compiler for vxWorks. Of course you
don't quite get real-time performance in NT. But if we needed to change
RTOS's or compiler vendors, it would be an almost painless process. I am
unaware of *any* other language that could provide this.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[relevance 4%]

* Re: GUI Design for Ada
  1999-10-29  0:00  4% ` Ted Dennison
@ 1999-10-29  0:00  0%   ` Andrew
  0 siblings, 0 replies; 6+ results
From: Andrew @ 1999-10-29  0:00 UTC (permalink / raw)


Thanks everyone for your suggestions.



--



-------------------------------------------------------------------
Andrew

Ted Dennison <dennison@telepath.com> wrote in message
news:7vcd4p$r9q$1@nnrp1.deja.com...
> In article <7vb03r$1ea$1@news5.fast.net>,
>   "Andrew" <mysig@fast.net> wrote:
>
> > However, the project I'm working on is a multi-process  simulation
> > that runs on a dual PowerPC system.
>
> Out of curiosity, what OS are you using?

PowerMAX OS


> > I'm looking for a good reference/tutorial type book that discusses
> > real-time programming in Ada that's new to this field.
>
> I'm not aware of an Ada book specific to real-time. Chapters 17 and 18
> in Cohen's Ada as a Second Language cover a lot of the issues.
> We also have a couple of copies of A Practitioner's Handbook for
> Real-Time Analysis, which covers a lot of issues related to
> Rate-Monotonic systems in a language-neutral manner.
>
> In Ada you can make a simple rate-monotonic system by putting each
> scheduled item in its own task. Each task should set its priority
> relative to the other tasks to be the same as its iteration rate
> relative to the other tasks (using Ada.Dynamic_Priorities). A global
> package that keeps track of everyone's priority and rate (perhaps as
> read from a configuration file) can be useful for this purpose.
>
> Before its first iteration, each task should save the current value of
> Ada.Real_Time.Clock. At the end of each iteration, the task will add its
> iteration rate to the saved time, and perform a "delay until" that time.
> More sophistacted logic can be added to detect and handle overruns.

we are using IRIG time. The code was originally written in Ada83.

>
> We discovered on our project that with careful attention given to using
> standard Ada constructs rather than their OS equivalents, one can create
> an entire real-time simulation in Ada that is souce code portable to
> other OS/compiler combinations (excepting specialized hardware
> interfaces, of course).

unfortunately, we use OS calls and have an enhanced Ada83 compiler.


   For instance, when hardware availability turned
> out to be a problem, we were able to compile and test early versions of
> our entire system on NT boxes using Gnat, even though the code was
> written for the GreenHills Ada cross-compiler for vxWorks. Of course you
> don't quite get real-time performance in NT. But if we needed to change
> RTOS's or compiler vendors, it would be an almost painless process. I am
> unaware of *any* other language that could provide this.
>
> --
> T.E.D.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.






^ permalink raw reply	[relevance 0%]

Results 1-6 of 6 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
1999-10-28  0:00     GUI Design for Ada Andrew
1999-10-29  0:00  4% ` Ted Dennison
1999-10-29  0:00  0%   ` Andrew
2003-02-04 12:04  7% gnat Dynamic Priority Dispatching Anomalies Ian Broster
2003-07-23 21:24  6% Priority Ceiling Stephan Heinemann
2003-07-23 22:19  3% ` Robert I. Eachus
2007-01-07 14:28     Task Scheduling   jpluto
2007-01-07 20:47  5% ` Jeffrey Creem

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