patch 'app/testpmd: fix interactive mode on Windows' has been queued to stable release 22.11.2

Xueming Li xuemingl at nvidia.com
Sun Apr 9 17:24:50 CEST 2023


Hi,

FYI, your patch has been queued to stable release 22.11.2

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 04/11/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://git.dpdk.org/dpdk-stable/log/?h=22.11-staging

This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging/commit/7d3df2701dc90f8f3c4e7f249a368ab684f27bf4

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From 7d3df2701dc90f8f3c4e7f249a368ab684f27bf4 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <stephen at networkplumber.org>
Date: Fri, 17 Mar 2023 09:59:41 -0700
Subject: [PATCH] app/testpmd: fix interactive mode on Windows
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit f1d0993e034e39968a2c80a8561b46c260c27487 ]

The cmdline_poll() function is broken and was not fully tested,
go back to using cmdline_interact().

Instead, use sigaction() to cancel read character on Unix OS's
and a new helper to cancel I/O on Windows.

Bugzilla ID: 1180
Fixes: 0fd1386c30c3 ("app/testpmd: cleanup cleanly from signal")

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Olivier Matz <olivier.matz at 6wind.com>
---
 app/test-pmd/cmdline.c           | 26 +++++++++++++-------------
 app/test-pmd/testpmd.c           | 11 +++++++++++
 lib/cmdline/cmdline.c            |  1 +
 lib/cmdline/cmdline_os_unix.c    |  6 ++++++
 lib/cmdline/cmdline_os_windows.c | 14 ++++++++++++++
 lib/cmdline/cmdline_private.h    |  5 ++++-
 6 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index bd31e16e0f..07432f3e57 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -65,6 +65,7 @@
 #include "cmdline_tm.h"
 #include "bpf_cmd.h"
 
+static struct cmdline *testpmd_cl;
 static cmdline_parse_ctx_t *main_ctx;
 static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head =
 	TAILQ_HEAD_INITIALIZER(driver_commands_head);
@@ -12916,26 +12917,25 @@ cmdline_read_from_file(const char *filename)
 	printf("Read CLI commands from %s\n", filename);
 }
 
+void
+prompt_exit(void)
+{
+	cmdline_quit(testpmd_cl);
+}
+
 /* prompt function, called from main on MAIN lcore */
 void
 prompt(void)
 {
-	struct cmdline *cl;
-
-	cl = cmdline_stdin_new(main_ctx, "testpmd> ");
-	if (cl == NULL)
+	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
+	if (testpmd_cl == NULL) {
+		fprintf(stderr,
+			"Failed to create stdin based cmdline context\n");
 		return;
-
-	/* loop until signal or quit command */
-	while (f_quit == 0 && cl_quit == 0) {
-		int status = cmdline_poll(cl);
-
-		if (status < 0 || status == RDLINE_EXITED)
-			break;
 	}
 
-	cmdline_quit(cl);
-	cmdline_stdin_exit(cl);
+	cmdline_interact(testpmd_cl);
+	cmdline_stdin_exit(testpmd_cl);
 }
 
 void
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 1b54698bf6..b69b248e47 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -4414,6 +4414,7 @@ static void
 signal_handler(int signum __rte_unused)
 {
 	f_quit = 1;
+	prompt_exit();
 }
 
 int
@@ -4424,8 +4425,18 @@ main(int argc, char** argv)
 	uint16_t count;
 	int ret;
 
+#ifdef RTE_EXEC_ENV_WINDOWS
 	signal(SIGINT, signal_handler);
 	signal(SIGTERM, signal_handler);
+#else
+	/* Want read() not to be restarted on signal */
+	struct sigaction action = {
+		.sa_handler = signal_handler,
+	};
+
+	sigaction(SIGINT, &action, NULL);
+	sigaction(SIGTERM, &action, NULL);
+#endif
 
 	testpmd_logtype = rte_log_register("testpmd");
 	if (testpmd_logtype < 0)
diff --git a/lib/cmdline/cmdline.c b/lib/cmdline/cmdline.c
index 8ad0690d85..355c7d8ca6 100644
--- a/lib/cmdline/cmdline.c
+++ b/lib/cmdline/cmdline.c
@@ -173,6 +173,7 @@ cmdline_quit(struct cmdline *cl)
 {
 	if (!cl)
 		return;
+	cmdline_cancel(cl);
 	rdline_quit(&cl->rdl);
 }
 
diff --git a/lib/cmdline/cmdline_os_unix.c b/lib/cmdline/cmdline_os_unix.c
index 64a945a34f..9a4ec4e334 100644
--- a/lib/cmdline/cmdline_os_unix.c
+++ b/lib/cmdline/cmdline_os_unix.c
@@ -51,3 +51,9 @@ cmdline_vdprintf(int fd, const char *format, va_list op)
 {
 	return vdprintf(fd, format, op);
 }
+
+/* This function is not needed on Linux, instead use sigaction() */
+void
+cmdline_cancel(__rte_unused struct cmdline *cl)
+{
+}
diff --git a/lib/cmdline/cmdline_os_windows.c b/lib/cmdline/cmdline_os_windows.c
index 73ed9ba290..80863bfc8a 100644
--- a/lib/cmdline/cmdline_os_windows.c
+++ b/lib/cmdline/cmdline_os_windows.c
@@ -203,3 +203,17 @@ cmdline_vdprintf(int fd, const char *format, va_list op)
 
 	return ret;
 }
+
+void
+cmdline_cancel(struct cmdline *cl)
+{
+	if (!cl)
+		return;
+
+	/* force the outstanding read on console to exit */
+	if (cl->oldterm.is_console_input) {
+		HANDLE handle = (HANDLE)_get_osfhandle(cl->s_in);
+
+		CancelIoEx(handle, NULL);
+	}
+}
diff --git a/lib/cmdline/cmdline_private.h b/lib/cmdline/cmdline_private.h
index a3271c7693..86a46cdea6 100644
--- a/lib/cmdline/cmdline_private.h
+++ b/lib/cmdline/cmdline_private.h
@@ -24,7 +24,7 @@
 #define RDLINE_HISTORY_MAX_LINE 64
 
 struct rdline {
-	enum rdline_status status;
+	volatile enum rdline_status status;
 	/* rdline bufs */
 	struct cirbuf left;
 	struct cirbuf right;
@@ -90,6 +90,9 @@ int cmdline_poll_char(struct cmdline *cl);
 /* Read one character from input. */
 ssize_t cmdline_read_char(struct cmdline *cl, char *c);
 
+/* Force current cmdline read to unblock. */
+void cmdline_cancel(struct cmdline *cl);
+
 /* vdprintf(3) */
 __rte_format_printf(2, 0)
 int cmdline_vdprintf(int fd, const char *format, va_list op);
-- 
2.25.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-04-09 21:45:41.369691600 +0800
+++ 0102-app-testpmd-fix-interactive-mode-on-Windows.patch	2023-04-09 21:45:38.729042200 +0800
@@ -1 +1 @@
-From f1d0993e034e39968a2c80a8561b46c260c27487 Mon Sep 17 00:00:00 2001
+From 7d3df2701dc90f8f3c4e7f249a368ab684f27bf4 Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit f1d0993e034e39968a2c80a8561b46c260c27487 ]
@@ -14 +16,0 @@
-Cc: stable at dpdk.org
@@ -28 +30 @@
-index 6fa870dc32..7b20bef4e9 100644
+index bd31e16e0f..07432f3e57 100644
@@ -31 +33 @@
-@@ -66,6 +66,7 @@
+@@ -65,6 +65,7 @@
@@ -39 +41 @@
-@@ -13028,26 +13029,25 @@ cmdline_read_from_file(const char *filename)
+@@ -12916,26 +12917,25 @@ cmdline_read_from_file(const char *filename)
@@ -79 +81 @@
-index 2ce19ed47a..5cb6f92523 100644
+index 1b54698bf6..b69b248e47 100644
@@ -82 +84 @@
-@@ -4469,6 +4469,7 @@ static void
+@@ -4414,6 +4414,7 @@ static void
@@ -90 +92 @@
-@@ -4479,8 +4480,18 @@ main(int argc, char** argv)
+@@ -4424,8 +4425,18 @@ main(int argc, char** argv)


More information about the stable mailing list