[dpdk-dev,1/3] app/test-pmd: Handle SIGINT and SIGTERM in testpmd

Message ID 1450900995-84185-2-git-send-email-zhihong.wang@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Zhihong Wang Dec. 23, 2015, 8:03 p.m. UTC
  Handle SIGINT and SIGTERM in testpmd.

Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
---
 app/test-pmd/testpmd.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
  

Comments

Michael Qiu Dec. 24, 2015, 8:09 a.m. UTC | #1
On 12/24/2015 11:07 AM, Zhihong Wang wrote:
> Handle SIGINT and SIGTERM in testpmd.
>
> Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
> ---
>  app/test-pmd/testpmd.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
> index 98ae46d..c259ba3 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -1573,6 +1573,7 @@ pmd_test_exit(void)
>  	FOREACH_PORT(pt_id, ports) {
>  		printf("Stopping port %d...", pt_id);
>  		fflush(stdout);
> +		rte_eth_dev_stop(pt_id);
>  		rte_eth_dev_close(pt_id);
>  		printf("done\n");
>  	}
> @@ -1984,12 +1985,34 @@ init_port(void)
>  		ports[pid].enabled = 1;
>  }
>  
> +/* When we receive a INT signal, close all ports */
> +static void
> +sigint_handler(__rte_unused int signum)
> +{
> +	unsigned portid;
> +
> +	printf("Preparing to exit...\n");

Better to notice user "Signal xxx received, reparing to exit... "

> +	FOREACH_PORT(portid, ports) {
> +		if (port_id_is_invalid(portid, ENABLED_WARN))
> +			continue;
> +		printf("Stopping port %d...", portid);
> +		rte_eth_dev_stop(portid);
> +		rte_eth_dev_close(portid);
> +		printf(" Done\n");
> +	}
> +	printf("Bye...\n");

Here why don't call pmd_test_exit()? Any issue with that func?

Thanks,
Michael
> +	exit(0);
> +}
> +
>  int
>  main(int argc, char** argv)
>  {
>  	int  diag;
>  	uint8_t port_id;
>  
> +	signal(SIGINT, sigint_handler);
> +	signal(SIGTERM, sigint_handler);
> +
>  	diag = rte_eal_init(argc, argv);
>  	if (diag < 0)
>  		rte_panic("Cannot init EAL\n");
  
Zhihong Wang Dec. 24, 2015, 10:18 a.m. UTC | #2
> > +/* When we receive a INT signal, close all ports */ static void
> > +sigint_handler(__rte_unused int signum) {
> > +	unsigned portid;
> > +
> > +	printf("Preparing to exit...\n");
> 
> Better to notice user "Signal xxx received, reparing to exit... "

Can do that.

> 
> > +	FOREACH_PORT(portid, ports) {
> > +		if (port_id_is_invalid(portid, ENABLED_WARN))
> > +			continue;
> > +		printf("Stopping port %d...", portid);
> > +		rte_eth_dev_stop(portid);
> > +		rte_eth_dev_close(portid);
> > +		printf(" Done\n");
> > +	}
> > +	printf("Bye...\n");
> 
> Here why don't call pmd_test_exit()? Any issue with that func?

Yes should just call this one :)

> 
> Thanks,
> Michael
> > +	exit(0);
> > +}
> > +
> >  int
> >  main(int argc, char** argv)
> >  {
> >  	int  diag;
> >  	uint8_t port_id;
> >
> > +	signal(SIGINT, sigint_handler);
> > +	signal(SIGTERM, sigint_handler);
> > +
> >  	diag = rte_eal_init(argc, argv);
> >  	if (diag < 0)
> >  		rte_panic("Cannot init EAL\n");
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 98ae46d..c259ba3 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -1573,6 +1573,7 @@  pmd_test_exit(void)
 	FOREACH_PORT(pt_id, ports) {
 		printf("Stopping port %d...", pt_id);
 		fflush(stdout);
+		rte_eth_dev_stop(pt_id);
 		rte_eth_dev_close(pt_id);
 		printf("done\n");
 	}
@@ -1984,12 +1985,34 @@  init_port(void)
 		ports[pid].enabled = 1;
 }
 
+/* When we receive a INT signal, close all ports */
+static void
+sigint_handler(__rte_unused int signum)
+{
+	unsigned portid;
+
+	printf("Preparing to exit...\n");
+	FOREACH_PORT(portid, ports) {
+		if (port_id_is_invalid(portid, ENABLED_WARN))
+			continue;
+		printf("Stopping port %d...", portid);
+		rte_eth_dev_stop(portid);
+		rte_eth_dev_close(portid);
+		printf(" Done\n");
+	}
+	printf("Bye...\n");
+	exit(0);
+}
+
 int
 main(int argc, char** argv)
 {
 	int  diag;
 	uint8_t port_id;
 
+	signal(SIGINT, sigint_handler);
+	signal(SIGTERM, sigint_handler);
+
 	diag = rte_eal_init(argc, argv);
 	if (diag < 0)
 		rte_panic("Cannot init EAL\n");