From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <marcinx.kerlin@intel.com>
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by dpdk.org (Postfix) with ESMTP id 29C0128FD
 for <dev@dpdk.org>; Fri, 30 Sep 2016 16:23:57 +0200 (CEST)
Received: from orsmga002.jf.intel.com ([10.7.209.21])
 by orsmga101.jf.intel.com with ESMTP; 30 Sep 2016 07:23:56 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.31,272,1473145200"; d="scan'208";a="1058786186"
Received: from gklab-246-021.igk.intel.com (HELO HANLANCREEK9755-232)
 ([10.217.246.21])
 by orsmga002.jf.intel.com with SMTP; 30 Sep 2016 07:23:53 -0700
Received: by HANLANCREEK9755-232 (sSMTP sendmail emulation);
 Fri, 30 Sep 2016 16:24:17 +0200
From: Marcin Kerlin <marcinx.kerlin@intel.com>
To: dev@dpdk.org
Cc: pablo.de.lara.guarch@intel.com, thomas.monjalon@6wind.com,
 Marcin Kerlin <marcinx.kerlin@intel.com>
Date: Fri, 30 Sep 2016 16:24:14 +0200
Message-Id: <1475245454-6396-1-git-send-email-marcinx.kerlin@intel.com>
X-Mailer: git-send-email 1.9.1
In-Reply-To: <1475244055-6309-1-git-send-email-marcinx.kerlin@intel.com>
References: <1475244055-6309-1-git-send-email-marcinx.kerlin@intel.com>
Subject: [dpdk-dev] [PATCH v5 2/2] app/testpmd: improve handling of
	multiprocess
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 30 Sep 2016 14:23:57 -0000

Added lookup for pool name because secondary process should attach to
mempool created by primary process rather than create new one.

Added function free_shared_dev_data() used at the exit of the testpmd.
This causes detach devices data from array rte_eth_dev_data[] shared
between all processes. This allows to have a up-to-date list of devices
data and run again secondary application with the same name.

Signed-off-by: Marcin Kerlin <marcinx.kerlin@intel.com>
---
 app/test-pmd/testpmd.c | 37 +++++++++++++++++++++++++++++++++++--
 app/test-pmd/testpmd.h |  1 +
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index e2403c3..78b3a39 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -452,8 +452,11 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
 			rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
 		} else {
 			/* wrapper to rte_mempool_create() */
-			rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
-				mb_mempool_cache, 0, mbuf_seg_size, socket_id);
+			rte_mp = rte_mempool_lookup(pool_name);
+			if (rte_mp == NULL)
+				rte_mp = rte_pktmbuf_pool_create(pool_name,
+						nb_mbuf, mb_mempool_cache, 0,
+						mbuf_seg_size, socket_id);
 		}
 	}
 
@@ -1611,6 +1614,35 @@ detach_port(uint8_t port_id)
 	return;
 }
 
+void free_shared_dev_data(portid_t pid)
+{
+	portid_t pi;
+
+	if (port_id_is_invalid(pid, ENABLED_WARN))
+		return;
+
+	/* free data only if the secondary process exits */
+	if (rte_eal_process_type() != RTE_PROC_SECONDARY)
+		return;
+
+	printf("Cleaning device data...\n");
+
+	FOREACH_PORT(pi, ports)
+	{
+		if (pid != pi && pid != (portid_t) RTE_PORT_ALL)
+			continue;
+
+		if (!port_is_closed(pi)) {
+			printf("Port %d is not closed now\n", pi);
+			continue;
+		}
+
+		if (rte_eth_dev_release_dev_data(pi) < 0)
+			return;
+	}
+	printf("Done\n");
+}
+
 void
 pmd_test_exit(void)
 {
@@ -1626,6 +1658,7 @@ pmd_test_exit(void)
 			fflush(stdout);
 			stop_port(pt_id);
 			close_port(pt_id);
+			free_shared_dev_data(pt_id);
 		}
 	}
 	printf("\nBye...\n");
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 2b281cc..3915a06 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -553,6 +553,7 @@ void attach_port(char *identifier);
 void detach_port(uint8_t port_id);
 int all_ports_stopped(void);
 int port_is_started(portid_t port_id);
+void free_shared_dev_data(portid_t pid);
 void pmd_test_exit(void);
 void fdir_get_infos(portid_t port_id);
 void fdir_set_flex_mask(portid_t port_id,
-- 
1.9.1