https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122056

            Bug ID: 122056
           Summary: "raised TASKING_ERROR :
                    System.Tasking.Stages.Activate_Tasks: Failure during
                    activation" when online CPUs are not contiguous
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: simon.marchi at polymtl dot ca
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

When trying to run this program [1] from the GDB testsuite, I get:

```
$ testsuite/outputs/gdb.ada/tasks/foo 

raised TASKING_ERROR : System.Tasking.Stages.Activate_Tasks: Failure during
activation
```

I traced the problem to this code, that sets the affinity of the thread, based
on the number of CPUs.

https://github.com/gcc-mirror/gcc/blob/0088e4a419eb5cc3563a8b4b90fe71f0e33a9a84/gcc/ada/libgnarl/s-taprop__linux.adb#L995-L1020

My machine (a CI worker container started using "incus") has this special CPU
configuration:

$ nproc
8
$ cat /sys/devices/system/cpu/online
12,16,38,52,87,90,96,139

Because it sees 8 CPUs, the gcc code above creates a CPU set with bits 0-7 set.
 That CPU set is passed to pthread_create, which fails with EINVAL.  I presume,
because the CPU set is disjoint from the CPU numbers online on the machine.  I
suppose that the CPU set should instead have bits 12,16,38,52,87,90,96,139 set
instead.  Or maybe we could also not set the affinity explicitly, if the goal
is to run on all available CPUs?  I don't really know, I don't know this code.

Here are some instructions to reproduce, assuming a Ubuntu 24.04 host:

$ sudo apt install incus
$ sudo usermod -aG incus-admin smarchi  # Replace smarchi with correct user
$ newgrp incus-admin
$ incus admin init --minimal
$ incus launch images:debian/13 mycontainer
$ incus exec mycontainer -- bash

You should now be at the prompt in the container

root@mycontainer:~# apt update && apt install gnat wget
root@mycontainer:~# wget
https://gitlab.com/gnutools/binutils-gdb/-/raw/5b582f86bd7a6ece68f4a979c40faeffde9eec5e/gdb/testsuite/gdb.ada/tasks/foo.adb
...
root@mycontainer:~# gnatmake foo.adb 
x86_64-linux-gnu-gcc-14 -c foo.adb
x86_64-linux-gnu-gnatbind-14 -x foo.ali
x86_64-linux-gnu-gnatlink-14 foo.ali
root@mycontainer:~# ./foo

The above ./foo is expected to work (produce no output, exit with 0).  If you
then modify the CPUs seen by the container, like so:

$ incus config set mycontainer limits.cpu=6,8

Then in the container, you see:

root@mycontainer:~# cat /sys/devices/system/cpu/online
6,8
root@mycontainer:~# ./foo

raised TASKING_ERROR : System.Tasking.Stages.Activate_Tasks: Failure during
activation


[1]
https://gitlab.com/gnutools/binutils-gdb/-/raw/5b582f86bd7a6ece68f4a979c40faeffde9eec5e/gdb/testsuite/gdb.ada/tasks/foo.adb
  • [Bug ada/122056] New: "ra... simon.marchi at polymtl dot ca via Gcc-bugs

Reply via email to