aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/odp_cpumask.c
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@nokia.com>2015-07-09 16:46:19 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-07-23 19:21:51 +0300
commitf97e134e3c599d03d56dd6a9820442374ef2f5a3 (patch)
tree424285e0a5af72241f3c28ae2f7c87a1a69ed9be /platform/linux-generic/odp_cpumask.c
parent3ef51bf33b7e0f7595587b6946d3a692981c7535 (diff)
api: cpumask: added default masks
Added default cpumask functions for worker and control threads. These will replace odph_linux_cpumask_default() helper. CPU masks and IDs are system specific, API is generic. Signed-off-by: Petri Savolainen <petri.savolainen@nokia.com> Reviewed-by: Christophe Milard <christophe.milard@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform/linux-generic/odp_cpumask.c')
-rw-r--r--platform/linux-generic/odp_cpumask.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c
index a89c3b6..1ea7dcb 100644
--- a/platform/linux-generic/odp_cpumask.c
+++ b/platform/linux-generic/odp_cpumask.c
@@ -8,6 +8,7 @@
#define _GNU_SOURCE
#endif
#include <sched.h>
+#include <pthread.h>
#include <odp/cpumask.h>
#include <odp_debug_internal.h>
@@ -204,3 +205,40 @@ int odp_cpumask_next(const odp_cpumask_t *mask, int cpu)
return cpu;
return -1;
}
+
+int odp_cpumask_def_worker(odp_cpumask_t *mask, int num)
+{
+ int ret, 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);
+
+ /*
+ * If no user supplied number or it's too large, then attempt
+ * to use all CPUs
+ */
+ if (0 == num || CPU_SETSIZE < num)
+ num = CPU_COUNT(&cpuset);
+
+ /* build the mask, allocating down from highest numbered CPU */
+ for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
+ if (CPU_ISSET(i, &cpuset)) {
+ odp_cpumask_set(mask, i);
+ cpu++;
+ }
+ }
+
+ return cpu;
+}
+
+int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED)
+{
+ /* By default all control threads on CPU 0 */
+ odp_cpumask_set(mask, 0);
+ return 1;
+}