From: Ferruh Yigit <ferruh.yigit@amd.com>
To: Aman Singh <aman.deep.singh@intel.com>,
Yuying Zhang <yuying.zhang@intel.com>
Cc: Thomas Monjalon <thomas@monjalon.net>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>, <dev@dpdk.org>,
Stephen Hemminger <stephen@networkplumber.org>,
Pier Damouny <pdamouny@nvidia.com>
Subject: [PATCH] app/testpmd: revert cleanup cleanly from signal
Date: Thu, 16 Mar 2023 17:27:39 +0000 [thread overview]
Message-ID: <20230316172739.77933-1-ferruh.yigit@amd.com> (raw)
In-Reply-To: <20230315173132.4044-1-stephen@networkplumber.org>
This reverts commit 0fd1386c30c3ad9365d7fdd2829bf7cb2e1b9dff.
Because of reported issues on Windows [1] and it is risky to fix it at
this stage, fixed feature will be considered in next version.
[1]
Bugzilla ID: 1180
Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
---
Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Pier Damouny <pdamouny@nvidia.com>
---
app/test-pmd/cmdline.c | 29 ++++++++++------
app/test-pmd/testpmd.c | 77 ++++++++++++++++++++++--------------------
app/test-pmd/testpmd.h | 1 -
3 files changed, 59 insertions(+), 48 deletions(-)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 6fa870dc329b..02c72d06b768 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -66,6 +66,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);
@@ -13032,22 +13033,28 @@ cmdline_read_from_file(const char *filename)
void
prompt(void)
{
- struct cmdline *cl;
+ int ret;
- cl = cmdline_stdin_new(main_ctx, "testpmd> ");
- if (cl == NULL)
+ testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
+ if (testpmd_cl == NULL)
return;
- /* loop until signal or quit command */
- while (f_quit == 0 && cl_quit == 0) {
- int status = cmdline_poll(cl);
+ ret = atexit(prompt_exit);
+ if (ret != 0)
+ fprintf(stderr, "Cannot set exit function for cmdline\n");
- if (status < 0 || status == RDLINE_EXITED)
- break;
- }
+ cmdline_interact(testpmd_cl);
+ if (ret != 0)
+ cmdline_stdin_exit(testpmd_cl);
+}
- cmdline_quit(cl);
- cmdline_stdin_exit(cl);
+void
+prompt_exit(void)
+{
+ if (testpmd_cl != NULL) {
+ cmdline_quit(testpmd_cl);
+ cmdline_stdin_exit(testpmd_cl);
+ }
}
void
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 2ce19ed47ab4..003269660801 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -11,7 +11,6 @@
#include <fcntl.h>
#ifndef RTE_EXEC_ENV_WINDOWS
#include <sys/mman.h>
-#include <sys/select.h>
#endif
#include <sys/types.h>
#include <errno.h>
@@ -232,7 +231,7 @@ unsigned int xstats_display_num; /**< Size of extended statistics to show */
* In container, it cannot terminate the process which running with 'stats-period'
* option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
*/
-volatile uint8_t f_quit;
+static volatile uint8_t f_quit;
uint8_t cl_quit; /* Quit testpmd from cmdline. */
/*
@@ -4448,6 +4447,13 @@ 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)
{
@@ -4466,9 +4472,28 @@ print_stats(void)
}
static void
-signal_handler(int signum __rte_unused)
+signal_handler(int signum)
{
- f_quit = 1;
+ 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
+ }
}
int
@@ -4652,9 +4677,15 @@ 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) {
@@ -4677,40 +4708,14 @@ 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);
-
- /* 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));
}
- }
- 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
+ printf("Press enter to exit\n");
+ rc = read(0, &c, 1);
+ pmd_test_exit();
+ if (rc < 0)
+ return 1;
+ }
ret = rte_eal_cleanup();
if (ret != 0)
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index bdfbfd36d3c5..b9215720b615 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -34,7 +34,6 @@
#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.34.1
next prev parent reply other threads:[~2023-03-16 17:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 17:19 [RFT] test-pmd: go back to using cmdline_interact Stephen Hemminger
2023-03-13 21:38 ` [RFT v2] " Stephen Hemminger
2023-03-14 7:06 ` Ling, WeiX
[not found] ` <MW4PR12MB56684FA660218F925D64BE09A4BE9@MW4PR12MB5668.namprd12.prod.outlook.com>
2023-03-14 12:07 ` Pier Damouny
2023-03-14 17:36 ` [PATCH v3 0/3] testpmd control C fixes Stephen Hemminger
2023-03-14 17:36 ` [PATCH v3 1/3] testpmd: go back to using cmdline_interact Stephen Hemminger
2023-03-14 17:36 ` [PATCH v3 2/3] testpmd: use sig_atomic_t for flag Stephen Hemminger
2023-03-15 16:31 ` Stephen Hemminger
2023-03-14 17:36 ` [PATCH v3 3/3] testpmd: enable interrupt in interactive mode Stephen Hemminger
2023-03-14 22:40 ` [PATCH v3 0/3] testpmd control C fixes Stephen Hemminger
2023-03-15 9:46 ` David Marchand
2023-03-15 17:31 ` [PATCH v4 0/2] Fix testpmd interrupt regression Stephen Hemminger
2023-03-15 17:31 ` [PATCH v4 1/2] testpmd: go back to using cmdline_interact Stephen Hemminger
2023-03-17 16:20 ` Olivier Matz
2023-03-17 16:38 ` Stephen Hemminger
2023-03-15 17:31 ` [PATCH v4 2/2] testpmd: enable interrupt in interactive mode Stephen Hemminger
2023-03-17 16:20 ` Olivier Matz
2023-03-17 16:25 ` Stephen Hemminger
2023-03-16 8:16 ` [PATCH v4 0/2] Fix testpmd interrupt regression Pier Damouny
2023-03-16 12:20 ` Ferruh Yigit
2023-03-16 15:31 ` Stephen Hemminger
2023-03-16 17:01 ` Ferruh Yigit
2023-03-16 17:05 ` Thomas Monjalon
2023-03-16 17:36 ` Ferruh Yigit
2023-03-16 17:27 ` Ferruh Yigit [this message]
2023-03-17 16:59 ` [PATCH v5] testpmd: go back to using cmdline_interact Stephen Hemminger
2023-03-17 21:12 ` Olivier Matz
2023-03-19 23:28 ` Thomas Monjalon
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=20230316172739.77933-1-ferruh.yigit@amd.com \
--to=ferruh.yigit@amd.com \
--cc=aman.deep.singh@intel.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=pdamouny@nvidia.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).