diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2022-11-04 10:07:09 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2022-11-08 16:51:35 -0500 |
commit | 2b142a9f83f56fbbc1c9fe45f2ea19cd11db2795 (patch) | |
tree | d2b613d3533cf80c11c73930690a5272bd7153ad /gdb/language.c | |
parent | 7a283d9cf5ccf26321f33812e79cf1515288ac94 (diff) | |
download | gdb-2b142a9f83f56fbbc1c9fe45f2ea19cd11db2795.zip gdb-2b142a9f83f56fbbc1c9fe45f2ea19cd11db2795.tar.gz gdb-2b142a9f83f56fbbc1c9fe45f2ea19cd11db2795.tar.bz2 |
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
Diffstat (limited to 'gdb/language.c')
0 files changed, 0 insertions, 0 deletions