diff options
-rw-r--r-- | platform/linux-generic/include/odp_internal.h | 2 | ||||
-rw-r--r-- | platform/linux-generic/odp_cpumask_task.c | 9 | ||||
-rw-r--r-- | platform/linux-generic/odp_system_info.c | 21 | ||||
-rw-r--r-- | platform/linux-keystone2/include/odp_internal.h | 2 |
4 files changed, 22 insertions, 12 deletions
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index cd0d35a2..3e402906 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -20,6 +20,7 @@ extern "C" { #include <odp/init.h> #include <odp/thread.h> +#include <sched.h> extern __thread int __odp_errno; @@ -51,6 +52,7 @@ int _odp_term_local(enum init_stage stage); int odp_system_info_init(void); int odp_system_info_term(void); +cpu_set_t _odp_cpuset(void); int odp_thread_init_global(void); int odp_thread_init_local(odp_thread_type_t type); diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c index 41f2bc94..43a5281d 100644 --- a/platform/linux-generic/odp_cpumask_task.c +++ b/platform/linux-generic/odp_cpumask_task.c @@ -10,19 +10,16 @@ #include <pthread.h> #include <odp/cpumask.h> +#include <odp_internal.h> #include <odp_debug_internal.h> int odp_cpumask_default_worker(odp_cpumask_t *mask, int num) { - int ret, cpu, i; + int cpu, i; cpu_set_t cpuset; - ret = pthread_getaffinity_np(pthread_self(), - sizeof(cpu_set_t), &cpuset); - if (ret != 0) - ODP_ABORT("failed to read CPU affinity value\n"); - odp_cpumask_zero(mask); + cpuset = _odp_cpuset(); /* * If no user supplied number or it's too large, then attempt diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 1e234f19..c4a56535 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -31,6 +31,7 @@ typedef struct { int cache_line_size; int cpu_count; char model_str[128]; + cpu_set_t cpuset; } odp_system_info_t; @@ -52,17 +53,20 @@ static odp_system_info_t odp_system_info; /* * Report the number of CPUs in the affinity mask of the main thread */ -static int sysconf_cpu_count(void) +static int sysconf_cpu_count(cpu_set_t *cpuset) { - cpu_set_t cpuset; + cpu_set_t tmp; int ret; + CPU_ZERO(&tmp); ret = pthread_getaffinity_np(pthread_self(), - sizeof(cpuset), &cpuset); + sizeof(cpuset), &tmp); if (ret != 0) return 0; - return CPU_COUNT(&cpuset); + *cpuset = tmp; + + return CPU_COUNT(cpuset); } #if defined __x86_64__ || defined __i386__ || defined __OCTEON__ || \ @@ -293,7 +297,7 @@ static int systemcpu(odp_system_info_t *sysinfo) { int ret; - ret = sysconf_cpu_count(); + ret = sysconf_cpu_count(&sysinfo->cpuset); if (ret == 0) { ODP_ERR("sysconf_cpu_count failed.\n"); return -1; @@ -331,7 +335,7 @@ static int systemcpu(odp_system_info_t *sysinfo) { int ret; - ret = sysconf_cpu_count(); + ret = sysconf_cpu_count(&sysinfo->cpuset); if (ret == 0) { ODP_ERR("sysconf_cpu_count failed.\n"); return -1; @@ -381,6 +385,11 @@ int odp_system_info_init(void) return 0; } +cpu_set_t _odp_cpuset(void) +{ + return odp_system_info.cpuset; +} + /* * System info termination */ diff --git a/platform/linux-keystone2/include/odp_internal.h b/platform/linux-keystone2/include/odp_internal.h index 54c2585f..897366dd 100644 --- a/platform/linux-keystone2/include/odp_internal.h +++ b/platform/linux-keystone2/include/odp_internal.h @@ -20,6 +20,7 @@ extern "C" { #endif #include <odp/thread.h> +#include <sched.h> extern __thread int __odp_errno; @@ -44,6 +45,7 @@ int _odp_term_global(enum init_stage stage); int odp_system_info_init(void); int odp_system_info_term(void); +cpu_set_t _odp_cpuset(void); int odp_thread_init_global(void); int odp_thread_init_local(odp_thread_type_t type); |