DPDK patches and discussions
 help / color / Atom feed
* [dpdk-dev] [PATCH 1/2] examples/l2fwd-jobstats: Free resources on exit
@ 2020-07-22 12:50 Ibtisam Tariq
  2020-07-22 12:50 ` [dpdk-dev] [PATCH 2/2] examples/l2fwd-crypto: " Ibtisam Tariq
  0 siblings, 1 reply; 3+ messages in thread
From: Ibtisam Tariq @ 2020-07-22 12:50 UTC (permalink / raw)
  To: declan.doherty; +Cc: dev, Ibtisam Tariq

When exiting the application, resources should be cleared.

Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
---
 examples/l2fwd-jobstats/main.c | 49 +++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/examples/l2fwd-jobstats/main.c b/examples/l2fwd-jobstats/main.c
index 47a3b0976..4f29f40ea 100644
--- a/examples/l2fwd-jobstats/main.c
+++ b/examples/l2fwd-jobstats/main.c
@@ -8,6 +8,7 @@
 #include <stdint.h>
 #include <ctype.h>
 #include <getopt.h>
+#include <signal.h>
 
 #include <rte_common.h>
 #include <rte_log.h>
@@ -36,6 +37,8 @@
 #include <rte_alarm.h>
 #include <rte_pause.h>
 
+static volatile bool force_quit;
+
 #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1
 
 #define NB_MBUF   8192
@@ -493,7 +496,7 @@ l2fwd_main_loop(void)
 
 	rte_jobstats_init(&qconf->idle_job, "idle", 0, 0, 0, 0);
 
-	for (;;) {
+	while (!force_quit) {
 		rte_spinlock_lock(&qconf->lock);
 
 		do {
@@ -508,6 +511,9 @@ l2fwd_main_loop(void)
 			uint64_t repeats = 0;
 
 			do {
+				if (force_quit)
+					break;
+
 				uint8_t i;
 				uint64_t now = rte_get_timer_cycles();
 
@@ -523,6 +529,9 @@ l2fwd_main_loop(void)
 
 			} while (!need_manage);
 
+			if (force_quit)
+				break;
+
 			if (likely(repeats != 1))
 				rte_jobstats_finish(&qconf->idle_job, qconf->idle_job.target);
 			else
@@ -693,8 +702,12 @@ check_all_ports_link_status(uint32_t port_mask)
 	printf("\nChecking link status");
 	fflush(stdout);
 	for (count = 0; count <= MAX_CHECK_TIME; count++) {
+		if (force_quit)
+			return;
 		all_ports_up = 1;
 		RTE_ETH_FOREACH_DEV(portid) {
+			if (force_quit)
+				return;
 			if ((port_mask & (1 << portid)) == 0)
 				continue;
 			memset(&link, 0, sizeof(link));
@@ -742,6 +755,27 @@ check_all_ports_link_status(uint32_t port_mask)
 	}
 }
 
+static void
+stop_and_close_eth_dev(uint16_t port_id)
+{
+	RTE_ETH_FOREACH_DEV(port_id) {
+		printf("Closing port %d...", port_id);
+		rte_eth_dev_stop(port_id);
+		rte_eth_dev_close(port_id);
+		printf(" Done\n");
+	}
+}
+
+static void
+signal_handler(int signum)
+{
+	if (signum == SIGINT || signum == SIGTERM) {
+		printf("\n\nSignal %d received, preparing to exit...\n",
+				signum);
+		force_quit = true;
+	}
+}
+
 int
 main(int argc, char **argv)
 {
@@ -762,6 +796,10 @@ main(int argc, char **argv)
 	argc -= ret;
 	argv += ret;
 
+	force_quit = false;
+	signal(SIGINT, signal_handler);
+	signal(SIGTERM, signal_handler);
+
 	/* parse application arguments (after the EAL ones) */
 	ret = l2fwd_parse_args(argc, argv);
 	if (ret < 0)
@@ -960,6 +998,12 @@ main(int argc, char **argv)
 	}
 
 	check_all_ports_link_status(l2fwd_enabled_port_mask);
+	if (force_quit) {
+		stop_and_close_eth_dev(portid);
+		rte_eal_cleanup();
+		printf("Bye...\n");
+		return 0;
+	}
 
 	drain_tsc = (hz + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
 
@@ -1028,5 +1072,8 @@ main(int argc, char **argv)
 			return -1;
 	}
 
+	stop_and_close_eth_dev(portid);
+	rte_eal_cleanup();
+	printf("Bye...\n");
 	return 0;
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [dpdk-dev] [PATCH 2/2] examples/l2fwd-crypto: Free resources on exit
  2020-07-22 12:50 [dpdk-dev] [PATCH 1/2] examples/l2fwd-jobstats: Free resources on exit Ibtisam Tariq
@ 2020-07-22 12:50 ` " Ibtisam Tariq
  2020-07-30 21:15   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Ibtisam Tariq @ 2020-07-22 12:50 UTC (permalink / raw)
  To: declan.doherty; +Cc: dev, Ibtisam Tariq

When exiting the application, resources should be cleared.

Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
---
 examples/l2fwd-crypto/main.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 827da9b3e..5b00e2ade 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -18,6 +18,7 @@
 #include <getopt.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <signal.h>
 
 #include <rte_string_fns.h>
 #include <rte_atomic.h>
@@ -47,6 +48,8 @@
 #include <rte_cryptodev_scheduler.h>
 #endif
 
+static volatile bool force_quit;
+
 enum cdev_type {
 	CDEV_TYPE_ANY,
 	CDEV_TYPE_HW,
@@ -838,7 +841,7 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
 	 * so user can see the crypto information.
 	 */
 	prev_tsc = rte_rdtsc();
-	while (1) {
+	while (!force_quit) {
 
 		cur_tsc = rte_rdtsc();
 
@@ -1738,8 +1741,12 @@ check_all_ports_link_status(uint32_t port_mask)
 	printf("\nChecking link status");
 	fflush(stdout);
 	for (count = 0; count <= MAX_CHECK_TIME; count++) {
+		if (force_quit)
+			return;
 		all_ports_up = 1;
 		RTE_ETH_FOREACH_DEV(portid) {
+			if (force_quit)
+				return;
 			if ((port_mask & (1 << portid)) == 0)
 				continue;
 			memset(&link, 0, sizeof(link));
@@ -2662,6 +2669,16 @@ reserve_key_memory(struct l2fwd_crypto_options *options)
 	options->aad.phys_addr = rte_malloc_virt2iova(options->aad.data);
 }
 
+static void
+signal_handler(int signum)
+{
+	if (signum == SIGINT || signum == SIGTERM) {
+		printf("\n\nSignal %d received, preparing to exit...\n",
+				signum);
+		force_quit = true;
+	}
+}
+
 int
 main(int argc, char **argv)
 {
@@ -2681,6 +2698,10 @@ main(int argc, char **argv)
 	argc -= ret;
 	argv += ret;
 
+	force_quit = false;
+	signal(SIGINT, signal_handler);
+	signal(SIGTERM, signal_handler);
+
 	/* reserve memory for Cipher/Auth key and IV */
 	reserve_key_memory(&options);
 
@@ -2807,6 +2828,14 @@ main(int argc, char **argv)
 		if (rte_eal_wait_lcore(lcore_id) < 0)
 			return -1;
 	}
+	RTE_ETH_FOREACH_DEV(portid) {
+		printf("Closing port %d...", portid);
+		rte_eth_dev_stop(portid);
+		rte_eth_dev_close(portid);
+		printf(" Done\n");
+	}
+	rte_eal_cleanup();
+	printf("Bye...\n");
 
 	return 0;
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH 2/2] examples/l2fwd-crypto: Free resources on exit
  2020-07-22 12:50 ` [dpdk-dev] [PATCH 2/2] examples/l2fwd-crypto: " Ibtisam Tariq
@ 2020-07-30 21:15   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2020-07-30 21:15 UTC (permalink / raw)
  To: Ibtisam Tariq
  Cc: declan.doherty, dev, akhil.goyal, anoobj, bruce.richardson,
	fiona.trahe, ruifeng.wang, pablo.de.lara.guarch

Declan is not reviewing patches anymore.
Adding more maintainers in Cc.

PS: Maybe we should update the file MAINTAINERS
to avoid patches being stuck.


22/07/2020 14:50, Ibtisam Tariq:
> When exiting the application, resources should be cleared.
> 
> Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
> ---
>  examples/l2fwd-crypto/main.c | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
> index 827da9b3e..5b00e2ade 100644
> --- a/examples/l2fwd-crypto/main.c
> +++ b/examples/l2fwd-crypto/main.c
> @@ -18,6 +18,7 @@
>  #include <getopt.h>
>  #include <fcntl.h>
>  #include <unistd.h>
> +#include <signal.h>
>  
>  #include <rte_string_fns.h>
>  #include <rte_atomic.h>
> @@ -47,6 +48,8 @@
>  #include <rte_cryptodev_scheduler.h>
>  #endif
>  
> +static volatile bool force_quit;
> +
>  enum cdev_type {
>  	CDEV_TYPE_ANY,
>  	CDEV_TYPE_HW,
> @@ -838,7 +841,7 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
>  	 * so user can see the crypto information.
>  	 */
>  	prev_tsc = rte_rdtsc();
> -	while (1) {
> +	while (!force_quit) {
>  
>  		cur_tsc = rte_rdtsc();
>  
> @@ -1738,8 +1741,12 @@ check_all_ports_link_status(uint32_t port_mask)
>  	printf("\nChecking link status");
>  	fflush(stdout);
>  	for (count = 0; count <= MAX_CHECK_TIME; count++) {
> +		if (force_quit)
> +			return;
>  		all_ports_up = 1;
>  		RTE_ETH_FOREACH_DEV(portid) {
> +			if (force_quit)
> +				return;
>  			if ((port_mask & (1 << portid)) == 0)
>  				continue;
>  			memset(&link, 0, sizeof(link));
> @@ -2662,6 +2669,16 @@ reserve_key_memory(struct l2fwd_crypto_options *options)
>  	options->aad.phys_addr = rte_malloc_virt2iova(options->aad.data);
>  }
>  
> +static void
> +signal_handler(int signum)
> +{
> +	if (signum == SIGINT || signum == SIGTERM) {
> +		printf("\n\nSignal %d received, preparing to exit...\n",
> +				signum);
> +		force_quit = true;
> +	}
> +}
> +
>  int
>  main(int argc, char **argv)
>  {
> @@ -2681,6 +2698,10 @@ main(int argc, char **argv)
>  	argc -= ret;
>  	argv += ret;
>  
> +	force_quit = false;
> +	signal(SIGINT, signal_handler);
> +	signal(SIGTERM, signal_handler);
> +
>  	/* reserve memory for Cipher/Auth key and IV */
>  	reserve_key_memory(&options);
>  
> @@ -2807,6 +2828,14 @@ main(int argc, char **argv)
>  		if (rte_eal_wait_lcore(lcore_id) < 0)
>  			return -1;
>  	}
> +	RTE_ETH_FOREACH_DEV(portid) {
> +		printf("Closing port %d...", portid);
> +		rte_eth_dev_stop(portid);
> +		rte_eth_dev_close(portid);
> +		printf(" Done\n");
> +	}
> +	rte_eal_cleanup();
> +	printf("Bye...\n");
>  
>  	return 0;
>  }
> 






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 12:50 [dpdk-dev] [PATCH 1/2] examples/l2fwd-jobstats: Free resources on exit Ibtisam Tariq
2020-07-22 12:50 ` [dpdk-dev] [PATCH 2/2] examples/l2fwd-crypto: " Ibtisam Tariq
2020-07-30 21:15   ` Thomas Monjalon

DPDK patches and discussions

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox