examples/l2fwd-crypto: support multiprocess

Message ID 20190327113622.13426-1-akhil.goyal@nxp.com
State New
Delegated to: akhil goyal
Headers show
Series
  • examples/l2fwd-crypto: support multiprocess
Related show

Checks

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

Commit Message

Akhil Goyal March 27, 2019, 11:45 a.m.
additional parameters(mp_emask and mp_cmask) need to be added for
each application instance for ethernet and crypto portmasks which
are actually getting used in that instance. Primary instance of the
application will init all the ports/cdevs and will use only the
mp_emask and mp_cmask for I/O.
net port mask and cryptodev_mask will be same for all the instances
of the application only mp_emask and mp_cmask will be different.

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
---
 .../sample_app_ug/l2_forward_crypto.rst       |  6 ++
 examples/l2fwd-crypto/main.c                  | 86 +++++++++++++++----
 2 files changed, 75 insertions(+), 17 deletions(-)

Patch

diff --git a/doc/guides/sample_app_ug/l2_forward_crypto.rst b/doc/guides/sample_app_ug/l2_forward_crypto.rst
index e8d52dad2..c0bb63af2 100644
--- a/doc/guides/sample_app_ug/l2_forward_crypto.rst
+++ b/doc/guides/sample_app_ug/l2_forward_crypto.rst
@@ -152,6 +152,12 @@  where,
 
 *   [no-]mac-updating: Enable or disable MAC addresses updating (enabled by default).
 
+*   mp-emask: mask applicable for multiprocess, defining the ethernet ports
+    which would be used by this instance. (Default is all ports).
+
+*   mp-cmask: mask applicable for multiprocess, defining the crypto ports
+    which would be used by this instance. (Default is all ports).
+
 
 The application requires that crypto devices capable of performing
 the specified crypto operation are available on application initialization.
diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 9982f07e9..c3ea17ee8 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -168,6 +168,8 @@  struct l2fwd_crypto_options {
 	uint64_t cryptodev_mask;
 
 	unsigned int mac_updating;
+	uint64_t mp_emask;
+	uint64_t mp_cmask;
 };
 
 /** l2fwd crypto lcore params */
@@ -254,6 +256,9 @@  struct l2fwd_crypto_statistics crypto_statistics[RTE_CRYPTO_MAX_DEVS];
 /* default period is 10 seconds */
 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000;
 
+/* Process type*/
+static enum rte_proc_type_t proc_type = RTE_PROC_AUTO;
+
 /* Print out statistics on packets dropped */
 static void
 print_stats(void)
@@ -994,7 +999,11 @@  l2fwd_crypto_usage(const char *prgname)
 		"  --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)\n"
 		"      When enabled:\n"
 		"       - The source MAC address is replaced by the TX port MAC address\n"
-		"       - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n",
+		"       - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n"
+		"  --mp-emask: mask applicable for multiprocess, defining the ethernet ports\n"
+		"              which would be used by this instance. Default is all ports\n"
+		"  --mp-cmask: mask applicable for multiprocess, defining the crypto ports\n"
+		"              which would be used by this instance. Default is all ports\n",
 	       prgname);
 }
 
@@ -1169,8 +1178,7 @@  parse_aead_op(enum rte_crypto_aead_operation *op, char *optarg)
 	return -1;
 }
 static int
-parse_cryptodev_mask(struct l2fwd_crypto_options *options,
-		const char *q_arg)
+parse_mask(uint64_t *mask, const char *q_arg, const char *type)
 {
 	char *end = NULL;
 	uint64_t pm;
@@ -1180,11 +1188,11 @@  parse_cryptodev_mask(struct l2fwd_crypto_options *options,
 	if ((pm == '\0') || (end == NULL) || (*end != '\0'))
 		pm = 0;
 
-	options->cryptodev_mask = pm;
-	if (options->cryptodev_mask == 0) {
-		printf("invalid cryptodev_mask specified\n");
+	if (pm == 0) {
+		printf("invalid %s mask specified\n", type);
 		return -1;
 	}
+	*mask = pm;
 
 	return 0;
 }
@@ -1343,7 +1351,8 @@  l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options,
 	}
 
 	else if (strcmp(lgopts[option_index].name, "cryptodev_mask") == 0)
-		return parse_cryptodev_mask(options, optarg);
+		return parse_mask(&options->cryptodev_mask, optarg,
+				"cryptodev_mask");
 
 	else if (strcmp(lgopts[option_index].name, "mac-updating") == 0) {
 		options->mac_updating = 1;
@@ -1355,6 +1364,12 @@  l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options,
 		return 0;
 	}
 
+	else if (strcmp(lgopts[option_index].name, "mp-emask") == 0)
+		return parse_mask(&options->mp_emask, optarg, "mp-emask");
+
+	else if (strcmp(lgopts[option_index].name, "mp-cmask") == 0)
+		return parse_mask(&options->mp_cmask, optarg, "mp-cmask");
+
 	return -1;
 }
 
@@ -1488,6 +1503,8 @@  l2fwd_crypto_default_options(struct l2fwd_crypto_options *options)
 
 	options->type = CDEV_TYPE_ANY;
 	options->cryptodev_mask = UINT64_MAX;
+	options->mp_emask = UINT64_MAX;
+	options->mp_cmask = UINT64_MAX;
 
 	options->mac_updating = 1;
 }
@@ -1654,6 +1671,9 @@  l2fwd_crypto_parse_args(struct l2fwd_crypto_options *options,
 			{ "mac-updating", no_argument, 0, 0},
 			{ "no-mac-updating", no_argument, 0, 0},
 
+			{ "mp-emask", required_argument, 0, 0},
+			{ "mp-cmask", required_argument, 0, 0},
+
 			{ NULL, 0, 0, 0 }
 	};
 
@@ -2282,6 +2302,8 @@  initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
 				"priv_sess_mp_%u", socket_id);
 
 			session_pool_socket[socket_id].priv_mp =
+					(proc_type == RTE_PROC_SECONDARY) ?
+					rte_mempool_lookup(mp_name) :
 					rte_mempool_create(mp_name,
 						sessions_needed,
 						max_sess_sz,
@@ -2305,6 +2327,8 @@  initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
 				"sess_mp_%u", socket_id);
 
 			session_pool_socket[socket_id].sess_mp =
+					(proc_type == RTE_PROC_SECONDARY) ?
+					rte_mempool_lookup(mp_name) :
 					rte_cryptodev_sym_session_pool_create(
 							mp_name,
 							sessions_needed,
@@ -2455,6 +2479,9 @@  initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
 						cap->sym.auth.digest_size.min;
 		}
 
+		if (proc_type == RTE_PROC_SECONDARY)
+			goto skip_cdev_init;
+
 		retval = rte_cryptodev_configure(cdev_id, &conf);
 		if (retval < 0) {
 			printf("Failed to configure cryptodev %u", cdev_id);
@@ -2480,6 +2507,12 @@  initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
 					cdev_id, retval);
 			return -1;
 		}
+skip_cdev_init:
+		if ((options->mp_cmask & (1 << cdev_id)) != 0) {
+			l2fwd_enabled_crypto_mask |= (((uint64_t)1) << cdev_id);
+			enabled_cdevs[cdev_id] = 1;
+			enabled_cdev_count++;
+		}
 	}
 
 	return enabled_cdev_count;
@@ -2512,6 +2545,9 @@  initialize_ports(struct l2fwd_crypto_options *options)
 		if ((options->portmask & (1 << portid)) == 0)
 			continue;
 
+		if (proc_type == RTE_PROC_SECONDARY)
+			goto skip_port_init;
+
 		/* init port */
 		printf("Initializing port %u... ", portid);
 		fflush(stdout);
@@ -2570,7 +2606,7 @@  initialize_ports(struct l2fwd_crypto_options *options)
 		}
 
 		rte_eth_promiscuous_enable(portid);
-
+skip_port_init:
 		rte_eth_macaddr_get(portid, &l2fwd_ports_eth_addr[portid]);
 
 		printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
@@ -2593,8 +2629,10 @@  initialize_ports(struct l2fwd_crypto_options *options)
 			last_portid = portid;
 		}
 
-		l2fwd_enabled_port_mask |= (1 << portid);
-		enabled_portcount++;
+		if ((options->mp_emask & (1 << portid)) != 0) {
+			l2fwd_enabled_port_mask |= (1 << portid);
+			enabled_portcount++;
+		}
 	}
 
 	if (enabled_portcount == 1) {
@@ -2675,17 +2713,22 @@  main(int argc, char **argv)
 	printf("MAC updating %s\n",
 			options.mac_updating ? "enabled" : "disabled");
 
+	proc_type = rte_eal_process_type();
 	/* create the mbuf pool */
-	l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 512,
-			sizeof(struct rte_crypto_op),
-			RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
+	l2fwd_pktmbuf_pool = (proc_type == RTE_PROC_SECONDARY) ?
+			rte_mempool_lookup("mbuf_pool") :
+			rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 512,
+				sizeof(struct rte_crypto_op),
+				RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
 	if (l2fwd_pktmbuf_pool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
 
 	/* create crypto op pool */
-	l2fwd_crypto_op_pool = rte_crypto_op_pool_create("crypto_op_pool",
-			RTE_CRYPTO_OP_TYPE_SYMMETRIC, NB_MBUF, 128, MAXIMUM_IV_LENGTH,
-			rte_socket_id());
+	l2fwd_crypto_op_pool = (proc_type == RTE_PROC_SECONDARY) ?
+			rte_mempool_lookup("crypto_op_pool") :
+			rte_crypto_op_pool_create("crypto_op_pool",
+				RTE_CRYPTO_OP_TYPE_SYMMETRIC, NB_MBUF, 128,
+				MAXIMUM_IV_LENGTH, rte_socket_id());
 	if (l2fwd_crypto_op_pool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n");
 
@@ -2700,6 +2743,8 @@  main(int argc, char **argv)
 		/* skip ports that are not enabled */
 		if ((options.portmask & (1 << portid)) == 0)
 			continue;
+		if ((options.mp_emask & (1 << portid)) == 0)
+			continue;
 
 		if (options.single_lcore && qconf == NULL) {
 			while (rte_lcore_is_enabled(rx_lcore_id) == 0) {
@@ -2731,8 +2776,13 @@  main(int argc, char **argv)
 	}
 
 	/* Enable Crypto devices */
-	enabled_cdevcount = initialize_cryptodevs(&options, enabled_portcount,
+	if (options.mp_cmask != UINT64_MAX)
+		enabled_cdevcount = initialize_cryptodevs(&options, nb_ports,
 			enabled_cdevs);
+	else
+		enabled_cdevcount = initialize_cryptodevs(&options,
+				enabled_portcount, enabled_cdevs);
+
 	if (enabled_cdevcount < 0)
 		rte_exit(EXIT_FAILURE, "Failed to initialize crypto devices\n");
 
@@ -2750,6 +2800,8 @@  main(int argc, char **argv)
 		/* Crypto op not supported by crypto device */
 		if (!enabled_cdevs[cdev_id])
 			continue;
+		if ((options.mp_cmask & (1 << cdev_id)) == 0)
+			continue;
 
 		if (options.single_lcore && qconf == NULL) {
 			while (rte_lcore_is_enabled(rx_lcore_id) == 0) {