DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v1] change hugepage sorting to avoid overlapping memcpy
@ 2015-09-04 10:14 Ralf Hoffmann
  2015-09-08 12:45 ` Gonzalez Monroy, Sergio
  0 siblings, 1 reply; 17+ messages in thread
From: Ralf Hoffmann @ 2015-09-04 10:14 UTC (permalink / raw)
  To: dev

with only one hugepage or already sorted hugepage addresses, the sort
function called memcpy with same src and dst pointer. Debugging with
valgrind will issue a warning about overlapping area. This patch changes
the bubble sort to avoid this behavior. Also, the function cannot fail
any longer.

Signed-off-by: Ralf Hoffmann <ralf.hoffmann@allegro-packets.com>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index ac2745e..6d01f61 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -699,25 +699,25 @@ error:
  * higher address first on powerpc). We use a slow algorithm, but we won't
  * have millions of pages, and this is only done at init time.
  */
-static int
+static void
 sort_by_physaddr(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
 {
 	unsigned i, j;
-	int compare_idx;
+	unsigned compare_idx;
 	uint64_t compare_addr;
 	struct hugepage_file tmp;
 
 	for (i = 0; i < hpi->num_pages[0]; i++) {
-		compare_addr = 0;
-		compare_idx = -1;
+		compare_addr = hugepg_tbl[i].physaddr;
+		compare_idx = i;
 
 		/*
-		 * browse all entries starting at 'i', and find the
+		 * browse all entries starting at 'i+1', and find the
 		 * entry with the smallest addr
 		 */
-		for (j=i; j< hpi->num_pages[0]; j++) {
+		for (j=i + 1; j < hpi->num_pages[0]; j++) {
 
-			if (compare_addr == 0 ||
+			if (
 #ifdef RTE_ARCH_PPC_64
 				hugepg_tbl[j].physaddr > compare_addr) {
 #else
@@ -728,10 +728,9 @@ sort_by_physaddr(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
 			}
 		}
 
-		/* should not happen */
-		if (compare_idx == -1) {
-			RTE_LOG(ERR, EAL, "%s(): error in physaddr sorting\n", __func__);
-			return -1;
+		if (compare_idx == i) {
+			/* no smaller page found */
+			continue;
 		}
 
 		/* swap the 2 entries in the table */
@@ -741,7 +740,8 @@ sort_by_physaddr(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
 			sizeof(struct hugepage_file));
 		memcpy(&hugepg_tbl[i], &tmp, sizeof(struct hugepage_file));
 	}
-	return 0;
+
+	return;
 }
 
 /*
@@ -1164,8 +1164,7 @@ rte_eal_hugepage_init(void)
 			goto fail;
 		}
 
-		if (sort_by_physaddr(&tmp_hp[hp_offset], hpi) < 0)
-			goto fail;
+		sort_by_physaddr(&tmp_hp[hp_offset], hpi);
 
 #ifdef RTE_EAL_SINGLE_FILE_SEGMENTS
 		/* remap all hugepages into single file segments */
-- 
2.1.4

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

end of thread, other threads:[~2016-03-02 16:13 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-04 10:14 [dpdk-dev] [PATCH v1] change hugepage sorting to avoid overlapping memcpy Ralf Hoffmann
2015-09-08 12:45 ` Gonzalez Monroy, Sergio
2015-09-08 13:29   ` Jay Rolette
2015-09-08 14:24     ` Gonzalez Monroy, Sergio
2016-01-05  9:25       ` [dpdk-dev] [PATCH v2 0/1] " Ralf Hoffmann
2016-01-05  9:25         ` [dpdk-dev] [PATCH v2 1/1] " Ralf Hoffmann
2016-01-05  9:37       ` [dpdk-dev] [PATCH v3 0/1] eal/linux: " Ralf Hoffmann
2016-01-05  9:37         ` [dpdk-dev] [PATCH v3 1/1] " Ralf Hoffmann
2016-01-07  9:33           ` Sergio Gonzalez Monroy
2016-01-07  9:51             ` Sergio Gonzalez Monroy
2016-01-07 10:38               ` Sergio Gonzalez Monroy
2016-01-07 13:58                 ` Ralf Hoffmann
2016-01-07 13:59               ` [dpdk-dev] [PATCH v4 1/1] " Ralf Hoffmann
2016-01-07 14:36                 ` Sergio Gonzalez Monroy
2016-01-07 14:54                   ` [dpdk-dev] [PATCH v5 1/1] eal/linux: " Ralf Hoffmann
2016-03-02 16:13                     ` Thomas Monjalon
2015-09-09  8:41   ` [dpdk-dev] [PATCH v1] " Ralf Hoffmann

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).