[API,NEXT,v6,10/14] api: cpumask: add new API odp_cpumask_all_available()

Message ID 1442495411-12362-11-git-send-email-hongbo.zhang@freescale.com
State New
Headers show

Commit Message

hongbo.zhang@freescale.com Sept. 17, 2015, 1:10 p.m.
From: Hongbo Zhang <hongbo.zhang@linaro.org>

In some cases, odp_cpu_count() isn't enough to show all the available
CPUs, so a new API odp_cpumask_all_available() is introduced, which
returns all the worker and control CPUs.

Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
---
 include/odp/api/cpumask.h                 | 10 ++++++++++
 platform/linux-generic/odp_cpumask_task.c | 11 +++++++++++
 2 files changed, 21 insertions(+)

Patch

diff --git a/include/odp/api/cpumask.h b/include/odp/api/cpumask.h
index 2ad7fea..5b458b5 100644
--- a/include/odp/api/cpumask.h
+++ b/include/odp/api/cpumask.h
@@ -218,6 +218,16 @@  int odp_cpumask_def_worker(odp_cpumask_t *mask, int num);
 int odp_cpumask_def_control(odp_cpumask_t *mask, int num);
 
 /**
+ * Report all the available CPUs
+ *
+ * All the available CPUs include both worker CPUs and control CPUs
+ *
+ * @param[out] mask    CPU mask to hold all available CPUs
+ * @return cpu number of all available CPUs
+ */
+int odp_cpumask_all_available(odp_cpumask_t *mask);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_cpumask_task.c b/platform/linux-generic/odp_cpumask_task.c
index 665e82a..9de0d71 100644
--- a/platform/linux-generic/odp_cpumask_task.c
+++ b/platform/linux-generic/odp_cpumask_task.c
@@ -50,3 +50,14 @@  int odp_cpumask_def_control(odp_cpumask_t *mask, int num ODP_UNUSED)
 	odp_cpumask_set(mask, 0);
 	return 1;
 }
+
+int odp_cpumask_all_available(odp_cpumask_t *mask)
+{
+	odp_cpumask_t mask_work, mask_ctrl;
+
+	odp_cpumask_def_worker(&mask_work, 0);
+	odp_cpumask_def_control(&mask_ctrl, 0);
+	odp_cpumask_or(mask, &mask_work, &mask_ctrl);
+
+	return odp_cpumask_count(mask);
+}