[01/12] eal: Make rte_eal_using_phys_addrs work sooner

Message ID 20190530174819.1160221-2-benjamin.walker@intel.com (mailing list archive)
State Superseded, archived
Headers
Series [01/12] eal: Make rte_eal_using_phys_addrs work sooner |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/Intel-compilation fail Compilation issues

Commit Message

Walker, Benjamin May 30, 2019, 5:48 p.m. UTC
  This function only returned the correct answer after
a call to initialize the memory subsystem. Make it work
prior to that.

Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Change-Id: I8f3c5128fbf5da884a956bbcc72c5a13564825d5
---
 lib/librte_eal/linux/eal/eal_memory.c | 63 ++++++++++++---------------
 1 file changed, 28 insertions(+), 35 deletions(-)
  

Patch

diff --git a/lib/librte_eal/linux/eal/eal_memory.c b/lib/librte_eal/linux/eal/eal_memory.c
index 416dad898..0c07bb946 100644
--- a/lib/librte_eal/linux/eal/eal_memory.c
+++ b/lib/librte_eal/linux/eal/eal_memory.c
@@ -66,34 +66,8 @@ 
  * zone as well as a physical contiguous zone.
  */
 
-static bool phys_addrs_available = true;
-
 #define RANDOMIZE_VA_SPACE_FILE "/proc/sys/kernel/randomize_va_space"
 
-static void
-test_phys_addrs_available(void)
-{
-	uint64_t tmp = 0;
-	phys_addr_t physaddr;
-
-	if (!rte_eal_has_hugepages()) {
-		RTE_LOG(ERR, EAL,
-			"Started without hugepages support, physical addresses not available\n");
-		phys_addrs_available = false;
-		return;
-	}
-
-	physaddr = rte_mem_virt2phy(&tmp);
-	if (physaddr == RTE_BAD_PHYS_ADDR) {
-		if (rte_eal_iova_mode() == RTE_IOVA_PA)
-			RTE_LOG(ERR, EAL,
-				"Cannot obtain physical addresses: %s. "
-				"Only vfio will function.\n",
-				strerror(errno));
-		phys_addrs_available = false;
-	}
-}
-
 /*
  * Get physical address of any mapped virtual address in the current process.
  */
@@ -107,7 +81,7 @@  rte_mem_virt2phy(const void *virtaddr)
 	off_t offset;
 
 	/* Cannot parse /proc/self/pagemap, no need to log errors everywhere */
-	if (!phys_addrs_available)
+	if (!rte_eal_using_phys_addrs())
 		return RTE_BAD_IOVA;
 
 	/* standard page size */
@@ -1336,8 +1310,6 @@  eal_legacy_hugepage_init(void)
 	int nr_hugefiles, nr_hugepages = 0;
 	void *addr;
 
-	test_phys_addrs_available();
-
 	memset(used_hp, 0, sizeof(used_hp));
 
 	/* get pointer to global configuration */
@@ -1516,7 +1488,7 @@  eal_legacy_hugepage_init(void)
 				continue;
 		}
 
-		if (phys_addrs_available &&
+		if (rte_eal_using_phys_addrs() &&
 				rte_eal_iova_mode() != RTE_IOVA_VA) {
 			/* find physical addresses for each hugepage */
 			if (find_physaddrs(&tmp_hp[hp_offset], hpi) < 0) {
@@ -1735,8 +1707,6 @@  eal_hugepage_init(void)
 	uint64_t memory[RTE_MAX_NUMA_NODES];
 	int hp_sz_idx, socket_id;
 
-	test_phys_addrs_available();
-
 	memset(used_hp, 0, sizeof(used_hp));
 
 	for (hp_sz_idx = 0;
@@ -1879,8 +1849,6 @@  eal_legacy_hugepage_attach(void)
 				"into secondary processes\n");
 	}
 
-	test_phys_addrs_available();
-
 	fd_hugepage = open(eal_hugepage_data_path(), O_RDONLY);
 	if (fd_hugepage < 0) {
 		RTE_LOG(ERR, EAL, "Could not open %s\n",
@@ -2020,7 +1988,32 @@  rte_eal_hugepage_attach(void)
 int
 rte_eal_using_phys_addrs(void)
 {
-	return phys_addrs_available;
+	static int using_phys_addrs = -1;
+	uint64_t tmp = 0;
+	phys_addr_t physaddr;
+
+	if (using_phys_addrs != -1)
+		return using_phys_addrs;
+
+	/* Set the default to 1 */
+	using_phys_addrs = 1;
+
+	if (!rte_eal_has_hugepages()) {
+		RTE_LOG(ERR, EAL,
+			"Started without hugepages support, physical addresses not available\n");
+		using_phys_addrs = 0;
+		return using_phys_addrs;
+	}
+
+	physaddr = rte_mem_virt2phy(&tmp);
+	if (physaddr == RTE_BAD_PHYS_ADDR) {
+		if (rte_eal_iova_mode() == RTE_IOVA_PA)
+			RTE_LOG(ERR, EAL,
+				"Cannot obtain physical addresses. Only vfio will function.\n");
+		using_phys_addrs = 0;
+	}
+
+	return using_phys_addrs;
 }
 
 static int __rte_unused