diff mbox

[PATCHv3,6/9] api: cpumask: add odp_cpumask_last

Message ID 1421275706-11176-7-git-send-email-anders.roxell@linaro.org
State Accepted
Commit f8263adac4d4610fe91f3125cd211d3726a303b1
Headers show

Commit Message

Anders Roxell Jan. 14, 2015, 10:48 p.m. UTC
From: Robbie King <robking@cisco.com>

To get the last element in order to find the highest CPU in the mask.

Signed-off-by: Robbie King <robking@cisco.com>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 platform/linux-generic/include/api/odp_cpumask.h |  7 +++++++
 platform/linux-generic/odp_cpumask.c             | 22 +++++++++++-----------
 2 files changed, 18 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_cpumask.h b/platform/linux-generic/include/api/odp_cpumask.h
index cccbb62..a81bca7 100644
--- a/platform/linux-generic/include/api/odp_cpumask.h
+++ b/platform/linux-generic/include/api/odp_cpumask.h
@@ -139,6 +139,13 @@  void odp_cpumask_copy(odp_cpumask_t *dest, const odp_cpumask_t *src);
 int odp_cpumask_first(const odp_cpumask_t *mask);
 
 /**
+ * Find last bit set in mask
+ *
+ * @return cpu else -1 if no bits set in cpumask
+ */
+int odp_cpumask_last(const odp_cpumask_t *mask);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c
index a3bb176..3930264 100644
--- a/platform/linux-generic/odp_cpumask.c
+++ b/platform/linux-generic/odp_cpumask.c
@@ -60,20 +60,10 @@  void odp_cpumask_from_str(odp_cpumask_t *mask, const char *str_in)
 	memcpy(&mask->set, &cpuset, sizeof(cpuset));
 }
 
-static int _odp_cpumask_last(const odp_cpumask_t *mask)
-{
-	int cpu;
-
-	for (cpu = CPU_SETSIZE - 1; cpu >= 0; cpu--)
-		if (odp_cpumask_isset(mask, cpu))
-			return cpu;
-	return -1;
-}
-
 void odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int len)
 {
 	char *p = str;
-	int cpu = _odp_cpumask_last(mask);
+	int cpu = odp_cpumask_last(mask);
 	int nibbles;
 	int value;
 
@@ -185,3 +175,13 @@  int odp_cpumask_first(const odp_cpumask_t *mask)
 			return cpu;
 	return -1;
 }
+
+int odp_cpumask_last(const odp_cpumask_t *mask)
+{
+	int cpu;
+
+	for (cpu = CPU_SETSIZE - 1; cpu >= 0; cpu--)
+		if (odp_cpumask_isset(mask, cpu))
+			return cpu;
+	return -1;
+}