patch 'app/testpmd: cleanup cleanly from signal' has been queued to stable release 20.11.8

luca.boccassi at gmail.com luca.boccassi at gmail.com
Wed Mar 22 01:41:42 CET 2023


Hi,

FYI, your patch has been queued to stable release 20.11.8

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 03/23/23. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/bluca/dpdk-stable

This queued commit can be viewed at:
https://github.com/bluca/dpdk-stable/commit/288b168640441ac2662abc069b462e73db8c59a7

Thanks.

Luca Boccassi

---
>From 288b168640441ac2662abc069b462e73db8c59a7 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <stephen at networkplumber.org>
Date: Fri, 3 Feb 2023 11:14:09 -0800
Subject: [PATCH] app/testpmd: cleanup cleanly from signal

[ upstream commit 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff ]

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.

The cmdline structure no longer needs to be global it can
just be local to the prompt() function.

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 at networkplumber.org>
Acked-by: Ferruh Yigit <ferruh.yigit at amd.com>
---
 app/test-pmd/cmdline.c | 30 +++++++----------
 app/test-pmd/testpmd.c | 75 ++++++++++++++++++++----------------------
 app/test-pmd/testpmd.h |  1 +
 3 files changed, 48 insertions(+), 58 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 9f46570cc4..8a7300bcf9 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -71,8 +71,6 @@
 #include "cmdline_tm.h"
 #include "bpf_cmd.h"
 
-static struct cmdline *testpmd_cl;
-
 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
 
 /* *** Help command with introduction. *** */
@@ -17199,31 +17197,25 @@ cmdline_read_from_file(const char *filename)
 void
 prompt(void)
 {
-	int ret;
+	struct cmdline *cl;
 	/* initialize non-constant commands */
 	cmd_set_fwd_mode_init();
 	cmd_set_fwd_retry_mode_init();
 
-	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
-	if (testpmd_cl == NULL)
+	cl = cmdline_stdin_new(main_ctx, "testpmd> ");
+	if (cl == NULL)
 		return;
 
-	ret = atexit(prompt_exit);
-	if (ret != 0)
-		printf("Cannot set exit function for cmdline\n");
+	/* loop until signal or quit command */
+	while (f_quit == 0 && cl_quit == 0) {
+		int status = cmdline_poll(cl);
 
-	cmdline_interact(testpmd_cl);
-	if (ret != 0)
-		cmdline_stdin_exit(testpmd_cl);
-}
-
-void
-prompt_exit(void)
-{
-	if (testpmd_cl != NULL) {
-		cmdline_quit(testpmd_cl);
-		cmdline_stdin_exit(testpmd_cl);
+		if (status < 0 || status == RDLINE_EXITED)
+			break;
 	}
+
+	cmdline_quit(cl);
+	cmdline_stdin_exit(cl);
 }
 
 static void
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index f22c05920f..a061e10385 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -10,6 +10,7 @@
 #include <time.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <sys/select.h>
 #include <sys/types.h>
 #include <errno.h>
 #include <stdbool.h>
@@ -216,7 +217,7 @@ 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.
  */
-static volatile uint8_t f_quit;
+volatile uint8_t f_quit;
 uint8_t cl_quit; /* Quit testpmd from cmdline. */
 
 /*
@@ -3826,13 +3827,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)
 {
@@ -3851,26 +3845,9 @@ print_stats(void)
 }
 
 static void
-signal_handler(int signum)
+signal_handler(int signum __rte_unused)
 {
-	if (signum == SIGINT || signum == SIGTERM) {
-		printf("\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 */
-		signal(signum, SIG_DFL);
-		kill(getpid(), signum);
-	}
+	f_quit = 1;
 }
 
 int
@@ -4044,15 +4021,9 @@ main(int argc, char** argv)
 			start_packet_forwarding(0);
 		}
 		prompt();
-		pmd_test_exit();
 	} else
 #endif
 	{
-		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) {
@@ -4075,15 +4046,41 @@ main(int argc, char** argv)
 				prev_time = cur_time;
 				sleep(1);
 			}
+		} else {
+			char c;
+			fd_set fds;
+
+			printf("Press enter to exit\n");
+
+			FD_ZERO(&fds);
+			FD_SET(0, &fds);
+
+			/* wait for signal or enter */
+			ret = select(1, &fds, NULL, NULL, NULL);
+			if (ret < 0 && errno != EINTR)
+				rte_exit(EXIT_FAILURE,
+					 "Select failed: %s\n",
+					 strerror(errno));
+
+			/* if got enter then consume it */
+			if (ret == 1 && read(0, &c, 1) < 0)
+				rte_exit(EXIT_FAILURE,
+					 "Read failed: %s\n",
+					 strerror(errno));
 		}
-
-		printf("Press enter to exit\n");
-		rc = read(0, &c, 1);
-		pmd_test_exit();
-		if (rc < 0)
-			return 1;
 	}
 
+	pmd_test_exit();
+
+#ifdef RTE_LIB_PDUMP
+	/* uninitialize packet capture framework */
+	rte_pdump_uninit();
+#endif
+#ifdef RTE_LIB_LATENCYSTATS
+	if (latencystats_enabled != 0)
+		rte_latencystats_uninit();
+#endif
+
 	ret = rte_eal_cleanup();
 	if (ret != 0)
 		rte_exit(EXIT_FAILURE,
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 76c2c55981..4ca1d59f09 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -25,6 +25,7 @@
 #define RTE_PORT_HANDLING       (uint16_t)3
 
 extern uint8_t cl_quit;
+extern volatile uint8_t f_quit;
 
 /*
  * It is used to allocate the memory for hash key.
-- 
2.39.2

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-03-21 21:56:37.291492843 +0000
+++ 0006-app-testpmd-cleanup-cleanly-from-signal.patch	2023-03-21 21:56:37.036806297 +0000
@@ -1 +1 @@
-From 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff Mon Sep 17 00:00:00 2001
+From 288b168640441ac2662abc069b462e73db8c59a7 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff ]
+
@@ -17 +18,0 @@
-Cc: stable at dpdk.org
@@ -22,2 +23,2 @@
- app/test-pmd/cmdline.c | 29 ++++++----------
- app/test-pmd/testpmd.c | 77 ++++++++++++++++++++----------------------
+ app/test-pmd/cmdline.c | 30 +++++++----------
+ app/test-pmd/testpmd.c | 75 ++++++++++++++++++++----------------------
@@ -25 +26 @@
- 3 files changed, 48 insertions(+), 59 deletions(-)
+ 3 files changed, 48 insertions(+), 58 deletions(-)
@@ -28 +29 @@
-index 02c72d06b7..6fa870dc32 100644
+index 9f46570cc4..8a7300bcf9 100644
@@ -31 +32 @@
-@@ -66,7 +66,6 @@
+@@ -71,8 +71,6 @@
@@ -36,4 +37,5 @@
- static cmdline_parse_ctx_t *main_ctx;
- static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head =
- 	TAILQ_HEAD_INITIALIZER(driver_commands_head);
-@@ -13033,28 +13032,22 @@ cmdline_read_from_file(const char *filename)
+-
+ static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
+ 
+ /* *** Help command with introduction. *** */
+@@ -17199,31 +17197,25 @@ cmdline_read_from_file(const char *filename)
@@ -44,0 +47,3 @@
+ 	/* initialize non-constant commands */
+ 	cmd_set_fwd_mode_init();
+ 	cmd_set_fwd_retry_mode_init();
@@ -54 +59 @@
--		fprintf(stderr, "Cannot set exit function for cmdline\n");
+-		printf("Cannot set exit function for cmdline\n");
@@ -78 +83 @@
- void
+ static void
@@ -80 +85 @@
-index 0032696608..2ce19ed47a 100644
+index f22c05920f..a061e10385 100644
@@ -83 +88,2 @@
-@@ -11,6 +11,7 @@
+@@ -10,6 +10,7 @@
+ #include <time.h>
@@ -85 +90,0 @@
- #ifndef RTE_EXEC_ENV_WINDOWS
@@ -88 +92,0 @@
- #endif
@@ -91 +95,2 @@
-@@ -231,7 +232,7 @@ unsigned int xstats_display_num; /**< Size of extended statistics to show */
+ #include <stdbool.h>
+@@ -216,7 +217,7 @@ uint16_t stats_period; /**< Period to show statistics (disabled by default) */
@@ -100 +105 @@
-@@ -4447,13 +4448,6 @@ init_port(void)
+@@ -3826,13 +3827,6 @@ init_port(void)
@@ -114 +119 @@
-@@ -4472,28 +4466,9 @@ print_stats(void)
+@@ -3851,26 +3845,9 @@ print_stats(void)
@@ -122,2 +127,2 @@
--		fprintf(stderr, "\nSignal %d received, preparing to exit...\n",
--			signum);
+-		printf("\nSignal %d received, preparing to exit...\n",
+-				signum);
@@ -136 +140,0 @@
--#ifndef RTE_EXEC_ENV_WINDOWS
@@ -139 +142,0 @@
--#endif
@@ -145 +148 @@
-@@ -4677,15 +4652,9 @@ main(int argc, char** argv)
+@@ -4044,15 +4021,9 @@ main(int argc, char** argv)
@@ -161 +164 @@
-@@ -4708,15 +4677,41 @@ main(int argc, char** argv)
+@@ -4075,15 +4046,41 @@ main(int argc, char** argv)
@@ -163 +166 @@
- 				rte_delay_us_sleep(US_PER_S);
+ 				sleep(1);
@@ -210 +213 @@
-index b9215720b6..bdfbfd36d3 100644
+index 76c2c55981..4ca1d59f09 100644
@@ -213 +216 @@
-@@ -34,6 +34,7 @@
+@@ -25,6 +25,7 @@


More information about the stable mailing list