1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . T A S K _ I N F O --
9 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package contains the definitions and routines associated with the
35 -- implementation of the Task_Info pragma.
37 -- This is the SGI (libathread) specific version of this module.
39 with System
.OS_Interface
;
40 with Unchecked_Deallocation
;
42 package System
.Task_Info
is
43 pragma Elaborate_Body
;
44 -- To ensure that a body is allowed
46 ---------------------------------------------------------
47 -- Binding of Tasks to sprocs and sprocs to processors --
48 ---------------------------------------------------------
50 -- The SGI implementation of the GNU Low-Level Interface (GNULLI)
51 -- implements each Ada task as a Posix thread (Pthread). The SGI
52 -- Pthread library distributes threads across one or more processes
53 -- that are members of a common share group. Irix distributes
54 -- processes across the available CPUs on a given machine. The
55 -- pragma Task_Info provides the mechanism to control the distribution
56 -- of tasks to sprocs, and sprocs to processors.
58 -- Each thread has a number of attributes that dictate it's scheduling.
59 -- These attributes are:
61 -- Bound_To_Sproc: whether the thread is bound to a specific sproc
62 -- for its entire lifetime.
64 -- Timeslice: Amount of time that a thread is allowed to execute
65 -- before the system yeilds control to another thread
68 -- Resource_Vector: A bitmask used to control the binding of threads
72 -- Each share group process (sproc)
74 -- The Task_Info pragma:
76 -- pragma Task_Info (EXPRESSION);
78 -- allows the specification on a task by task basis of a value of type
79 -- System.Task_Info.Task_Info_Type to be passed to a task when it is
80 -- created. The specification of this type, and the effect on the task
81 -- that is created is target dependent.
83 -- The Task_Info pragma appears within a task definition (compare the
84 -- definition and implementation of pragma Priority). If no such pragma
85 -- appears, then the value Task_Info_Unspecified is passed. If a pragma
86 -- is present, then it supplies an alternative value. If the argument of
87 -- the pragma is a discriminant reference, then the value can be set on
88 -- a task by task basis by supplying the appropriate discriminant value.
90 -- Note that this means that the type used for Task_Info_Type must be
91 -- suitable for use as a discriminant (i.e. a scalar or access type).
93 ----------------------
94 -- Resource Vectors --
95 ----------------------
99 type Resource_Vector_T
is array (0 .. 31) of Boolean;
100 pragma Pack
(Resource_Vector_T
);
102 NO_RESOURCES
: constant Resource_Vector_T
:= (others => False);
105 type Resource_T
is (<>);
106 -- Discrete type up to 32 entries
108 package Resource_Vector_Functions
is
111 return Resource_Vector_T
;
116 return Resource_Vector_T
;
120 S
: Resource_Vector_T
)
121 return Resource_Vector_T
;
124 (S
: Resource_Vector_T
;
126 return Resource_Vector_T
;
129 (S1
: Resource_Vector_T
;
130 S2
: Resource_Vector_T
)
131 return Resource_Vector_T
;
134 (S
: Resource_Vector_T
;
136 return Resource_Vector_T
;
137 end Resource_Vector_Functions
;
139 ----------------------
140 -- Sproc Attributes --
141 ----------------------
143 subtype sproc_t
is System
.OS_Interface
.sproc_t
;
145 subtype CPU_Number
is Integer range -1 .. Integer'Last;
147 ANY_CPU
: constant CPU_Number
:= CPU_Number
'First;
149 type Non_Degrading_Priority
is range 0 .. 255;
150 -- Specification of IRIX Non Degrading Priorities.
152 -- WARNING: IRIX priorities have the reverse meaning of Ada priorities.
153 -- The lower the priority value, the greater the greater the
154 -- scheduling preference.
156 -- See the schedctl(2) man page for a complete discussion of non-degrading
159 NDPHIMAX
: constant Non_Degrading_Priority
:= 30;
160 NDPHIMIN
: constant Non_Degrading_Priority
:= 39;
161 -- These priorities are higher than ALL normal user process priorities
163 subtype NDP_High
is Non_Degrading_Priority
range NDPHIMAX
.. NDPHIMIN
;
165 NDPNORMMAX
: constant Non_Degrading_Priority
:= 40;
166 NDPNORMMIN
: constant Non_Degrading_Priority
:= 127;
167 -- These priorities overlap normal user process priorities
169 subtype NDP_Norm
is Non_Degrading_Priority
range NDPNORMMAX
.. NDPNORMMIN
;
171 NDPLOMAX
: constant Non_Degrading_Priority
:= 128;
172 NDPLOMIN
: constant Non_Degrading_Priority
:= 254;
173 -- These priorities are below ALL normal user process priorities
175 NDP_NONE
: constant Non_Degrading_Priority
:= 255;
177 subtype NDP_LOW
is Non_Degrading_Priority
range NDPLOMAX
.. NDPLOMIN
;
180 (NOLOCK
, -- Do not lock pages in memory
181 PROCLOCK
, -- Lock text and data segments into memory (process lock)
182 TXTLOCK
, -- Lock text segment into memory (text lock)
183 DATLOCK
-- Lock data segment into memory (data lock)
186 type Sproc_Attributes
is record
187 Sproc_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
188 CPU
: CPU_Number
:= ANY_CPU
;
189 Resident
: Page_Locking
:= NOLOCK
;
190 NDPRI
: Non_Degrading_Priority
:= NDP_NONE
;
191 -- ??? why is that commented out, should it be removed ?
192 -- Sproc_Slice : Duration := 0.0;
193 -- Deadline_Period : Duration := 0.0;
194 -- Deadline_Alloc : Duration := 0.0;
197 Default_Sproc_Attributes
: constant Sproc_Attributes
:=
198 (NO_RESOURCES
, ANY_CPU
, NOLOCK
, NDP_NONE
);
200 function New_Sproc
(Attr
: Sproc_Attributes
) return sproc_t
;
202 (Sproc_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
203 CPU
: CPU_Number
:= ANY_CPU
;
204 Resident
: Page_Locking
:= NOLOCK
;
205 NDPRI
: Non_Degrading_Priority
:= NDP_NONE
)
207 -- Allocates a sproc_t control structure and creates the
208 -- corresponding sproc.
210 Invalid_CPU_Number
: exception;
211 Permission_Error
: exception;
212 Sproc_Create_Error
: exception;
214 -----------------------
215 -- Thread Attributes --
216 -----------------------
218 type Thread_Attributes
(Bound_To_Sproc
: Boolean) is record
219 Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
221 Thread_Timeslice
: Duration := 0.0;
223 case Bound_To_Sproc
is
231 Default_Thread_Attributes
: constant Thread_Attributes
:=
232 (False, NO_RESOURCES
, 0.0);
234 function Unbound_Thread_Attributes
235 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
236 Thread_Timeslice
: Duration := 0.0)
237 return Thread_Attributes
;
239 function Bound_Thread_Attributes
240 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
241 Thread_Timeslice
: Duration := 0.0;
243 return Thread_Attributes
;
245 function Bound_Thread_Attributes
246 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
247 Thread_Timeslice
: Duration := 0.0;
248 Sproc_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
249 CPU
: CPU_Number
:= ANY_CPU
;
250 Resident
: Page_Locking
:= NOLOCK
;
251 NDPRI
: Non_Degrading_Priority
:= NDP_NONE
)
252 return Thread_Attributes
;
254 type Task_Info_Type
is access all Thread_Attributes
;
256 function New_Unbound_Thread_Attributes
257 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
258 Thread_Timeslice
: Duration := 0.0)
259 return Task_Info_Type
;
261 function New_Bound_Thread_Attributes
262 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
263 Thread_Timeslice
: Duration := 0.0;
265 return Task_Info_Type
;
267 function New_Bound_Thread_Attributes
268 (Thread_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
269 Thread_Timeslice
: Duration := 0.0;
270 Sproc_Resources
: Resource_Vector_T
:= NO_RESOURCES
;
271 CPU
: CPU_Number
:= ANY_CPU
;
272 Resident
: Page_Locking
:= NOLOCK
;
273 NDPRI
: Non_Degrading_Priority
:= NDP_NONE
)
274 return Task_Info_Type
;
276 type Task_Image_Type
is access String;
277 -- Used to generate a meaningful identifier for tasks that are variables
278 -- and components of variables.
280 procedure Free_Task_Image
is new
281 Unchecked_Deallocation
(String, Task_Image_Type
);
283 Unspecified_Task_Info
: constant Task_Info_Type
:= null;
285 end System
.Task_Info
;