binutils-gdb/gdb/nat
Simon Marchi 2b142a9f83 gdb/linux-nat: get core count using /sys/devices/system/cpu/possible
I get this test failure on my CI;

  FAIL: gdb.base/info-os.exp: get process list

The particularity of this setup is that builds are done in containers
who are allocated 4 CPUs on a machine that has 40.  The code in
nat/linux-osdata.c fails to properly fetch the core number for each
task.

linux_xfer_osdata_processes uses `sysconf (_SC_NPROCESSORS_ONLN)`, which
returns 4, so it allocates an array of 4 integers.  However, the core
numbers read from /proc/pid/task/tid/stat, by function
linux_common_core_of_thread, returns a value anywhere between 0 and 39.
The core numbers above 3 are therefore ignored, many processes end up
with no core value, and the regexp in the test doesn't match (it
requires an integer as the core field).

The way this the CPUs are exposed to the container is that the container
sees 40 CPUs "present" and "possible", but only 4 arbitrary CPUs
actually online:

    root@ci-node-jammy-amd64-04-08:~# cat /sys/devices/system/cpu/present
    0-39
    root@ci-node-jammy-amd64-04-08:~# cat /sys/devices/system/cpu/online
    5,11,24,31
    root@ci-node-jammy-amd64-04-08:~# cat /sys/devices/system/cpu/possible
    0-39

The solution proposed in this patch is to find out the number of
possible CPUs using /sys/devices/system/cpu/possible.  In practice, this
will probably always contain `0-N`, where N is the number of CPUs, minus
one.  But the documentation [1] doesn't such guarantee, so I'll assume
that it can contain a more complex range list such as `2,4-31,32-63`,
like the other files in that directory can have.  The solution is to
iterate over these numbers to find the highest possible CPU id, and
use that that value plus one as the size of the array to allocate.

[1] https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst

Change-Id: I7abce2e43b000c1327fa94cd7b99d46e49d7ccf3
2022-11-08 16:51:35 -05:00
..
aarch64-hw-point.c
aarch64-hw-point.h
aarch64-linux-hw-point.c
aarch64-linux-hw-point.h
aarch64-linux.c
aarch64-linux.h
aarch64-mte-linux-ptrace.c
aarch64-mte-linux-ptrace.h
aarch64-sve-linux-ptrace.c
aarch64-sve-linux-ptrace.h
aarch64-sve-linux-sigcontext.h
amd64-linux-siginfo.c
amd64-linux-siginfo.h
fork-inferior.c
fork-inferior.h
gdb_ptrace.h
gdb_thread_db.h
glibc_thread_db.h
linux-btrace.c gdb, btrace: fix family and model computation 2022-10-28 07:42:53 +02:00
linux-btrace.h
linux-namespaces.c internal_error: remove need to pass __FILE__/__LINE__ 2022-10-19 15:32:36 +01:00
linux-namespaces.h
linux-nat.h
linux-osdata.c gdb/linux-nat: get core count using /sys/devices/system/cpu/possible 2022-11-08 16:51:35 -05:00
linux-osdata.h
linux-personality.c
linux-personality.h
linux-procfs.c Constify target_pid_to_exec_file 2022-05-13 08:21:16 -06:00
linux-procfs.h Constify target_pid_to_exec_file 2022-05-13 08:21:16 -06:00
linux-ptrace.c
linux-ptrace.h
linux-waitpid.c
linux-waitpid.h
mips-linux-watch.c internal_error: remove need to pass __FILE__/__LINE__ 2022-10-19 15:32:36 +01:00
mips-linux-watch.h
netbsd-nat.c
netbsd-nat.h
ppc-linux.c
ppc-linux.h
riscv-linux-tdesc.c
riscv-linux-tdesc.h
windows-nat.c Fix Cygwin build after bcb9251f 2022-11-02 14:36:14 +00:00
windows-nat.h Use subclasses of windows_process_info 2022-06-07 11:44:53 -06:00
x86-cpuid.h
x86-dregs.c internal_error: remove need to pass __FILE__/__LINE__ 2022-10-19 15:32:36 +01:00
x86-dregs.h
x86-gcc-cpuid.h
x86-linux-dregs.c
x86-linux-dregs.h
x86-linux.c
x86-linux.h