aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/libgnarl
diff options
context:
space:
mode:
authorRonan Desplanques <desplanques@adacore.com>2023-06-29 10:00:44 +0200
committerMarc Poulhiès <poulhies@adacore.com>2023-07-18 15:11:47 +0200
commit82ed6ed61113f110f474f7a638b7032a105a65f8 (patch)
tree1da9b721f607d72db86ddd4b0136ddec72b1e7a4 /gcc/ada/libgnarl
parentae250f9e3c6f469ff8ed6799225a7aaf6f75cce6 (diff)
downloadgcc-82ed6ed61113f110f474f7a638b7032a105a65f8.zip
gcc-82ed6ed61113f110f474f7a638b7032a105a65f8.tar.gz
gcc-82ed6ed61113f110f474f7a638b7032a105a65f8.tar.bz2
ada: Tweak CPU affinity handling on Linux
Before this patch, the run-time assumed that not specifying a CPU affinity mask when creating a thread was equivalent to specifying a CPU affinity mask that included all CPUs. As documented in the man pages for pthread_create and pthread_setaffinity_np, this assumption is incorrect: a thread created using pthread_create inherits the CPU affinity mask of the creating thread by default. There was a comment in Set_Task_Affinity that acknowledged this behavior, but the actual code made the erroneous assumption mentioned above. That assumption caused the run-time to behave incorrectly when tasks were explicity assigned to Not_A_Specific_CPU: those tasks were assigned to the same CPUs as their parents instead of being allowed to run on any CPU. This patch fixes that behavior. This patch has the negative effect of making the runtime issue sched_setaffinity syscalls that are not necessary. gcc/ada/ * libgnarl/s-taprop__linux.adb (Set_Task_Affinity, Create_Task): Tweak handling of CPU affinities.
Diffstat (limited to 'gcc/ada/libgnarl')
-rw-r--r--gcc/ada/libgnarl/s-taprop__linux.adb38
1 files changed, 7 insertions, 31 deletions
diff --git a/gcc/ada/libgnarl/s-taprop__linux.adb b/gcc/ada/libgnarl/s-taprop__linux.adb
index 821ceef..efb99b3 100644
--- a/gcc/ada/libgnarl/s-taprop__linux.adb
+++ b/gcc/ada/libgnarl/s-taprop__linux.adb
@@ -966,16 +966,7 @@ package body System.Task_Primitives.Operations is
-- Handle dispatching domains
- -- To avoid changing CPU affinities when not needed, we set the
- -- affinity only when assigning to a domain other than the default
- -- one, or when the default one has been modified.
-
- elsif T.Common.Domain /= null and then
- (T.Common.Domain /= ST.System_Domain
- or else T.Common.Domain.all /=
- [Multiprocessors.CPU'First ..
- Multiprocessors.Number_Of_CPUs => True])
- then
+ else
declare
CPUs : constant size_t :=
C.size_t (Multiprocessors.Number_Of_CPUs);
@@ -1497,17 +1488,9 @@ package body System.Task_Primitives.Operations is
-- Handle dispatching domains
- elsif T.Common.Domain /= null and then
- (T.Common.Domain /= ST.System_Domain
- or else T.Common.Domain.all /=
- [Multiprocessors.CPU'First ..
- Multiprocessors.Number_Of_CPUs => True])
- then
+ else
-- Set the affinity to all the processors belonging to the
- -- dispatching domain. To avoid changing CPU affinities when
- -- not needed, we set the affinity only when assigning to a
- -- domain other than the default one, or when the default one
- -- has been modified.
+ -- dispatching domain.
CPU_Set := CPU_ALLOC (CPUs);
System.OS_Interface.CPU_ZERO (Size, CPU_Set);
@@ -1519,18 +1502,11 @@ package body System.Task_Primitives.Operations is
end loop;
end if;
- -- We set the new affinity if needed. Otherwise, the new task
- -- will inherit its creator's CPU affinity mask (according to
- -- the documentation of pthread_setaffinity_np), which is
- -- consistent with Ada's required semantics.
-
- if CPU_Set /= null then
- Result :=
- pthread_setaffinity_np (T.Common.LL.Thread, Size, CPU_Set);
- pragma Assert (Result = 0);
+ Result :=
+ pthread_setaffinity_np (T.Common.LL.Thread, Size, CPU_Set);
+ pragma Assert (Result = 0);
- CPU_FREE (CPU_Set);
- end if;
+ CPU_FREE (CPU_Set);
end;
end if;
end Set_Task_Affinity;