diff options
author | Jose Ruiz <ruiz@adacore.com> | 2011-09-01 13:40:48 +0000 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2011-09-01 15:40:48 +0200 |
commit | 9d1e0e72dbd7a6cd71bd18adeb8d4c8e5cd2d86f (patch) | |
tree | 43c635534492841d32b301dc46c16759c59ad6a5 /gcc/ada/s-taprop-linux.adb | |
parent | a95be2d47a4e851e44f04765e549e34c43b2f006 (diff) | |
download | gcc-9d1e0e72dbd7a6cd71bd18adeb8d4c8e5cd2d86f.tar.gz |
adaint.c, adaint.h (__gnat_cpu_alloc, [...]): Create these wrappers around the CPU_ALLOC...
2011-09-01 Jose Ruiz <ruiz@adacore.com>
* adaint.c, adaint.h (__gnat_cpu_alloc, __gnat_cpu_alloc_size,
__gnat_cpu_set_free): Create these wrappers around the CPU_ALLOC,
CPU_ALLOC_SIZE and CPU_FREE linux macros.
(__gnat_cpu_zero, __gnat_cpu_set): Use the CPU_ZERO_S and
CPU_SET_S respectively because we are now using dynamically allocated
CPU sets which are more portable across different glibc versions.
* s-osinte-linux.ads (cpu_set_t_ptr, CPU_ALLOC, CPU_ALLOC_SIZE,
CPU_FREE): Add this type and subprograms to be able to create cpu_set_t
masks dynamically according to the number of processors in the target
platform.
(CPU_ZERO, CPU_SET): They are now mapped to the CPU_ZERO_S and CPU_SET_S
respectively, so we need to pass the size of the masks as
parameters.
* s-taprop-linux.adb (Create_Task, Set_Task_Affinity): Use dynamically
created cpu_set_t masks
with the number of processors available in the target platform,
instead of static bit arrays. It enhances portability because
it uses the information from the target platform.
* sem_ch8.adb: (Attribute_Renaming): When checking whether we
are using a restricted run-time library, use the flag
Configurable_Run_Time_Mode instead of Restricted_Profile.
From-SVN: r178416
Diffstat (limited to 'gcc/ada/s-taprop-linux.adb')
-rw-r--r-- | gcc/ada/s-taprop-linux.adb | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/gcc/ada/s-taprop-linux.adb b/gcc/ada/s-taprop-linux.adb index eced89a051f..20345666683 100644 --- a/gcc/ada/s-taprop-linux.adb +++ b/gcc/ada/s-taprop-linux.adb @@ -869,25 +869,25 @@ package body System.Task_Primitives.Operations is elsif T.Common.Base_CPU /= System.Multiprocessors.Not_A_Specific_CPU then declare - CPU_Set : aliased cpu_set_t; + CPUs : constant size_t := + Interfaces.C.size_t (System.Multiprocessors.Number_Of_CPUs); + CPU_Set : constant cpu_set_t_ptr := CPU_ALLOC (CPUs); + Size : constant size_t := CPU_ALLOC_SIZE (CPUs); begin - System.OS_Interface.CPU_ZERO (CPU_Set'Access); + CPU_ZERO (Size, CPU_Set); System.OS_Interface.CPU_SET - (int (T.Common.Base_CPU), CPU_Set'Access); + (int (T.Common.Base_CPU), Size, CPU_Set); Result := - pthread_attr_setaffinity_np - (Attributes'Access, - CPU_SETSIZE / 8, - CPU_Set'Access); + pthread_attr_setaffinity_np (Attributes'Access, Size, CPU_Set); pragma Assert (Result = 0); + + CPU_FREE (CPU_Set); end; -- Handle Task_Info - elsif T.Common.Task_Info /= null - and then T.Common.Task_Info.CPU_Affinity /= Task_Info.Any_CPU - then + elsif T.Common.Task_Info /= null then Result := pthread_attr_setaffinity_np (Attributes'Access, @@ -908,26 +908,28 @@ package body System.Task_Primitives.Operations is Multiprocessors.Number_Of_CPUs => True)) then declare - CPU_Set : aliased cpu_set_t; + CPUs : constant size_t := + Interfaces.C.size_t (System.Multiprocessors.Number_Of_CPUs); + CPU_Set : constant cpu_set_t_ptr := CPU_ALLOC (CPUs); + Size : constant size_t := CPU_ALLOC_SIZE (CPUs); begin - System.OS_Interface.CPU_ZERO (CPU_Set'Access); + CPU_ZERO (Size, CPU_Set); -- Set the affinity to all the processors belonging to the -- dispatching domain. for Proc in T.Common.Domain'Range loop if T.Common.Domain (Proc) then - System.OS_Interface.CPU_SET (int (Proc), CPU_Set'Access); + System.OS_Interface.CPU_SET (int (Proc), Size, CPU_Set); end if; end loop; Result := - pthread_attr_setaffinity_np - (Attributes'Access, - CPU_SETSIZE / 8, - CPU_Set'Access); + pthread_attr_setaffinity_np (Attributes'Access, Size, CPU_Set); pragma Assert (Result = 0); + + CPU_FREE (CPU_Set); end; end if; @@ -1400,9 +1402,10 @@ package body System.Task_Primitives.Operations is and then T.Common.LL.Thread /= Null_Thread_Id then declare - type cpu_set_t_ptr is access all cpu_set_t; - CPU_Set : aliased cpu_set_t; - CPU_Set_Ptr : cpu_set_t_ptr := null; + CPUs : constant size_t := + Interfaces.C.size_t (System.Multiprocessors.Number_Of_CPUs); + CPU_Set : cpu_set_t_ptr := null; + Size : constant size_t := CPU_ALLOC_SIZE (CPUs); Result : Interfaces.C.int; @@ -1414,17 +1417,16 @@ package body System.Task_Primitives.Operations is if T.Common.Base_CPU /= Multiprocessors.Not_A_Specific_CPU then -- Set the affinity to an unique CPU - System.OS_Interface.CPU_ZERO (CPU_Set'Access); + + CPU_Set := CPU_ALLOC (CPUs); + System.OS_Interface.CPU_ZERO (Size, CPU_Set); System.OS_Interface.CPU_SET - (int (T.Common.Base_CPU), CPU_Set'Access); - CPU_Set_Ptr := CPU_Set'Access; + (int (T.Common.Base_CPU), Size, CPU_Set); -- Handle Task_Info - elsif T.Common.Task_Info /= null - and then T.Common.Task_Info.CPU_Affinity /= Task_Info.Any_CPU - then - CPU_Set_Ptr := T.Common.Task_Info.CPU_Affinity'Access; + elsif T.Common.Task_Info /= null then + CPU_Set := T.Common.Task_Info.CPU_Affinity'Access; -- Handle dispatching domains @@ -1440,13 +1442,12 @@ package body System.Task_Primitives.Operations is -- domain other than the default one, or when the default one -- has been modified. - System.OS_Interface.CPU_ZERO (CPU_Set'Access); + CPU_Set := CPU_ALLOC (CPUs); + System.OS_Interface.CPU_ZERO (Size, CPU_Set); for Proc in T.Common.Domain'Range loop - System.OS_Interface.CPU_SET (int (Proc), CPU_Set'Access); + System.OS_Interface.CPU_SET (int (Proc), Size, CPU_Set); end loop; - - CPU_Set_Ptr := CPU_Set'Access; end if; -- We set the new affinity if needed. Otherwise, the new task @@ -1454,11 +1455,12 @@ package body System.Task_Primitives.Operations is -- the documentation of pthread_setaffinity_np), which is -- consistent with Ada's required semantics. - if CPU_Set_Ptr /= null then + if CPU_Set /= null then Result := - pthread_setaffinity_np - (T.Common.LL.Thread, CPU_SETSIZE / 8, CPU_Set_Ptr); + pthread_setaffinity_np (T.Common.LL.Thread, Size, CPU_Set); pragma Assert (Result = 0); + + CPU_FREE (CPU_Set); end if; end; end if; |