1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . T A S K _ I N F O --
11 -- Copyright (C) 1992-2000 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 -- This package contains the definitions and routines associated with the
37 -- implementation of the Task_Info pragma.
39 -- This is the SGI (libathread) specific version of this module.
41 with System
.OS_Interface
;
42 with Unchecked_Deallocation
;
43 package System
.Task_Info
is
44 pragma Elaborate_Body
;
45 -- To ensure that a body is allowed
47 ---------------------------------------------------------
48 -- Binding of Tasks to sprocs and sprocs to processors --
49 ---------------------------------------------------------
51 -- The SGI implementation of the GNU Low-Level Interface (GNULLI)
52 -- implements each Ada task as a Posix thread (Pthread). The SGI
53 -- Pthread library distributes threads across one or more processes
54 -- that are members of a common share group. Irix distributes
55 -- processes across the available CPUs on a given machine. The
56 -- pragma Task_Info provides the mechanism to control the distribution
57 -- of tasks to sprocs, and sprocs to processors.
59 -- Each thread has a number of attributes that dictate it's scheduling.
60 -- These attributes are:
62 -- Bound_To_Sproc: whether the thread is bound to a specific sproc
63 -- for its entire lifetime.
65 -- Timeslice: Amount of time that a thread is allowed to execute
66 -- before the system yeilds control to another thread
69 -- Resource_Vector: A bitmask used to control the binding of threads
73 -- Each share group process (sproc)
75 -- The Task_Info pragma:
77 -- pragma Task_Info (EXPRESSION);
79 -- allows the specification on a task by task basis of a value of type
80 -- System.Task_Info.Task_Info_Type to be passed to a task when it is
81 -- created. The specification of this type, and the effect on the task
82 -- that is created is target dependent.
84 -- The Task_Info pragma appears within a task definition (compare the
85 -- definition and implementation of pragma Priority). If no such pragma
86 -- appears, then the value Task_Info_Unspecified is passed. If a pragma
87 -- is present, then it supplies an alternative value. If the argument of
88 -- the pragma is a discriminant reference, then the value can be set on
89 -- a task by task basis by supplying the appropriate discriminant value.
91 -- Note that this means that the type used for Task_Info_Type must be
92 -- suitable for use as a discriminant (i.e. a scalar or access type).
94 ----------------------
95 -- Resource Vectors --
96 ----------------------
100 type Resource_Vector_T
is array (0 .. 31) of Boolean;
101 pragma Pack
(Resource_Vector_T
);
103 NO_RESOURCES
: constant Resource_Vector_T
:= (others => False);
106 type Resource_T
is (<>); -- Discrete type up to 32 entries
107 package Resource_Vector_Functions
is
108 function "+"(R
: Resource_T
)
109 return Resource_Vector_T
;
110 function "+"(R1
, R2
: Resource_T
)
111 return Resource_Vector_T
;
112 function "+"(R
: Resource_T
; S
: Resource_Vector_T
)
113 return Resource_Vector_T
;
114 function "+"(S
: Resource_Vector_T
; R
: Resource_T
)
115 return Resource_Vector_T
;
116 function "+"(S1
, S2
: Resource_Vector_T
)
117 return Resource_Vector_T
;
118 function "-"(S
: Resource_Vector_T
; R
: Resource_T
)
119 return Resource_Vector_T
;
120 end Resource_Vector_Functions
;
122 ----------------------
123 -- Sproc Attributes --
124 ----------------------
126 subtype sproc_t
is System
.OS_Interface
.sproc_t
;
128 subtype CPU_Number
is Integer range -1 .. Integer'Last;
130 ANY_CPU
: constant CPU_Number
:= CPU_Number
'First;
133 -- Specification of IRIX Non Degrading Priorities.
135 -- WARNING: IRIX priorities have the reverse meaning of Ada priorities.
136 -- The lower the priority value, the greater the greater the
137 -- scheduling preference.
139 -- See the schedctl(2) man page for a complete discussion of non-degrading
142 type Non_Degrading_Priority
is range 0 .. 255;
144 -- these priorities are higher than ALL normal user process priorities
145 NDPHIMAX
: constant Non_Degrading_Priority
:= 30;
146 NDPHIMIN
: constant Non_Degrading_Priority
:= 39;
148 subtype NDP_High
is Non_Degrading_Priority
range NDPHIMAX
.. NDPHIMIN
;
150 -- these priorities overlap normal user process priorities
151 NDPNORMMAX
: constant Non_Degrading_Priority
:= 40;
152 NDPNORMMIN
: constant Non_Degrading_Priority
:= 127;
154 subtype NDP_Norm
is Non_Degrading_Priority
range NDPNORMMAX
.. NDPNORMMIN
;
156 -- these priorities are below ALL normal user process priorities
157 NDPLOMAX
: constant Non_Degrading_Priority
:= 128;
158 NDPLOMIN
: constant Non_Degrading_Priority
:= 254;
160 NDP_NONE
: constant Non_Degrading_Priority
:= 255;
162 subtype NDP_LOW
is Non_Degrading_Priority
range NDPLOMAX
.. NDPLOMIN
;
165 (NOLOCK
, -- Do not lock pages in memory
166 PROCLOCK
, -- Lock text and data segments into memory (process lock)
167 TXTLOCK
, -- Lock text segment into memory (text lock)
168 DATLOCK
-- Lock data segment into memory (data lock)
171 type Sproc_Attributes
is
173 Sproc_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
174 CPU
: CPU_Number
:= ANY_CPU
;
175 Resident
: Page_Locking
:= NOLOCK
;
176 NDPRI
: Non_Degrading_Priority
:= NDP_NONE
;
177 -- Sproc_Slice : Duration := 0.0;
178 -- Deadline_Period : Duration := 0.0;
179 -- Deadline_Alloc : Duration := 0.0;
183 Default_Sproc_Attributes
: constant Sproc_Attributes
:=
184 (NO_RESOURCES
, ANY_CPU
, NOLOCK
, NDP_NONE
);
186 function New_Sproc
(Attr
: Sproc_Attributes
) return sproc_t
;
188 (Sproc_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
189 CPU
: CPU_Number
:= ANY_CPU
;
190 Resident
: Page_Locking
:= NOLOCK
;
191 NDPRI
: Non_Degrading_Priority
:= NDP_NONE
)
194 -- Allocates a sproc_t controll structure and creates the
195 -- corresponding sproc.
198 Invalid_CPU_Number
: exception;
199 Permission_Error
: exception;
200 Sproc_Create_Error
: exception;
202 -----------------------
203 -- Thread Attributes --
204 -----------------------
206 type Thread_Attributes
(Bound_To_Sproc
: Boolean) is
208 Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
209 Thread_Timeslice
: Duration := 0.0;
210 case Bound_To_Sproc
is
218 Default_Thread_Attributes
: constant Thread_Attributes
:=
219 (False, NO_RESOURCES
, 0.0);
221 function Unbound_Thread_Attributes
222 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
223 Thread_Timeslice
: Duration := 0.0)
224 return Thread_Attributes
;
226 function Bound_Thread_Attributes
227 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
228 Thread_Timeslice
: Duration := 0.0;
230 return Thread_Attributes
;
232 function Bound_Thread_Attributes
233 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
234 Thread_Timeslice
: Duration := 0.0;
235 Sproc_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
236 CPU
: CPU_Number
:= ANY_CPU
;
237 Resident
: Page_Locking
:= NOLOCK
;
238 NDPRI
: Non_Degrading_Priority
:= NDP_NONE
)
239 return Thread_Attributes
;
241 type Task_Info_Type
is access all Thread_Attributes
;
243 function New_Unbound_Thread_Attributes
244 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
245 Thread_Timeslice
: Duration := 0.0)
246 return Task_Info_Type
;
248 function New_Bound_Thread_Attributes
249 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
250 Thread_Timeslice
: Duration := 0.0;
252 return Task_Info_Type
;
254 function New_Bound_Thread_Attributes
255 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
256 Thread_Timeslice
: Duration := 0.0;
257 Sproc_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
258 CPU
: CPU_Number
:= ANY_CPU
;
259 Resident
: Page_Locking
:= NOLOCK
;
260 NDPRI
: Non_Degrading_Priority
:= NDP_NONE
)
261 return Task_Info_Type
;
263 type Task_Image_Type
is access String;
264 -- Used to generate a meaningful identifier for tasks that are variables
265 -- and components of variables.
267 procedure Free_Task_Image
is new
268 Unchecked_Deallocation
(String, Task_Image_Type
);
270 Unspecified_Task_Info
: constant Task_Info_Type
:= null;
272 end System
.Task_Info
;