From: Robbie King <[email protected]> A default cpumask based on number of requested CPUs and bounded by number of CPUs in the system.
Signed-off-by: Robbie King <[email protected]> Signed-off-by: Anders Roxell <[email protected]> --- helper/include/odph_linux.h | 11 +++++++++++ platform/linux-generic/odp_linux.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/helper/include/odph_linux.h b/helper/include/odph_linux.h index 26ff278..6458fde 100644 --- a/helper/include/odph_linux.h +++ b/helper/include/odph_linux.h @@ -22,6 +22,7 @@ extern "C" { #endif +#include <odp.h> #include <pthread.h> #include <sys/types.h> @@ -50,6 +51,16 @@ typedef struct { int status; /**< Process state change status */ } odph_linux_process_t; +/** + * Creates default pthread/process cpumask + * + * Creates cpumask based on starting count, actual value returned + * + * @param mask CPU mask to initialize + * @param num Number of threads to create, zero for all available + * @return Actual values of CPUs used to create mask + */ +int odph_linux_cpumask_default(odp_cpumask_t *mask, int num); /** * Creates and launches pthreads diff --git a/platform/linux-generic/odp_linux.c b/platform/linux-generic/odp_linux.c index ba1da1f..a051024 100644 --- a/platform/linux-generic/odp_linux.c +++ b/platform/linux-generic/odp_linux.c @@ -25,6 +25,41 @@ #include <odp_system_info.h> #include <odp_debug_internal.h> +int odph_linux_cpumask_default(odp_cpumask_t *mask, int num_in) +{ + int i; + int first_cpu = 1; + int num = num_in; + int cpu_count; + + cpu_count = odp_sys_cpu_count(); + + /* + * If no user supplied number or it's too large, then attempt + * to use all CPUs + */ + if (0 == num) + num = cpu_count; + if (cpu_count < num) + num = cpu_count; + + /* + * Always force "first_cpu" to a valid CPU + */ + if (first_cpu >= cpu_count) + first_cpu = cpu_count - 1; + + /* Build the mask */ + odp_cpumask_zero(mask); + for (i = 0; i < num; i++) { + int cpu; + + cpu = (first_cpu + i) % cpu_count; + odp_cpumask_set(mask, cpu); + } + + return num; +} static void *odp_run_start_routine(void *arg) { -- 2.1.4 _______________________________________________ lng-odp mailing list [email protected] http://lists.linaro.org/mailman/listinfo/lng-odp
