All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ferruh Yigit <ferruh.yigit@amd.com>
To: Stephen Hemminger <stephen@networkplumber.org>, dev@dpdk.org
Cc: Aman Singh <aman.deep.singh@intel.com>,
	Yuying Zhang <yuying.zhang@intel.com>,
	Phil Yang <phil.yang@arm.com>, Jianbo Liu <jianbo.liu@linaro.org>
Subject: Re: [PATCH v8] testpmd: cleanup cleanly from signal
Date: Thu, 19 Jan 2023 15:53:05 +0000	[thread overview]
Message-ID: <07a31181-948a-75ee-4272-a30cc5466a33@amd.com> (raw)
In-Reply-To: <20221112172839.70087-1-stephen@networkplumber.org>

On 11/12/2022 5:28 PM, Stephen Hemminger wrote:
> Do a clean shutdown of testpmd when a signal is received;
> instead of having testpmd kill itself.
> This fixes the problem where a signal could be received
> in the middle of a PMD and then the signal handler would call
> PMD's close routine leading to locking problems.
> 
> An added benefit is it gets rid of some Windows specific code.
> 
> Fixes: d9a191a00e81 ("app/testpmd: fix quitting in container")
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> v8 - fix build on Windows (again)
>      Windows doesn't have FILENO_STDIN
> 
>  app/test-pmd/testpmd.c | 67 +++++++++++++++++++-----------------------
>  1 file changed, 31 insertions(+), 36 deletions(-)
> 
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
> index aa7ea29f15ba..b4fb6a2bcbcf 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -11,6 +11,7 @@
>  #include <fcntl.h>
>  #ifndef RTE_EXEC_ENV_WINDOWS
>  #include <sys/mman.h>
> +#include <sys/select.h>
>  #endif
>  #include <sys/types.h>
>  #include <errno.h>
> @@ -4224,13 +4225,6 @@ init_port(void)
>  	memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
>  }
>  
> -static void
> -force_quit(void)
> -{
> -	pmd_test_exit();
> -	prompt_exit();
> -}
> -
>  static void
>  print_stats(void)
>  {
> @@ -4249,28 +4243,9 @@ print_stats(void)
>  }
>  
>  static void
> -signal_handler(int signum)
> +signal_handler(int signum __rte_unused)
>  {
> -	if (signum == SIGINT || signum == SIGTERM) {
> -		fprintf(stderr, "\nSignal %d received, preparing to exit...\n",
> -			signum);
> -#ifdef RTE_LIB_PDUMP
> -		/* uninitialize packet capture framework */
> -		rte_pdump_uninit();
> -#endif
> -#ifdef RTE_LIB_LATENCYSTATS
> -		if (latencystats_enabled != 0)
> -			rte_latencystats_uninit();
> -#endif
> -		force_quit();
> -		/* Set flag to indicate the force termination. */
> -		f_quit = 1;
> -		/* exit with the expected status */
> -#ifndef RTE_EXEC_ENV_WINDOWS
> -		signal(signum, SIG_DFL);
> -		kill(getpid(), signum);
> -#endif
> -	}
> +	f_quit = 1;
>  }

Signal handler used for interactive mode too, that is why
'force_quit();' is still needed in signal handler.

Perhaps different signal handlers can be set for interactive and
non-interactive modes.

>  
>  int
> @@ -4449,9 +4424,6 @@ main(int argc, char** argv)
>  	} else
>  #endif
>  	{
> -		char c;
> -		int rc;
> -
>  		f_quit = 0;
>  
>  		printf("No commandline core given, start packet forwarding\n");
> @@ -4476,15 +4448,38 @@ main(int argc, char** argv)
>  				prev_time = cur_time;
>  				rte_delay_us_sleep(US_PER_S);
>  			}
> -		}
> +		} else {
> +			char c;
> +			fd_set fds;
> +
> +			printf("Press enter to exit\n");
> +
> +			FD_ZERO(&fds);
> +			FD_SET(0, &fds);
>  
> -		printf("Press enter to exit\n");
> -		rc = read(0, &c, 1);
> +			ret = select(1, &fds, NULL, NULL, NULL);
> +			if (ret < 0 && errno != EINTR)
> +				rte_exit(EXIT_FAILURE,
> +					 "Select failed: %s\n",
> +					 strerror(errno));
> +
> +			if (ret == 1 && read(0, &c, 1) < 0)
> +				rte_exit(EXIT_FAILURE,
> +					 "Read failed: %s\n",
> +					 strerror(errno));
> +		}
>  		pmd_test_exit();
> -		if (rc < 0)
> -			return 1;
>  	}
>  
> +#ifdef RTE_LIB_PDUMP
> +	/* uninitialize packet capture framework */
> +	rte_pdump_uninit();
> +#endif
> +#ifdef RTE_LIB_LATENCYSTATS
> +	if (latencystats_enabled != 0)
> +		rte_latencystats_uninit();
> +#endif

+1 to move these functions here, but signal handler for the interactive
mode also needs these functions.

> +
>  	ret = rte_eal_cleanup();
>  	if (ret != 0)
>  		rte_exit(EXIT_FAILURE,


  reply	other threads:[~2023-01-19 15:53 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 17:23 [RFC 1/2] testpmd: make f_quit flag volatile Stephen Hemminger
2022-10-14 17:23 ` [RFC 2/2] testpmd: cleanup cleanly from signal Stephen Hemminger
2022-11-06 10:50   ` Andrew Rybchenko
2022-11-08 18:16     ` Stephen Hemminger
2022-11-08 18:53   ` [PATCH v2] " Stephen Hemminger
2022-11-08 20:24   ` [PATCH v3] " Stephen Hemminger
2022-11-09  4:10   ` [PATCH v4] " Stephen Hemminger
2022-11-09 21:46     ` Mattias Rönnblom
2022-11-09 22:53       ` Stephen Hemminger
2022-11-10  7:50         ` Mattias Rönnblom
2022-11-10 16:14           ` Stephen Hemminger
2022-11-10 22:06             ` Mattias Rönnblom
2022-11-09 17:29   ` [PATCH v5] " Stephen Hemminger
2022-11-10  7:14     ` Andrew Rybchenko
2022-11-10 16:13       ` Stephen Hemminger
2022-11-10 16:53   ` [PATCH v6] " Stephen Hemminger
2022-11-11  8:05     ` Andrew Rybchenko
2022-11-11 16:49       ` Stephen Hemminger
2022-11-11 16:51   ` [PATCH v7] " Stephen Hemminger
2022-11-12 17:28   ` [PATCH v8] " Stephen Hemminger
2023-01-19 15:53     ` Ferruh Yigit [this message]
2023-01-25 18:32     ` [PATCH v9] " Stephen Hemminger
2023-01-30 18:48       ` Ferruh Yigit
2023-01-30 20:11         ` Stephen Hemminger
2022-11-06 10:48 ` [RFC 1/2] testpmd: make f_quit flag volatile Andrew Rybchenko
2022-11-08 18:07 ` [PATCH v2] " Stephen Hemminger
2022-11-09 10:11   ` Ruifeng Wang
2022-11-09 10:37     ` Andrew Rybchenko
2023-01-30 20:09 ` [PATCH v10 0/2] testpmd: handle signals safely Stephen Hemminger
2023-01-30 20:09   ` [PATCH v10 1/2] cmdline: handle EOF in cmdline_poll Stephen Hemminger
2023-01-30 22:12     ` Ferruh Yigit
2023-01-31  2:54       ` Stephen Hemminger
2023-01-30 20:09   ` [PATCH v10 2/2] testpmd: cleanup cleanly from signal Stephen Hemminger
2023-01-31  9:30     ` Ferruh Yigit
2023-01-30 22:13   ` [PATCH v10 0/2] testpmd: handle signals safely Ferruh Yigit
2023-02-03 19:14   ` [PATCH v11 0/3] Fix cmdline_poll and testpmd signal handling Stephen Hemminger
2023-02-03 19:14     ` [PATCH v11 1/3] cmdline: make rdline status not private Stephen Hemminger
2023-02-06  2:31       ` fengchengwen
2023-02-03 19:14     ` [PATCH v11 2/3] cmdline: handle EOF in cmdline_poll Stephen Hemminger
2023-02-03 19:14     ` [PATCH v11 3/3] testpmd: cleanup cleanly from signal Stephen Hemminger
2023-02-07 14:49       ` Ferruh Yigit
2023-02-07 14:48     ` [PATCH v11 0/3] Fix cmdline_poll and testpmd signal handling Ferruh Yigit
2023-02-19 17:53     ` Stephen Hemminger
2023-03-11 10:17       ` Thomas Monjalon
2023-03-12 17:18         ` Tal Shnaiderman
2023-03-13 10:34           ` Ling, WeiX
2023-03-13 15:53             ` Stephen Hemminger
2023-03-14  7:05               ` Ling, WeiX

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07a31181-948a-75ee-4272-a30cc5466a33@amd.com \
    --to=ferruh.yigit@amd.com \
    --cc=aman.deep.singh@intel.com \
    --cc=dev@dpdk.org \
    --cc=jianbo.liu@linaro.org \
    --cc=phil.yang@arm.com \
    --cc=stephen@networkplumber.org \
    --cc=yuying.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.