DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function
@ 2018-12-11 17:57 Anatoly Burakov
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 2/6] common: add bsf64 function similar to existing bsf32 Anatoly Burakov
                   ` (9 more replies)
  0 siblings, 10 replies; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-11 17:57 UTC (permalink / raw)
  To: dev
  Cc: Neil Horman, John McNamara, Marko Kovacevic, Cristian Dumitrescu,
	thomas, jasvinder.singh, jerin.jacob

The function rte_bsf64 was deprecated in a previous release, so
remove the function, and the deprecation notice associated with
it.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 doc/guides/rel_notes/deprecation.rst       | 5 -----
 doc/guides/rel_notes/release_19_02.rst     | 4 ++++
 lib/librte_eal/common/include/rte_bitmap.h | 6 ------
 3 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index b48486d36..aa96d9b19 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -20,11 +20,6 @@ Deprecation Notices
 * kvargs: The function ``rte_kvargs_process`` will get a new parameter
   for returning key match count. It will ease handling of no-match case.
 
-* eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to
-  ``rte_bsf64_safe`` and moved to ``rte_common.h``. A new ``rte_bsf64`` function
-  will be added in the next release in ``rte_common.h`` that follows convention
-  set by existing ``rte_bsf32`` function.
-
 * eal: both declaring and identifying devices will be streamlined in v18.11.
   New functions will appear to query a specific port from buses, classes of
   device and device drivers. Device declaration will be made coherent with the
diff --git a/doc/guides/rel_notes/release_19_02.rst b/doc/guides/rel_notes/release_19_02.rst
index a94fa86a7..ff81357d4 100644
--- a/doc/guides/rel_notes/release_19_02.rst
+++ b/doc/guides/rel_notes/release_19_02.rst
@@ -84,6 +84,10 @@ API Changes
    =========================================================
 
 
+* eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to
+  ``rte_bsf64_safe`` and moved to ``rte_common.h``.
+
+
 ABI Changes
 -----------
 
diff --git a/lib/librte_eal/common/include/rte_bitmap.h b/lib/librte_eal/common/include/rte_bitmap.h
index 77727c828..6b846f251 100644
--- a/lib/librte_eal/common/include/rte_bitmap.h
+++ b/lib/librte_eal/common/include/rte_bitmap.h
@@ -93,12 +93,6 @@ __rte_bitmap_index2_set(struct rte_bitmap *bmp)
 	bmp->index2 = (((bmp->index1 << RTE_BITMAP_SLAB_BIT_SIZE_LOG2) + bmp->offset1) << RTE_BITMAP_CL_SLAB_SIZE_LOG2);
 }
 
-static inline int __rte_deprecated
-rte_bsf64(uint64_t slab, uint32_t *pos)
-{
-	return rte_bsf64_safe(slab, pos);
-}
-
 static inline uint32_t
 __rte_bitmap_get_memory_footprint(uint32_t n_bits,
 	uint32_t *array1_byte_offset, uint32_t *array1_slabs,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH 2/6] common: add bsf64 function similar to existing bsf32
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
@ 2018-12-11 17:57 ` Anatoly Burakov
  2018-12-20  9:08   ` Thomas Monjalon
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 3/6] common: add missing implementations Anatoly Burakov
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-11 17:57 UTC (permalink / raw)
  To: dev
  Cc: John McNamara, Marko Kovacevic, thomas, jasvinder.singh,
	cristian.dumitrescu, jerin.jacob

Implement a new rte_bsf64 function that is following convention
set by existing rte_bsf32 function. Also, document the change in
release notes.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 doc/guides/rel_notes/release_19_02.rst     |  4 +++-
 lib/librte_eal/common/include/rte_common.h | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/doc/guides/rel_notes/release_19_02.rst b/doc/guides/rel_notes/release_19_02.rst
index ff81357d4..1d56ad43e 100644
--- a/doc/guides/rel_notes/release_19_02.rst
+++ b/doc/guides/rel_notes/release_19_02.rst
@@ -85,7 +85,9 @@ API Changes
 
 
 * eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to
-  ``rte_bsf64_safe`` and moved to ``rte_common.h``.
+  ``rte_bsf64_safe`` and moved to ``rte_common.h``. A new ``rte_bsf64`` function
+  has been added in ``rte_common.h`` that follows convention set by existing
+  ``rte_bsf32`` function.
 
 
 ABI Changes
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 66cdf60b2..2735dcca7 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -482,6 +482,23 @@ rte_fls_u32(uint32_t x)
 	return (x == 0) ? 0 : 32 - __builtin_clz(x);
 }
 
+/**
+ * Searches the input parameter for the least significant set bit
+ * (starting from zero).
+ * If a least significant 1 bit is found, its bit index is returned.
+ * If the content of the input parameter is zero, then the content of the return
+ * value is undefined.
+ * @param v
+ *     input parameter, should not be zero.
+ * @return
+ *     least significant set bit in the input parameter.
+ */
+static inline int
+rte_bsf64(uint64_t v)
+{
+	return (uint32_t)__builtin_ctzll(v);
+}
+
 /**
  * Searches the input parameter for the least significant set bit
  * (starting from zero). Safe version (checks for input parameter being zero).
@@ -502,7 +519,7 @@ rte_bsf64_safe(uint64_t v, uint32_t *pos)
 	if (v == 0)
 		return 0;
 
-	*pos = __builtin_ctzll(v);
+	*pos = rte_bsf64(v);
 	return 1;
 }
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH 3/6] common: add missing implementations
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 2/6] common: add bsf64 function similar to existing bsf32 Anatoly Burakov
@ 2018-12-11 17:57 ` Anatoly Burakov
  2018-12-20  9:09   ` Thomas Monjalon
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 4/6] memalloc: use library implementation of 64-bit log2 Anatoly Burakov
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-11 17:57 UTC (permalink / raw)
  To: dev; +Cc: thomas, jasvinder.singh, cristian.dumitrescu, jerin.jacob

Implement missing functions for 32-bit safe bsf, as well as 64-bit
fls and log2.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---

Notes:
    v4:
    - Fixed to use proper rte_bsf64
    
    v3:
    - Added clarification that pos is not checked

 lib/librte_eal/common/include/rte_common.h | 62 +++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 2735dcca7..4bbfef7a0 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -447,6 +447,30 @@ rte_bsf32(uint32_t v)
 	return (uint32_t)__builtin_ctz(v);
 }
 
+/**
+ * Searches the input parameter for the least significant set bit
+ * (starting from zero). Safe version (checks for input parameter being zero).
+ *
+ * @warning ``pos`` must be a valid pointer. It is not checked!
+ *
+ * @param v
+ *     The input parameter.
+ * @param pos
+ *     If ``v`` was not 0, this value will contain position of least significant
+ *     bit within the input parameter.
+ * @return
+ *     Returns 0 if ``v`` was 0, otherwise returns 1.
+ */
+static inline int
+rte_bsf32_safe(uint64_t v, uint32_t *pos)
+{
+	if (v == 0)
+		return 0;
+
+	*pos = rte_bsf32(v);
+	return 1;
+}
+
 /**
  * Return the rounded-up log2 of a integer.
  *
@@ -464,7 +488,6 @@ rte_log2_u32(uint32_t v)
 	return rte_bsf32(v);
 }
 
-
 /**
  * Return the last (most-significant) bit set.
  *
@@ -523,6 +546,43 @@ rte_bsf64_safe(uint64_t v, uint32_t *pos)
 	return 1;
 }
 
+/**
+ * Return the last (most-significant) bit set.
+ *
+ * @note The last (most significant) bit is at position 64.
+ * @note rte_fls_u64(0) = 0, rte_fls_u64(1) = 1,
+ *       rte_fls_u64(0x8000000000000000) = 64
+ *
+ * @param x
+ *     The input parameter.
+ * @return
+ *     The last (most-significant) bit set, or 0 if the input is 0.
+ */
+static inline int
+rte_fls_u64(uint64_t x)
+{
+	return (x == 0) ? 0 : 64 - __builtin_clzll(x);
+}
+
+/**
+ * Return the rounded-up log2 of a 64-bit integer.
+ *
+ * @param v
+ *     The input parameter.
+ * @return
+ *     The rounded-up log2 of the input, or 0 if the input is 0.
+ */
+static inline uint32_t
+rte_log2_u64(uint64_t v)
+{
+	if (v == 0)
+		return 0;
+	v = rte_align64pow2(v);
+	/* we checked for v being 0 already, so no undefined behavior */
+	return rte_bsf64(v);
+}
+
+
 #ifndef offsetof
 /** Return the offset of a field in a structure. */
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH 4/6] memalloc: use library implementation of 64-bit log2
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 2/6] common: add bsf64 function similar to existing bsf32 Anatoly Burakov
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 3/6] common: add missing implementations Anatoly Burakov
@ 2018-12-11 17:57 ` Anatoly Burakov
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 5/6] testpmd: " Anatoly Burakov
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-11 17:57 UTC (permalink / raw)
  To: dev; +Cc: thomas, jasvinder.singh, cristian.dumitrescu, jerin.jacob

Remove duplicated code and use library version of 64-bit log2.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memalloc.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index 784939566..6e6af5b06 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -208,28 +208,13 @@ get_file_size(int fd)
 	return st.st_size;
 }
 
-static inline uint32_t
-bsf64(uint64_t v)
-{
-	return (uint32_t)__builtin_ctzll(v);
-}
-
-static inline uint32_t
-log2_u64(uint64_t v)
-{
-	if (v == 0)
-		return 0;
-	v = rte_align64pow2(v);
-	return bsf64(v);
-}
-
 static int
 pagesz_flags(uint64_t page_sz)
 {
 	/* as per mmap() manpage, all page sizes are log2 of page size
 	 * shifted by MAP_HUGE_SHIFT
 	 */
-	int log2 = log2_u64(page_sz);
+	int log2 = rte_log2_u64(page_sz);
 	return log2 << RTE_MAP_HUGE_SHIFT;
 }
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH 5/6] testpmd: use library implementation of 64-bit log2
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
                   ` (2 preceding siblings ...)
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 4/6] memalloc: use library implementation of 64-bit log2 Anatoly Burakov
@ 2018-12-11 17:57 ` Anatoly Burakov
  2018-12-12 11:22   ` Iremonger, Bernard
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 6/6] test/common: extend autotest to newly added functions Anatoly Burakov
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-11 17:57 UTC (permalink / raw)
  To: dev
  Cc: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, thomas,
	jasvinder.singh, cristian.dumitrescu, jerin.jacob

Remove duplicated code and use library version of 64-bit log2.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 app/test-pmd/testpmd.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 4c75587d0..0c75e123b 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -649,28 +649,13 @@ calc_mem_size(uint32_t nb_mbufs, uint32_t mbuf_sz, size_t pgsz, size_t *out)
 	return 0;
 }
 
-static inline uint32_t
-bsf64(uint64_t v)
-{
-	return (uint32_t)__builtin_ctzll(v);
-}
-
-static inline uint32_t
-log2_u64(uint64_t v)
-{
-	if (v == 0)
-		return 0;
-	v = rte_align64pow2(v);
-	return bsf64(v);
-}
-
 static int
 pagesz_flags(uint64_t page_sz)
 {
 	/* as per mmap() manpage, all page sizes are log2 of page size
 	 * shifted by MAP_HUGE_SHIFT
 	 */
-	int log2 = log2_u64(page_sz);
+	int log2 = rte_log2_u64(page_sz);
 
 	return (log2 << HUGE_SHIFT);
 }
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH 6/6] test/common: extend autotest to newly added functions
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
                   ` (3 preceding siblings ...)
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 5/6] testpmd: " Anatoly Burakov
@ 2018-12-11 17:57 ` Anatoly Burakov
  2018-12-20 12:07 ` [dpdk-dev] [PATCH v2] common: add 64-bit log2 function Anatoly Burakov
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-11 17:57 UTC (permalink / raw)
  To: dev; +Cc: thomas, jasvinder.singh, cristian.dumitrescu, jerin.jacob

Add a new autotest for bsf32, bsf64, bsf32_safe and bsf64_safe
functions, and extend existing fls and log2 autotests to also
cover 64-bit versions.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 test/test/test_common.c | 82 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 79 insertions(+), 3 deletions(-)

diff --git a/test/test/test_common.c b/test/test/test_common.c
index c6d17baae..94d367471 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -50,12 +50,48 @@ test_macros(int __rte_unused unused_parm)
 	return 0;
 }
 
+static int
+test_bsf(void)
+{
+	uint32_t shift, pos;
+
+	/* safe versions should be able to handle 0 */
+	if (rte_bsf32_safe(0, &pos) != 0)
+		FAIL("rte_bsf32_safe");
+	if (rte_bsf64_safe(0, &pos) != 0)
+		FAIL("rte_bsf64_safe");
+
+	for (shift = 0; shift < 63; shift++) {
+		uint32_t val32;
+		uint64_t val64;
+
+		val64 = 1ULL << shift;
+		if ((uint32_t)rte_bsf64(val64) != shift)
+			FAIL("rte_bsf64");
+		if (rte_bsf64_safe(val64, &pos) != 1)
+			FAIL("rte_bsf64_safe");
+		if (pos != shift)
+			FAIL("rte_bsf64_safe");
+
+		if (shift > 31)
+			continue;
+
+		val32 = 1U << shift;
+		if ((uint32_t)rte_bsf32(val32) != shift)
+			FAIL("rte_bsf32");
+		if (rte_bsf32_safe(val32, &pos) != 1)
+			FAIL("rte_bsf32_safe");
+		if (pos != shift)
+			FAIL("rte_bsf32_safe");
+	}
+
+	return 0;
+}
+
 static int
 test_misc(void)
 {
 	char memdump[] = "memdump_test";
-	if (rte_bsf32(129))
-		FAIL("rte_bsf32");
 
 	rte_memdump(stdout, "test", memdump, sizeof(memdump));
 	rte_hexdump(stdout, "test", memdump, sizeof(memdump));
@@ -177,13 +213,31 @@ test_log2(void)
 	const uint32_t step = 1;
 
 	for (i = 0; i < max; i = i + step) {
+		uint64_t i64;
+
+		/* extend range for 64-bit */
+		i64 = (uint64_t)i << 32;
+		base = (uint32_t)ceilf(log2(i64));
+		compare = rte_log2_u64(i64);
+		if (base != compare) {
+			printf("Wrong rte_log2_u64(%" PRIx64 ") val %x, expected %x\n",
+				i64, compare, base);
+			return TEST_FAILED;
+		}
+
 		base = (uint32_t)ceilf(log2((uint32_t)i));
-		compare = rte_log2_u32(i);
+		compare = rte_log2_u32((uint32_t)i);
 		if (base != compare) {
 			printf("Wrong rte_log2_u32(%x) val %x, expected %x\n",
 				i, compare, base);
 			return TEST_FAILED;
 		}
+		compare = rte_log2_u64((uint64_t)i);
+		if (base != compare) {
+			printf("Wrong rte_log2_u64(%x) val %x, expected %x\n",
+				i, compare, base);
+			return TEST_FAILED;
+		}
 	}
 	return 0;
 }
@@ -206,6 +260,8 @@ test_fls(void)
 	};
 
 	for (i = 0; i < RTE_DIM(test); i++) {
+		uint64_t arg64;
+
 		arg = test[i].arg;
 		rc = rte_fls_u32(arg);
 		expected = test[i].rc;
@@ -214,6 +270,25 @@ test_fls(void)
 				arg, rc, expected);
 			return TEST_FAILED;
 		}
+		/* 64-bit version */
+		arg = test[i].arg;
+		rc = rte_fls_u64(arg);
+		expected = test[i].rc;
+		if (rc != expected) {
+			printf("Wrong rte_fls_u64(0x%x) rc=%d, expected=%d\n",
+				arg, rc, expected);
+			return TEST_FAILED;
+		}
+		/* 64-bit version shifted by 32 bits */
+		arg64 = (uint64_t)test[i].arg << 32;
+		rc = rte_fls_u64(arg64);
+		/* don't shift zero */
+		expected = test[i].rc == 0 ? 0 : test[i].rc + 32;
+		if (rc != expected) {
+			printf("Wrong rte_fls_u64(0x%" PRIx64 ") rc=%d, expected=%d\n",
+				arg64, rc, expected);
+			return TEST_FAILED;
+		}
 	}
 
 	return 0;
@@ -226,6 +301,7 @@ test_common(void)
 	ret |= test_align();
 	ret |= test_macros(0);
 	ret |= test_misc();
+	ret |= test_bsf();
 	ret |= test_log2();
 	ret |= test_fls();
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 5/6] testpmd: use library implementation of 64-bit log2
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 5/6] testpmd: " Anatoly Burakov
@ 2018-12-12 11:22   ` Iremonger, Bernard
  0 siblings, 0 replies; 18+ messages in thread
From: Iremonger, Bernard @ 2018-12-12 11:22 UTC (permalink / raw)
  To: Burakov, Anatoly, dev
  Cc: Lu, Wenzhuo, Wu, Jingjing, thomas, Singh, Jasvinder, Dumitrescu,
	Cristian, jerin.jacob


> -----Original Message-----
> From: Burakov, Anatoly
> Sent: Tuesday, December 11, 2018 5:57 PM
> To: dev@dpdk.org
> Cc: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Wu, Jingjing
> <jingjing.wu@intel.com>; Iremonger, Bernard <bernard.iremonger@intel.com>;
> thomas@monjalon.net; Singh, Jasvinder <jasvinder.singh@intel.com>;
> Dumitrescu, Cristian <cristian.dumitrescu@intel.com>;
> jerin.jacob@caviumnetworks.com
> Subject: [PATCH 5/6] testpmd: use library implementation of 64-bit log2
> 
> Remove duplicated code and use library version of 64-bit log2.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---

./devtools/check-git-log.sh -1
Wrong headline label:
        testpmd: use library implementation of 64-bit log2

Should be app/testpmd:

Otherwise

Acked-by: Bernard Iremonger <ernard.iremonger@intel.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 2/6] common: add bsf64 function similar to existing bsf32
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 2/6] common: add bsf64 function similar to existing bsf32 Anatoly Burakov
@ 2018-12-20  9:08   ` Thomas Monjalon
  0 siblings, 0 replies; 18+ messages in thread
From: Thomas Monjalon @ 2018-12-20  9:08 UTC (permalink / raw)
  To: Anatoly Burakov
  Cc: dev, John McNamara, Marko Kovacevic, jasvinder.singh,
	cristian.dumitrescu, jerin.jacob

11/12/2018 18:57, Anatoly Burakov:
> Implement a new rte_bsf64 function that is following convention
> set by existing rte_bsf32 function. Also, document the change in
> release notes.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>  doc/guides/rel_notes/release_19_02.rst     |  4 +++-
>  lib/librte_eal/common/include/rte_common.h | 19 ++++++++++++++++++-
>  2 files changed, 21 insertions(+), 2 deletions(-)

Could remove here the implementations in eal_memalloc.c and testpmd?
You could also update the test in this patch.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 3/6] common: add missing implementations
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 3/6] common: add missing implementations Anatoly Burakov
@ 2018-12-20  9:09   ` Thomas Monjalon
  2018-12-20  9:16     ` Burakov, Anatoly
  0 siblings, 1 reply; 18+ messages in thread
From: Thomas Monjalon @ 2018-12-20  9:09 UTC (permalink / raw)
  To: Anatoly Burakov; +Cc: dev, jasvinder.singh, cristian.dumitrescu, jerin.jacob

11/12/2018 18:57, Anatoly Burakov:
> Implement missing functions for 32-bit safe bsf, as well as 64-bit
> fls and log2.

It would be better to make 3 patches, for each function,
updating eal_memalloc.c, testpmd and tests at the same time.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 3/6] common: add missing implementations
  2018-12-20  9:09   ` Thomas Monjalon
@ 2018-12-20  9:16     ` Burakov, Anatoly
  0 siblings, 0 replies; 18+ messages in thread
From: Burakov, Anatoly @ 2018-12-20  9:16 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, jasvinder.singh, cristian.dumitrescu, jerin.jacob

On 20-Dec-18 9:09 AM, Thomas Monjalon wrote:
> 11/12/2018 18:57, Anatoly Burakov:
>> Implement missing functions for 32-bit safe bsf, as well as 64-bit
>> fls and log2.
> 
> It would be better to make 3 patches, for each function,
> updating eal_memalloc.c, testpmd and tests at the same time.
> 

Sure, will respin.

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v2] common: add 64-bit log2 function
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
                   ` (4 preceding siblings ...)
  2018-12-11 17:57 ` [dpdk-dev] [PATCH 6/6] test/common: extend autotest to newly added functions Anatoly Burakov
@ 2018-12-20 12:07 ` Anatoly Burakov
  2018-12-20 12:10   ` Burakov, Anatoly
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 1/4] bitmap: remove deprecated bsf64 function Anatoly Burakov
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-20 12:07 UTC (permalink / raw)
  To: dev; +Cc: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, thomas, jerin.jacob

Add missing implementation for 64-bit log2 function, and extend
the unit test to test this new function. Also, remove duplicate
reimplementation of this function from testpmd and memalloc.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 app/test-pmd/testpmd.c                     | 17 +----------------
 lib/librte_eal/common/include/rte_common.h | 18 ++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memalloc.c | 17 +----------------
 test/test/test_common.c                    | 20 +++++++++++++++++++-
 4 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index a10bc40bb..8d584b008 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -649,28 +649,13 @@ calc_mem_size(uint32_t nb_mbufs, uint32_t mbuf_sz, size_t pgsz, size_t *out)
 	return 0;
 }
 
-static inline uint32_t
-bsf64(uint64_t v)
-{
-	return (uint32_t)__builtin_ctzll(v);
-}
-
-static inline uint32_t
-log2_u64(uint64_t v)
-{
-	if (v == 0)
-		return 0;
-	v = rte_align64pow2(v);
-	return bsf64(v);
-}
-
 static int
 pagesz_flags(uint64_t page_sz)
 {
 	/* as per mmap() manpage, all page sizes are log2 of page size
 	 * shifted by MAP_HUGE_SHIFT
 	 */
-	int log2 = log2_u64(page_sz);
+	int log2 = rte_log2_u64(page_sz);
 
 	return (log2 << HUGE_SHIFT);
 }
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 7b50b8479..7178ba1e9 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -565,6 +565,24 @@ rte_fls_u64(uint64_t x)
 	return (x == 0) ? 0 : 64 - __builtin_clzll(x);
 }
 
+/**
+ * Return the rounded-up log2 of a 64-bit integer.
+ *
+ * @param v
+ *     The input parameter.
+ * @return
+ *     The rounded-up log2 of the input, or 0 if the input is 0.
+ */
+static inline uint32_t
+rte_log2_u64(uint64_t v)
+{
+	if (v == 0)
+		return 0;
+	v = rte_align64pow2(v);
+	/* we checked for v being 0 already, so no undefined behavior */
+	return rte_bsf64(v);
+}
+
 #ifndef offsetof
 /** Return the offset of a field in a structure. */
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index 784939566..6e6af5b06 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -208,28 +208,13 @@ get_file_size(int fd)
 	return st.st_size;
 }
 
-static inline uint32_t
-bsf64(uint64_t v)
-{
-	return (uint32_t)__builtin_ctzll(v);
-}
-
-static inline uint32_t
-log2_u64(uint64_t v)
-{
-	if (v == 0)
-		return 0;
-	v = rte_align64pow2(v);
-	return bsf64(v);
-}
-
 static int
 pagesz_flags(uint64_t page_sz)
 {
 	/* as per mmap() manpage, all page sizes are log2 of page size
 	 * shifted by MAP_HUGE_SHIFT
 	 */
-	int log2 = log2_u64(page_sz);
+	int log2 = rte_log2_u64(page_sz);
 	return log2 << RTE_MAP_HUGE_SHIFT;
 }
 
diff --git a/test/test/test_common.c b/test/test/test_common.c
index f6dd4c18d..94d367471 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -213,13 +213,31 @@ test_log2(void)
 	const uint32_t step = 1;
 
 	for (i = 0; i < max; i = i + step) {
+		uint64_t i64;
+
+		/* extend range for 64-bit */
+		i64 = (uint64_t)i << 32;
+		base = (uint32_t)ceilf(log2(i64));
+		compare = rte_log2_u64(i64);
+		if (base != compare) {
+			printf("Wrong rte_log2_u64(%" PRIx64 ") val %x, expected %x\n",
+				i64, compare, base);
+			return TEST_FAILED;
+		}
+
 		base = (uint32_t)ceilf(log2((uint32_t)i));
-		compare = rte_log2_u32(i);
+		compare = rte_log2_u32((uint32_t)i);
 		if (base != compare) {
 			printf("Wrong rte_log2_u32(%x) val %x, expected %x\n",
 				i, compare, base);
 			return TEST_FAILED;
 		}
+		compare = rte_log2_u64((uint64_t)i);
+		if (base != compare) {
+			printf("Wrong rte_log2_u64(%x) val %x, expected %x\n",
+				i, compare, base);
+			return TEST_FAILED;
+		}
 	}
 	return 0;
 }
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v2 1/4] bitmap: remove deprecated bsf64 function
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
                   ` (5 preceding siblings ...)
  2018-12-20 12:07 ` [dpdk-dev] [PATCH v2] common: add 64-bit log2 function Anatoly Burakov
@ 2018-12-20 12:09 ` Anatoly Burakov
  2018-12-20 23:44   ` Thomas Monjalon
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 2/4] common: add bsf64 and bsf32_safe functions Anatoly Burakov
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-20 12:09 UTC (permalink / raw)
  To: dev
  Cc: Neil Horman, John McNamara, Marko Kovacevic, Cristian Dumitrescu,
	jerin.jacob, thomas

The function rte_bsf64 was deprecated in a previous release, so
remove the function, and the deprecation notice associated with
it.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 doc/guides/rel_notes/deprecation.rst       | 5 -----
 doc/guides/rel_notes/release_19_02.rst     | 4 ++++
 lib/librte_eal/common/include/rte_bitmap.h | 6 ------
 3 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst
index ac7fb29a7..61d94c7de 100644
--- a/doc/guides/rel_notes/deprecation.rst
+++ b/doc/guides/rel_notes/deprecation.rst
@@ -20,11 +20,6 @@ Deprecation Notices
 * kvargs: The function ``rte_kvargs_process`` will get a new parameter
   for returning key match count. It will ease handling of no-match case.
 
-* eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to
-  ``rte_bsf64_safe`` and moved to ``rte_common.h``. A new ``rte_bsf64`` function
-  will be added in the next release in ``rte_common.h`` that follows convention
-  set by existing ``rte_bsf32`` function.
-
 * eal: both declaring and identifying devices will be streamlined in v18.11.
   New functions will appear to query a specific port from buses, classes of
   device and device drivers. Device declaration will be made coherent with the
diff --git a/doc/guides/rel_notes/release_19_02.rst b/doc/guides/rel_notes/release_19_02.rst
index 069f429a7..c4cce4c98 100644
--- a/doc/guides/rel_notes/release_19_02.rst
+++ b/doc/guides/rel_notes/release_19_02.rst
@@ -99,6 +99,10 @@ API Changes
   since 18.05 and are removed in this release.
 
 
+* eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to
+  ``rte_bsf64_safe`` and moved to ``rte_common.h``.
+
+
 ABI Changes
 -----------
 
diff --git a/lib/librte_eal/common/include/rte_bitmap.h b/lib/librte_eal/common/include/rte_bitmap.h
index 77727c828..6b846f251 100644
--- a/lib/librte_eal/common/include/rte_bitmap.h
+++ b/lib/librte_eal/common/include/rte_bitmap.h
@@ -93,12 +93,6 @@ __rte_bitmap_index2_set(struct rte_bitmap *bmp)
 	bmp->index2 = (((bmp->index1 << RTE_BITMAP_SLAB_BIT_SIZE_LOG2) + bmp->offset1) << RTE_BITMAP_CL_SLAB_SIZE_LOG2);
 }
 
-static inline int __rte_deprecated
-rte_bsf64(uint64_t slab, uint32_t *pos)
-{
-	return rte_bsf64_safe(slab, pos);
-}
-
 static inline uint32_t
 __rte_bitmap_get_memory_footprint(uint32_t n_bits,
 	uint32_t *array1_byte_offset, uint32_t *array1_slabs,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v2 2/4] common: add bsf64 and bsf32_safe functions
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
                   ` (6 preceding siblings ...)
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 1/4] bitmap: remove deprecated bsf64 function Anatoly Burakov
@ 2018-12-20 12:09 ` Anatoly Burakov
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 3/4] common: add 64-bit fls function Anatoly Burakov
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 4/4] common: add 64-bit log2 function Anatoly Burakov
  9 siblings, 0 replies; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-20 12:09 UTC (permalink / raw)
  To: dev; +Cc: John McNamara, Marko Kovacevic, jerin.jacob, thomas

Add an rte_bsf64 function that follows the convention of existing
rte_bsf32 function. Also, add missing implementation for safe
version of rte_bsf32, and implement unit tests for all recently
added bsf varieties.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 doc/guides/rel_notes/release_19_02.rst     |  4 +-
 lib/librte_eal/common/include/rte_common.h | 43 +++++++++++++++++++++-
 test/test/test_common.c                    | 41 ++++++++++++++++++++-
 3 files changed, 84 insertions(+), 4 deletions(-)

diff --git a/doc/guides/rel_notes/release_19_02.rst b/doc/guides/rel_notes/release_19_02.rst
index c4cce4c98..0f446ed74 100644
--- a/doc/guides/rel_notes/release_19_02.rst
+++ b/doc/guides/rel_notes/release_19_02.rst
@@ -100,7 +100,9 @@ API Changes
 
 
 * eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to
-  ``rte_bsf64_safe`` and moved to ``rte_common.h``.
+  ``rte_bsf64_safe`` and moved to ``rte_common.h``. A new ``rte_bsf64`` function
+  has been added in ``rte_common.h`` that follows convention set by existing
+  ``rte_bsf32`` function.
 
 
 ABI Changes
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 66cdf60b2..d102f2cec 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -447,6 +447,30 @@ rte_bsf32(uint32_t v)
 	return (uint32_t)__builtin_ctz(v);
 }
 
+/**
+ * Searches the input parameter for the least significant set bit
+ * (starting from zero). Safe version (checks for input parameter being zero).
+ *
+ * @warning ``pos`` must be a valid pointer. It is not checked!
+ *
+ * @param v
+ *     The input parameter.
+ * @param pos
+ *     If ``v`` was not 0, this value will contain position of least significant
+ *     bit within the input parameter.
+ * @return
+ *     Returns 0 if ``v`` was 0, otherwise returns 1.
+ */
+static inline int
+rte_bsf32_safe(uint64_t v, uint32_t *pos)
+{
+	if (v == 0)
+		return 0;
+
+	*pos = rte_bsf32(v);
+	return 1;
+}
+
 /**
  * Return the rounded-up log2 of a integer.
  *
@@ -482,6 +506,23 @@ rte_fls_u32(uint32_t x)
 	return (x == 0) ? 0 : 32 - __builtin_clz(x);
 }
 
+/**
+ * Searches the input parameter for the least significant set bit
+ * (starting from zero).
+ * If a least significant 1 bit is found, its bit index is returned.
+ * If the content of the input parameter is zero, then the content of the return
+ * value is undefined.
+ * @param v
+ *     input parameter, should not be zero.
+ * @return
+ *     least significant set bit in the input parameter.
+ */
+static inline int
+rte_bsf64(uint64_t v)
+{
+	return (uint32_t)__builtin_ctzll(v);
+}
+
 /**
  * Searches the input parameter for the least significant set bit
  * (starting from zero). Safe version (checks for input parameter being zero).
@@ -502,7 +543,7 @@ rte_bsf64_safe(uint64_t v, uint32_t *pos)
 	if (v == 0)
 		return 0;
 
-	*pos = __builtin_ctzll(v);
+	*pos = rte_bsf64(v);
 	return 1;
 }
 
diff --git a/test/test/test_common.c b/test/test/test_common.c
index c6d17baae..4a42aaed8 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -50,12 +50,48 @@ test_macros(int __rte_unused unused_parm)
 	return 0;
 }
 
+static int
+test_bsf(void)
+{
+	uint32_t shift, pos;
+
+	/* safe versions should be able to handle 0 */
+	if (rte_bsf32_safe(0, &pos) != 0)
+		FAIL("rte_bsf32_safe");
+	if (rte_bsf64_safe(0, &pos) != 0)
+		FAIL("rte_bsf64_safe");
+
+	for (shift = 0; shift < 63; shift++) {
+		uint32_t val32;
+		uint64_t val64;
+
+		val64 = 1ULL << shift;
+		if ((uint32_t)rte_bsf64(val64) != shift)
+			FAIL("rte_bsf64");
+		if (rte_bsf64_safe(val64, &pos) != 1)
+			FAIL("rte_bsf64_safe");
+		if (pos != shift)
+			FAIL("rte_bsf64_safe");
+
+		if (shift > 31)
+			continue;
+
+		val32 = 1U << shift;
+		if ((uint32_t)rte_bsf32(val32) != shift)
+			FAIL("rte_bsf32");
+		if (rte_bsf32_safe(val32, &pos) != 1)
+			FAIL("rte_bsf32_safe");
+		if (pos != shift)
+			FAIL("rte_bsf32_safe");
+	}
+
+	return 0;
+}
+
 static int
 test_misc(void)
 {
 	char memdump[] = "memdump_test";
-	if (rte_bsf32(129))
-		FAIL("rte_bsf32");
 
 	rte_memdump(stdout, "test", memdump, sizeof(memdump));
 	rte_hexdump(stdout, "test", memdump, sizeof(memdump));
@@ -226,6 +262,7 @@ test_common(void)
 	ret |= test_align();
 	ret |= test_macros(0);
 	ret |= test_misc();
+	ret |= test_bsf();
 	ret |= test_log2();
 	ret |= test_fls();
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v2 3/4] common: add 64-bit fls function
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
                   ` (7 preceding siblings ...)
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 2/4] common: add bsf64 and bsf32_safe functions Anatoly Burakov
@ 2018-12-20 12:09 ` Anatoly Burakov
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 4/4] common: add 64-bit log2 function Anatoly Burakov
  9 siblings, 0 replies; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-20 12:09 UTC (permalink / raw)
  To: dev; +Cc: jerin.jacob, thomas

Add missing implementation for 64-bit fls function, and extend
unit test to test the new function as well.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/common/include/rte_common.h | 18 ++++++++++++++++++
 test/test/test_common.c                    | 21 +++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index d102f2cec..7b50b8479 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -547,6 +547,24 @@ rte_bsf64_safe(uint64_t v, uint32_t *pos)
 	return 1;
 }
 
+/**
+ * Return the last (most-significant) bit set.
+ *
+ * @note The last (most significant) bit is at position 64.
+ * @note rte_fls_u64(0) = 0, rte_fls_u64(1) = 1,
+ *       rte_fls_u64(0x8000000000000000) = 64
+ *
+ * @param x
+ *     The input parameter.
+ * @return
+ *     The last (most-significant) bit set, or 0 if the input is 0.
+ */
+static inline int
+rte_fls_u64(uint64_t x)
+{
+	return (x == 0) ? 0 : 64 - __builtin_clzll(x);
+}
+
 #ifndef offsetof
 /** Return the offset of a field in a structure. */
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
diff --git a/test/test/test_common.c b/test/test/test_common.c
index 4a42aaed8..f6dd4c18d 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -242,6 +242,8 @@ test_fls(void)
 	};
 
 	for (i = 0; i < RTE_DIM(test); i++) {
+		uint64_t arg64;
+
 		arg = test[i].arg;
 		rc = rte_fls_u32(arg);
 		expected = test[i].rc;
@@ -250,6 +252,25 @@ test_fls(void)
 				arg, rc, expected);
 			return TEST_FAILED;
 		}
+		/* 64-bit version */
+		arg = test[i].arg;
+		rc = rte_fls_u64(arg);
+		expected = test[i].rc;
+		if (rc != expected) {
+			printf("Wrong rte_fls_u64(0x%x) rc=%d, expected=%d\n",
+				arg, rc, expected);
+			return TEST_FAILED;
+		}
+		/* 64-bit version shifted by 32 bits */
+		arg64 = (uint64_t)test[i].arg << 32;
+		rc = rte_fls_u64(arg64);
+		/* don't shift zero */
+		expected = test[i].rc == 0 ? 0 : test[i].rc + 32;
+		if (rc != expected) {
+			printf("Wrong rte_fls_u64(0x%" PRIx64 ") rc=%d, expected=%d\n",
+				arg64, rc, expected);
+			return TEST_FAILED;
+		}
 	}
 
 	return 0;
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v2 4/4] common: add 64-bit log2 function
  2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
                   ` (8 preceding siblings ...)
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 3/4] common: add 64-bit fls function Anatoly Burakov
@ 2018-12-20 12:09 ` Anatoly Burakov
  2018-12-20 22:37   ` Thomas Monjalon
  9 siblings, 1 reply; 18+ messages in thread
From: Anatoly Burakov @ 2018-12-20 12:09 UTC (permalink / raw)
  To: dev; +Cc: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, jerin.jacob, thomas

Add missing implementation for 64-bit log2 function, and extend
the unit test to test this new function. Also, remove duplicate
reimplementation of this function from testpmd and memalloc.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 app/test-pmd/testpmd.c                     | 17 +----------------
 lib/librte_eal/common/include/rte_common.h | 18 ++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memalloc.c | 17 +----------------
 test/test/test_common.c                    | 20 +++++++++++++++++++-
 4 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index a10bc40bb..8d584b008 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -649,28 +649,13 @@ calc_mem_size(uint32_t nb_mbufs, uint32_t mbuf_sz, size_t pgsz, size_t *out)
 	return 0;
 }
 
-static inline uint32_t
-bsf64(uint64_t v)
-{
-	return (uint32_t)__builtin_ctzll(v);
-}
-
-static inline uint32_t
-log2_u64(uint64_t v)
-{
-	if (v == 0)
-		return 0;
-	v = rte_align64pow2(v);
-	return bsf64(v);
-}
-
 static int
 pagesz_flags(uint64_t page_sz)
 {
 	/* as per mmap() manpage, all page sizes are log2 of page size
 	 * shifted by MAP_HUGE_SHIFT
 	 */
-	int log2 = log2_u64(page_sz);
+	int log2 = rte_log2_u64(page_sz);
 
 	return (log2 << HUGE_SHIFT);
 }
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 7b50b8479..7178ba1e9 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -565,6 +565,24 @@ rte_fls_u64(uint64_t x)
 	return (x == 0) ? 0 : 64 - __builtin_clzll(x);
 }
 
+/**
+ * Return the rounded-up log2 of a 64-bit integer.
+ *
+ * @param v
+ *     The input parameter.
+ * @return
+ *     The rounded-up log2 of the input, or 0 if the input is 0.
+ */
+static inline uint32_t
+rte_log2_u64(uint64_t v)
+{
+	if (v == 0)
+		return 0;
+	v = rte_align64pow2(v);
+	/* we checked for v being 0 already, so no undefined behavior */
+	return rte_bsf64(v);
+}
+
 #ifndef offsetof
 /** Return the offset of a field in a structure. */
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index 784939566..6e6af5b06 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -208,28 +208,13 @@ get_file_size(int fd)
 	return st.st_size;
 }
 
-static inline uint32_t
-bsf64(uint64_t v)
-{
-	return (uint32_t)__builtin_ctzll(v);
-}
-
-static inline uint32_t
-log2_u64(uint64_t v)
-{
-	if (v == 0)
-		return 0;
-	v = rte_align64pow2(v);
-	return bsf64(v);
-}
-
 static int
 pagesz_flags(uint64_t page_sz)
 {
 	/* as per mmap() manpage, all page sizes are log2 of page size
 	 * shifted by MAP_HUGE_SHIFT
 	 */
-	int log2 = log2_u64(page_sz);
+	int log2 = rte_log2_u64(page_sz);
 	return log2 << RTE_MAP_HUGE_SHIFT;
 }
 
diff --git a/test/test/test_common.c b/test/test/test_common.c
index f6dd4c18d..94d367471 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -213,13 +213,31 @@ test_log2(void)
 	const uint32_t step = 1;
 
 	for (i = 0; i < max; i = i + step) {
+		uint64_t i64;
+
+		/* extend range for 64-bit */
+		i64 = (uint64_t)i << 32;
+		base = (uint32_t)ceilf(log2(i64));
+		compare = rte_log2_u64(i64);
+		if (base != compare) {
+			printf("Wrong rte_log2_u64(%" PRIx64 ") val %x, expected %x\n",
+				i64, compare, base);
+			return TEST_FAILED;
+		}
+
 		base = (uint32_t)ceilf(log2((uint32_t)i));
-		compare = rte_log2_u32(i);
+		compare = rte_log2_u32((uint32_t)i);
 		if (base != compare) {
 			printf("Wrong rte_log2_u32(%x) val %x, expected %x\n",
 				i, compare, base);
 			return TEST_FAILED;
 		}
+		compare = rte_log2_u64((uint64_t)i);
+		if (base != compare) {
+			printf("Wrong rte_log2_u64(%x) val %x, expected %x\n",
+				i, compare, base);
+			return TEST_FAILED;
+		}
 	}
 	return 0;
 }
-- 
2.17.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH v2] common: add 64-bit log2 function
  2018-12-20 12:07 ` [dpdk-dev] [PATCH v2] common: add 64-bit log2 function Anatoly Burakov
@ 2018-12-20 12:10   ` Burakov, Anatoly
  0 siblings, 0 replies; 18+ messages in thread
From: Burakov, Anatoly @ 2018-12-20 12:10 UTC (permalink / raw)
  To: dev; +Cc: Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, thomas, jerin.jacob

On 20-Dec-18 12:07 PM, Anatoly Burakov wrote:
> Add missing implementation for 64-bit log2 function, and extend
> the unit test to test this new function. Also, remove duplicate
> reimplementation of this function from testpmd and memalloc.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---

Disregard this patch.

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH v2 4/4] common: add 64-bit log2 function
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 4/4] common: add 64-bit log2 function Anatoly Burakov
@ 2018-12-20 22:37   ` Thomas Monjalon
  0 siblings, 0 replies; 18+ messages in thread
From: Thomas Monjalon @ 2018-12-20 22:37 UTC (permalink / raw)
  To: Anatoly Burakov
  Cc: dev, Wenzhuo Lu, Jingjing Wu, Bernard Iremonger, jerin.jacob

20/12/2018 13:09, Anatoly Burakov:
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c>
> -static inline uint32_t
> -bsf64(uint64_t v)
> -{
> -	return (uint32_t)__builtin_ctzll(v);
> -}
> -
[...]
> --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
> -static inline uint32_t
> -bsf64(uint64_t v)
> -{
> -	return (uint32_t)__builtin_ctzll(v);
> -}
> -

bsf64 code should have been removed in patch 2

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/4] bitmap: remove deprecated bsf64 function
  2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 1/4] bitmap: remove deprecated bsf64 function Anatoly Burakov
@ 2018-12-20 23:44   ` Thomas Monjalon
  0 siblings, 0 replies; 18+ messages in thread
From: Thomas Monjalon @ 2018-12-20 23:44 UTC (permalink / raw)
  To: Anatoly Burakov
  Cc: dev, Neil Horman, John McNamara, Marko Kovacevic,
	Cristian Dumitrescu, jerin.jacob

20/12/2018 13:09, Anatoly Burakov:
> The function rte_bsf64 was deprecated in a previous release, so
> remove the function, and the deprecation notice associated with
> it.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied with change suggested in patch 4, thanks

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2018-12-20 23:44 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-11 17:57 [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function Anatoly Burakov
2018-12-11 17:57 ` [dpdk-dev] [PATCH 2/6] common: add bsf64 function similar to existing bsf32 Anatoly Burakov
2018-12-20  9:08   ` Thomas Monjalon
2018-12-11 17:57 ` [dpdk-dev] [PATCH 3/6] common: add missing implementations Anatoly Burakov
2018-12-20  9:09   ` Thomas Monjalon
2018-12-20  9:16     ` Burakov, Anatoly
2018-12-11 17:57 ` [dpdk-dev] [PATCH 4/6] memalloc: use library implementation of 64-bit log2 Anatoly Burakov
2018-12-11 17:57 ` [dpdk-dev] [PATCH 5/6] testpmd: " Anatoly Burakov
2018-12-12 11:22   ` Iremonger, Bernard
2018-12-11 17:57 ` [dpdk-dev] [PATCH 6/6] test/common: extend autotest to newly added functions Anatoly Burakov
2018-12-20 12:07 ` [dpdk-dev] [PATCH v2] common: add 64-bit log2 function Anatoly Burakov
2018-12-20 12:10   ` Burakov, Anatoly
2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 1/4] bitmap: remove deprecated bsf64 function Anatoly Burakov
2018-12-20 23:44   ` Thomas Monjalon
2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 2/4] common: add bsf64 and bsf32_safe functions Anatoly Burakov
2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 3/4] common: add 64-bit fls function Anatoly Burakov
2018-12-20 12:09 ` [dpdk-dev] [PATCH v2 4/4] common: add 64-bit log2 function Anatoly Burakov
2018-12-20 22:37   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).