[dpdk-dev,v2] app/testpmd: fix stats period can't quit normally in container

Message ID 1506061292-2814-1-git-send-email-phil.yang@arm.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Phil Yang Sept. 22, 2017, 6:21 a.m. UTC
  In container, the process cannot be terminated by SIGINT/SIGTERM when
execute with 'stats-period' option.
Fixed by adding a flag to exit stats period loop after received either
SIGINT or SIGTERM.

Signed-off-by: Phil Yang <phil.yang@arm.com>
---
 app/test-pmd/testpmd.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
  

Comments

Jianbo Liu Sept. 22, 2017, 10:32 a.m. UTC | #1
On 22 September 2017 at 14:21, Phil Yang <phil.yang@arm.com> wrote:
> In container, the process cannot be terminated by SIGINT/SIGTERM when
> execute with 'stats-period' option.
> Fixed by adding a flag to exit stats period loop after received either
> SIGINT or SIGTERM.
>
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> ---
>  app/test-pmd/testpmd.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
> index e097ee0..3ccc9ba 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -183,6 +183,13 @@ uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
>  uint32_t param_total_num_mbufs = 0;  /**< number of mbufs in all pools - if
>                                        * specified on command-line. */
>  uint16_t stats_period; /**< Period to show statistics (disabled by default) */
> +
> +/*
> + * In container, it cannot terminate the process which running with 'stats-period'
> + * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
> + */
> +uint8_t f_quit;
> +
>  /*
>   * Configuration of packet segments used by the "txonly" processing engine.
>   */
> @@ -2318,6 +2325,8 @@ signal_handler(int signum)
>                 rte_latencystats_uninit();
>  #endif
>                 force_quit();
> +               /* Set flag to indicate the force termination. */
> +               f_quit = 1;
>                 /* exit with the expected status */
>                 signal(signum, SIG_DFL);
>                 kill(getpid(), signum);
> @@ -2435,6 +2444,8 @@ main(int argc, char** argv)
>                 char c;
>                 int rc;
>
> +               f_quit = 0;
> +
>                 printf("No commandline core given, start packet forwarding\n");
>                 start_packet_forwarding(tx_first);
>                 if (stats_period != 0) {
> @@ -2444,7 +2455,7 @@ main(int argc, char** argv)
>                         /* Convert to number of cycles */
>                         timer_period = stats_period * rte_get_timer_hz();
>
> -                       while (1) {
> +                       while (f_quit == 0) {
>                                 cur_time = rte_get_timer_cycles();
>                                 diff_time += cur_time - prev_time;
>
> --
> 2.7.4
>

Acked-by: Jianbo Liu <jianbo.liu@linaro.org>
  
Ferruh Yigit Oct. 9, 2017, 5:27 a.m. UTC | #2
On 9/22/2017 11:32 AM, Jianbo Liu wrote:
> On 22 September 2017 at 14:21, Phil Yang <phil.yang@arm.com> wrote:
>> In container, the process cannot be terminated by SIGINT/SIGTERM when
>> execute with 'stats-period' option.
>> Fixed by adding a flag to exit stats period loop after received either
>> SIGINT or SIGTERM.
>>
>> Signed-off-by: Phil Yang <phil.yang@arm.com>>
> Acked-by: Jianbo Liu <jianbo.liu@linaro.org> 

Applied to dpdk-next-net/master, thanks.

Welcome Phil Yang!
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index e097ee0..3ccc9ba 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -183,6 +183,13 @@  uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
 uint32_t param_total_num_mbufs = 0;  /**< number of mbufs in all pools - if
                                       * specified on command-line. */
 uint16_t stats_period; /**< Period to show statistics (disabled by default) */
+
+/*
+ * In container, it cannot terminate the process which running with 'stats-period'
+ * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
+ */
+uint8_t f_quit;
+
 /*
  * Configuration of packet segments used by the "txonly" processing engine.
  */
@@ -2318,6 +2325,8 @@  signal_handler(int signum)
 		rte_latencystats_uninit();
 #endif
 		force_quit();
+		/* Set flag to indicate the force termination. */
+		f_quit = 1;
 		/* exit with the expected status */
 		signal(signum, SIG_DFL);
 		kill(getpid(), signum);
@@ -2435,6 +2444,8 @@  main(int argc, char** argv)
 		char c;
 		int rc;
 
+		f_quit = 0;
+
 		printf("No commandline core given, start packet forwarding\n");
 		start_packet_forwarding(tx_first);
 		if (stats_period != 0) {
@@ -2444,7 +2455,7 @@  main(int argc, char** argv)
 			/* Convert to number of cycles */
 			timer_period = stats_period * rte_get_timer_hz();
 
-			while (1) {
+			while (f_quit == 0) {
 				cur_time = rte_get_timer_cycles();
 				diff_time += cur_time - prev_time;