[PATCH v3] app/testpmd: stop secondary process fwd_lcores during primary teardown
Khadem Ullah
14pwcse1224 at uetpeshawar.edu.pk
Mon Sep 15 13:25:13 CEST 2025
When the secondary process testpmd application running any fwd_engine
and after that primary has exited will cause a crash.
This patch forces secondary process forwarding lcores
in fwd_engine to stop before the primary process exits.
Fixes: a550baf24af90f ("app/testpmd: support multi-process")
Cc: stable at dpdk.org
Signed-off-by: Khadem Ullah <14pwcse1224 at uetpeshawar.edu.pk>
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
app/test-pmd/testpmd.c | 27 ++++++++++++++++++++++++---
lib/eal/common/hotplug_mp.c | 4 ++++
lib/eal/common/hotplug_mp.h | 2 ++
3 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 0f58a31eb5..bf2f578b80 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -75,6 +75,7 @@
#endif
#include "testpmd.h"
+#include "hotplug_mp.h"
#ifndef MAP_HUGETLB
/* FreeBSD may not have MAP_HUGETLB (in fact, it probably doesn't) */
@@ -103,7 +104,7 @@ uint16_t verbose_level = 0; /**< Silent by default. */
int testpmd_logtype; /**< Log type for testpmd logs */
/* Maximum delay for exiting after primary process. */
-#define MONITOR_INTERVAL (500 * 1000)
+#define MONITOR_INTERVAL (500)
/* use main core for command line ? */
uint8_t interactive = 0;
@@ -2563,7 +2564,12 @@ stop_packet_forwarding(void)
for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++)
fwd_lcores[lc_id]->stopped = 1;
printf("\nWaiting for lcores to finish...\n");
- rte_eal_mp_wait_lcore();
+#ifndef RTE_EXEC_ENV_WINDOWS
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+ rte_eal_mp_wait_lcore();
+#else
+ rte_eal_mp_wait_lcore();
+#endif
port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end;
if (port_fwd_end != NULL) {
for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
@@ -3634,6 +3640,15 @@ pmd_test_exit(void)
printf("\nStopping port %d...\n", pt_id);
fflush(stdout);
stop_port(pt_id);
+#ifndef RTE_EXEC_ENV_WINDOWS
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+ printf("Stopping secondary process...\n");
+ struct eal_dev_mp_req req;
+ memset(&req, 0, sizeof(req));
+ req.t = EAL_DEV_REQ_TYPE_STOP;
+ eal_dev_hotplug_request_to_secondary(&req);
+ }
+#endif
}
RTE_ETH_FOREACH_DEV(pt_id) {
printf("\nShutting down port %d...\n", pt_id);
@@ -4371,7 +4386,13 @@ static void
monitor_primary(void *arg __rte_unused)
{
if (rte_eal_primary_proc_alive(NULL)) {
- rte_eal_alarm_set(MONITOR_INTERVAL, monitor_primary, NULL);
+ if (f_exit_sec) {
+ stop_packet_forwarding();
+ fprintf(stderr, "\nPrimary process is no longer active, exiting...\n");
+ exit(EXIT_FAILURE);
+ } else {
+ rte_eal_alarm_set(MONITOR_INTERVAL, monitor_primary, NULL);
+ }
} else {
/*
* If primary process exits, then all the device information
diff --git a/lib/eal/common/hotplug_mp.c b/lib/eal/common/hotplug_mp.c
index 17089ca3db..d1913c50db 100644
--- a/lib/eal/common/hotplug_mp.c
+++ b/lib/eal/common/hotplug_mp.c
@@ -15,6 +15,7 @@
#include "eal_private.h"
#define MP_TIMEOUT_S 5 /**< 5 seconds timeouts */
+uint8_t f_exit_sec;
struct mp_reply_bundle {
struct rte_mp_msg msg;
@@ -239,6 +240,9 @@ static void __handle_primary_request(void *param)
memset(&mp_resp, 0, sizeof(mp_resp));
switch (req->t) {
+ case EAL_DEV_REQ_TYPE_STOP:
+ f_exit_sec = 1;
+ break;
case EAL_DEV_REQ_TYPE_ATTACH:
case EAL_DEV_REQ_TYPE_DETACH_ROLLBACK:
ret = local_dev_probe(req->devargs, &dev);
diff --git a/lib/eal/common/hotplug_mp.h b/lib/eal/common/hotplug_mp.h
index 7221284286..a33e3cbcc5 100644
--- a/lib/eal/common/hotplug_mp.h
+++ b/lib/eal/common/hotplug_mp.h
@@ -9,6 +9,7 @@
#define EAL_DEV_MP_ACTION_REQUEST "eal_dev_mp_request"
#define EAL_DEV_MP_ACTION_RESPONSE "eal_dev_mp_response"
+extern uint8_t f_exit_sec;
#define EAL_DEV_MP_DEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN
#define EAL_DEV_MP_BUS_NAME_MAX_LEN 32
@@ -19,6 +20,7 @@ enum eal_dev_req_type {
EAL_DEV_REQ_TYPE_DETACH,
EAL_DEV_REQ_TYPE_ATTACH_ROLLBACK,
EAL_DEV_REQ_TYPE_DETACH_ROLLBACK,
+ EAL_DEV_REQ_TYPE_STOP,
};
struct eal_dev_mp_req {
--
2.27.0
More information about the stable
mailing list