[dpdk-dev] mem: support page locking on FreeBSD

Message ID 20170615175055.27032-1-thomas@monjalon.net (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Thomas Monjalon June 15, 2017, 5:50 p.m. UTC
  The function rte_mem_lock_page() was added for Linux only.
The file eal_common_memory.c is a better place to make it
available in FreeBSD also.

The issue is seen when trying to compile bnxt on FreeBSD:
	bnxt_hwrm.c: undefined reference to `rte_mem_lock_page'

Fixes: 3097de6e6bfb ("mem: get physical address of any pointer")

Reported-by: Fangfang Wei <fangfangx.wei@intel.com>
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/librte_eal/common/eal_common_memory.c | 12 ++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c  | 10 ----------
 2 files changed, 12 insertions(+), 10 deletions(-)
  

Comments

Bruce Richardson June 16, 2017, 2:31 p.m. UTC | #1
On Thu, Jun 15, 2017 at 07:50:55PM +0200, Thomas Monjalon wrote:
> The function rte_mem_lock_page() was added for Linux only.
> The file eal_common_memory.c is a better place to make it
> available in FreeBSD also.
> 
> The issue is seen when trying to compile bnxt on FreeBSD:
> 	bnxt_hwrm.c: undefined reference to `rte_mem_lock_page'
> 
> Fixes: 3097de6e6bfb ("mem: get physical address of any pointer")
> 
> Reported-by: Fangfang Wei <fangfangx.wei@intel.com>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
This fixes gcc and clang errors on FreeBSD so

Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Thomas Monjalon June 16, 2017, 2:52 p.m. UTC | #2
16/06/2017 16:31, Bruce Richardson:
> On Thu, Jun 15, 2017 at 07:50:55PM +0200, Thomas Monjalon wrote:
> > The function rte_mem_lock_page() was added for Linux only.
> > The file eal_common_memory.c is a better place to make it
> > available in FreeBSD also.
> > 
> > The issue is seen when trying to compile bnxt on FreeBSD:
> > 	bnxt_hwrm.c: undefined reference to `rte_mem_lock_page'
> > 
> > Fixes: 3097de6e6bfb ("mem: get physical address of any pointer")
> > 
> > Reported-by: Fangfang Wei <fangfangx.wei@intel.com>
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> > ---
> This fixes gcc and clang errors on FreeBSD so
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied
  

Patch

diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index 6155752e9..279457001 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -35,7 +35,9 @@ 
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <unistd.h>
 #include <inttypes.h>
+#include <sys/mman.h>
 #include <sys/queue.h>
 
 #include <rte_memory.h>
@@ -135,6 +137,16 @@  rte_eal_memdevice_init(void)
 	return 0;
 }
 
+/* Lock page in physical memory and prevent from swapping. */
+int
+rte_mem_lock_page(const void *virt)
+{
+	unsigned long virtual = (unsigned long)virt;
+	int page_size = getpagesize();
+	unsigned long aligned = (virtual & ~ (page_size - 1));
+	return mlock((void*)aligned, page_size);
+}
+
 /* init memory subsystem */
 int
 rte_eal_memory_init(void)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 9c9baf628..e17c9cb5d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -118,16 +118,6 @@  test_phys_addrs_available(void)
 	}
 }
 
-/* Lock page in physical memory and prevent from swapping. */
-int
-rte_mem_lock_page(const void *virt)
-{
-	unsigned long virtual = (unsigned long)virt;
-	int page_size = getpagesize();
-	unsigned long aligned = (virtual & ~ (page_size - 1));
-	return mlock((void*)aligned, page_size);
-}
-
 /*
  * Get physical address of any mapped virtual address in the current process.
  */