diff options
author | John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> | 2016-07-04 20:23:17 +0200 |
---|---|---|
committer | Tanu Kaskinen <tanuk@iki.fi> | 2016-08-15 17:23:36 +0300 |
commit | 1df21e6ab6cd42e2f7601a6c5577c20b7e3d1046 (patch) | |
tree | 4924a717e6d783b6847c36cd7d33458fd73110c7 | |
parent | 9e4ee38c17dfe81da2c7e40b18f3d47f8a55be80 (diff) |
core-util: Use _SC_NPROCESSORS_ONLN instead of _SC_NPROCESSORS_CONF
pa_ncpu() is supposed to report the number of processors available on
the system. For that, it currently calls sysconf(_SC_NPROCESSORS_CONF).
However, since the operating system can disable individual processors,
we should call sysconf(_SC_NPROCESSORS_ONLN) to determine the number
of processors currently available [1]. Consequently, the once-test will
fail since pthread_setaffinity_np() is called with CPUs that are
currently not available.
It might also be advisable to change the code in the future to use CPU
sets on Linux as even the suggested change is not 100% safe but at least
it improves over the existing code. If PulseAudio was to be run in a CPU
set [2], the number of processors available to PulseAudio could be even
less than the number of CPUs currently online (_SC_NPROCESSORS_CONF).
[1] https://www.gnu.org/software/libc/manual/html_node/Processor-Resources.html
[2] http://man7.org/linux/man-pages/man7/cpuset.7.html
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=96809
Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
-rw-r--r-- | src/pulsecore/core-util.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index f816da9f..f648af8a 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -3179,8 +3179,8 @@ void pa_reduce(unsigned *num, unsigned *den) { unsigned pa_ncpus(void) { long ncpus; -#ifdef _SC_NPROCESSORS_CONF - ncpus = sysconf(_SC_NPROCESSORS_CONF); +#ifdef _SC_NPROCESSORS_ONLN + ncpus = sysconf(_SC_NPROCESSORS_ONLN); #else ncpus = 1; #endif |