Bug 96809 - once-test fails on systems with dynamic CPU configurations
Summary: once-test fails on systems with dynamic CPU configurations
Status: RESOLVED FIXED
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: All Linux (All)
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-04 20:52 UTC by John Paul Adrian Glaubitz
Modified: 2016-08-15 14:25 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Change pa_npcus() to call sysconf with _SC_PROCESSOR_ONLN (1.37 KB, patch)
2016-07-04 20:53 UTC, John Paul Adrian Glaubitz
Details | Splinter Review

Description John Paul Adrian Glaubitz 2016-07-04 20:52:00 UTC
Hello!

PulseAudio currently fails to build from source on sparc64 [1]:

FAIL: once-test
===============

Running suite(s): Once
0%: Checks: 1, Failures: 1, Errors: 0
tests/once-test.c:74:F:once:once_test:0: Assertion 'pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) == 0' failed
FAIL once-test (exit status: 1)

This happens because pthread_setaffinity_np() returned -EINVAL on the test system. After some debugging, it became quickly obvious why this was happening, the test tried to call the function on CPUs that were currently not present on the test system, more precisely, it tried to set the affinity on CPU 64 and higher while the machine had currently only 64 CPUs (index 0-63) online.

The reason for this is the improper use of sysconf(_SC_NPROCESSORS_CONF) in pulsecore/core-util.c:pa_ncpus() to determine the number of available CPUs which is not correct as the operating system may disable individual CPUs without this number changing. Thus, the proper call to determine the number of available CPUs is sysconf(_SC_NPROCESSORS_ONLN). This is also documented in the glibc manual in [2].

After patching pulsecore/core-util.c with the attached patch, the number of currently available CPUs is correctly detected and the once-test succeeds on the test system.

I therefore suggest applying the attached patch.

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 [3], the number of processors available to PulseAudio could be even less than the number of CPUs currently online (_SC_NPROCESSORS_CONF).

Thanks,
Adrian

> [1] https://buildd.debian.org/status/fetch.php?pkg=pulseaudio&arch=sparc64&ver=9.0-1&stamp=1467572458
> [2] https://www.gnu.org/software/libc/manual/html_node/Processor-Resources.html
> [3] http://man7.org/linux/man-pages/man7/cpuset.7.html
Comment 1 John Paul Adrian Glaubitz 2016-07-04 20:53:21 UTC
Created attachment 124897 [details] [review]
Change pa_npcus() to call sysconf with _SC_PROCESSOR_ONLN
Comment 2 Tanu Kaskinen 2016-08-15 14:25:43 UTC
Thanks! Patch applied. I edited the commit message a bit: https://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/?id=1df21e6ab6cd42e2f7601a6c5577c20b7e3d1046


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.