From patchwork Thu May 30 17:48:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Walker, Benjamin" X-Patchwork-Id: 53916 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5335D1B94A; Thu, 30 May 2019 19:48:35 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id A54722B9A for ; Thu, 30 May 2019 19:48:28 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2019 10:48:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,532,1549958400"; d="scan'208";a="180020076" Received: from bwalker-desk.ch.intel.com ([143.182.136.145]) by fmsmga002.fm.intel.com with ESMTP; 30 May 2019 10:48:26 -0700 From: Ben Walker To: dev@dpdk.org Cc: Ben Walker Date: Thu, 30 May 2019 10:48:08 -0700 Message-Id: <20190530174819.1160221-2-benjamin.walker@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190530174819.1160221-1-benjamin.walker@intel.com> References: <20190530174819.1160221-1-benjamin.walker@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 01/12] eal: Make rte_eal_using_phys_addrs work sooner X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Change-Id: I8f3c5128fbf5da884a956bbcc72c5a13564825d5 --- lib/librte_eal/linux/eal/eal_memory.c | 63 ++++++++++++--------------- 1 file changed, 28 insertions(+), 35 deletions(-) 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