[dpdk-stable] [PATCH 2/6] mem: add hugepages check

Alejandro Lucero alejandro.lucero at netronome.com
Tue Jun 26 19:37:29 CEST 2018


Devices can have addressing limitations and a driver can set a dma
mask. This patch adds a function for checking hugepages iovas are within
the range supported by the dma mask.

Signed-off-by: Alejandro Lucero <alejandro.lucero at netronome.com>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 36 ++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 17c20d4..4c196a6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1334,6 +1334,42 @@ void numa_error(char *where)
 	return -1;
 }
 
+int
+rte_eal_memory_dma_mask_check(void)
+{
+	struct rte_mem_config *mcfg;
+	int i;
+	int total_segs_checked = 0;
+	uint64_t mask;
+
+	if (!internal_config.dma_mask)
+		return 0;
+
+	mask = 1ULL << internal_config.dma_mask;
+	mask -= 1;
+
+	/* get pointer to global configuration */
+	mcfg = rte_eal_get_configuration()->mem_config;
+
+	for (i = 0; i < RTE_MAX_MEMSEG; i++) {
+		RTE_LOG(DEBUG, EAL, "Memseg %d with iova %"PRIx64" and mask %"PRIx64"\n", i,
+				    mcfg->memseg[i].iova, mask);
+
+		if (!mcfg->memseg[i].iova)
+			break;
+
+		if (mcfg->memseg[i].iova & ~mask) {
+			return -1;
+		}
+		total_segs_checked++;
+	}
+
+	RTE_LOG(DEBUG, EAL, "ALEJ: %d segments successfully checked with dma mask\n",
+			    total_segs_checked);
+
+	return 0;
+}
+
 /*
  * uses fstat to report the size of a file on disk
  */
-- 
1.9.1



More information about the stable mailing list