aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic
diff options
context:
space:
mode:
authorStuart Haslam <stuart.haslam@linaro.org>2015-04-02 16:21:59 +0100
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-05-08 13:16:56 +0300
commit03caea94f5675c55db7ba6c33b9a03fe4da519e4 (patch)
tree8bcc04e786dd8f0834457edf681c0196ff34c5ac /platform/linux-generic
parent7844f011b5f70d18769a9af47dab86d09831c9ac (diff)
linux-generic: support running with restricted cpu set
odp_cpu_count() returns the number of online CPUs, but when running in a control group access may be restricted to only a subset of these. This combined with a lack of error handling in odph_linux_pthread_create() means a number of the applications create more threads than there are cores available to them, leading to deadlocks in odp_barrier_wait(). Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org> Reviewed-and-tested-by: Mike Holmes <mike.holmes@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform/linux-generic')
-rw-r--r--platform/linux-generic/odp_system_info.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 077e01529..31df29ed4 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -4,11 +4,14 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
+#define _GNU_SOURCE
#include <odp/system_info.h>
#include <odp_internal.h>
#include <odp_debug_internal.h>
#include <odp/align.h>
#include <odp/cpu.h>
+#include <pthread.h>
+#include <sched.h>
#include <string.h>
#include <stdio.h>
@@ -35,20 +38,21 @@ typedef struct {
/*
- * Report the number of online CPU's
+ * Report the number of CPUs in the affinity mask of the main thread
*/
static int sysconf_cpu_count(void)
{
- long ret;
+ cpu_set_t cpuset;
+ int ret;
- ret = sysconf(_SC_NPROCESSORS_ONLN);
- if (ret < 0)
+ ret = pthread_getaffinity_np(pthread_self(),
+ sizeof(cpuset), &cpuset);
+ if (ret != 0)
return 0;
- return (int)ret;
+ return CPU_COUNT(&cpuset);
}
-
#if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \
defined __powerpc__
/*