diff mbox

[NETMAP,08/12] linux-netmap: pktio: use single mmap address for all pktios

Message ID 1425322017-14636-9-git-send-email-ciprian.barbu@linaro.org
State New
Headers show

Commit Message

Ciprian Barbu March 2, 2015, 6:46 p.m. UTC
Signed-off-by: Ciprian Barbu <ciprian.barbu@linaro.org>
---
 platform/linux-netmap/odp_packet_netmap.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c
index 361f639..632ae49 100644
--- a/platform/linux-netmap/odp_packet_netmap.c
+++ b/platform/linux-netmap/odp_packet_netmap.c
@@ -55,8 +55,14 @@ 
 #define WAITLINK_TMO 2
 #define POLL_TMO     0
 
+static struct nm_desc mmap_desc;	/** Used to store the mmap address;
+					  filled in first time, used for
+					  subsequent calls to nm_open */
+static odp_spinlock_t nm_global_lock;
+
 int odp_netmap_init_global(void)
 {
+	odp_spinlock_init(&nm_global_lock);
 	return 0;
 }
 
@@ -142,13 +148,30 @@  int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev,
 
 	strncpy(pkt_nm->ifname, netdev, sizeof(pkt_nm->ifname));
 	snprintf(ifname, sizeof(ifname), "netmap:%s", netdev);
-	pkt_nm->desc = nm_open(ifname, NULL, 0, 0);
+
+	odp_spinlock_lock(&nm_global_lock);
+	ODP_DBG("[%04d] Initial mmap addr: %p\n",
+		odp_thread_id(),
+		mmap_desc.mem);
+
+	if (mmap_desc.mem == NULL)
+		pkt_nm->desc = nm_open(ifname, NULL, 0, NULL);
+	else
+		pkt_nm->desc = nm_open(ifname, NULL, NM_OPEN_NO_MMAP,
+					  &mmap_desc);
 
 	if (pkt_nm->desc == NULL) {
 		ODP_ERR("Error opening nm interface: %s\n", strerror(errno));
+		odp_spinlock_unlock(&nm_global_lock);
 		return -1;
 	}
 
+	if (mmap_desc.mem == NULL) {
+		mmap_desc.mem = pkt_nm->desc->mem;
+		mmap_desc.memsize = pkt_nm->desc->memsize;
+	}
+	odp_spinlock_unlock(&nm_global_lock);
+
 	ODP_DBG("[%04d] mmap addr %p\n",
 		odp_thread_id(),
 		pkt_nm->desc->mem);