fix: num_possible_cpus() with hot-unplugged CPUs
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 25 Jul 2022 18:21:12 +0000 (14:21 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Jul 2022 15:08:03 +0000 (11:08 -0400)
commitf1d40e23350c25f90cbe46afd8ca87d9b0a01cab
treec76aab1d569421931c827879a3a18b66570f1cea
parent9cafd2a88db9db1d2cf2d91ec657eb595d43337e
fix: num_possible_cpus() with hot-unplugged CPUs

We rely on sysconf(_SC_NPROCESSORS_CONF) to get the maximum possible
number of CPUs that can be attached to the system for the lifetime of an
application. We use this value to allocate an array of per-CPU buffers
that is indexed by the numerical id of the CPUs.

As such we expect that the highest possible CPU id would be one less
than the number returned by sysconf(_SC_NPROCESSORS_CONF) which is
unfortunatly not always the case and can vary across libc
implementations and versions.

Glibc up to 2.35 will count the number of "cpuX" directories in
"/sys/devices/system/cpu" which doesn't include CPUS that were
hot-unplugged.

This information is however provided by the kernel in
"/sys/devices/system/cpu/possible" in the form of a mask listing all the
CPUs that could possibly be hot-plugged in the system.

This patch changes the implementation of num_possible_cpus() to first
try parsing the possible CPU mask to extract the highest possible value
and if this fails fallback to the previous behavior.

Change-Id: I1a3cb1a446154ec443a391d6689cb7d4165726fd
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
libringbuffer/smp.c
libringbuffer/smp.h
This page took 0.025038 seconds and 4 git commands to generate.